-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
96 lines (90 loc) · 2.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/** @jsx jsx */
import { get } from '@styled-system/css'
import { icons } from 'feather-icons'
import { rgba } from 'polished'
import { parse } from 'serialize-query-params'
import { jsx } from 'theme-ui'
import { StringParam, useQueryParam } from 'use-query-params'
import Footer from '../components/Footer'
import Hero from '../components/Hero'
import IconGrid from '../components/IconGrid'
import Layout from '../components/Layout'
import NoResults from '../components/NoResults'
import SearchInput from '../components/SearchInput'
import Sidebar from '../components/Sidebar'
import useSearch from '../utils/useSearch'
// TODO: Remove `g` and `alpha` if `alpha` is added to @theme-ui/color.
// Reference: https://github.com/system-ui/theme-ui/pull/441
const g = (t, c) =>
get(t, `colors.${c}`, c)
.replace(/^var\(--(\w+)(.*?), /, '')
.replace(/\)/, '')
const alpha = (c, n) => t => rgba(g(t, c), n)
function IndexPage({ location }) {
const [query, setQuery] = useQueryParam(
'query',
StringParam,
parse(location.search),
)
const results = useSearch(query || '')
return (
<Layout>
<Hero />
<div
sx={{
display: 'grid',
gridTemplateColumns: [null, null, '1fr 360px'],
gridAutoFlow: 'dense',
paddingX: 2,
}}
>
<div
sx={{
gridColumn: [null, null, 2],
position: [null, null, 'sticky'],
top: 0,
maxHeight: [null, null, '100vh'],
overflow: 'auto',
}}
>
<Sidebar />
</div>
<div>
<div
sx={{
position: 'sticky',
top: 0,
paddingY: 5,
paddingX: 4,
background: theme =>
`linear-gradient(${theme.colors.muted} 50%, ${alpha(
'muted',
0,
)(theme)})`,
zIndex: 1,
}}
>
<SearchInput
placeholder={`Search ${
Object.keys(icons).length
} icons (Press "/" to focus)`}
value={query || ''}
onChange={event => setQuery(event.target.value)}
/>
</div>
<div sx={{ paddingX: 4 }}>
{results.length > 0 ? (
<IconGrid icons={results} />
) : (
<NoResults query={query} />
)}
</div>
<div sx={{ paddingY: 5, paddingX: 4 }}>
<Footer />
</div>
</div>
</div>
</Layout>
)
}
export default IndexPage