-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(landing): add examples section (#160)
- Loading branch information
Showing
24 changed files
with
1,407 additions
and
226 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { | ||
ClasserProvider, | ||
SandpackLayout, | ||
SandpackPreview, | ||
SandpackProvider, | ||
SandpackThemeProvider, | ||
} from "@codesandbox/sandpack-react"; | ||
import { motion, useTransform, useViewportScroll } from "framer-motion"; | ||
import { useLayoutEffect, useRef, useState } from "react"; | ||
|
||
import { Box, List } from "../common"; | ||
import { useBreakpoint } from "../common/useBreakpoint"; | ||
|
||
import { SandpackExample } from "./SandpackExample"; | ||
import { CustomExample } from "./Sections/Custom"; | ||
import { EditorExample } from "./Sections/Editor"; | ||
import { LayoutExample } from "./Sections/Layout"; | ||
import { useLayoutExampleContext } from "./Sections/LayoutContext"; | ||
import { TemplateExample } from "./Sections/Template"; | ||
import { ThemeExample } from "./Sections/Theme"; | ||
|
||
export const Examples: React.FC = () => { | ||
const { layoutFiles, visibility } = useLayoutExampleContext(); | ||
|
||
const sandpackSection = useRef<HTMLDivElement>(null); | ||
const { scrollY } = useViewportScroll(); | ||
const isLarge = useBreakpoint("2260"); | ||
|
||
const [sandpackSectionTop, setSandpackSectionTop] = useState(0); | ||
const [sandpackSectionHeight, setSandpackSectionHeight] = useState(0); | ||
|
||
useLayoutEffect(() => { | ||
if (!sandpackSection.current) return; | ||
|
||
const onResize = () => { | ||
if (!sandpackSection.current) return; | ||
|
||
setSandpackSectionTop(sandpackSection.current?.offsetTop); | ||
setSandpackSectionHeight(sandpackSection.current?.offsetHeight); | ||
}; | ||
|
||
onResize(); | ||
window.addEventListener("resize", onResize); | ||
|
||
return () => window.removeEventListener("resize", onResize); | ||
}, [sandpackSection]); | ||
|
||
const scrollRangeX = [ | ||
sandpackSectionTop * 0.7, | ||
(sandpackSectionTop + sandpackSectionHeight) * 0.8, | ||
]; | ||
|
||
const progressRangeX = ["0vw", isLarge ? "0vw" : "30vw"]; | ||
const x = useTransform(scrollY, scrollRangeX, progressRangeX); | ||
|
||
return ( | ||
<> | ||
<motion.div | ||
ref={sandpackSection} | ||
style={{ x, position: "sticky", top: "calc(50vh - 25%)" }} | ||
> | ||
<Box | ||
css={{ | ||
right: 0, | ||
display: "none", | ||
position: "relative", | ||
|
||
"@bp2": { | ||
display: "block", | ||
}, | ||
|
||
"*": { | ||
transition: ".2s ease background, .2s ease color", | ||
}, | ||
}} | ||
> | ||
<motion.div | ||
animate={{ opacity: visibility ? 0 : 1 }} | ||
initial={{ opacity: 0 }} | ||
style={{ position: "relative", zIndex: 1 }} | ||
> | ||
<SandpackExample /> | ||
</motion.div> | ||
|
||
<Box | ||
css={{ | ||
position: "absolute", | ||
top: 0, | ||
zIndex: visibility ? 2 : 0, | ||
|
||
".custom-wrapper": { | ||
"--sp-border-radius": "10px", | ||
}, | ||
|
||
".custom-layout": { | ||
width: "342px", | ||
height: "512px", | ||
border: 0, | ||
|
||
"@bp1": { | ||
width: "384px", | ||
height: "608px", | ||
}, | ||
|
||
"@bp2": { | ||
height: "448px", | ||
width: "996px", | ||
}, | ||
}, | ||
|
||
".custom-stack": { | ||
"@bp2": { | ||
height: "100% !important", | ||
width: "100% !important", | ||
}, | ||
}, | ||
}} | ||
> | ||
<motion.div | ||
animate={{ opacity: visibility ? 1 : 0 }} | ||
initial={{ opacity: 0 }} | ||
> | ||
<SandpackProvider | ||
customSetup={{ | ||
files: layoutFiles, | ||
dependencies: { "@codesandbox/sandpack-react": "latest" }, | ||
}} | ||
template="react" | ||
> | ||
<ClasserProvider | ||
classes={{ | ||
"sp-layout": "custom-layout", | ||
"sp-stack": "custom-stack", | ||
"sp-wrapper": "custom-wrapper", | ||
}} | ||
> | ||
<SandpackThemeProvider> | ||
<SandpackLayout> | ||
<SandpackPreview /> | ||
</SandpackLayout> | ||
</SandpackThemeProvider> | ||
</ClasserProvider> | ||
</SandpackProvider> | ||
</motion.div> | ||
</Box> | ||
</Box> | ||
</motion.div> | ||
|
||
<List | ||
css={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "148px", | ||
|
||
"@bp2": { gap: "0" }, | ||
}} | ||
> | ||
<TemplateExample /> | ||
|
||
<SandpackProvider> | ||
<CustomExample /> | ||
</SandpackProvider> | ||
|
||
<SandpackProvider> | ||
<EditorExample /> | ||
</SandpackProvider> | ||
|
||
<ThemeExample /> | ||
|
||
<SandpackProvider template="react"> | ||
<LayoutExample /> | ||
</SandpackProvider> | ||
</List> | ||
</> | ||
); | ||
}; |
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,50 @@ | ||
import content from "../../website.config.json"; | ||
import { Box, CodeBlock, Text } from "../common"; | ||
|
||
export const Header: React.FC = () => { | ||
const { commands, intro } = content; | ||
|
||
return ( | ||
<Box | ||
css={{ | ||
alignItems: "center", | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "64px", | ||
marginBottom: "100px", | ||
overflow: "hidden", | ||
}} | ||
> | ||
<Text | ||
as="h2" | ||
css={{ | ||
fontSize: "36px", | ||
fontWeight: "$semiBold", | ||
letterSpacing: "-0.05em", | ||
lineHeight: "1", | ||
textAlign: "center", | ||
|
||
"@bp1": { | ||
fontSize: "72px", | ||
}, | ||
|
||
"@bp2": { | ||
fontSize: "96px", | ||
}, | ||
|
||
"@bp3": { | ||
fontSize: "144px", | ||
}, | ||
}} | ||
dangerouslySetInnerHTML={{ __html: intro.title }} | ||
/> | ||
<Box | ||
css={{ | ||
maxWidth: "calc(100vw - 16px)", | ||
}} | ||
> | ||
<CodeBlock oneLiner>{commands.import}</CodeBlock> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.