Skip to content

Commit 5a8928f

Browse files
committed
Animate client edge on small screens
1 parent 97ad416 commit 5a8928f

File tree

1 file changed

+66
-41
lines changed
  • src/components/index-page/what-is-graphql

1 file changed

+66
-41
lines changed

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

Lines changed: 66 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ function ClientEdges({
4545
highlightedEdge,
4646
highlightedVisible,
4747
edges,
48+
baseStroke = "url(#paint_lr_light_linear_671_9150)",
49+
highlightedStroke = "url(#paint_lr_dark_linear_671_9150)",
4850
}: {
4951
highlightedEdge?: number
5052
highlightedVisible: boolean
5153
edges: string[]
54+
baseStroke?: string
55+
highlightedStroke?: string
5256
}) {
5357
return (
5458
<>
5559
{moveHighlightedToTop(
5660
highlightedEdge,
5761
edges.map((path, index) => (
5862
<Fragment key={index}>
59-
<path
60-
d={path}
61-
stroke="url(#paint_lr_light_linear_671_9150)"
62-
strokeWidth="1"
63-
/>
63+
<path d={path} stroke={baseStroke} strokeWidth="1" />
6464
{highlightedEdge === index && (
6565
<path
6666
d={path}
67-
stroke="url(#paint_lr_dark_linear_671_9150)"
67+
stroke={highlightedStroke}
6868
strokeWidth="3"
6969
className={highlightedVisible ? "opacity-100" : "opacity-0"}
7070
/>
@@ -479,7 +479,7 @@ const components = {
479479
<Pre
480480
{...props}
481481
tabIndex={-1}
482-
containerClassName="!absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-sm:scale-75 pointer-events-auto"
482+
containerClassName="!absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-sm:scale-90 pointer-events-auto"
483483
// the border color on white and black backgrounds blends into border-neu-200 (and border-neu-50 in dark mode)
484484
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)]"
485485
>
@@ -514,6 +514,7 @@ export function Wires({ className }: { className?: string }) {
514514
return () => animate?.removeEventListener("repeatEvent", onAnimationRepeat)
515515
}, [])
516516

517+
// todo: remove this per Uri's request OR switch it to development only
517518
const onBackgroundClick = useMemo(
518519
() =>
519520
throttle(() => {
@@ -536,7 +537,7 @@ export function Wires({ className }: { className?: string }) {
536537
styles.wires,
537538
)}
538539
>
539-
<MobileDiagram />
540+
<MobileDiagram step={step} />
540541
<svg
541542
id="what-is-graphql--wires"
542543
width="1248"
@@ -545,7 +546,7 @@ export function Wires({ className }: { className?: string }) {
545546
fill="none"
546547
xmlns="http://www.w3.org/2000/svg"
547548
aria-label="GraphQL allows you to build API Gateways to bring data from multiple sources to your clients in a single query"
548-
className="relative h-auto w-full max-sm:hidden"
549+
className="relative h-auto min-h-[320px] w-full max-sm:hidden"
549550
ref={ref}
550551
>
551552
<ClientEdges
@@ -634,7 +635,14 @@ function Curtain() {
634635
)
635636
}
636637

637-
// Mobile diagram data
638+
const mobileClientEdges = [
639+
"M154 157L155 85L24 84.8443L24 48",
640+
"M154 157L154 84.9209L88 84.9209L88 48",
641+
"M154 107.855L154 157L155 48",
642+
"M154 157L154 85L219 85L219 48",
643+
"M154 157L154.002 85L284 85L284 48",
644+
]
645+
638646
/* eslint-disable react/jsx-key */
639647
const mobileClientBoxes: Array<[string, React.ReactNode]> = [
640648
["translate(0, 0)", <DesktopIcon />],
@@ -653,34 +661,6 @@ const mobileServerBoxes: Array<[string, React.ReactNode]> = [
653661
]
654662
/* eslint-enable react/jsx-key */
655663

656-
function MobileClientEdges() {
657-
return (
658-
<>
659-
<path
660-
d="M154 157L154 85L219 85L219 48"
661-
stroke="url(#smallscreen_linear1)"
662-
/>
663-
<path
664-
d="M154 157L154 84.9209L88 84.9209L88 48"
665-
stroke="url(#smallscreen_linear1)"
666-
/>
667-
<path
668-
d="M154 107.855L154 157L155 48"
669-
stroke="url(#smallscreen_linear1)"
670-
/>
671-
<path
672-
d="M154 157L154.002 85L284 85L284 48"
673-
stroke="url(#smallscreen_linear1)"
674-
/>
675-
<path
676-
d="M154 158L154 136.031L154 85L24 84.8443L24 48"
677-
stroke="url(#smallscreen_linear1)"
678-
strokeWidth="2"
679-
/>
680-
</>
681-
)
682-
}
683-
684664
function MobileServerEdges() {
685665
return (
686666
<>
@@ -729,6 +709,45 @@ function MobileSVGDefinitions() {
729709
className="dark:[stop-color:hsl(var(--color-neu-100))]"
730710
/>
731711
</linearGradient>
712+
<linearGradient
713+
id="smallscreen_linear1_high"
714+
gradientUnits="userSpaceOnUse"
715+
>
716+
<stop
717+
stopColor="hsl(var(--color-neu-300))"
718+
className="dark:[stop-color:hsl(var(--color-neu-200))]"
719+
>
720+
<animate
721+
attributeName="offset"
722+
values="-2.562;1.438;-2.562"
723+
begin="2.5s"
724+
dur="5s"
725+
repeatCount="indefinite"
726+
/>
727+
</stop>
728+
<stop stopColor="hsl(var(--color-neu-700))">
729+
<animate
730+
attributeName="offset"
731+
values="-1.562;2.438;-1.562"
732+
begin="2.5s"
733+
dur="5s"
734+
repeatCount="indefinite"
735+
/>
736+
</stop>
737+
<stop
738+
stopColor="hsl(var(--color-neu-300))"
739+
className="dark:[stop-color:hsl(var(--color-neu-200))]"
740+
>
741+
<animate
742+
attributeName="offset"
743+
values="-0.562;3.438;-0.562"
744+
begin="2.5s"
745+
dur="5s"
746+
repeatCount="indefinite"
747+
/>
748+
</stop>
749+
</linearGradient>
750+
732751
<linearGradient
733752
id="smallscrean_linear2"
734753
x1="66.6927"
@@ -751,19 +770,25 @@ function MobileSVGDefinitions() {
751770
)
752771
}
753772

754-
function MobileDiagram() {
773+
function MobileDiagram({ step }: { step: number }) {
755774
return (
756775
<svg
757776
width="310"
758-
height="450"
777+
height="490"
759778
viewBox="0 0 310 502"
760779
fill="none"
761780
preserveAspectRatio="xMidYMid"
762781
xmlns="http://www.w3.org/2000/svg"
763782
className="mx-auto sm:hidden"
764783
aria-label="GraphQL allows you to build API Gateways to bring data from multiple sources to your clients in a single query"
765784
>
766-
<MobileClientEdges />
785+
<ClientEdges
786+
edges={mobileClientEdges}
787+
highlightedEdge={0}
788+
highlightedVisible={step === 0}
789+
baseStroke="url(#smallscreen_linear1)"
790+
highlightedStroke="url(#smallscreen_linear1_high)"
791+
/>
767792
<ClientBoxes boxes={mobileClientBoxes} />
768793
<MobileServerEdges />
769794
<ServerBoxes highlighted={[]} boxes={mobileServerBoxes} />

0 commit comments

Comments
 (0)