-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathApp.js
394 lines (361 loc) · 10.5 KB
/
App.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
import React from 'react'
import { Router, Location, Link as RouterLink } from '@reach/router'
import { Global } from '@emotion/core'
import {
ThemeProvider,
Heading,
Element,
Grid,
Column,
Button,
Stack,
Link,
Text,
Menu,
calc,
merge,
version
} from 'react-ui'
import * as base from 'react-ui/themes/base'
import * as light from 'react-ui/themes/light'
import * as dark from 'react-ui/themes/dark'
import { components as themeComponents } from './theme-components'
import { Page, Section, Divider, List } from './components'
import * as Pages from './pages'
import './style.css'
const themes = { base, light, dark }
const useThemeState = (defaultValue, key) => {
const [value, setValue] = React.useState(() => {
const theme = window.localStorage.getItem(key)
return theme !== null ? JSON.parse(theme) : defaultValue
})
React.useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(value))
}, [key, value])
return [value, setValue]
}
const App = () => {
const [menuVisible, setMenuVisibility] = React.useState(false)
const [locationKey, setLocationKey] = React.useState()
const [theme, setTheme] = useThemeState('light', 'theme')
document.querySelector('#favicon').href = `favicon-${theme}.png`
React.useEffect(() => {
setMenuVisibility(false)
}, [locationKey])
const components = merge(themes[theme].components, themeComponents)
return (
<ThemeProvider tokens={themes[theme].tokens} components={components}>
<Global
styles={{
body: { transition: 'background 500ms, color 500ms' }
}}
/>
<Stack
as="header"
justify="space-between"
align="center"
css={{
height: 12,
borderBottom: '1px solid',
borderColor: 'App.borderColor',
paddingRight: 2
}}
marginBottom={12}
>
<Button
variant="link"
css={{
color: 'text.body',
visibility: ['visible', 'visible', 'hidden']
}}
onClick={() => setMenuVisibility(!menuVisible)}
>
<MenuIcon />
</Button>
<div>
<Text variant="subtle" size={3}>
v{version}
</Text>
<Menu>
<Menu.Button variant="link" style={{ paddingRight: 1 }}>
<Text marginRight={1} css={{ textTransform: 'capitalize' }}>
Theme: {theme}
</Text>
{chevron}
</Menu.Button>
<Menu.List>
<Menu.Item onSelect={_ => setTheme('base')}>Base</Menu.Item>
<Menu.Item onSelect={_ => setTheme('light')}>Light</Menu.Item>
<Menu.Item onSelect={_ => setTheme('dark')}>Dark</Menu.Item>
</Menu.List>
</Menu>
</div>
</Stack>
<Grid
css={{
maxWidth: '1024px',
marginX: 'auto',
color: 'text.body'
}}
>
<Location>
{({ location }) => {
setLocationKey(location.key)
return (
<>
<Navigation
id="desktop-navigation"
span={[0, 0, 3]}
css={{
height: calc('100vh - 12'),
paddingLeft: 8
}}
/>
<Navigation
id="mobile-navigation"
span={[menuVisible ? 12 : 0, menuVisible ? 12 : 0, 0]}
css={{ paddingLeft: 8 }}
/>
</>
)
}}
</Location>
<Column
as="main"
span={[12, 12, 9]}
css={{
paddingX: [8, 16, 16],
paddingBottom: calc('16 * 2'),
height: calc('100vh - 12')
}}
>
<Router>
<ScrollToTop path="/">
<Home path="/" />
<Documentation path="getting-started">
<Pages.GettingStarted path="/" />
</Documentation>
<Documentation path="core-concepts">
<Pages.CoreConcepts path="/" />
<Pages.Ideas path="/ideas" />
<Pages.Constraints path="/constraints-based-design" />
<Pages.CreatingNewComponents path="/creating-new-components" />
<Pages.CustomisingComponents path="/customising-components" />
<Pages.CustomisingTokens path="/customising-tokens" />
<Pages.IntegratingWithReachUI path="/integrating-with-reach-ui" />
<Pages.Layouts path="/layouts" />
</Documentation>
<Documentation path="components">
<Pages.ComponentsIndex path="/" />
{Object.keys(Pages).map(name => {
const Page = Pages[name]
return <Page key={name} path={name} />
})}
</Documentation>
<Documentation path="changelog">
<Pages.Changelog path="/" />
</Documentation>
<Documentation path="ecosystem">
<Pages.EcosystemIndex path="/" />
{Object.keys(Pages).map(name => {
const Page = Pages[name]
return <Page key={name} path={name} />
})}
</Documentation>
</ScrollToTop>
</Router>
</Column>
</Grid>
</ThemeProvider>
)
}
export default App
const ScrollToTop = ({ children, location }) => {
React.useEffect(() => window.scrollTo(0, 0), [location.pathname])
return children
}
const CoreConcepts = () => {
const items = Pages.CoreConcepts.items
return <NavSection items={items} />
}
const ComponentNav = () => {
return (
<>
<Text size={3} color="text.subtle" marginBottom={3}>
Primitives:
</Text>
<NavSection
items={[
{ title: 'Element', path: 'Element' },
{ title: 'ThemeProvider', path: 'ThemeProvider' }
]}
/>
<Text size={3} color="text.subtle" marginBottom={3}>
Building blocks:
</Text>
<NavSection
items={[
{ title: 'Avatar', path: 'Avatar' },
{ title: 'Checkbox', path: 'Checkbox' },
{ title: 'Button', path: 'Button' },
{ title: 'Heading', path: 'Heading' },
{ title: 'Image', path: 'Image' },
{ title: 'Input', path: 'Input' },
{ title: 'Link', path: 'Link' },
{ title: 'Select', path: 'Select' },
{ title: 'Skeleton', path: 'Skeleton' },
{ title: 'Spinner', path: 'Spinner' },
{ title: 'Switch', path: 'Switch' },
{ title: 'Text', path: 'Text' },
{ title: 'Textarea', path: 'Textarea' }
]}
/>
<Text size={3} color="text.subtle" marginBottom={3}>
Layout:
</Text>
<NavSection
items={[
{ title: 'Stack', path: 'Stack' },
{ title: 'Grid', path: 'Grid' }
]}
/>
<Text size={3} color="text.subtle" marginBottom={3}>
Molecules:
</Text>
<NavSection
items={[
{ title: 'Alert', path: 'Alert' },
{ title: 'Breadcrumb', path: 'Breadcrumb' },
{ title: 'Card', path: 'Card' },
{ title: 'Dialog', path: 'Dialog' },
{ title: 'Form', path: 'Form' },
{ title: 'Menu', path: 'Menu' },
{ title: 'Paragraph', path: 'Paragraph' },
{ title: 'Tabs', path: 'Tabs' },
{ title: 'Tooltip', path: 'Tooltip' }
]}
/>
</>
)
}
const NavSection = ({ items, ...props }) => {
return (
<Element
as="ul"
marginTop={0}
marginBottom={8}
css={{
listStyle: 'none',
fontSize: 3,
paddingLeft: 0,
li: {
paddingY: 2
}
}}
{...props}
>
{items.map(item => (
<li key={item.path}>
{item.external ? (
<Link href={item.path} target="_blank">
{item.title}
</Link>
) : (
<Link as={RouterLink} to={item.path}>
{item.title}
</Link>
)}
</li>
))}
</Element>
)
}
const Documentation = props => <Element {...props} />
const Navigation = props => (
<Column as="aside" {...props}>
<Element>
<NavSection
marginBottom={16}
items={[
{ title: 'Getting started', path: 'getting-started' },
{ title: 'Core concepts', path: 'core-concepts' },
{ title: 'Components', path: 'components' },
// { title: 'Ecosystem', path: 'ecosystem' },
{
title: 'GitHub',
path: 'https://github.com/siddharthkp/react-ui',
external: true
},
{
title: 'Changelog',
path: 'changelog'
}
// { title: 'Videos', path: 'videos' },
]}
/>
<Router>
<CoreConcepts path="core-concepts/*" />
<ComponentNav path="components/*" />
</Router>
</Element>
</Column>
)
const MenuIcon = props => (
<Element
as="svg"
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
{...props}
>
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</Element>
)
const Home = props => {
return (
<Page>
<Section>
<Heading>
React UI comes with a set of components that are{' '}
<Text color="blues.700">accessible,</Text>{' '}
<Text color="blues.700">responsive</Text> and{' '}
<Text color="blues.700">customisable.</Text>
</Heading>
</Section>
<Section>
<List>
<Text>Start here:</Text>
<Link href="/core-concepts/ideas">
Read old and new ideas in React UI →
</Link>
<Link href="/components">Explore the components →</Link>
<Link href="https://codesandbox.io/s/react-ui-template-302iq">
Try out React UI on CodeSandbox →
</Link>
</List>
</Section>
<Divider />
</Page>
)
}
const chevron = (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
)