@@ -13,7 +13,7 @@ const components = {
13
13
// todo: this bg style might need to become global for all code blocks
14
14
className = { clsx (
15
15
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" ,
17
17
) }
18
18
tabIndex = { - 1 }
19
19
/>
@@ -27,25 +27,31 @@ export function ConsistencyFigure() {
27
27
const [ queryCode , responseCode ] = queryRef . current ! . querySelectorAll (
28
28
"code" ,
29
29
) as unknown as HTMLElement [ ]
30
- let line = 0
30
+ let i = 0
31
31
const typeLines = [ 1 , 5 , 6 , 5 , 7 , 12 , 13 , 8 , 17 , 18 , 19 , 12 ]
32
32
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
34
34
35
35
const highlightLine = ( ) => {
36
36
// 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 (
41
39
"highlighted" ,
42
40
)
43
41
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
49
55
50
56
timer = setTimeout ( highlightLine , 1_000 + Math . random ( ) * 200 )
51
57
}
0 commit comments