@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
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
type Scheme = 'light' | 'dark'
|
|
8
|
+
|
|
9
|
+
/** The switch between the light and the dark theme, on when dark, with the scheme's icon. */
|
|
10
|
+
export function SchemeSwitch({
|
|
11
|
+
scheme,
|
|
12
|
+
onSchemeChange,
|
|
13
|
+
}: {
|
|
14
|
+
readonly scheme: Scheme
|
|
15
|
+
readonly onSchemeChange: (scheme: Scheme) => void
|
|
16
|
+
}) {
|
|
17
|
+
const isDark = scheme === 'dark'
|
|
18
|
+
return (
|
|
19
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
20
|
+
{/* Hidden on a phone, so the bar fits: the switch keeps its label. */}
|
|
21
|
+
<Typography
|
|
22
|
+
variant="caption"
|
|
23
|
+
letterSpacing="widest"
|
|
24
|
+
color="primary"
|
|
25
|
+
display={['none', 'block']}
|
|
26
|
+
>
|
|
27
|
+
MODE
|
|
28
|
+
</Typography>
|
|
29
|
+
<Switch
|
|
30
|
+
checked={isDark}
|
|
31
|
+
onChange={() => onSchemeChange(isDark ? 'light' : 'dark')}
|
|
32
|
+
variant="inside"
|
|
33
|
+
color="primary"
|
|
34
|
+
size="sm"
|
|
35
|
+
aria-label="Toggle theme"
|
|
36
|
+
/>
|
|
37
|
+
<Icon name={isDark ? 'dark_mode' : 'light_mode'} size={14} color="primary" />
|
|
38
|
+
</Flex>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
// @endif
|
|
@@ -3,12 +3,6 @@ import { useState, type ReactNode } from 'react'
|
|
|
3
3
|
// @else
|
|
4
4
|
import type { ReactNode } from 'react'
|
|
5
5
|
// @endif
|
|
6
|
-
// @if !ssg
|
|
7
|
-
import { Button } from '@soroush.tech/design-system/Button'
|
|
8
|
-
// @endif
|
|
9
|
-
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
10
|
-
import { Link } from '@soroush.tech/design-system/Link'
|
|
11
|
-
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
12
6
|
import { View } from '@soroush.tech/design-system/View'
|
|
13
7
|
// @if tanstack-query
|
|
14
8
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -22,6 +16,10 @@ import { schemeAtom } from '../state/scheme'
|
|
|
22
16
|
import { useDispatch, useSelector } from 'react-redux'
|
|
23
17
|
import { schemeChanged, type RootState } from '../state/store'
|
|
24
18
|
// @endif
|
|
19
|
+
import { Header } from '../components/Header'
|
|
20
|
+
// @if !ssg
|
|
21
|
+
import { SchemeSwitch } from '../components/SchemeSwitch'
|
|
22
|
+
// @endif
|
|
25
23
|
import { Providers } from '../theme/Providers'
|
|
26
24
|
|
|
27
25
|
/**
|
|
@@ -54,39 +52,10 @@ export default function Layout({ children }: { readonly children: ReactNode }) {
|
|
|
54
52
|
// @elif !ssg
|
|
55
53
|
const [scheme, setScheme] = useState<'light' | 'dark'>('__SCHEME__')
|
|
56
54
|
// @endif
|
|
57
|
-
// @if !ssg
|
|
58
|
-
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
59
|
-
// @endif
|
|
60
55
|
// @if ssg
|
|
61
56
|
return (
|
|
62
57
|
<Providers>
|
|
63
|
-
<
|
|
64
|
-
as="header"
|
|
65
|
-
flexDirection="row"
|
|
66
|
-
alignItems="center"
|
|
67
|
-
justifyContent="space-between"
|
|
68
|
-
gap={2}
|
|
69
|
-
px={3}
|
|
70
|
-
py={2}
|
|
71
|
-
bg="paper"
|
|
72
|
-
>
|
|
73
|
-
<Typography variant="h6" as="span">
|
|
74
|
-
__TITLE__
|
|
75
|
-
</Typography>
|
|
76
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
77
|
-
<Link href="/" underline="hover">
|
|
78
|
-
Home
|
|
79
|
-
</Link>
|
|
80
|
-
<Link href="/about" underline="hover">
|
|
81
|
-
About
|
|
82
|
-
</Link>
|
|
83
|
-
{/* @if sample-data */}
|
|
84
|
-
<Link href="/items" underline="hover">
|
|
85
|
-
Items
|
|
86
|
-
</Link>
|
|
87
|
-
{/* @endif */}
|
|
88
|
-
</Flex>
|
|
89
|
-
</Flex>
|
|
58
|
+
<Header />
|
|
90
59
|
<View as="main" px={3} py={4}>
|
|
91
60
|
{children}
|
|
92
61
|
</View>
|
|
@@ -96,41 +65,9 @@ export default function Layout({ children }: { readonly children: ReactNode }) {
|
|
|
96
65
|
return (
|
|
97
66
|
<QueryClientProvider client={queryClient}>
|
|
98
67
|
<Providers scheme={scheme}>
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
alignItems="center"
|
|
103
|
-
justifyContent="space-between"
|
|
104
|
-
gap={2}
|
|
105
|
-
px={3}
|
|
106
|
-
py={2}
|
|
107
|
-
bg="paper"
|
|
108
|
-
>
|
|
109
|
-
<Typography variant="h6" as="span">
|
|
110
|
-
__TITLE__
|
|
111
|
-
</Typography>
|
|
112
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
113
|
-
<Link href="/" underline="hover">
|
|
114
|
-
Home
|
|
115
|
-
</Link>
|
|
116
|
-
<Link href="/about" underline="hover">
|
|
117
|
-
About
|
|
118
|
-
</Link>
|
|
119
|
-
{/* @if sample-data */}
|
|
120
|
-
<Link href="/items" underline="hover">
|
|
121
|
-
Items
|
|
122
|
-
</Link>
|
|
123
|
-
{/* @endif */}
|
|
124
|
-
{/* @if react-hook-form */}
|
|
125
|
-
<Link href="/form" underline="hover">
|
|
126
|
-
Form
|
|
127
|
-
</Link>
|
|
128
|
-
{/* @endif */}
|
|
129
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
130
|
-
{otherScheme}
|
|
131
|
-
</Button>
|
|
132
|
-
</Flex>
|
|
133
|
-
</Flex>
|
|
68
|
+
<Header>
|
|
69
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
70
|
+
</Header>
|
|
134
71
|
<View as="main" px={3} py={4}>
|
|
135
72
|
{children}
|
|
136
73
|
</View>
|
|
@@ -140,41 +77,9 @@ export default function Layout({ children }: { readonly children: ReactNode }) {
|
|
|
140
77
|
// @else
|
|
141
78
|
return (
|
|
142
79
|
<Providers scheme={scheme}>
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
alignItems="center"
|
|
147
|
-
justifyContent="space-between"
|
|
148
|
-
gap={2}
|
|
149
|
-
px={3}
|
|
150
|
-
py={2}
|
|
151
|
-
bg="paper"
|
|
152
|
-
>
|
|
153
|
-
<Typography variant="h6" as="span">
|
|
154
|
-
__TITLE__
|
|
155
|
-
</Typography>
|
|
156
|
-
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
157
|
-
<Link href="/" underline="hover">
|
|
158
|
-
Home
|
|
159
|
-
</Link>
|
|
160
|
-
<Link href="/about" underline="hover">
|
|
161
|
-
About
|
|
162
|
-
</Link>
|
|
163
|
-
{/* @if sample-data */}
|
|
164
|
-
<Link href="/items" underline="hover">
|
|
165
|
-
Items
|
|
166
|
-
</Link>
|
|
167
|
-
{/* @endif */}
|
|
168
|
-
{/* @if react-hook-form */}
|
|
169
|
-
<Link href="/form" underline="hover">
|
|
170
|
-
Form
|
|
171
|
-
</Link>
|
|
172
|
-
{/* @endif */}
|
|
173
|
-
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
174
|
-
{otherScheme}
|
|
175
|
-
</Button>
|
|
176
|
-
</Flex>
|
|
177
|
-
</Flex>
|
|
80
|
+
<Header>
|
|
81
|
+
<SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
|
|
82
|
+
</Header>
|
|
178
83
|
<View as="main" px={3} py={4}>
|
|
179
84
|
{children}
|
|
180
85
|
</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'
|
|
@@ -10,7 +10,7 @@ import { PageShell } from './PageShell'
|
|
|
10
10
|
* in the head, so it is drawn styled before any script runs.
|
|
11
11
|
*/
|
|
12
12
|
export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
|
|
13
|
-
const { extractCriticalToChunks, constructStyleTagsFromChunks } =
|
|
13
|
+
const { extractCriticalToChunks, constructStyleTagsFromChunks } = createStyleServer(styleCache)
|
|
14
14
|
const html = renderToString(<PageShell pageContext={pageContext} />)
|
|
15
15
|
const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
|
|
16
16
|
return escapeInject`<!doctype html>
|
|
@@ -10,7 +10,7 @@ import { store } from '../state/store'
|
|
|
10
10
|
import { PageContextProvider } from './usePageContext'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* The page inside its +Layout. The
|
|
13
|
+
* The page inside its +Layout. The style cache is the design system's, so the styles the page
|
|
14
14
|
* uses are found where it is drawn, and every component of the page can read its pageContext.
|
|
15
15
|
*/
|
|
16
16
|
export function PageShell({ pageContext }: { readonly pageContext: 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'
|
|
@@ -10,7 +10,7 @@ import { PageShell } from './PageShell'
|
|
|
10
10
|
* head, so it is drawn styled before any script runs.
|
|
11
11
|
*/
|
|
12
12
|
export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
|
|
13
|
-
const { extractCriticalToChunks, constructStyleTagsFromChunks } =
|
|
13
|
+
const { extractCriticalToChunks, constructStyleTagsFromChunks } = createStyleServer(styleCache)
|
|
14
14
|
const html = renderToString(<PageShell pageContext={pageContext} />)
|
|
15
15
|
const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
|
|
16
16
|
return escapeInject`<!doctype html>
|