Skip to content

Commit 353acab

Browse files
committed
Highlight query
1 parent 7d1a444 commit 353acab

File tree

4 files changed

+71
-32
lines changed

4 files changed

+71
-32
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ReactElement } from "react"
2+
3+
export function isSpanElement(
4+
child: React.ReactNode,
5+
): child is ReactElement<{ children: React.ReactNode }> {
6+
return (
7+
typeof child === "object" &&
8+
!!child &&
9+
(child as ReactElement).type === "span"
10+
)
11+
}

src/components/index-page/data-colocation/index.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import json from "./data-colocation.json"
1919
import Query from "./data-colocation.mdx"
2020
import "./data-colocation.css"
2121
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
22+
import { isSpanElement } from "@/app/conf/_design-system/utils/isSpanElement"
2223

2324
const highlightedFragments = {
2425
GetFriendList: 1,
@@ -39,12 +40,15 @@ const components = {
3940
tabIndex={-1}
4041
/>
4142
),
42-
code: ({ children, ...rest }: ComponentPropsWithoutRef<typeof Code>) => {
43-
let sectorIndex: number | undefined
44-
let depth = 0
45-
46-
if (children) {
47-
children = React.Children.map(children, child => {
43+
code: function Code2({
44+
children,
45+
...rest
46+
}: ComponentPropsWithoutRef<typeof Code>) {
47+
const childrenTransformed = React.useMemo(() => {
48+
let sectorIndex: number | undefined
49+
let depth = 0
50+
51+
return React.Children.map(children, child => {
4852
if (isSpanElement(child)) {
4953
let children = (child as ReactElement).props.children
5054

@@ -86,19 +90,10 @@ const components = {
8690

8791
return child
8892
})
89-
}
90-
return <Code {...rest}>{children}</Code>
91-
},
92-
}
93+
}, [children])
9394

94-
function isSpanElement(
95-
child: React.ReactNode,
96-
): child is ReactElement<{ children: React.ReactNode }> {
97-
return (
98-
typeof child === "object" &&
99-
!!child &&
100-
(child as ReactElement).type === "span"
101-
)
95+
return <Code {...rest}>{childrenTransformed}</Code>
96+
},
10297
}
10398

10499
export function DataColocation() {

src/components/index-page/what-is-graphql/wires.module.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,26 @@
77
opacity 1s linear;
88
}
99
}
10+
11+
.highlightsQuery {
12+
& pre > code:global(.nextra-code) > span {
13+
transition: background-color 1s ease-out;
14+
transition-delay: 1s;
15+
16+
&:nth-child(2),
17+
&:nth-child(3) {
18+
@apply bg-pri-lighter/20 dark:bg-pri-light/5;
19+
}
20+
&:nth-child(4) {
21+
@apply bg-gradient-to-b from-pri-lighter/20 to-sec-lighter/20 dark:from-pri-light/5 dark:to-sec-light/5;
22+
background-image: linear-gradient(
23+
to bottom in oklab,
24+
var(--tw-gradient-stops)
25+
);
26+
}
27+
&:nth-child(5),
28+
&:nth-child(6) {
29+
@apply bg-sec-light/20 dark:bg-sec-light/5;
30+
}
31+
}
32+
}

src/components/index-page/what-is-graphql/wires.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { Pre } from "@/components/pre"
1+
import clsx from "clsx"
2+
import {
3+
ComponentPropsWithoutRef,
4+
ReactNode,
5+
useEffect,
6+
useReducer,
7+
useRef,
8+
} from "react"
9+
210
import { Code } from "nextra/components"
311

12+
import { Pre } from "@/components/pre"
13+
414
import {
515
DesktopIcon,
616
PhoneIcon,
@@ -12,17 +22,7 @@ import {
1222
ModemIcon,
1323
ServerIcon,
1424
} from "./icons"
15-
1625
import QueryMdx from "./api-gateway-query.mdx"
17-
import clsx from "clsx"
18-
import {
19-
ComponentPropsWithoutRef,
20-
ReactNode,
21-
useEffect,
22-
useReducer,
23-
useRef,
24-
} from "react"
25-
2626
import classes from "./wires.module.css"
2727

2828
function ClientEdges({
@@ -469,8 +469,10 @@ const components = {
469469
{...props}
470470
containerClassName="!absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-sm:scale-75"
471471
// the border color on white and black backgrounds blends into border-neu-200 (and border-neu-50 in dark mode)
472-
className="overflow-hidden border-none !bg-transparent before:absolute before:inset-0 before:-z-10 before:rounded-md before:border before:border-transparent before:bg-[rgba(55,72,13,0.12)] before:bg-clip-border before:[backdrop-filter:url(#what-is-graphql--code-backdrop)] after:absolute after:inset-[1.5px] after:z-[-9] after:rounded-[5px] after:bg-[linear-gradient(to_right,transparent,hsl(var(--color-neu-0))_15%,hsl(var(--color-neu-0))_85%,transparent)] after:[backdrop-filter:url(#what-is-graphql--code-backdrop-2)] dark:before:border-[rgba(235,252,191,0.2)] dark:before:bg-none dark:before:backdrop-blur-xl dark:before:[backdrop-filter:url(#what-is-graphql--code-backdrop-2-dark)] dark:after:bg-[linear-gradient(to_right,hsl(var(--color-neu-0)/0.5),hsl(var(--color-neu-0)/.8)_10%,hsl(var(--color-neu-0)/.8)_90%,hsl(var(--color-neu-0)/0.5))] dark:after:[backdrop-filter:blur(24px)]"
473-
/>
472+
className="overflow-hidden border-none !bg-transparent before:absolute before:inset-0 before:-z-10 before:rounded-md before:border before:border-transparent before:bg-[rgba(55,72,13,0.12)] before:bg-clip-border before:[backdrop-filter:url(#what-is-graphql--code-backdrop)] after:absolute after:inset-[1.5px] after:z-[-9] after:rounded-[5px] after:bg-[linear-gradient(to_right,transparent,hsl(var(--color-neu-0))_15%,hsl(var(--color-neu-0))_85%,transparent)] after:[backdrop-filter:url(#what-is-graphql--code-backdrop-2)] dark:before:border-[rgba(235,252,191,0.2)] dark:before:bg-none dark:before:backdrop-blur-xl dark:before:[backdrop-filter:url(#what-is-graphql--code-backdrop-2-dark)] dark:after:bg-[linear-gradient(to_right,hsl(var(--color-neu-0)/0.5),hsl(var(--color-neu-0)/.8)_10%,hsl(var(--color-neu-0)/.8)_83%,hsl(var(--color-neu-0)/0.4))] dark:after:[backdrop-filter:blur(24px)]"
473+
>
474+
{props.children}
475+
</Pre>
474476
),
475477
code: Code,
476478
}
@@ -496,7 +498,15 @@ export function Wires({ className }: { className?: string }) {
496498
// todo: highlight the lines in step 3
497499

498500
return (
499-
<div className={clsx(className, "relative", classes.wires)}>
501+
<div
502+
className={clsx(
503+
className,
504+
"relative isolate",
505+
classes.wires,
506+
step === 1 && classes.highlightsQuery,
507+
step === 2 && classes.highlightsResponse,
508+
)}
509+
>
500510
<svg
501511
id="what-is-graphql--wires"
502512
width="1248"

0 commit comments

Comments
 (0)