-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathscrollycoding.tsx
More file actions
61 lines (57 loc) · 1.63 KB
/
scrollycoding.tsx
File metadata and controls
61 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { z } from "zod"
import {
Selection,
Selectable,
SelectionProvider,
} from "codehike/utils/selection"
import { Block, CodeBlock, parseProps } from "codehike/blocks"
import { highlight, Pre, RawCode } from "codehike/code"
import { tokenTransitions } from "../../components/annotations/token-transitions"
import { wordWrap } from "../../components/annotations/word-wrap"
import styles from "./scrollycoding.module.css"
const Schema = Block.extend({
steps: z.array(
Block.extend({
code: CodeBlock,
})
),
})
export function Scrollycoding(props: unknown) {
const { steps } = parseProps(props, Schema)
return (
<SelectionProvider className={styles.container}>
<div className={styles.stepsContainer}>
{steps.map((step, i) => (
<Selectable
key={i}
index={i}
selectOn={["click", "scroll"]}
className={styles.step}
>
<h2 className={styles.stepTitle}>{step.title}</h2>
<div>{step.children}</div>
</Selectable>
))}
</div>
<Selection
from={steps.map((step) => (
<CodeSticker codeblock={step.code} />
))}
/>
</SelectionProvider>
)
}
async function CodeSticker({ codeblock }: { codeblock: RawCode }) {
const highlighted = await highlight(codeblock, "github-dark")
return (
<div className={styles.sticker}>
<div className={styles.stickyCode}>
<Pre
code={highlighted}
handlers={[tokenTransitions, wordWrap]}
style={{ minHeight: "40rem", backgroundColor: "transparent" }}
/>
</div>
</div>
)
}