@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.
Files changed (33) hide show
  1. package/dist/bin.mjs +4 -4
  2. package/dist/index.d.mts +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/{io-CqI2BTaP.mjs → io-BFbf4S_u.mjs} +178 -124
  5. package/package.json +3 -3
  6. package/templates/astro/js/base/README.md +2 -5
  7. package/templates/astro/js/base/src/components/About.jsx +1 -4
  8. package/templates/astro/js/base/src/components/Header.jsx +64 -69
  9. package/templates/astro/js/base/src/components/SchemeSwitch.jsx +33 -0
  10. package/templates/astro/js/base/src/layouts/Layout.astro +24 -13
  11. package/templates/astro/ts/base/README.md +2 -5
  12. package/templates/astro/ts/base/src/components/About.tsx +1 -4
  13. package/templates/astro/ts/base/src/components/Header.tsx +65 -69
  14. package/templates/astro/ts/base/src/components/SchemeSwitch.tsx +41 -0
  15. package/templates/astro/ts/base/src/layouts/Layout.astro +24 -13
  16. package/templates/react-router/js/base/src/components/Header.jsx +59 -0
  17. package/templates/react-router/js/base/src/components/SchemeSwitch.jsx +31 -0
  18. package/templates/react-router/js/base/src/pages/Layout.jsx +8 -75
  19. package/templates/react-router/ts/base/src/components/Header.tsx +60 -0
  20. package/templates/react-router/ts/base/src/components/SchemeSwitch.tsx +39 -0
  21. package/templates/react-router/ts/base/src/pages/Layout.tsx +8 -75
  22. package/templates/vike/js/base/src/components/Header.jsx +59 -0
  23. package/templates/vike/js/base/src/components/SchemeSwitch.jsx +33 -0
  24. package/templates/vike/js/base/src/pages/+Layout.jsx +11 -106
  25. package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +2 -2
  26. package/templates/vike/js/base/src/pages/PageShell.jsx +1 -1
  27. package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +2 -2
  28. package/templates/vike/ts/base/src/components/Header.tsx +60 -0
  29. package/templates/vike/ts/base/src/components/SchemeSwitch.tsx +41 -0
  30. package/templates/vike/ts/base/src/pages/+Layout.tsx +11 -106
  31. package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +2 -2
  32. package/templates/vike/ts/base/src/pages/PageShell.tsx +1 -1
  33. package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +2 -2
@@ -1,98 +1,93 @@
1
- // @if !ssg
2
- import { Button } from '@soroush.tech/design-system/Button'
3
- // @endif
1
+ import { AppBar } from '@soroush.tech/design-system/AppBar'
4
2
  import { Flex } from '@soroush.tech/design-system/Flex'
5
3
  import { Link } from '@soroush.tech/design-system/Link'
4
+ import { useTheme } from '@soroush.tech/design-system/theme'
6
5
  import { Typography } from '@soroush.tech/design-system/Typography'
6
+ import { alpha } from '@soroush.tech/design-system/utils'
7
7
  import { Providers } from '../theme/Providers'
8
8
  // @if !ssg
9
9
  import { setScheme, useScheme } from '../theme/scheme'
10
+ import { SchemeSwitch } from './SchemeSwitch'
10
11
  // @endif
11
12
 
13
+ /**
14
+ * The app bar: the app's title, its links, and `children` at its end. It sticks to the top as the
15
+ * page scrolls; on a phone, the links move to a row of their own.
16
+ */
17
+ function Bar({ children }) {
18
+ const theme = useTheme()
19
+ return (
20
+ <AppBar
21
+ position="sticky"
22
+ top={0}
23
+ elevation={0}
24
+ color="appBar"
25
+ blur
26
+ flexDirection="row"
27
+ flexWrap="wrap"
28
+ alignItems="center"
29
+ justifyContent="space-between"
30
+ gap={2}
31
+ borderBottom={`1px solid ${alpha(theme.border.primary, 0.2)}`}
32
+ >
33
+ <Typography variant="h6" as="span">
34
+ __TITLE__
35
+ </Typography>
36
+ <Flex
37
+ as="nav"
38
+ flexDirection="row"
39
+ alignItems="center"
40
+ gap={3}
41
+ order={[1, 0]}
42
+ width={['100%', 'auto']}
43
+ >
44
+ <Link href="/" underline="hover">
45
+ Home
46
+ </Link>
47
+ <Link href="/about" underline="hover">
48
+ About
49
+ </Link>
50
+ {/* @if sample-data */}
51
+ <Link href="/items" underline="hover">
52
+ Items
53
+ </Link>
54
+ {/* @endif */}
55
+ {/* @if react-hook-form */}
56
+ <Link href="/form" underline="hover">
57
+ Form
58
+ </Link>
59
+ {/* @endif */}
60
+ </Flex>
61
+ {children}
62
+ </AppBar>
63
+ )
64
+ }
65
+
12
66
  /**
13
67
  // @if ssg
14
- * The header of every page. Its Providers draw the base styles, once a
15
- * page.
68
+ * The header of every page. Its Providers draw the base styles, once a page. A page has no
69
+ * JavaScript, so it has no theme switch.
16
70
  // @else
17
71
  * The header of every page, an island of its own. Its Providers draw the base styles, once a
18
- * page, and its button switches the scheme of every island.
72
+ * page, and its switch changes the scheme of every island.
19
73
  // @endif
20
74
  */
21
75
  // @if ssg
22
76
  export default function Header() {
23
77
  return (
24
78
  <Providers>
25
- <Flex
26
- as="header"
27
- flexDirection="row"
28
- alignItems="center"
29
- justifyContent="space-between"
30
- gap={2}
31
- px={3}
32
- py={2}
33
- bg="paper"
34
- >
35
- <Typography variant="h6" as="span">
36
- __TITLE__
37
- </Typography>
38
- <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
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
- </Flex>
51
- </Flex>
79
+ <Bar />
52
80
  </Providers>
53
81
  )
54
82
  }
55
83
  // @else
56
84
  export default function Header() {
57
85
  const scheme = useScheme()
58
- const otherScheme = scheme === 'light' ? 'dark' : 'light'
59
86
  return (
60
87
  <Providers scheme={scheme}>
61
- <Flex
62
- as="header"
63
- flexDirection="row"
64
- alignItems="center"
65
- justifyContent="space-between"
66
- gap={2}
67
- px={3}
68
- py={2}
69
- bg="paper"
70
- >
71
- <Typography variant="h6" as="span">
72
- __TITLE__
73
- </Typography>
74
- <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
75
- <Link href="/" underline="hover">
76
- Home
77
- </Link>
78
- <Link href="/about" underline="hover">
79
- About
80
- </Link>
81
- {/* @if sample-data */}
82
- <Link href="/items" underline="hover">
83
- Items
84
- </Link>
85
- {/* @endif */}
86
- {/* @if react-hook-form */}
87
- <Link href="/form" underline="hover">
88
- Form
89
- </Link>
90
- {/* @endif */}
91
- <Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
92
- {otherScheme}
93
- </Button>
94
- </Flex>
95
- </Flex>
88
+ <Bar>
89
+ <SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
90
+ </Bar>
96
91
  </Providers>
97
92
  )
98
93
  }
@@ -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
@@ -25,25 +25,36 @@ import Header from '../components/Header'
25
25
  </main>
26
26
  {/* @if !ssg */}
27
27
  <script>
28
- // Astro's client router replaces the head on each move between pages, and with it the
29
- // styles the design system keeps there. Each of them gets an id the router keeps. The next
30
- // page's own styles, which its HTML holds next to each island, move into its head, where
31
- // the islands expect them as they hydrate - but not its base styles: the header, which
32
- // the router keeps, draws those in the scheme picked.
28
+ // Astro's client router replaces the head on each move between pages, and with it the style
29
+ // elements of the styling engine: the one its cache writes its rules into (`data-style`),
30
+ // the ones it adopted from the server (`data-umber`, and React's own, `data-precedence`),
31
+ // and its two markers (a `<meta>` named `...-options` and one named `...-global`). They must
32
+ // stay the very elements the cache holds, or it writes into one the page no longer has, so
33
+ // each gets an id the router keeps. The next page's own styles, which its HTML holds next to
34
+ // each island, move into its head, where the cache reads each element as it arrives and the
35
+ // islands expect them as they hydrate - but not its base styles (the global rules and the
36
+ // root theme): the header, which the router keeps, draws those in the scheme picked.
37
+ const engineElements =
38
+ 'style[data-style], style[data-umber], style[data-precedence], meta[name$="-global"], meta[name$="-options"]'
39
+ const nameAttributes = ['data-umber', 'data-href', 'data-style', 'name']
33
40
  document.addEventListener('astro:before-swap', ({ newDocument }) => {
34
41
  const kept = new Set()
35
- document.head.querySelectorAll('style[data-emotion]').forEach((style, index) => {
42
+ document.head.querySelectorAll(engineElements).forEach((element, index) => {
36
43
  const id = `soroush-styles-${index}`
37
- style.setAttribute('data-astro-transition-persist', id)
38
- const placeholder = newDocument.createElement('style')
44
+ element.setAttribute('data-astro-transition-persist', id)
45
+ const placeholder = newDocument.createElement(element.localName)
39
46
  placeholder.setAttribute('data-astro-transition-persist', id)
40
47
  newDocument.head.append(placeholder)
41
- kept.add(style.getAttribute('data-emotion'))
48
+ const name =
49
+ nameAttributes.map((attribute) => element.getAttribute(attribute)).find(Boolean) ?? ''
50
+ kept.add(name)
42
51
  })
43
- newDocument.body.querySelectorAll('style[data-emotion]').forEach((style) => {
44
- const name = style.getAttribute('data-emotion') ?? ''
45
- if (kept.has(name) || name.includes('-global')) style.remove()
46
- else newDocument.head.append(style)
52
+ newDocument.body.querySelectorAll(engineElements).forEach((element) => {
53
+ const name =
54
+ nameAttributes.map((attribute) => element.getAttribute(attribute)).find(Boolean) ?? ''
55
+ const isBase = name.split(' ').some((part) => part.includes('-global'))
56
+ if (kept.has(name) || isBase) element.remove()
57
+ else newDocument.head.append(element)
47
58
  })
48
59
  })
49
60
  </script>
@@ -1,13 +1,10 @@
1
1
  # __TITLE__
2
2
 
3
3
  An [Astro](https://astro.build) app on the [@soroush.tech design system](https://docs.soroush.tech):
4
- <!-- @if isomorphic -->
5
- every page is HTML from the build, with its styles, and its parts are React islands
6
- that hydrate in the browser. Astro's client router moves between pages with no reload.
7
- <!-- @elif ssr -->
4
+ <!-- @if ssr -->
8
5
  every page is rendered on the server, on each request, with its styles, and its parts are
9
6
  React islands that hydrate in the browser. Astro's client router moves between pages with no
10
- reload.
7
+ reload: it fetches the next page's HTML from the server and swaps it in.
11
8
  <!-- @else -->
12
9
  every page is HTML from the build, with its styles, and no JavaScript in the browser: its
13
10
  React parts render at build time only.
@@ -10,11 +10,8 @@ function About() {
10
10
  {/* @if ssr */}
11
11
  A second page: the server renders it, with its styles, and the app moves to it without a
12
12
  reload.
13
- {/* @elif ssg */}
14
- A second page: it is HTML with its styles from the build, and a link loads it as a new page.
15
13
  {/* @else */}
16
- A second page: it is HTML with its styles from the build, and the app moves to it without a
17
- reload.
14
+ A second page: it is HTML with its styles from the build, and a link loads it as a new page.
18
15
  {/* @endif */}
19
16
  </Typography>
20
17
  </Flex>
@@ -1,98 +1,94 @@
1
- // @if !ssg
2
- import { Button } from '@soroush.tech/design-system/Button'
3
- // @endif
1
+ import type { ReactNode } from 'react'
2
+ import { AppBar } from '@soroush.tech/design-system/AppBar'
4
3
  import { Flex } from '@soroush.tech/design-system/Flex'
5
4
  import { Link } from '@soroush.tech/design-system/Link'
5
+ import { useTheme } from '@soroush.tech/design-system/theme'
6
6
  import { Typography } from '@soroush.tech/design-system/Typography'
7
+ import { alpha } from '@soroush.tech/design-system/utils'
7
8
  import { Providers } from '../theme/Providers'
8
9
  // @if !ssg
9
10
  import { setScheme, useScheme } from '../theme/scheme'
11
+ import { SchemeSwitch } from './SchemeSwitch'
10
12
  // @endif
11
13
 
14
+ /**
15
+ * The app bar: the app's title, its links, and `children` at its end. It sticks to the top as the
16
+ * page scrolls; on a phone, the links move to a row of their own.
17
+ */
18
+ function Bar({ children }: { readonly children?: ReactNode }) {
19
+ const theme = useTheme()
20
+ return (
21
+ <AppBar
22
+ position="sticky"
23
+ top={0}
24
+ elevation={0}
25
+ color="appBar"
26
+ blur
27
+ flexDirection="row"
28
+ flexWrap="wrap"
29
+ alignItems="center"
30
+ justifyContent="space-between"
31
+ gap={2}
32
+ borderBottom={`1px solid ${alpha(theme.border.primary, 0.2)}`}
33
+ >
34
+ <Typography variant="h6" as="span">
35
+ __TITLE__
36
+ </Typography>
37
+ <Flex
38
+ as="nav"
39
+ flexDirection="row"
40
+ alignItems="center"
41
+ gap={3}
42
+ order={[1, 0]}
43
+ width={['100%', 'auto']}
44
+ >
45
+ <Link href="/" underline="hover">
46
+ Home
47
+ </Link>
48
+ <Link href="/about" underline="hover">
49
+ About
50
+ </Link>
51
+ {/* @if sample-data */}
52
+ <Link href="/items" underline="hover">
53
+ Items
54
+ </Link>
55
+ {/* @endif */}
56
+ {/* @if react-hook-form */}
57
+ <Link href="/form" underline="hover">
58
+ Form
59
+ </Link>
60
+ {/* @endif */}
61
+ </Flex>
62
+ {children}
63
+ </AppBar>
64
+ )
65
+ }
66
+
12
67
  /**
13
68
  // @if ssg
14
- * The header of every page. Its Providers draw the base styles, once a
15
- * page.
69
+ * The header of every page. Its Providers draw the base styles, once a page. A page has no
70
+ * JavaScript, so it has no theme switch.
16
71
  // @else
17
72
  * The header of every page, an island of its own. Its Providers draw the base styles, once a
18
- * page, and its button switches the scheme of every island.
73
+ * page, and its switch changes the scheme of every island.
19
74
  // @endif
20
75
  */
21
76
  // @if ssg
22
77
  export default function Header() {
23
78
  return (
24
79
  <Providers>
25
- <Flex
26
- as="header"
27
- flexDirection="row"
28
- alignItems="center"
29
- justifyContent="space-between"
30
- gap={2}
31
- px={3}
32
- py={2}
33
- bg="paper"
34
- >
35
- <Typography variant="h6" as="span">
36
- __TITLE__
37
- </Typography>
38
- <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
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
- </Flex>
51
- </Flex>
80
+ <Bar />
52
81
  </Providers>
53
82
  )
54
83
  }
55
84
  // @else
56
85
  export default function Header() {
57
86
  const scheme = useScheme()
58
- const otherScheme = scheme === 'light' ? 'dark' : 'light'
59
87
  return (
60
88
  <Providers scheme={scheme}>
61
- <Flex
62
- as="header"
63
- flexDirection="row"
64
- alignItems="center"
65
- justifyContent="space-between"
66
- gap={2}
67
- px={3}
68
- py={2}
69
- bg="paper"
70
- >
71
- <Typography variant="h6" as="span">
72
- __TITLE__
73
- </Typography>
74
- <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
75
- <Link href="/" underline="hover">
76
- Home
77
- </Link>
78
- <Link href="/about" underline="hover">
79
- About
80
- </Link>
81
- {/* @if sample-data */}
82
- <Link href="/items" underline="hover">
83
- Items
84
- </Link>
85
- {/* @endif */}
86
- {/* @if react-hook-form */}
87
- <Link href="/form" underline="hover">
88
- Form
89
- </Link>
90
- {/* @endif */}
91
- <Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
92
- {otherScheme}
93
- </Button>
94
- </Flex>
95
- </Flex>
89
+ <Bar>
90
+ <SchemeSwitch scheme={scheme} onSchemeChange={setScheme} />
91
+ </Bar>
96
92
  </Providers>
97
93
  )
98
94
  }
@@ -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
@@ -25,25 +25,36 @@ import Header from '../components/Header'
25
25
  </main>
26
26
  {/* @if !ssg */}
27
27
  <script>
28
- // Astro's client router replaces the head on each move between pages, and with it the
29
- // styles the design system keeps there. Each of them gets an id the router keeps. The next
30
- // page's own styles, which its HTML holds next to each island, move into its head, where
31
- // the islands expect them as they hydrate - but not its base styles: the header, which
32
- // the router keeps, draws those in the scheme picked.
28
+ // Astro's client router replaces the head on each move between pages, and with it the style
29
+ // elements of the styling engine: the one its cache writes its rules into (`data-style`),
30
+ // the ones it adopted from the server (`data-umber`, and React's own, `data-precedence`),
31
+ // and its two markers (a `<meta>` named `...-options` and one named `...-global`). They must
32
+ // stay the very elements the cache holds, or it writes into one the page no longer has, so
33
+ // each gets an id the router keeps. The next page's own styles, which its HTML holds next to
34
+ // each island, move into its head, where the cache reads each element as it arrives and the
35
+ // islands expect them as they hydrate - but not its base styles (the global rules and the
36
+ // root theme): the header, which the router keeps, draws those in the scheme picked.
37
+ const engineElements =
38
+ 'style[data-style], style[data-umber], style[data-precedence], meta[name$="-global"], meta[name$="-options"]'
39
+ const nameAttributes = ['data-umber', 'data-href', 'data-style', 'name']
33
40
  document.addEventListener('astro:before-swap', ({ newDocument }) => {
34
41
  const kept = new Set()
35
- document.head.querySelectorAll('style[data-emotion]').forEach((style, index) => {
42
+ document.head.querySelectorAll(engineElements).forEach((element, index) => {
36
43
  const id = `soroush-styles-${index}`
37
- style.setAttribute('data-astro-transition-persist', id)
38
- const placeholder = newDocument.createElement('style')
44
+ element.setAttribute('data-astro-transition-persist', id)
45
+ const placeholder = newDocument.createElement(element.localName)
39
46
  placeholder.setAttribute('data-astro-transition-persist', id)
40
47
  newDocument.head.append(placeholder)
41
- kept.add(style.getAttribute('data-emotion'))
48
+ const name =
49
+ nameAttributes.map((attribute) => element.getAttribute(attribute)).find(Boolean) ?? ''
50
+ kept.add(name)
42
51
  })
43
- newDocument.body.querySelectorAll('style[data-emotion]').forEach((style) => {
44
- const name = style.getAttribute('data-emotion') ?? ''
45
- if (kept.has(name) || name.includes('-global')) style.remove()
46
- else newDocument.head.append(style)
52
+ newDocument.body.querySelectorAll(engineElements).forEach((element) => {
53
+ const name =
54
+ nameAttributes.map((attribute) => element.getAttribute(attribute)).find(Boolean) ?? ''
55
+ const isBase = name.split(' ').some((part) => part.includes('-global'))
56
+ if (kept.has(name) || isBase) element.remove()
57
+ else newDocument.head.append(element)
47
58
  })
48
59
  })
49
60
  </script>
@@ -0,0 +1,59 @@
1
+ import { AppBar } from '@soroush.tech/design-system/AppBar'
2
+ import { Flex } from '@soroush.tech/design-system/Flex'
3
+ import { useTheme } from '@soroush.tech/design-system/theme'
4
+ import { Typography } from '@soroush.tech/design-system/Typography'
5
+ import { alpha } from '@soroush.tech/design-system/utils'
6
+ import { RouterLink } from './RouterLink'
7
+
8
+ /**
9
+ * The app bar around 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
+ <RouterLink to="/" underline="hover">
40
+ Home
41
+ </RouterLink>
42
+ <RouterLink to="/about" underline="hover">
43
+ About
44
+ </RouterLink>
45
+ {/* @if sample-data */}
46
+ <RouterLink to="/items" underline="hover">
47
+ Items
48
+ </RouterLink>
49
+ {/* @endif */}
50
+ {/* @if react-hook-form */}
51
+ <RouterLink to="/form" underline="hover">
52
+ Form
53
+ </RouterLink>
54
+ {/* @endif */}
55
+ </Flex>
56
+ {children}
57
+ </AppBar>
58
+ )
59
+ }
@@ -0,0 +1,31 @@
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
+ /** The switch between the light and the dark theme, on when dark, with the scheme's icon. */
7
+ export function SchemeSwitch({ scheme, onSchemeChange }) {
8
+ const isDark = scheme === 'dark'
9
+ return (
10
+ <Flex flexDirection="row" alignItems="center" gap={2}>
11
+ {/* Hidden on a phone, so the bar fits: the switch keeps its label. */}
12
+ <Typography
13
+ variant="caption"
14
+ letterSpacing="widest"
15
+ color="primary"
16
+ display={['none', 'block']}
17
+ >
18
+ MODE
19
+ </Typography>
20
+ <Switch
21
+ checked={isDark}
22
+ onChange={() => onSchemeChange(isDark ? 'light' : 'dark')}
23
+ variant="inside"
24
+ color="primary"
25
+ size="sm"
26
+ aria-label="Toggle theme"
27
+ />
28
+ <Icon name={isDark ? 'dark_mode' : 'light_mode'} size={14} color="primary" />
29
+ </Flex>
30
+ )
31
+ }