Skip to content

Commit d1d7b60

Browse files
committed
Scroll in Consistency figure
1 parent 22b82e0 commit d1d7b60

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/components/index-page/graphql-advantages/consistency.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const components = {
1313
// todo: this bg style might need to become global for all code blocks
1414
className={clsx(
1515
props.className,
16-
"!bg-neu-0/[.48] backdrop-blur-[6px] max-xs:[&_span]:!text-xs",
16+
"!bg-neu-0/[.48] backdrop-blur-[6px] [scrollbar-width:none] [&::-webkit-scrollbar]:size-0 max-xs:[&_span]:!text-xs",
1717
)}
1818
tabIndex={-1}
1919
/>
@@ -27,25 +27,31 @@ export function ConsistencyFigure() {
2727
const [queryCode, responseCode] = queryRef.current!.querySelectorAll(
2828
"code",
2929
) as unknown as HTMLElement[]
30-
let line = 0
30+
let i = 0
3131
const typeLines = [1, 5, 6, 5, 7, 12, 13, 8, 17, 18, 19, 12]
3232
const queryLines = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13]
33-
let timer: any
33+
let timer: ReturnType<typeof setTimeout> | undefined = undefined
3434

3535
const highlightLine = () => {
3636
// Reset previous line
37-
queryCode.children[queryLines.at(line - 1)!].classList.remove(
38-
"highlighted",
39-
)
40-
responseCode.children[typeLines.at(line - 1)!].classList.remove(
37+
queryCode.children[queryLines.at(i - 1)!].classList.remove("highlighted")
38+
responseCode.children[typeLines.at(i - 1)!].classList.remove(
4139
"highlighted",
4240
)
4341

44-
// TODO: Whenever we're adding .highlighted, we should also ensure it's visible on screen.
45-
// We can simplify this by scrolling to bottom in last 3 steps.
46-
queryCode.children[queryLines.at(line)!].classList.add("highlighted")
47-
responseCode.children[typeLines.at(line)!].classList.add("highlighted")
48-
line = (line + 1) % typeLines.length
42+
queryCode.children[queryLines.at(i)!].classList.add("highlighted")
43+
responseCode.children[typeLines.at(i)!].classList.add("highlighted")
44+
45+
// We're scrolling to top when the first line is highlighted and we're
46+
// scrolling to the bottom when the last line is highlighted.
47+
const pre = responseCode.parentElement!
48+
if (i === 0) {
49+
pre.scrollTo({ top: 0, behavior: "smooth" })
50+
} else if (i === typeLines.length - 3) {
51+
pre.scrollTo({ top: pre.scrollHeight, behavior: "smooth" })
52+
}
53+
54+
i = (i + 1) % typeLines.length
4955

5056
timer = setTimeout(highlightLine, 1_000 + Math.random() * 200)
5157
}

src/components/index-page/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Hero } from "./hero"
22
import { TrustedBy } from "./trusted-by"
33
import { SingleRequest } from "./single-request"
4-
import { WithoutVersion } from "./without-version"
54
import { BringYourOwnCode } from "./bring-your-own-code"
65
import { WhoIsUsing } from "./who-is-using"
76
import { HowItWorks } from "./how-it-works"
@@ -31,7 +30,6 @@ export function IndexPage() {
3130
</p>
3231
</section>
3332
<SingleRequest />
34-
<WithoutVersion />
3533
<BringYourOwnCode />
3634
<WhoIsUsing />
3735
</div>

0 commit comments

Comments
 (0)