@soroush.design/cli 0.2.0-alpha.5 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +4 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{io-CqI2BTaP.mjs → io-BFbf4S_u.mjs} +178 -124
- package/package.json +3 -3
- package/templates/astro/js/base/README.md +2 -5
- package/templates/astro/js/base/src/components/About.jsx +1 -4
- package/templates/astro/js/base/src/components/Header.jsx +64 -69
- package/templates/astro/js/base/src/components/SchemeSwitch.jsx +33 -0
- package/templates/astro/js/base/src/layouts/Layout.astro +24 -13
- package/templates/astro/ts/base/README.md +2 -5
- package/templates/astro/ts/base/src/components/About.tsx +1 -4
- package/templates/astro/ts/base/src/components/Header.tsx +65 -69
- package/templates/astro/ts/base/src/components/SchemeSwitch.tsx +41 -0
- package/templates/astro/ts/base/src/layouts/Layout.astro +24 -13
- package/templates/react-router/js/base/src/components/Header.jsx +59 -0
- package/templates/react-router/js/base/src/components/SchemeSwitch.jsx +31 -0
- package/templates/react-router/js/base/src/pages/Layout.jsx +8 -75
- package/templates/react-router/ts/base/src/components/Header.tsx +60 -0
- package/templates/react-router/ts/base/src/components/SchemeSwitch.tsx +39 -0
- package/templates/react-router/ts/base/src/pages/Layout.tsx +8 -75
- package/templates/vike/js/base/src/components/Header.jsx +59 -0
- package/templates/vike/js/base/src/components/SchemeSwitch.jsx +33 -0
- package/templates/vike/js/base/src/pages/+Layout.jsx +11 -106
- package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +2 -2
- package/templates/vike/js/base/src/pages/PageShell.jsx +1 -1
- package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +2 -2
- package/templates/vike/ts/base/src/components/Header.tsx +60 -0
- package/templates/vike/ts/base/src/components/SchemeSwitch.tsx +41 -0
- package/templates/vike/ts/base/src/pages/+Layout.tsx +11 -106
- package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +2 -2
- package/templates/vike/ts/base/src/pages/PageShell.tsx +1 -1
- package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +2 -2
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// @if tanstack-query || (!zustand && !jotai && !redux-toolkit)
|
|
2
2
|
import { useState } from 'react'
|
|
3
3
|
// @endif
|
|
4
|
-
import { Button } from '@soroush.tech/design-system/Button'
|
|
5
|
-
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
6
|
-
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
7
4
|
import { View } from '@soroush.tech/design-system/View'
|
|
8
5
|
// @if tanstack-query
|
|
9
6
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -18,7 +15,8 @@ import { schemeAtom } from '../state/scheme'
|
|
|
18
15
|
import { useDispatch, useSelector } from 'react-redux'
|
|
19
16
|
import { schemeChanged } from '../state/store'
|
|
20
17
|
// @endif
|
|
21
|
-
import {
|
|
18
|
+
import { Header } from '../components/Header'
|
|
19
|
+
import { SchemeSwitch } from '../components/SchemeSwitch'
|
|
22
20
|
import { Providers } from '../theme/Providers'
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -48,46 +46,13 @@ export function Layout() {
|
|
|
48
46
|
// @else
|
|
49
47
|
const [scheme, setScheme] = useState('__SCHEME__')
|
|
50
48
|
// @endif
|
|
51
|
-
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
52
49
|
// @if tanstack-query
|
|
53
50
|
return (
|
|
54
51
|
<QueryClientProvider client={queryClient}>
|
|
55
52
|
<Providers scheme={scheme}>
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
alignItems="center"
|
|
60
|
-
justifyContent="space-between"
|
|
61
|
-
gap={2}
|
|
62
|
-
px={3}
|
|
63
|
-
py={2}
|
|
64
|
-
bg="paper"
|
|
65
|
-
>
|
|
66
|
-
<Typography variant="h6" as="span">
|
|
67
|
-
__TITLE__
|
|
68
|
-
</Typography>
|
|
69
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
70
|
-
<RouterLink to="/" underline="hover">
|
|
71
|
-
Home
|
|
72
|
-
</RouterLink>
|
|
73
|
-
<RouterLink to="/about" underline="hover">
|
|
74
|
-
About
|
|
75
|
-
</RouterLink>
|
|
76
|
-
{/* @if sample-data */}
|
|
77
|
-
<RouterLink to="/items" underline="hover">
|
|
78
|
-
Items
|
|
79
|
-
</RouterLink>
|
|
80
|
-
{/* @endif */}
|
|
81
|
-
{/* @if react-hook-form */}
|
|
82
|
-
<RouterLink to="/form" underline="hover">
|
|
83
|
-
Form
|
|
84
|
-
</RouterLink>
|
|
85
|
-
{/* @endif */}
|
|
86
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
87
|
-
{otherScheme}
|
|
88
|
-
</Button>
|
|
89
|
-
</Flex>
|
|
90
|
-
</Flex>
|
|
53
|
+
<Header>
|
|
54
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
55
|
+
</Header>
|
|
91
56
|
<View as="main" px={3} py={4}>
|
|
92
57
|
<Outlet />
|
|
93
58
|
</View>
|
|
@@ -97,41 +62,9 @@ export function Layout() {
|
|
|
97
62
|
// @else
|
|
98
63
|
return (
|
|
99
64
|
<Providers scheme={scheme}>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
alignItems="center"
|
|
104
|
-
justifyContent="space-between"
|
|
105
|
-
gap={2}
|
|
106
|
-
px={3}
|
|
107
|
-
py={2}
|
|
108
|
-
bg="paper"
|
|
109
|
-
>
|
|
110
|
-
<Typography variant="h6" as="span">
|
|
111
|
-
__TITLE__
|
|
112
|
-
</Typography>
|
|
113
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
114
|
-
<RouterLink to="/" underline="hover">
|
|
115
|
-
Home
|
|
116
|
-
</RouterLink>
|
|
117
|
-
<RouterLink to="/about" underline="hover">
|
|
118
|
-
About
|
|
119
|
-
</RouterLink>
|
|
120
|
-
{/* @if sample-data */}
|
|
121
|
-
<RouterLink to="/items" underline="hover">
|
|
122
|
-
Items
|
|
123
|
-
</RouterLink>
|
|
124
|
-
{/* @endif */}
|
|
125
|
-
{/* @if react-hook-form */}
|
|
126
|
-
<RouterLink to="/form" underline="hover">
|
|
127
|
-
Form
|
|
128
|
-
</RouterLink>
|
|
129
|
-
{/* @endif */}
|
|
130
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
131
|
-
{otherScheme}
|
|
132
|
-
</Button>
|
|
133
|
-
</Flex>
|
|
134
|
-
</Flex>
|
|
65
|
+
<Header>
|
|
66
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
67
|
+
</Header>
|
|
135
68
|
<View as="main" px={3} py={4}>
|
|
136
69
|
<Outlet />
|
|
137
70
|
</View>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { AppBar } from '@soroush.tech/design-system/AppBar'
|
|
3
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
4
|
+
import { useTheme } from '@soroush.tech/design-system/theme'
|
|
5
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
6
|
+
import { alpha } from '@soroush.tech/design-system/utils'
|
|
7
|
+
import { RouterLink } from './RouterLink'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The app bar around every page: the app's title, its links, and `children` at its end. It sticks to
|
|
11
|
+
* the top as the page scrolls; on a phone, the links move to a row of their own.
|
|
12
|
+
*/
|
|
13
|
+
export function Header({ children }: { readonly children?: ReactNode }) {
|
|
14
|
+
const theme = useTheme()
|
|
15
|
+
return (
|
|
16
|
+
<AppBar
|
|
17
|
+
position="sticky"
|
|
18
|
+
top={0}
|
|
19
|
+
elevation={0}
|
|
20
|
+
color="appBar"
|
|
21
|
+
blur
|
|
22
|
+
flexDirection="row"
|
|
23
|
+
flexWrap="wrap"
|
|
24
|
+
alignItems="center"
|
|
25
|
+
justifyContent="space-between"
|
|
26
|
+
gap={2}
|
|
27
|
+
borderBottom={`1px solid ${alpha(theme.border.primary, 0.2)}`}
|
|
28
|
+
>
|
|
29
|
+
<Typography variant="h6" as="span">
|
|
30
|
+
__TITLE__
|
|
31
|
+
</Typography>
|
|
32
|
+
<Flex
|
|
33
|
+
as="nav"
|
|
34
|
+
flexDirection="row"
|
|
35
|
+
alignItems="center"
|
|
36
|
+
gap={3}
|
|
37
|
+
order={[1, 0]}
|
|
38
|
+
width={['100%', 'auto']}
|
|
39
|
+
>
|
|
40
|
+
<RouterLink to="/" underline="hover">
|
|
41
|
+
Home
|
|
42
|
+
</RouterLink>
|
|
43
|
+
<RouterLink to="/about" underline="hover">
|
|
44
|
+
About
|
|
45
|
+
</RouterLink>
|
|
46
|
+
{/* @if sample-data */}
|
|
47
|
+
<RouterLink to="/items" underline="hover">
|
|
48
|
+
Items
|
|
49
|
+
</RouterLink>
|
|
50
|
+
{/* @endif */}
|
|
51
|
+
{/* @if react-hook-form */}
|
|
52
|
+
<RouterLink to="/form" underline="hover">
|
|
53
|
+
Form
|
|
54
|
+
</RouterLink>
|
|
55
|
+
{/* @endif */}
|
|
56
|
+
</Flex>
|
|
57
|
+
{children}
|
|
58
|
+
</AppBar>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Icon } from '@soroush.tech/design-system/Icon'
|
|
3
|
+
import { Switch } from '@soroush.tech/design-system/Switch'
|
|
4
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
5
|
+
|
|
6
|
+
type Scheme = 'light' | 'dark'
|
|
7
|
+
|
|
8
|
+
/** The switch between the light and the dark theme, on when dark, with the scheme's icon. */
|
|
9
|
+
export function SchemeSwitch({
|
|
10
|
+
scheme,
|
|
11
|
+
onSchemeChange,
|
|
12
|
+
}: {
|
|
13
|
+
readonly scheme: Scheme
|
|
14
|
+
readonly onSchemeChange: (scheme: Scheme) => void
|
|
15
|
+
}) {
|
|
16
|
+
const isDark = scheme === 'dark'
|
|
17
|
+
return (
|
|
18
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
19
|
+
{/* Hidden on a phone, so the bar fits: the switch keeps its label. */}
|
|
20
|
+
<Typography
|
|
21
|
+
variant="caption"
|
|
22
|
+
letterSpacing="widest"
|
|
23
|
+
color="primary"
|
|
24
|
+
display={['none', 'block']}
|
|
25
|
+
>
|
|
26
|
+
MODE
|
|
27
|
+
</Typography>
|
|
28
|
+
<Switch
|
|
29
|
+
checked={isDark}
|
|
30
|
+
onChange={() => onSchemeChange(isDark ? 'light' : 'dark')}
|
|
31
|
+
variant="inside"
|
|
32
|
+
color="primary"
|
|
33
|
+
size="sm"
|
|
34
|
+
aria-label="Toggle theme"
|
|
35
|
+
/>
|
|
36
|
+
<Icon name={isDark ? 'dark_mode' : 'light_mode'} size={14} color="primary" />
|
|
37
|
+
</Flex>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// @if tanstack-query || (!zustand && !jotai && !redux-toolkit)
|
|
2
2
|
import { useState } from 'react'
|
|
3
3
|
// @endif
|
|
4
|
-
import { Button } from '@soroush.tech/design-system/Button'
|
|
5
|
-
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
6
|
-
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
7
4
|
import { View } from '@soroush.tech/design-system/View'
|
|
8
5
|
// @if tanstack-query
|
|
9
6
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -18,7 +15,8 @@ import { schemeAtom } from '../state/scheme'
|
|
|
18
15
|
import { useDispatch, useSelector } from 'react-redux'
|
|
19
16
|
import { schemeChanged, type RootState } from '../state/store'
|
|
20
17
|
// @endif
|
|
21
|
-
import {
|
|
18
|
+
import { Header } from '../components/Header'
|
|
19
|
+
import { SchemeSwitch } from '../components/SchemeSwitch'
|
|
22
20
|
import { Providers } from '../theme/Providers'
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -48,46 +46,13 @@ export function Layout() {
|
|
|
48
46
|
// @else
|
|
49
47
|
const [scheme, setScheme] = useState<'light' | 'dark'>('__SCHEME__')
|
|
50
48
|
// @endif
|
|
51
|
-
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
52
49
|
// @if tanstack-query
|
|
53
50
|
return (
|
|
54
51
|
<QueryClientProvider client={queryClient}>
|
|
55
52
|
<Providers scheme={scheme}>
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
alignItems="center"
|
|
60
|
-
justifyContent="space-between"
|
|
61
|
-
gap={2}
|
|
62
|
-
px={3}
|
|
63
|
-
py={2}
|
|
64
|
-
bg="paper"
|
|
65
|
-
>
|
|
66
|
-
<Typography variant="h6" as="span">
|
|
67
|
-
__TITLE__
|
|
68
|
-
</Typography>
|
|
69
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
70
|
-
<RouterLink to="/" underline="hover">
|
|
71
|
-
Home
|
|
72
|
-
</RouterLink>
|
|
73
|
-
<RouterLink to="/about" underline="hover">
|
|
74
|
-
About
|
|
75
|
-
</RouterLink>
|
|
76
|
-
{/* @if sample-data */}
|
|
77
|
-
<RouterLink to="/items" underline="hover">
|
|
78
|
-
Items
|
|
79
|
-
</RouterLink>
|
|
80
|
-
{/* @endif */}
|
|
81
|
-
{/* @if react-hook-form */}
|
|
82
|
-
<RouterLink to="/form" underline="hover">
|
|
83
|
-
Form
|
|
84
|
-
</RouterLink>
|
|
85
|
-
{/* @endif */}
|
|
86
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
87
|
-
{otherScheme}
|
|
88
|
-
</Button>
|
|
89
|
-
</Flex>
|
|
90
|
-
</Flex>
|
|
53
|
+
<Header>
|
|
54
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
55
|
+
</Header>
|
|
91
56
|
<View as="main" px={3} py={4}>
|
|
92
57
|
<Outlet />
|
|
93
58
|
</View>
|
|
@@ -97,41 +62,9 @@ export function Layout() {
|
|
|
97
62
|
// @else
|
|
98
63
|
return (
|
|
99
64
|
<Providers scheme={scheme}>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
alignItems="center"
|
|
104
|
-
justifyContent="space-between"
|
|
105
|
-
gap={2}
|
|
106
|
-
px={3}
|
|
107
|
-
py={2}
|
|
108
|
-
bg="paper"
|
|
109
|
-
>
|
|
110
|
-
<Typography variant="h6" as="span">
|
|
111
|
-
__TITLE__
|
|
112
|
-
</Typography>
|
|
113
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
114
|
-
<RouterLink to="/" underline="hover">
|
|
115
|
-
Home
|
|
116
|
-
</RouterLink>
|
|
117
|
-
<RouterLink to="/about" underline="hover">
|
|
118
|
-
About
|
|
119
|
-
</RouterLink>
|
|
120
|
-
{/* @if sample-data */}
|
|
121
|
-
<RouterLink to="/items" underline="hover">
|
|
122
|
-
Items
|
|
123
|
-
</RouterLink>
|
|
124
|
-
{/* @endif */}
|
|
125
|
-
{/* @if react-hook-form */}
|
|
126
|
-
<RouterLink to="/form" underline="hover">
|
|
127
|
-
Form
|
|
128
|
-
</RouterLink>
|
|
129
|
-
{/* @endif */}
|
|
130
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
131
|
-
{otherScheme}
|
|
132
|
-
</Button>
|
|
133
|
-
</Flex>
|
|
134
|
-
</Flex>
|
|
65
|
+
<Header>
|
|
66
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
67
|
+
</Header>
|
|
135
68
|
<View as="main" px={3} py={4}>
|
|
136
69
|
<Outlet />
|
|
137
70
|
</View>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AppBar } from '@soroush.tech/design-system/AppBar'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Link } from '@soroush.tech/design-system/Link'
|
|
4
|
+
import { useTheme } from '@soroush.tech/design-system/theme'
|
|
5
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
6
|
+
import { alpha } from '@soroush.tech/design-system/utils'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The app bar on every page: the app's title, its links, and `children` at its end. It sticks to
|
|
10
|
+
* the top as the page scrolls; on a phone, the links move to a row of their own.
|
|
11
|
+
*/
|
|
12
|
+
export function Header({ children }) {
|
|
13
|
+
const theme = useTheme()
|
|
14
|
+
return (
|
|
15
|
+
<AppBar
|
|
16
|
+
position="sticky"
|
|
17
|
+
top={0}
|
|
18
|
+
elevation={0}
|
|
19
|
+
color="appBar"
|
|
20
|
+
blur
|
|
21
|
+
flexDirection="row"
|
|
22
|
+
flexWrap="wrap"
|
|
23
|
+
alignItems="center"
|
|
24
|
+
justifyContent="space-between"
|
|
25
|
+
gap={2}
|
|
26
|
+
borderBottom={`1px solid ${alpha(theme.border.primary, 0.2)}`}
|
|
27
|
+
>
|
|
28
|
+
<Typography variant="h6" as="span">
|
|
29
|
+
__TITLE__
|
|
30
|
+
</Typography>
|
|
31
|
+
<Flex
|
|
32
|
+
as="nav"
|
|
33
|
+
flexDirection="row"
|
|
34
|
+
alignItems="center"
|
|
35
|
+
gap={3}
|
|
36
|
+
order={[1, 0]}
|
|
37
|
+
width={['100%', 'auto']}
|
|
38
|
+
>
|
|
39
|
+
<Link href="/" underline="hover">
|
|
40
|
+
Home
|
|
41
|
+
</Link>
|
|
42
|
+
<Link href="/about" underline="hover">
|
|
43
|
+
About
|
|
44
|
+
</Link>
|
|
45
|
+
{/* @if sample-data */}
|
|
46
|
+
<Link href="/items" underline="hover">
|
|
47
|
+
Items
|
|
48
|
+
</Link>
|
|
49
|
+
{/* @endif */}
|
|
50
|
+
{/* @if react-hook-form */}
|
|
51
|
+
<Link href="/form" underline="hover">
|
|
52
|
+
Form
|
|
53
|
+
</Link>
|
|
54
|
+
{/* @endif */}
|
|
55
|
+
</Flex>
|
|
56
|
+
{children}
|
|
57
|
+
</AppBar>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @if !ssg
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Icon } from '@soroush.tech/design-system/Icon'
|
|
4
|
+
import { Switch } from '@soroush.tech/design-system/Switch'
|
|
5
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
6
|
+
|
|
7
|
+
/** The switch between the light and the dark theme, on when dark, with the scheme's icon. */
|
|
8
|
+
export function SchemeSwitch({ scheme, onSchemeChange }) {
|
|
9
|
+
const isDark = scheme === 'dark'
|
|
10
|
+
return (
|
|
11
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
12
|
+
{/* Hidden on a phone, so the bar fits: the switch keeps its label. */}
|
|
13
|
+
<Typography
|
|
14
|
+
variant="caption"
|
|
15
|
+
letterSpacing="widest"
|
|
16
|
+
color="primary"
|
|
17
|
+
display={['none', 'block']}
|
|
18
|
+
>
|
|
19
|
+
MODE
|
|
20
|
+
</Typography>
|
|
21
|
+
<Switch
|
|
22
|
+
checked={isDark}
|
|
23
|
+
onChange={() => onSchemeChange(isDark ? 'light' : 'dark')}
|
|
24
|
+
variant="inside"
|
|
25
|
+
color="primary"
|
|
26
|
+
size="sm"
|
|
27
|
+
aria-label="Toggle theme"
|
|
28
|
+
/>
|
|
29
|
+
<Icon name={isDark ? 'dark_mode' : 'light_mode'} size={14} color="primary" />
|
|
30
|
+
</Flex>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
// @endif
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
import { useState } from 'react'
|
|
3
3
|
// @else
|
|
4
4
|
// @endif
|
|
5
|
-
// @if !ssg
|
|
6
|
-
import { Button } from '@soroush.tech/design-system/Button'
|
|
7
|
-
// @endif
|
|
8
|
-
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
9
|
-
import { Link } from '@soroush.tech/design-system/Link'
|
|
10
|
-
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
11
5
|
import { View } from '@soroush.tech/design-system/View'
|
|
12
6
|
// @if tanstack-query
|
|
13
7
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -21,6 +15,10 @@ import { schemeAtom } from '../state/scheme'
|
|
|
21
15
|
import { useDispatch, useSelector } from 'react-redux'
|
|
22
16
|
import { schemeChanged } from '../state/store'
|
|
23
17
|
// @endif
|
|
18
|
+
import { Header } from '../components/Header'
|
|
19
|
+
// @if !ssg
|
|
20
|
+
import { SchemeSwitch } from '../components/SchemeSwitch'
|
|
21
|
+
// @endif
|
|
24
22
|
import { Providers } from '../theme/Providers'
|
|
25
23
|
|
|
26
24
|
/**
|
|
@@ -53,39 +51,10 @@ export default function Layout({ children }) {
|
|
|
53
51
|
// @elif !ssg
|
|
54
52
|
const [scheme, setScheme] = useState('__SCHEME__')
|
|
55
53
|
// @endif
|
|
56
|
-
// @if !ssg
|
|
57
|
-
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
58
|
-
// @endif
|
|
59
54
|
// @if ssg
|
|
60
55
|
return (
|
|
61
56
|
<Providers>
|
|
62
|
-
<
|
|
63
|
-
as="header"
|
|
64
|
-
flexDirection="row"
|
|
65
|
-
alignItems="center"
|
|
66
|
-
justifyContent="space-between"
|
|
67
|
-
gap={2}
|
|
68
|
-
px={3}
|
|
69
|
-
py={2}
|
|
70
|
-
bg="paper"
|
|
71
|
-
>
|
|
72
|
-
<Typography variant="h6" as="span">
|
|
73
|
-
__TITLE__
|
|
74
|
-
</Typography>
|
|
75
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
76
|
-
<Link href="/" underline="hover">
|
|
77
|
-
Home
|
|
78
|
-
</Link>
|
|
79
|
-
<Link href="/about" underline="hover">
|
|
80
|
-
About
|
|
81
|
-
</Link>
|
|
82
|
-
{/* @if sample-data */}
|
|
83
|
-
<Link href="/items" underline="hover">
|
|
84
|
-
Items
|
|
85
|
-
</Link>
|
|
86
|
-
{/* @endif */}
|
|
87
|
-
</Flex>
|
|
88
|
-
</Flex>
|
|
57
|
+
<Header />
|
|
89
58
|
<View as="main" px={3} py={4}>
|
|
90
59
|
{children}
|
|
91
60
|
</View>
|
|
@@ -95,41 +64,9 @@ export default function Layout({ children }) {
|
|
|
95
64
|
return (
|
|
96
65
|
<QueryClientProvider client={queryClient}>
|
|
97
66
|
<Providers scheme={scheme}>
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
alignItems="center"
|
|
102
|
-
justifyContent="space-between"
|
|
103
|
-
gap={2}
|
|
104
|
-
px={3}
|
|
105
|
-
py={2}
|
|
106
|
-
bg="paper"
|
|
107
|
-
>
|
|
108
|
-
<Typography variant="h6" as="span">
|
|
109
|
-
__TITLE__
|
|
110
|
-
</Typography>
|
|
111
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
112
|
-
<Link href="/" underline="hover">
|
|
113
|
-
Home
|
|
114
|
-
</Link>
|
|
115
|
-
<Link href="/about" underline="hover">
|
|
116
|
-
About
|
|
117
|
-
</Link>
|
|
118
|
-
{/* @if sample-data */}
|
|
119
|
-
<Link href="/items" underline="hover">
|
|
120
|
-
Items
|
|
121
|
-
</Link>
|
|
122
|
-
{/* @endif */}
|
|
123
|
-
{/* @if react-hook-form */}
|
|
124
|
-
<Link href="/form" underline="hover">
|
|
125
|
-
Form
|
|
126
|
-
</Link>
|
|
127
|
-
{/* @endif */}
|
|
128
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
129
|
-
{otherScheme}
|
|
130
|
-
</Button>
|
|
131
|
-
</Flex>
|
|
132
|
-
</Flex>
|
|
67
|
+
<Header>
|
|
68
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
69
|
+
</Header>
|
|
133
70
|
<View as="main" px={3} py={4}>
|
|
134
71
|
{children}
|
|
135
72
|
</View>
|
|
@@ -139,41 +76,9 @@ export default function Layout({ children }) {
|
|
|
139
76
|
// @else
|
|
140
77
|
return (
|
|
141
78
|
<Providers scheme={scheme}>
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
alignItems="center"
|
|
146
|
-
justifyContent="space-between"
|
|
147
|
-
gap={2}
|
|
148
|
-
px={3}
|
|
149
|
-
py={2}
|
|
150
|
-
bg="paper"
|
|
151
|
-
>
|
|
152
|
-
<Typography variant="h6" as="span">
|
|
153
|
-
__TITLE__
|
|
154
|
-
</Typography>
|
|
155
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
156
|
-
<Link href="/" underline="hover">
|
|
157
|
-
Home
|
|
158
|
-
</Link>
|
|
159
|
-
<Link href="/about" underline="hover">
|
|
160
|
-
About
|
|
161
|
-
</Link>
|
|
162
|
-
{/* @if sample-data */}
|
|
163
|
-
<Link href="/items" underline="hover">
|
|
164
|
-
Items
|
|
165
|
-
</Link>
|
|
166
|
-
{/* @endif */}
|
|
167
|
-
{/* @if react-hook-form */}
|
|
168
|
-
<Link href="/form" underline="hover">
|
|
169
|
-
Form
|
|
170
|
-
</Link>
|
|
171
|
-
{/* @endif */}
|
|
172
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
173
|
-
{otherScheme}
|
|
174
|
-
</Button>
|
|
175
|
-
</Flex>
|
|
176
|
-
</Flex>
|
|
79
|
+
<Header>
|
|
80
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
81
|
+
</Header>
|
|
177
82
|
<View as="main" px={3} py={4}>
|
|
178
83
|
{children}
|
|
179
84
|
</View>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import createStyleServer from '@umber-style/server/create-instance'
|
|
2
2
|
import { renderToString } from 'react-dom/server'
|
|
3
3
|
import { styleCache } from '@soroush.tech/design-system/engine'
|
|
4
4
|
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
|
|
@@ -9,7 +9,7 @@ import { PageShell } from './PageShell'
|
|
|
9
9
|
* in the head, so it is drawn styled before any script runs.
|
|
10
10
|
*/
|
|
11
11
|
export const onRenderHtml = (pageContext) => {
|
|
12
|
-
const { extractCriticalToChunks, constructStyleTagsFromChunks } =
|
|
12
|
+
const { extractCriticalToChunks, constructStyleTagsFromChunks } = createStyleServer(styleCache)
|
|
13
13
|
const html = renderToString(<PageShell pageContext={pageContext} />)
|
|
14
14
|
const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
|
|
15
15
|
return escapeInject`<!doctype html>
|
|
@@ -9,7 +9,7 @@ import { store } from '../state/store'
|
|
|
9
9
|
import { PageContextProvider } from './usePageContext'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* The page inside its +Layout. The
|
|
12
|
+
* The page inside its +Layout. The style cache is the design system's, so the styles the page
|
|
13
13
|
* uses are found where it is drawn, and every component of the page can read its pageContext.
|
|
14
14
|
*/
|
|
15
15
|
export function PageShell({ pageContext }) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import createStyleServer from '@umber-style/server/create-instance'
|
|
2
2
|
import { renderToString } from 'react-dom/server'
|
|
3
3
|
import { styleCache } from '@soroush.tech/design-system/engine'
|
|
4
4
|
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
|
|
@@ -9,7 +9,7 @@ import { PageShell } from './PageShell'
|
|
|
9
9
|
* head, so it is drawn styled before any script runs.
|
|
10
10
|
*/
|
|
11
11
|
export const onRenderHtml = (pageContext) => {
|
|
12
|
-
const { extractCriticalToChunks, constructStyleTagsFromChunks } =
|
|
12
|
+
const { extractCriticalToChunks, constructStyleTagsFromChunks } = createStyleServer(styleCache)
|
|
13
13
|
const html = renderToString(<PageShell pageContext={pageContext} />)
|
|
14
14
|
const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
|
|
15
15
|
return escapeInject`<!doctype html>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { AppBar } from '@soroush.tech/design-system/AppBar'
|
|
3
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
4
|
+
import { Link } from '@soroush.tech/design-system/Link'
|
|
5
|
+
import { useTheme } from '@soroush.tech/design-system/theme'
|
|
6
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
7
|
+
import { alpha } from '@soroush.tech/design-system/utils'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The app bar on every page: the app's title, its links, and `children` at its end. It sticks to
|
|
11
|
+
* the top as the page scrolls; on a phone, the links move to a row of their own.
|
|
12
|
+
*/
|
|
13
|
+
export function Header({ children }: { readonly children?: ReactNode }) {
|
|
14
|
+
const theme = useTheme()
|
|
15
|
+
return (
|
|
16
|
+
<AppBar
|
|
17
|
+
position="sticky"
|
|
18
|
+
top={0}
|
|
19
|
+
elevation={0}
|
|
20
|
+
color="appBar"
|
|
21
|
+
blur
|
|
22
|
+
flexDirection="row"
|
|
23
|
+
flexWrap="wrap"
|
|
24
|
+
alignItems="center"
|
|
25
|
+
justifyContent="space-between"
|
|
26
|
+
gap={2}
|
|
27
|
+
borderBottom={`1px solid ${alpha(theme.border.primary, 0.2)}`}
|
|
28
|
+
>
|
|
29
|
+
<Typography variant="h6" as="span">
|
|
30
|
+
__TITLE__
|
|
31
|
+
</Typography>
|
|
32
|
+
<Flex
|
|
33
|
+
as="nav"
|
|
34
|
+
flexDirection="row"
|
|
35
|
+
alignItems="center"
|
|
36
|
+
gap={3}
|
|
37
|
+
order={[1, 0]}
|
|
38
|
+
width={['100%', 'auto']}
|
|
39
|
+
>
|
|
40
|
+
<Link href="/" underline="hover">
|
|
41
|
+
Home
|
|
42
|
+
</Link>
|
|
43
|
+
<Link href="/about" underline="hover">
|
|
44
|
+
About
|
|
45
|
+
</Link>
|
|
46
|
+
{/* @if sample-data */}
|
|
47
|
+
<Link href="/items" underline="hover">
|
|
48
|
+
Items
|
|
49
|
+
</Link>
|
|
50
|
+
{/* @endif */}
|
|
51
|
+
{/* @if react-hook-form */}
|
|
52
|
+
<Link href="/form" underline="hover">
|
|
53
|
+
Form
|
|
54
|
+
</Link>
|
|
55
|
+
{/* @endif */}
|
|
56
|
+
</Flex>
|
|
57
|
+
{children}
|
|
58
|
+
</AppBar>
|
|
59
|
+
)
|
|
60
|
+
}
|