Skip to content

Commit 0387c06

Browse files
authored
feat: improve Explorer UI (#36)
* feat: improve Explorer UI: - link hooks and styling libs shown in example badges - improve layouts for responsiveness - improve file organization * fix: fix types issue
1 parent 38d8ddd commit 0387c06

File tree

18 files changed

+244
-147
lines changed

18 files changed

+244
-147
lines changed

apps/sdk-explorer/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import {type JSX} from 'react'
55
import {BrowserRouter, Link, Route, Routes} from 'react-router'
66
import {createGlobalStyle} from 'styled-components'
77

8-
import DocumentSearch from './document-collections/DocumentSearch/DocumentSearch'
9-
import DocumentTable from './document-collections/DocumentTable/DocumentTable'
10-
import PreviewGrid from './document-collections/PreviewGrid/PreviewGrid'
11-
import PreviewList from './document-collections/PreviewList/PreviewList'
12-
import MoviesByActor from './groq/MoviesByActor/MoviesByActor'
8+
import ScrollOnPathChange from './components/ScollOnPathChange'
9+
import DocumentSearch from './examples/document-collections/DocumentSearch/DocumentSearch'
10+
import DocumentTable from './examples/document-collections/DocumentTable/DocumentTable'
11+
import PreviewGrid from './examples/document-collections/PreviewGrid/PreviewGrid'
12+
import PreviewList from './examples/document-collections/PreviewList/PreviewList'
13+
import MoviesByActor from './examples/groq/MoviesByActor/MoviesByActor'
1314
import Home from './Home'
14-
import ScrollOnPathChange from './ScollOnPathChange'
1515

1616
const Body = createGlobalStyle`
1717
body {

apps/sdk-explorer/src/ExampleAttributes.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/sdk-explorer/src/ExampleCard.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

apps/sdk-explorer/src/Home.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {Box, Heading, Stack, Text} from '@sanity/ui'
22
import {type JSX} from 'react'
33

4-
import ExampleCard from './ExampleCard'
4+
import ExampleCard from './components/ExampleCard'
5+
import {documents, paginatedDocuments, projection, query} from './components/Hooks'
56
import DocumentTableImage from './images/DocumentTable.svg'
67
import DocumentSearchImage from './images/DoumentSearch.svg'
78
import MoviesByActorImage from './images/MoviesByActor.svg'
@@ -15,7 +16,7 @@ export default function Home(): JSX.Element {
1516
<Heading
1617
as="h1"
1718
style={{
18-
fontSize: '4rem',
19+
fontSize: '3.5rem',
1920
fontWeight: 400,
2021
letterSpacing: '-0.025em',
2122
}}
@@ -47,31 +48,31 @@ export default function Home(): JSX.Element {
4748
to="/document-collections/document-search"
4849
title="Document search"
4950
description="An interface for generating dynamic document searches"
50-
hooks={['useDocuments', 'useProjection']}
51+
hooks={[documents, projection]}
5152
styling="Sanity UI"
5253
img={DocumentSearchImage}
5354
/>
5455
<ExampleCard
5556
to="/document-collections/document-table"
5657
title="Document table"
5758
description="A tabular rendering of documents and their content"
58-
hooks={['usePaginatedDocuments', 'useProjection']}
59+
hooks={[paginatedDocuments, projection]}
5960
styling="Tailwind"
6061
img={DocumentTableImage}
6162
/>
6263
<ExampleCard
6364
to="/document-collections/preview-grid"
6465
title="Preview grid"
6566
description="A grid of document previews"
66-
hooks={['useDocuments', 'useProjection']}
67+
hooks={[documents, projection]}
6768
styling="Tailwind"
6869
img={PreviewGridImage}
6970
/>
7071
<ExampleCard
7172
to="/document-collections/preview-list"
7273
title="Preview list"
7374
description="A list of document previews"
74-
hooks={['useDocuments', 'useProjection']}
75+
hooks={[documents, projection]}
7576
styling="Sanity UI"
7677
img={PreviewListImage}
7778
/>
@@ -90,7 +91,7 @@ export default function Home(): JSX.Element {
9091
to="/groq/movies-by-actor"
9192
title="Movies by actor"
9293
description="Use multiple useQuery hooks to fetch and filter data"
93-
hooks={['useQuery']}
94+
hooks={[query]}
9495
styling="Sanity UI"
9596
img={MoviesByActorImage}
9697
/>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {LaunchIcon} from '@sanity/icons'
2+
import {Badge, Box, Inline, Label, Stack} from '@sanity/ui'
3+
import {type JSX} from 'react'
4+
5+
import Hooks, {type HookReference} from './Hooks'
6+
7+
const labelInset = '14ch'
8+
9+
export interface ExampleAttributeProps {
10+
hooks: HookReference[]
11+
styling: 'Sanity UI' | 'Tailwind'
12+
}
13+
14+
const stylingLinks = {
15+
'Sanity UI': 'https://sanity.io/ui',
16+
'Tailwind': 'https://tailwindcss.com',
17+
}
18+
19+
/**
20+
* Lists the hooks and styling choices for a given example
21+
*/
22+
export default function ExampleAttributes({hooks, styling}: ExampleAttributeProps): JSX.Element {
23+
return (
24+
<Stack space={3}>
25+
<Inline space={3}>
26+
<Label size={1} style={{width: labelInset}}>
27+
Hooks:
28+
</Label>
29+
<Hooks hooks={hooks} />
30+
</Inline>
31+
<Inline space={3}>
32+
<Label size={1} style={{width: labelInset}}>
33+
Styled with:
34+
</Label>
35+
<Badge tone="primary">
36+
<a href={stylingLinks[styling]} style={{display: 'inline-block'}}>
37+
<Box padding={1}>
38+
{styling}
39+
<Box display="inline-block" paddingLeft={2} paddingRight={1}>
40+
<LaunchIcon />
41+
</Box>
42+
</Box>
43+
</a>
44+
</Badge>
45+
</Inline>
46+
</Stack>
47+
)
48+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {hues} from '@sanity/color'
2+
import {Box, Card, Stack, Text} from '@sanity/ui'
3+
import {type JSX} from 'react'
4+
import {Link} from 'react-router'
5+
import styled from 'styled-components'
6+
7+
import ExampleAttributes, {type ExampleAttributeProps} from './ExampleAttributes'
8+
9+
interface ExampleCardProps {
10+
description: string
11+
hooks: ExampleAttributeProps['hooks']
12+
img: string
13+
styling: ExampleAttributeProps['styling']
14+
title: string
15+
to: string
16+
}
17+
18+
const StyledLink = styled(Link)`
19+
&:after {
20+
content: '';
21+
position: absolute;
22+
inset: 0;
23+
}
24+
`
25+
26+
const CardGrid = styled.div`
27+
display: grid;
28+
grid-auto-flow: row;
29+
grid-template-columns: 1fr;
30+
align-items: center;
31+
gap: 1rem;
32+
33+
@media (width >= 600px) {
34+
grid-template-columns: minmax(50px, 0.25fr) 1fr;
35+
}
36+
`
37+
38+
/**
39+
* Shows a summary of an example on the Home page
40+
*/
41+
export default function ExampleCard({
42+
title,
43+
description,
44+
hooks,
45+
img,
46+
styling,
47+
to,
48+
}: ExampleCardProps): JSX.Element {
49+
return (
50+
<Card shadow={2} paddingX={3} paddingY={4} radius={3} style={{position: 'relative'}}>
51+
<CardGrid>
52+
<Box
53+
display={['none', 'none', 'inline-block']}
54+
style={{
55+
backgroundImage: `url(${img})`,
56+
backgroundSize: 'contain',
57+
backgroundRepeat: 'no-repeat',
58+
maskImage: 'linear-gradient(to bottom right, white, transparent)',
59+
maskMode: 'alpha',
60+
aspectRatio: 1,
61+
}}
62+
/>
63+
<Stack space={4}>
64+
<StyledLink to={to} style={{textDecoration: 'none'}}>
65+
<Text as="h3" size={3} weight="medium" style={{color: hues.blue['500'].hex}}>
66+
{title}
67+
</Text>
68+
</StyledLink>
69+
<Text size={1} muted>
70+
{description}
71+
</Text>
72+
<ExampleAttributes hooks={hooks} styling={styling} />
73+
</Stack>
74+
</CardGrid>
75+
</Card>
76+
)
77+
}

apps/sdk-explorer/src/ExampleLayout.tsx renamed to apps/sdk-explorer/src/components/ExampleLayout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {Box, Card, Heading, Stack, Text} from '@sanity/ui'
22
import {type JSX} from 'react'
33

4-
import ExampleAttributes from './ExampleAttributes'
4+
import ExampleAttributes, {type ExampleAttributeProps} from './ExampleAttributes'
55
import ViewCode from './ViewCode'
66

77
interface ExampleLayoutProps {
88
children: React.ReactNode
99
title: string
1010
codeUrl: string
11-
hooks: Array<string>
12-
styling: string
11+
hooks: ExampleAttributeProps['hooks']
12+
styling: ExampleAttributeProps['styling']
1313
summary: string
1414
}
1515

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {Badge, Box, Inline} from '@sanity/ui'
2+
import {type JSX} from 'react'
3+
4+
export interface HookReference {
5+
name: 'useDocuments' | 'usePaginatedDocuments' | 'useProjection' | 'useQuery'
6+
reference: `https://${string}`
7+
}
8+
9+
// These consts can't begin with the word `use` or eslint yells at you for
10+
// passing around a 'hook' reference
11+
12+
const documents: HookReference = {
13+
name: 'useDocuments',
14+
reference: 'https://sdk-docs.sanity.dev/functions/sdk-react.index.useDocuments.html',
15+
}
16+
17+
const paginatedDocuments: HookReference = {
18+
name: 'usePaginatedDocuments',
19+
reference: 'https://sdk-docs.sanity.dev/functions/sdk-react.index.usePaginatedDocuments.html',
20+
}
21+
22+
const projection: HookReference = {
23+
name: 'useProjection',
24+
reference: 'https://sdk-docs.sanity.dev/functions/sdk-react.index.useProjection.html',
25+
}
26+
27+
const query: HookReference = {
28+
name: 'useQuery',
29+
reference: 'https://sdk-docs.sanity.dev/functions/sdk-react.index.useQuery.html',
30+
}
31+
32+
export {documents, paginatedDocuments, projection, query}
33+
34+
interface HooksProps {
35+
hooks: HookReference[]
36+
}
37+
38+
export default function Hooks({hooks}: HooksProps): JSX.Element {
39+
return (
40+
<Inline space={3}>
41+
{hooks.map((hook) => (
42+
<Badge key={hook.name} tone="primary">
43+
<a href={hook.reference} style={{display: 'inline-block'}}>
44+
<Box as="span" padding={1}>
45+
{hook.name}
46+
</Box>
47+
</a>
48+
</Badge>
49+
))}
50+
</Inline>
51+
)
52+
}

0 commit comments

Comments
 (0)