Skip to content

Commit 8466f87

Browse files
committed
Add Precision figure
1 parent 828d268 commit 8466f87

File tree

5 files changed

+52
-56
lines changed

5 files changed

+52
-56
lines changed

src/components/code-blocks/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ export const QueryHeroFriends = () => (
4949
export const ResponseHeroFriends = () => (
5050
<_ResponseHeroFriends components={components} />
5151
)
52-
export const PredictableResult = () => (
53-
<_PredictableResult components={components} />
54-
)

src/components/index-page/graphql-advantages/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import { Button } from "@/app/conf/_design-system/button"
22
import { SectionLabel } from "@/app/conf/_design-system/section-label"
33
import { ReactNode } from "react"
44

5+
import { PrecisionFigure } from "./precision"
6+
57
export function GraphQLAdvantages() {
68
return (
7-
<section className="bg-neu-50">
9+
<section className="bg-neu-50 dark:bg-neu-50/25">
810
<div className="gql-container gql-section">
911
<SectionLabel>GraphQL advantages</SectionLabel>
1012
<div className="mt-8 flex flex-col gap-y-10">
1113
<Subsection
1214
name="Precision"
1315
bigText="Ask for what you need, get exactly that"
1416
text="Send a GraphQL query to your API and get precisely the data you request — no over-fetching, no under-fetching. Predictable responses keep apps efficient and performant."
15-
figure={null}
17+
figure={<PrecisionFigure />}
1618
cta={
1719
<Button href="/learn" variant="secondary">
1820
Learn GraphQL
@@ -106,7 +108,7 @@ function Subsection({
106108
</strong>
107109
<div className="max-lg:mt-6 lg:![grid-column:2]">{figure}</div>
108110
<p className="typography-body-lg my-6 lg:mb-4 lg:mt-8">{text}</p>
109-
{cta}
111+
<div>{cta}</div>
110112
</article>
111113
)
112114
}

src/components/index-page/predictable-results/index.tsx renamed to src/components/index-page/graphql-advantages/precision.tsx

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import { useEffect, useRef } from "react"
2-
import { PredictableResult } from "../../code-blocks"
3-
import { Pre } from "nextra/components"
1+
import { ComponentPropsWithoutRef, useEffect, useRef } from "react"
2+
import { Pre, Code } from "nextra/components"
43
import { clsx } from "clsx"
5-
import classes from "./index.module.css"
64

7-
export function PredictableResults() {
5+
import PredictableResult from "../../code-blocks/predictable-result.mdx"
6+
7+
import classes from "./precision.module.css"
8+
9+
const components = {
10+
pre: (props: ComponentPropsWithoutRef<typeof Pre>) => (
11+
<Pre
12+
{...props}
13+
className={clsx(props.className, "!bg-neu-0/[.48]")}
14+
tabIndex={-1}
15+
/>
16+
),
17+
code: Code,
18+
}
19+
20+
export function PrecisionFigure() {
821
const ref = useRef<HTMLDivElement>(null)
22+
923
useEffect(() => {
1024
const showResponse = (num: Number) => {
1125
const lines = ref.current!.querySelectorAll(
@@ -66,51 +80,35 @@ export function PredictableResults() {
6680

6781
return () => clearTimeout(timer)
6882
}, [])
83+
84+
const Pre = components.pre
85+
6986
return (
70-
<div className="index-gradient">
71-
<section
72-
className="conf-block container flex flex-col justify-around gap-14 lg:flex-row-reverse lg:items-start lg:*:w-1/2"
73-
id="predictable-results"
74-
>
75-
<div className="max-lg:text-center">
76-
<h2>
77-
Ask for what you need, <br className="max-lg:hidden" />
78-
get exactly that
79-
</h2>
80-
{/*[Illustration: just a simple query and response?]*/}
81-
<p>
82-
Send a GraphQL query to your API and get exactly what you need,
83-
nothing more and nothing less. GraphQL queries always return
84-
predictable results. Apps using GraphQL are fast and stable because
85-
they control the data they get, not the server.
86-
</p>
87-
</div>
88-
<div
89-
ref={ref}
90-
className="nextra-codeblocks flex *:w-1/2 [&_pre]:!h-48"
91-
aria-hidden
92-
>
93-
<Pre data-filename="Query" className="p-4">
94-
{"{"}
95-
{"\n hero {"}
96-
{"\n name"}
97-
{"\n height\n mass".split("").map((char, i) => (
98-
<span key={i} id={"ch" + i} className="hidden">
99-
{char === "\n" ? <br /> : char}
100-
</span>
101-
))}
102-
<span
103-
className={clsx(
104-
"-mb-0.5 ml-px inline-block h-4 w-2 !bg-primary/50",
105-
classes.cursor,
106-
)}
107-
/>
108-
{"\n }"}
109-
{"\n}"}
110-
</Pre>
111-
<PredictableResult />
112-
</div>
113-
</section>
87+
<div
88+
ref={ref}
89+
id="predictable-results"
90+
className="nextra-codeblocks flex bg-gradient-to-b from-transparent to-sec-lighter px-[14px] py-[30px] *:w-1/2 dark:to-sec-darker/25 [&_pre]:!h-48"
91+
aria-hidden
92+
>
93+
<Pre data-filename="Query" className="p-4">
94+
{"{"}
95+
{"\n hero {"}
96+
{"\n name"}
97+
{"\n height\n mass".split("").map((char, i) => (
98+
<span key={i} id={"ch" + i} className="hidden">
99+
{char === "\n" ? <br /> : char}
100+
</span>
101+
))}
102+
<span
103+
className={clsx(
104+
"-mb-0.5 ml-px inline-block h-4 w-2 !bg-pri-base/50 dark:!bg-sec-base/50",
105+
classes.cursor,
106+
)}
107+
/>
108+
{"\n }"}
109+
{"\n}"}
110+
</Pre>
111+
<PredictableResult components={components} />
114112
</div>
115113
)
116114
}

src/components/index-page/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export function IndexPage() {
3333
easier to evolve APIs over time, and enables powerful developer tools.
3434
</p>
3535
</section>
36-
<PredictableResults />
3736
<SingleRequest />
3837
<TypeSystem />
3938
<PowerFulTools />

0 commit comments

Comments
 (0)