@@ -17,7 +17,11 @@ import QueryMdx from "./api-gateway-query.mdx"
17
17
import clsx from "clsx"
18
18
import { ComponentPropsWithoutRef , useReducer } from "react"
19
19
20
- function ClientEdges ( { pathHighlighted } : { pathHighlighted : number } ) {
20
+ function ClientEdges ( {
21
+ highlighted : pathHighlighted ,
22
+ } : {
23
+ highlighted ?: number
24
+ } ) {
21
25
const paths = [
22
26
"M514.5 220H424.5V76H72" ,
23
27
"M446 220H424.5V112H144" ,
@@ -92,60 +96,65 @@ function Box({
92
96
transform,
93
97
fill = "hsl(var(--color-neu-100))" ,
94
98
children,
99
+ className,
95
100
} : {
96
101
transform : string
97
102
fill ?: string
98
103
children : React . ReactNode
104
+ className ?: string
99
105
} ) {
100
106
return (
101
107
< g
102
108
transform = { transform }
103
- className = "[&>path]:translate-x-4 [&>path]:translate-y-4 [:where(&>path:not([fill]))]:fill-neu-600"
109
+ className = { clsx (
110
+ "[&>path]:translate-x-4 [&>path]:translate-y-4 [:where(&>path:not([fill]))]:fill-neu-600" ,
111
+ className ,
112
+ ) }
104
113
>
105
114
< rect width = "56" height = "56" fill = { fill } />
106
115
{ children }
107
116
</ g >
108
117
)
109
118
}
110
119
111
- function ClientBoxes ( ) {
120
+ function ClientBoxes ( { highlighted } : { highlighted ?: number } ) {
121
+ /* eslint-disable react/jsx-key */
122
+ const boxes = [
123
+ [ "translate(16, 48)" , < DesktopIcon /> ] ,
124
+ [ "translate(88, 84)" , < PhoneIcon /> ] ,
125
+ [ "translate(16, 120)" , < PhoneIcon /> ] ,
126
+ [ "translate(88, 156)" , < WristwatchIcon /> ] ,
127
+ [ "translate(16, 192)" , < TelevisionIcon /> ] ,
128
+ [ "translate(88, 228)" , < DesktopIcon /> ] ,
129
+ [ "translate(16, 264)" , < TabletIcon /> ] ,
130
+ [ "translate(88, 300)" , < PhoneIcon /> ] ,
131
+ [ "translate(16, 336)" , < WristwatchIcon /> ] ,
132
+ ] as const
133
+ /* eslint-enable react/jsx-key */
134
+
112
135
return (
113
136
< >
114
- < Box transform = "translate(16, 48)" fill = "hsl(var(--color-neu-300))" >
115
- < DesktopIcon className = "fill-neu-800 dark:fill-neu-0" />
116
- </ Box >
117
-
118
- < Box transform = "translate(88, 84)" >
119
- < PhoneIcon />
120
- </ Box >
121
-
122
- < Box transform = "translate(16, 120)" >
123
- < PhoneIcon />
124
- </ Box >
125
-
126
- < Box transform = "translate(88, 156)" >
127
- < WristwatchIcon />
128
- </ Box >
129
-
130
- < Box transform = "translate(16, 192)" >
131
- < TelevisionIcon />
132
- </ Box >
133
-
134
- < Box transform = "translate(88, 228)" >
135
- < DesktopIcon />
136
- </ Box >
137
-
138
- < Box transform = "translate(16, 264)" >
139
- < TabletIcon />
140
- </ Box >
141
-
142
- < Box transform = "translate(88, 300)" >
143
- < PhoneIcon />
144
- </ Box >
145
-
146
- < Box transform = "translate(16, 336)" >
147
- < WristwatchIcon />
148
- </ Box >
137
+ { boxes . map ( ( [ transform , children ] , index ) => {
138
+ const isHighlighted = index === highlighted
139
+ return (
140
+ < Box
141
+ key = { index }
142
+ transform = { transform }
143
+ fill = {
144
+ isHighlighted
145
+ ? "hsl(var(--color-neu-300))"
146
+ : "hsl(var(--color-neu-100))"
147
+ }
148
+ className = {
149
+ isHighlighted
150
+ ? "[&_path]:fill-neu-800 dark:[&_path]:fill-neu-0"
151
+ : undefined
152
+ }
153
+ >
154
+ { children }
155
+ </ Box >
156
+ )
157
+ } ) }
149
158
</ >
150
159
)
151
160
}
@@ -341,7 +350,7 @@ const components = {
341
350
export function Wires ( { className } : { className ?: string } ) {
342
351
// 1: Query visible, first client wire selected.
343
352
const STEPS = 3
344
- const [ step , inc ] = useReducer ( x => ( x + 1 ) % STEPS , 0 )
353
+ const [ step , inc ] = useReducer ( x => ( x + 1 ) % STEPS , 1 )
345
354
346
355
return (
347
356
< div className = { clsx ( className , "relative" ) } >
@@ -355,13 +364,13 @@ export function Wires({ className }: { className?: string }) {
355
364
aria-label = "GraphQL allows you to build API Gateways to bring data from multiple sources to your clients in a single query"
356
365
className = "relative h-auto w-full"
357
366
>
358
- < ClientEdges pathHighlighted = { step === 0 ? 0 : 0 } />
359
- < ClientBoxes />
367
+ < ClientEdges highlighted = { step === 0 ? 0 : undefined } />
368
+ < ClientBoxes highlighted = { step === 0 ? 0 : undefined } />
360
369
< ServerEdges />
361
370
< ServerBoxes />
362
371
< SVGDefinitions />
363
372
</ svg >
364
- { /* <QueryMdx components={components} /> */ }
373
+ < QueryMdx components = { components } />
365
374
</ div >
366
375
)
367
376
}
0 commit comments