Skip to content

Commit 54ad328

Browse files
committed
Add line groups story
1 parent c7a536a commit 54ad328

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

packages/storybook/src/code-tween.story.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,72 @@ const x = (y) => y++ * foobarbaz
9393
</WithProgress>
9494
)
9595
}
96+
97+
export const lineGroups = ({ center }) => {
98+
const prevCode = `
99+
console.log(1)
100+
console.log(2)
101+
console.log(3)
102+
console.log(4)
103+
`.trim()
104+
105+
const nextCode = `
106+
console.log(1)
107+
console.log(3)
108+
const x = (y) => y++ * foobarbaz
109+
`.trim()
110+
111+
const prevAnnotations = [
112+
{ focus: "2:3" },
113+
{ focus: "4[6:8]" },
114+
]
115+
116+
const nextAnnotations = []
117+
const [tween, setTween] = React.useState(null)
118+
119+
React.useEffect(() => {
120+
Promise.all([
121+
highlight({ code: prevCode, lang: "js", theme }),
122+
highlight({ code: nextCode, lang: "js", theme }),
123+
]).then(([prevCode, nextCode]) =>
124+
setTween({
125+
prev: {
126+
code: prevCode,
127+
focus: "1:2",
128+
annotations: prevAnnotations,
129+
},
130+
next: {
131+
code: nextCode,
132+
focus: "2,3",
133+
annotations: nextAnnotations,
134+
},
135+
})
136+
)
137+
}, [])
138+
139+
return (
140+
<WithProgress>
141+
{progress => (
142+
<div
143+
style={{ height: 300, outline: "1px solid red" }}
144+
>
145+
{tween ? (
146+
<CodeTween
147+
progress={progress}
148+
tween={tween}
149+
style={{ height: "100%" }}
150+
config={{
151+
horizontalCenter: center,
152+
theme,
153+
minZoom: 0.5,
154+
maxZoom: 2,
155+
}}
156+
/>
157+
) : (
158+
"Loading..."
159+
)}
160+
</div>
161+
)}
162+
</WithProgress>
163+
)
164+
}

0 commit comments

Comments
 (0)