Skip to content

Commit 8978300

Browse files
committed
Rotate queries in X axis
I had to do it because of a bug with opacity and backdrop-filter.
1 parent d9945d8 commit 8978300

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"[typescript]": {
1010
"editor.defaultFormatter": "esbenp.prettier-vscode"
1111
},
12-
"tailwindCSS.classFunctions": ["clsx"]
12+
"tailwindCSS.classFunctions": ["clsx"],
13+
"editor.quickSuggestions": {
14+
"strings": "on"
15+
}
1316
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function throttle(fn: () => void, delay: number) {
2+
let timeout: NodeJS.Timeout | null = null
3+
return () => {
4+
if (timeout) return
5+
timeout = setTimeout(() => {
6+
fn()
7+
timeout = null
8+
}, delay)
9+
}
10+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
.highlightsQuery,
1212
.highlightsResponse {
13+
overflow: hidden;
14+
1315
& pre > code:global(.nextra-code) > span {
1416
position: relative;
1517

@@ -73,3 +75,12 @@
7375
}
7476
}
7577
}
78+
79+
@keyframes query-exit {
80+
from {
81+
transform: rotateX(0deg) translateY(0px) translateZ(150px);
82+
}
83+
to {
84+
transform: rotateX(-90deg) translateY(60px) translateZ(150px);
85+
}
86+
}

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ComponentPropsWithoutRef,
44
ReactNode,
55
useEffect,
6+
useMemo,
67
useReducer,
78
useRef,
89
} from "react"
@@ -24,7 +25,8 @@ import {
2425
} from "./icons"
2526
import QueryMdx from "./api-gateway-query.mdx"
2627
import ResponseMdx from "./api-gateway-response.mdx"
27-
import classes from "./wires.module.css"
28+
import styles from "./wires.module.css"
29+
import { throttle } from "@/app/conf/_design-system/utils/throttle"
2830

2931
function ClientEdges({
3032
highlightedEdge,
@@ -171,14 +173,9 @@ function ClientBoxes({ highlighted }: { highlighted?: number }) {
171173
<Box
172174
key={index}
173175
transform={transform}
174-
fill={
175-
isHighlighted
176-
? "hsl(var(--color-neu-300))"
177-
: "hsl(var(--color-neu-100))"
178-
}
179176
className={
180177
isHighlighted
181-
? "[&_path]:fill-neu-800 dark:[&_path]:fill-neu-0 dark:[&_rect]:fill-neu-400"
178+
? "[&_path]:fill-neu-800 dark:[&_path]:fill-neu-0 [&_rect]:fill-neu-300 dark:[&_rect]:fill-neu-400"
182179
: undefined
183180
}
184181
>
@@ -468,9 +465,10 @@ const components = {
468465
pre: (props: ComponentPropsWithoutRef<typeof Pre>) => (
469466
<Pre
470467
{...props}
471-
containerClassName="!absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-sm:scale-75"
468+
tabIndex={-1}
469+
containerClassName="!absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-sm:scale-75 pointer-events-auto"
472470
// the border color on white and black backgrounds blends into border-neu-200 (and border-neu-50 in dark mode)
473-
className="safari:after:[backdrop-filter:blur(12px)] 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)]"
471+
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)] safari:after:[backdrop-filter:blur(12px)] 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)]"
474472
>
475473
{props.children}
476474
</Pre>
@@ -496,22 +494,10 @@ export function Wires({ className }: { className?: string }) {
496494
return () => animate?.removeEventListener("repeatEvent", inc)
497495
}, [])
498496

499-
useEffect(() => {
500-
const handleKeyDown = (e: KeyboardEvent) => {
501-
console.log(e.key)
502-
if (e.key === "x") {
503-
inc()
504-
}
505-
}
506-
507-
document.addEventListener("keydown", handleKeyDown)
508-
return () => document.removeEventListener("keydown", handleKeyDown)
509-
}, [])
510-
511-
console.log({ step })
497+
const onBackgroundClick = useMemo(() => throttle(inc, 150), [])
512498

513499
return (
514-
<div className={clsx(className, "relative isolate", classes.wires)}>
500+
<div className={clsx(className, "relative isolate", styles.wires)}>
515501
<svg
516502
id="what-is-graphql--wires"
517503
width="1248"
@@ -529,12 +515,25 @@ export function Wires({ className }: { className?: string }) {
529515
<ServerBoxes highlighted={step > 0 ? [1, 6] : []} />
530516
<SVGDefinitions />
531517
</svg>
518+
<button
519+
tabIndex={-1}
520+
onClick={onBackgroundClick}
521+
aria-label={step === 2 ? "Show query again" : "Next step"}
522+
className="absolute inset-0 outline-none"
523+
/>
532524
<div
533525
aria-hidden={step === 2}
534-
className={clsx("absolute inset-0 transition", classes.highlightsQuery)}
526+
className={clsx(
527+
"pointer-events-none absolute inset-0 transition duration-[600ms]",
528+
styles.highlightsQuery,
529+
step === 2
530+
? "[transform:rotateX(90deg)_translateY(60px)_translateZ(150px)]"
531+
: "[transform:rotateX(0deg)_translateY(0px)_translateZ(150px)]",
532+
)}
535533
style={
536534
{
537535
"--highlight-opacity": step === 1 ? 1 : 0,
536+
animation: step === 2 ? `${styles["query-exit"]} 600ms` : undefined,
538537
} as React.CSSProperties
539538
}
540539
>
@@ -543,8 +542,13 @@ export function Wires({ className }: { className?: string }) {
543542
<div
544543
aria-hidden={step !== 2}
545544
className={clsx(
546-
"absolute inset-0 translate-y-full",
547-
classes.highlightsResponse,
545+
"pointer-events-none absolute inset-0 transition duration-[600ms]",
546+
styles.highlightsResponse,
547+
step === 2
548+
? "[transform:rotateX(0deg)_translateY(0px)_translateZ(150px)]"
549+
: step === 1
550+
? "duration-0 [transform:rotateX(90deg)_translateY(60px)_translateZ(150px)]"
551+
: "[transform:rotateX(-90deg)_translateY(-60px)_translateZ(150px)]",
548552
)}
549553
>
550554
<ResponseMdx components={components} />

0 commit comments

Comments
 (0)