Skip to content

Commit 3bd7f06

Browse files
committed
Extract Kbd component, add an info box to How It Works section
1 parent c1468b6 commit 3bd7f06

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

src/_design-system/kbd.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import clsx from "clsx"
2+
3+
export function Kbd(props: React.HTMLAttributes<HTMLElement>) {
4+
return (
5+
<kbd
6+
{...props}
7+
className={clsx(
8+
"inline-flex h-5 items-center gap-0.5 rounded border border-b-2 border-neu-300 bg-white px-1.5 font-mono text-[11px] font-medium text-neu-700 contrast-more:border-current contrast-more:text-current dark:border-neu-100/30 dark:bg-neu-0/50 dark:text-neu-500 contrast-more:dark:border-current max-sm:hidden",
9+
props.className,
10+
)}
11+
/>
12+
)
13+
}

src/components/index-page/how-it-works/index.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { useRef } from "react"
1+
import { useRef, useState } from "react"
22
import { useInView } from "motion/react"
33
import dynamic from "next/dynamic"
4+
import { clsx } from "clsx"
45

56
import { Button } from "@/app/conf/_design-system/button"
67
import { SectionLabel } from "@/app/conf/_design-system/section-label"
8+
import InfoIcon from "@/app/conf/_design-system/pixelarticons/info.svg?svgr"
79
import {
810
HowItWorks_Schema,
911
HowItWorks_Query,
@@ -12,6 +14,7 @@ import {
1214

1315
import { HowItWorksListItem } from "./how-it-works-list-item"
1416
import { PlayButton } from "./play-button"
17+
import { Kbd } from "../../../_design-system/kbd"
1518

1619
const InteractiveEditor = dynamic(() => import("./interactive-editor"), {
1720
ssr: false,
@@ -24,6 +27,7 @@ export function HowItWorks() {
2427
// todo: we could technically consider loading the chunk on hover or focus,
2528
// just so people scrolling through the page don't download CodeMirror
2629
const inView = useInView(sectionRef)
30+
const [interacted, setInteracted] = useState(false)
2731

2832
return (
2933
<section
@@ -55,15 +59,46 @@ export function HowItWorks() {
5559
<ol
5660
// this is rendered *on top* of the static version to avoid layout shift
5761
className="max-lg:before pointer-events-none absolute inset-0 list-none gap-px [counter-set:list-item_1] *:pointer-events-auto max-lg:before:absolute max-lg:before:inset-x-0 max-lg:before:-top-2 max-lg:before:bottom-[98%] max-lg:before:bg-[rgb(var(--nextra-bg))] max-sm:top-[191px] sm:max-lg:top-[214px] lg:grid lg:grid-cols-3 lg:[&>:first-child]:col-start-2"
62+
onKeyDown={() => {
63+
if (!interacted) setInteracted(true)
64+
}}
5865
>
5966
<InteractiveEditor />
6067
</ol>
6168
)}
6269
</div>
70+
<FigureInfo className={interacted ? "hidden" : ""} />
6371

6472
<Button className="mx-auto mt-8 w-fit lg:mt-16" href={TRY_IT_OUT_URL}>
6573
Try GraphiQL
6674
</Button>
6775
</section>
6876
)
6977
}
78+
79+
function FigureInfo({ className }: { className?: string }) {
80+
return (
81+
<div
82+
className={clsx(
83+
"typography-body-sm mx-auto mt-12 flex w-fit gap-2 text-neu-800 hover-none:hidden dark:text-neu-600",
84+
className,
85+
)}
86+
>
87+
<InfoIcon className="size-4 shrink-0 translate-y-[2.25px]" />
88+
<p className="text-neu-800">
89+
Press <Kbd>Ctrl</Kbd>
90+
<Kbd className="ml-0.5">Space</Kbd> to show the completions, <MetaKey />
91+
<Kbd>Enter</Kbd> to run the query.
92+
</p>
93+
</div>
94+
)
95+
}
96+
97+
function MetaKey() {
98+
return (
99+
<>
100+
<Kbd className="mx-0.5 hidden [.mac_&]:inline-flex"></Kbd>
101+
<Kbd className="mx-0.5 [.mac_&]:hidden">Ctrl</Kbd>
102+
</>
103+
)
104+
}

src/components/interactive-code-block/query-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class QueryEditor extends Component<QueryEditorProps> {
8484
graphql(this.props.schema, {}),
8585
autocompletion({
8686
icons: false,
87+
activateOnTyping: true,
8788
}),
8889
EditorView.updateListener.of(update => {
8990
if (update.docChanged && !this.ignoreChangeEvent) {

src/components/search.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
SyntheticEvent,
1818
} from "react"
1919
import { Fragment, useCallback, useEffect, useRef, useState } from "react"
20+
import { Kbd } from "../_design-system/kbd"
2021

2122
export type SearchResult = {
2223
children: ReactNode
@@ -83,24 +84,15 @@ export function Search({
8384
}, [])
8485

8586
const icon = mounted && !focused && (
86-
<kbd
87-
className={clsx(
88-
"absolute right-1.5 my-1.5 select-none rtl:left-1.5",
89-
"h-5 bg-white px-1.5 font-mono text-[11px] font-medium text-neu-600",
90-
"border dark:border-neu-100/20 dark:bg-neu-0/50",
91-
"contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current",
92-
"flex items-center gap-1",
93-
"max-sm:hidden",
94-
)}
95-
>
87+
<Kbd className="absolute right-1.5 my-1.5 select-none max-sm:hidden rtl:left-1.5">
9688
{navigator.userAgent.includes("Mac") ? (
9789
<>
98-
<span className="_text-xs"></span>K
90+
<span className="text-xs"></span>K
9991
</>
10092
) : (
10193
"CTRL K"
10294
)}
103-
</kbd>
95+
</Kbd>
10496
)
10597

10698
const handleFocus = useCallback<FocusEventHandler>(

src/pages/_document.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export default function Document() {
77
<body>
88
<Main />
99
<NextScript />
10+
<script
11+
dangerouslySetInnerHTML={{
12+
__html:
13+
'if (window.navigator.platform.includes("Mac")) document.documentElement.classList.add("mac")',
14+
}}
15+
/>
1016
</body>
1117
</Html>
1218
)

0 commit comments

Comments
 (0)