-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Article updates + dark theme and a11y improvements
- Loading branch information
1 parent
a40a63c
commit 2811ff9
Showing
7 changed files
with
129 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import clsx from "clsx"; | ||
import { type ComponentProps, splitProps } from "solid-js"; | ||
|
||
type BlitzProps = ComponentProps<"iframe"> & { | ||
blitzId: string; | ||
file?: string; | ||
/** | ||
* @default "preview" | ||
*/ | ||
view?: "editor" | "preview" | "both"; | ||
|
||
params?: { | ||
ctl?: boolean; | ||
devtoolsheight?: number; | ||
hidedevtools?: boolean; | ||
hideExplorer?: boolean; | ||
hideNavigation?: boolean; | ||
initialpath?: string; | ||
showSidebar?: boolean; | ||
startScript?: string; | ||
terminalHeight?: number; | ||
theme?: "light" | "dark"; | ||
}; | ||
}; | ||
|
||
const DEFAULTS = { | ||
view: "preview", | ||
hideNavigation: true, | ||
}; | ||
|
||
function toParamValue(value: string | number | boolean) { | ||
if (typeof value === "boolean") return value ? "1" : "0"; | ||
return value.toString(); | ||
} | ||
|
||
export function Blitz(props: BlitzProps) { | ||
const [blitzProps, htmlProps] = splitProps(props, [ | ||
"blitzId", | ||
"file", | ||
"view", | ||
"params", | ||
]); | ||
const searchParams = () => { | ||
const params = new URLSearchParams({ embed: "1" }); | ||
|
||
// Set defaults. | ||
Object.entries(DEFAULTS).forEach(([key, value]) => | ||
params.set(key, toParamValue(value)) | ||
); | ||
|
||
// Set user-defined values. | ||
if (blitzProps.file) params.set("file", blitzProps.file); | ||
if (blitzProps.view) params.set("view", blitzProps.view); | ||
if (blitzProps.params) { | ||
for (const [key, value] of Object.entries(blitzProps.params)) { | ||
params.set(key, toParamValue(value)); | ||
} | ||
} | ||
return params; | ||
}; | ||
return ( | ||
<iframe | ||
loading="lazy" | ||
src={`https://stackblitz.com/edit/${ | ||
blitzProps.blitzId | ||
}?${searchParams()}`} | ||
{...htmlProps} | ||
class={clsx( | ||
"w-[calc(100%+2rem)] min-h-[32rem] -mx-4 my-[1.25em] rounded-lg", | ||
htmlProps.class | ||
)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters