@soroush.design/cli 0.2.0-alpha.3 → 0.2.0-alpha.5
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 +2 -15
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/{io-Bybgct-f.mjs → io-CqI2BTaP.mjs} +430 -1032
- package/package.json +14 -5
- package/templates/astro/js/base/README.md +93 -0
- package/templates/astro/js/base/_gitignore +5 -0
- package/templates/astro/js/base/astro.config.mjs +23 -0
- package/templates/astro/js/base/src/components/About.jsx +24 -0
- package/templates/astro/js/base/src/components/Counter.jsx +26 -0
- package/templates/astro/js/base/src/components/Greeting.jsx +60 -0
- package/templates/astro/js/base/src/components/Header.jsx +99 -0
- package/templates/astro/js/base/src/components/Home.jsx +32 -0
- package/templates/astro/js/base/src/components/Home.test.jsx +39 -0
- package/templates/astro/js/base/src/components/NotFound.jsx +17 -0
- package/templates/astro/js/base/src/data/api.js +84 -0
- package/templates/astro/js/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/js/base/src/pages/404.astro +12 -0
- package/templates/astro/js/base/src/pages/about.astro +12 -0
- package/templates/astro/js/base/src/pages/index.astro +23 -0
- package/templates/astro/js/base/src/theme/Island.jsx +89 -0
- package/templates/astro/js/base/src/theme/scheme.js +32 -0
- package/templates/astro/js/base/vitest.config.js +12 -0
- package/templates/astro/js/sample-data/src/components/ItemDetails.jsx +64 -0
- package/templates/astro/js/sample-data/src/components/ItemList.jsx +100 -0
- package/templates/astro/js/sample-data/src/components/StatusChip.jsx +8 -0
- package/templates/astro/js/sample-data/src/data/items.js +65 -0
- package/templates/astro/js/sample-data/src/pages/items/[id].astro +37 -0
- package/templates/astro/js/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/js/with/jotai/src/components/Counter.jsx +26 -0
- package/templates/astro/js/with/jotai/src/state/counter.js +4 -0
- package/templates/astro/js/with/msw/_env +3 -0
- package/templates/astro/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/astro/js/with/msw/src/mocks/server.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/astro/js/with/msw/src/mocks/start.js +14 -0
- package/templates/astro/js/with/react-hook-form/src/components/Form.jsx +313 -0
- package/templates/astro/js/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/js/with/redux-toolkit/src/components/Counter.jsx +27 -0
- package/templates/astro/js/with/redux-toolkit/src/state/store.js +18 -0
- package/templates/astro/js/with/tanstack-query/src/data/queryClient.js +13 -0
- package/templates/astro/js/with/zustand/src/components/Counter.jsx +24 -0
- package/templates/astro/js/with/zustand/src/state/counter.js +14 -0
- package/templates/astro/ts/base/README.md +93 -0
- package/templates/astro/ts/base/_gitignore +5 -0
- package/templates/astro/ts/base/astro.config.mjs +23 -0
- package/templates/astro/ts/base/src/components/About.tsx +24 -0
- package/templates/astro/ts/base/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/base/src/components/Greeting.tsx +61 -0
- package/templates/astro/ts/base/src/components/Header.tsx +99 -0
- package/templates/astro/ts/base/src/components/Home.test.tsx +39 -0
- package/templates/astro/ts/base/src/components/Home.tsx +33 -0
- package/templates/astro/ts/base/src/components/NotFound.tsx +17 -0
- package/templates/astro/ts/base/src/data/api.ts +92 -0
- package/templates/astro/ts/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/ts/base/src/pages/404.astro +12 -0
- package/templates/astro/ts/base/src/pages/about.astro +12 -0
- package/templates/astro/ts/base/src/pages/index.astro +23 -0
- package/templates/astro/ts/base/src/theme/Island.tsx +90 -0
- package/templates/astro/ts/base/src/theme/scheme.ts +34 -0
- package/templates/astro/ts/base/tsconfig.json +9 -0
- package/templates/astro/ts/base/vitest.config.ts +12 -0
- package/templates/astro/ts/sample-data/src/components/ItemDetails.tsx +65 -0
- package/templates/astro/ts/sample-data/src/components/ItemList.tsx +109 -0
- package/templates/astro/ts/sample-data/src/components/StatusChip.tsx +9 -0
- package/templates/astro/ts/sample-data/src/data/items.ts +71 -0
- package/templates/astro/ts/sample-data/src/pages/items/[id].astro +39 -0
- package/templates/astro/ts/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/ts/with/jotai/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/astro/ts/with/msw/_env +3 -0
- package/templates/astro/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/astro/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/astro/ts/with/msw/src/mocks/start.ts +14 -0
- package/templates/astro/ts/with/react-hook-form/src/components/Form.tsx +317 -0
- package/templates/astro/ts/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/ts/with/redux-toolkit/src/components/Counter.tsx +27 -0
- package/templates/astro/ts/with/redux-toolkit/src/state/store.ts +19 -0
- package/templates/astro/ts/with/tanstack-query/src/data/queryClient.ts +13 -0
- package/templates/astro/ts/with/zustand/src/components/Counter.tsx +24 -0
- package/templates/astro/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/react-router/js/base/README.md +67 -0
- package/templates/react-router/js/base/_gitignore +4 -0
- package/templates/react-router/js/base/index.html +12 -0
- package/templates/react-router/js/base/src/components/RouterLink.jsx +12 -0
- package/templates/react-router/js/base/src/data/api.js +76 -0
- package/templates/react-router/js/base/src/main.jsx +38 -0
- package/templates/react-router/js/base/src/pages/ErrorPage.jsx +14 -0
- package/templates/react-router/js/base/src/pages/Layout.jsx +141 -0
- package/templates/react-router/js/base/src/pages/about/Page.jsx +14 -0
- package/templates/react-router/js/base/src/pages/index/Counter.jsx +18 -0
- package/templates/react-router/js/base/src/pages/index/Greeting.jsx +48 -0
- package/templates/react-router/js/base/src/pages/index/Page.jsx +29 -0
- package/templates/react-router/js/base/src/pages/index/Page.test.jsx +61 -0
- package/templates/react-router/js/base/src/routes.jsx +46 -0
- package/templates/react-router/js/base/vite.config.js +13 -0
- package/templates/react-router/js/base/vitest.config.js +13 -0
- package/templates/react-router/js/sample-data/src/data/items.js +55 -0
- package/templates/react-router/js/sample-data/src/pages/item/Page.jsx +49 -0
- package/templates/react-router/js/sample-data/src/pages/item/loader.js +14 -0
- package/templates/react-router/js/sample-data/src/pages/items/Page.jsx +48 -0
- package/templates/react-router/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
- package/templates/react-router/js/sample-data/src/pages/items/loader.js +11 -0
- package/templates/react-router/js/with/jotai/src/pages/index/Counter.jsx +19 -0
- package/templates/react-router/js/with/jotai/src/state/counter.js +4 -0
- package/templates/react-router/js/with/jotai/src/state/scheme.js +4 -0
- package/templates/react-router/js/with/msw/_env +3 -0
- package/templates/react-router/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/react-router/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/react-router/js/with/msw/src/mocks/server.js +5 -0
- package/templates/react-router/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/react-router/js/with/msw/src/mocks/start.js +10 -0
- package/templates/react-router/js/with/react-hook-form/src/pages/form/Page.jsx +294 -0
- package/templates/react-router/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
- package/templates/react-router/js/with/redux-toolkit/src/state/store.js +27 -0
- package/templates/react-router/js/with/zustand/src/pages/index/Counter.jsx +17 -0
- package/templates/react-router/js/with/zustand/src/state/counter.js +14 -0
- package/templates/react-router/js/with/zustand/src/state/scheme.js +14 -0
- package/templates/react-router/ts/base/README.md +67 -0
- package/templates/react-router/ts/base/_gitignore +4 -0
- package/templates/react-router/ts/base/index.html +12 -0
- package/templates/react-router/ts/base/src/components/RouterLink.tsx +12 -0
- package/templates/react-router/ts/base/src/data/api.ts +84 -0
- package/templates/react-router/ts/base/src/main.tsx +38 -0
- package/templates/react-router/ts/base/src/pages/ErrorPage.tsx +14 -0
- package/templates/react-router/ts/base/src/pages/Layout.tsx +141 -0
- package/templates/react-router/ts/base/src/pages/about/Page.tsx +14 -0
- package/templates/react-router/ts/base/src/pages/index/Counter.tsx +18 -0
- package/templates/react-router/ts/base/src/pages/index/Greeting.tsx +49 -0
- package/templates/react-router/ts/base/src/pages/index/Page.test.tsx +61 -0
- package/templates/react-router/ts/base/src/pages/index/Page.tsx +29 -0
- package/templates/react-router/ts/base/src/routes.tsx +47 -0
- package/templates/react-router/ts/base/tsconfig.json +18 -0
- package/templates/react-router/ts/base/vite.config.ts +13 -0
- package/templates/react-router/ts/base/vitest.config.ts +13 -0
- package/templates/react-router/ts/sample-data/src/data/items.ts +61 -0
- package/templates/react-router/ts/sample-data/src/pages/item/Page.tsx +50 -0
- package/templates/react-router/ts/sample-data/src/pages/item/loader.ts +14 -0
- package/templates/react-router/ts/sample-data/src/pages/items/Page.tsx +49 -0
- package/templates/react-router/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
- package/templates/react-router/ts/sample-data/src/pages/items/loader.ts +11 -0
- package/templates/react-router/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
- package/templates/react-router/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/react-router/ts/with/jotai/src/state/scheme.ts +4 -0
- package/templates/react-router/ts/with/msw/_env +3 -0
- package/templates/react-router/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/react-router/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/react-router/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/react-router/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/react-router/ts/with/msw/src/mocks/start.ts +10 -0
- package/templates/react-router/ts/with/react-hook-form/src/pages/form/Page.tsx +298 -0
- package/templates/react-router/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
- package/templates/react-router/ts/with/redux-toolkit/src/state/store.ts +29 -0
- package/templates/react-router/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
- package/templates/react-router/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/react-router/ts/with/zustand/src/state/scheme.ts +19 -0
- package/templates/templates.md +67 -0
- package/templates/vike/js/base/README.md +83 -0
- package/templates/vike/js/base/_gitignore +4 -0
- package/templates/vike/js/base/src/data/api.js +76 -0
- package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
- package/templates/vike/js/base/src/pages/+config.js +12 -0
- package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
- package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
- package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
- package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
- package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
- package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
- package/templates/vike/js/base/vite.config.js +14 -0
- package/templates/vike/js/base/vitest.config.js +13 -0
- package/templates/vike/js/sample-data/src/data/items.js +58 -0
- package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
- package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
- package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
- package/templates/vike/js/ssg/src/pages/+config.js +11 -0
- package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
- package/templates/vike/js/ssr/src/pages/+config.js +12 -0
- package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
- package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
- package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
- package/templates/vike/js/with/msw/_env +3 -0
- package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
- package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
- package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
- package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
- package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
- package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
- package/templates/vike/ts/base/README.md +83 -0
- package/templates/vike/ts/base/_gitignore +4 -0
- package/templates/vike/ts/base/src/data/api.ts +84 -0
- package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
- package/templates/vike/ts/base/src/pages/+config.ts +14 -0
- package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
- package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
- package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
- package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
- package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
- package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
- package/templates/vike/ts/base/src/vike.d.ts +20 -0
- package/templates/vike/ts/base/tsconfig.json +18 -0
- package/templates/vike/ts/base/vite.config.ts +14 -0
- package/templates/vike/ts/base/vitest.config.ts +13 -0
- package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
- package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
- package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
- package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
- package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
- package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
- package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
- package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
- package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
- package/templates/vike/ts/with/msw/_env +3 -0
- package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
- package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
- package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
- package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
- package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @if ssr
|
|
2
|
+
import { items } from '../../data/items'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The list page's data: what it shows of each item. It runs on the server, on each request. https://vike.dev/data
|
|
6
|
+
*/
|
|
7
|
+
export function data() {
|
|
8
|
+
return items.map(({ id, title, status }) => ({ id, title, status }))
|
|
9
|
+
}
|
|
10
|
+
// @if ts
|
|
11
|
+
|
|
12
|
+
// @endif
|
|
13
|
+
// @else
|
|
14
|
+
import { items } from '../../data/items'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The list page's data: what it shows of each item. It runs at build time, as the page is
|
|
18
|
+
* prerendered. https://vike.dev/data
|
|
19
|
+
*/
|
|
20
|
+
export function data() {
|
|
21
|
+
return items.map(({ id, title, status }) => ({ id, title, status }))
|
|
22
|
+
}
|
|
23
|
+
// @if ts
|
|
24
|
+
|
|
25
|
+
// @endif
|
|
26
|
+
// @endif
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Link } from '@soroush.tech/design-system/Link'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
// @if tanstack-query
|
|
5
|
+
import { useQuery } from '@tanstack/react-query'
|
|
6
|
+
import { fetchItem } from '../../../data/api'
|
|
7
|
+
// @elif swr
|
|
8
|
+
import useSWR from 'swr'
|
|
9
|
+
import { fetchItem } from '../../../data/api'
|
|
10
|
+
// @endif
|
|
11
|
+
import { useData } from '../../usePageContext'
|
|
12
|
+
import { StatusChip } from '../StatusChip'
|
|
13
|
+
|
|
14
|
+
export default function Page() {
|
|
15
|
+
// @if tanstack-query
|
|
16
|
+
const initialItem = useData()
|
|
17
|
+
const { data: item } = useQuery({
|
|
18
|
+
queryKey: ['items', initialItem.id],
|
|
19
|
+
queryFn: () => fetchItem(initialItem.id),
|
|
20
|
+
initialData: initialItem,
|
|
21
|
+
})
|
|
22
|
+
// @elif swr
|
|
23
|
+
const initialItem = useData()
|
|
24
|
+
const { data: item = initialItem } = useSWR(
|
|
25
|
+
['items', initialItem.id],
|
|
26
|
+
() => fetchItem(initialItem.id),
|
|
27
|
+
{ fallbackData: initialItem }
|
|
28
|
+
)
|
|
29
|
+
// @else
|
|
30
|
+
const item = useData()
|
|
31
|
+
// @endif
|
|
32
|
+
return (
|
|
33
|
+
<Flex gap={2} alignItems="flex-start">
|
|
34
|
+
<Typography variant="h2">{item.title}</Typography>
|
|
35
|
+
<StatusChip status={item.status} />
|
|
36
|
+
<Typography color="secondary">{item.summary}</Typography>
|
|
37
|
+
<Link href="/items">All items</Link>
|
|
38
|
+
</Flex>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @if ssr
|
|
2
|
+
import { render } from 'vike/abort'
|
|
3
|
+
import { items } from '../../../data/items'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One item's data, by the id in the URL, or the 404 page for an id with no item. It runs on the
|
|
7
|
+
* server, on each request. https://vike.dev/data
|
|
8
|
+
*/
|
|
9
|
+
export function data(pageContext) {
|
|
10
|
+
const item = items.find(({ id }) => id === pageContext.routeParams.id)
|
|
11
|
+
if (!item) throw render(404)
|
|
12
|
+
return item
|
|
13
|
+
}
|
|
14
|
+
// @if ts
|
|
15
|
+
|
|
16
|
+
// @endif
|
|
17
|
+
// @else
|
|
18
|
+
import { render } from 'vike/abort'
|
|
19
|
+
import { items } from '../../../data/items'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One item's data, by the id in the URL, or the 404 page for an id with no item. It runs at build
|
|
23
|
+
* time, for each URL +onBeforePrerenderStart lists. https://vike.dev/data
|
|
24
|
+
*/
|
|
25
|
+
export function data(pageContext) {
|
|
26
|
+
const item = items.find(({ id }) => id === pageContext.routeParams.id)
|
|
27
|
+
if (!item) throw render(404)
|
|
28
|
+
return item
|
|
29
|
+
}
|
|
30
|
+
// @if ts
|
|
31
|
+
|
|
32
|
+
// @endif
|
|
33
|
+
// @endif
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @if !ssr
|
|
2
|
+
import { items } from '../../../data/items'
|
|
3
|
+
|
|
4
|
+
/** The URLs of this route the build prerenders: one per item. https://vike.dev/onBeforePrerenderStart */
|
|
5
|
+
export function onBeforePrerenderStart() {
|
|
6
|
+
return items.map(({ id }) => `/items/${id}`)
|
|
7
|
+
}
|
|
8
|
+
// @endif
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Chip } from '@soroush.tech/design-system/Chip'
|
|
2
|
+
|
|
3
|
+
const COLORS = { todo: 'default', doing: 'primary', done: 'success' }
|
|
4
|
+
|
|
5
|
+
/** An item's status, in its palette color. */
|
|
6
|
+
export function StatusChip({ status }) {
|
|
7
|
+
return <Chip label={status} size="sm" variant="outlined" color={COLORS[status]} />
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The settings of every page: https://vike.dev/config
|
|
2
|
+
export default {
|
|
3
|
+
// SSG: every page is HTML at build time, with no JavaScript in the browser: a link loads the
|
|
4
|
+
// next page.
|
|
5
|
+
prerender: true,
|
|
6
|
+
// The page and +Layout, a setting of this app's own, load at build time only.
|
|
7
|
+
meta: {
|
|
8
|
+
Page: { env: { server: true, client: false } },
|
|
9
|
+
Layout: { env: { server: true, client: false } },
|
|
10
|
+
},
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
3
|
+
|
|
4
|
+
export default function Page() {
|
|
5
|
+
return (
|
|
6
|
+
<Flex gap={2}>
|
|
7
|
+
<Typography variant="h2">About</Typography>
|
|
8
|
+
<Typography color="secondary">
|
|
9
|
+
A second page: it is HTML with its styles from the build, and a link loads it as a new page.
|
|
10
|
+
</Typography>
|
|
11
|
+
</Flex>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The settings of every page: https://vike.dev/config
|
|
2
|
+
export default {
|
|
3
|
+
// SSR: every page is rendered on the server, on each request, then the app moves between pages
|
|
4
|
+
// in the browser, with no reload. Vike's own server runs the build: npm start.
|
|
5
|
+
server: true,
|
|
6
|
+
clientRouting: true,
|
|
7
|
+
hydrationCanBeAborted: true,
|
|
8
|
+
// +Layout is a setting of this app's own: the component every page renders inside.
|
|
9
|
+
meta: {
|
|
10
|
+
Layout: { env: { server: true, client: true } },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import createEmotionServer from '@emotion/server/create-instance'
|
|
2
|
+
import { renderToString } from 'react-dom/server'
|
|
3
|
+
import { styleCache } from '@soroush.tech/design-system/engine'
|
|
4
|
+
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
|
|
5
|
+
import { PageShell } from './PageShell'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders the page to HTML - on the server, on each request - with the styles it uses in the
|
|
9
|
+
* head, so it is drawn styled before any script runs.
|
|
10
|
+
*/
|
|
11
|
+
export const onRenderHtml = (pageContext) => {
|
|
12
|
+
const { extractCriticalToChunks, constructStyleTagsFromChunks } = createEmotionServer(styleCache)
|
|
13
|
+
const html = renderToString(<PageShell pageContext={pageContext} />)
|
|
14
|
+
const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
|
|
15
|
+
return escapeInject`<!doctype html>
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<head>
|
|
18
|
+
<meta charset="UTF-8" />
|
|
19
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
20
|
+
<title>__TITLE__</title>
|
|
21
|
+
${dangerouslySkipEscape(styles)}
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div id="root">${dangerouslySkipEscape(html)}</div>
|
|
25
|
+
</body>
|
|
26
|
+
</html>`
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
3
|
+
|
|
4
|
+
export default function Page() {
|
|
5
|
+
return (
|
|
6
|
+
<Flex gap={2}>
|
|
7
|
+
<Typography variant="h2">About</Typography>
|
|
8
|
+
<Typography color="secondary">
|
|
9
|
+
A second page: the server renders it, with its styles, and the app moves to it without a
|
|
10
|
+
reload.
|
|
11
|
+
</Typography>
|
|
12
|
+
</Flex>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { useAtom } from 'jotai'
|
|
5
|
+
import { countAtom } from '../../state/counter'
|
|
6
|
+
|
|
7
|
+
/** A count, held in a Jotai atom, src/state/counter, and the button that adds to it. */
|
|
8
|
+
export function Counter() {
|
|
9
|
+
const [count, setCount] = useAtom(countAtom)
|
|
10
|
+
const increment = () => setCount(count + 1)
|
|
11
|
+
return (
|
|
12
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
13
|
+
<Button size="sm" variant="outlined" onClick={increment}>
|
|
14
|
+
Count
|
|
15
|
+
</Button>
|
|
16
|
+
<Typography>Count: {count}</Typography>
|
|
17
|
+
</Flex>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { http, HttpResponse } from 'msw'
|
|
2
|
+
// @if sample-data
|
|
3
|
+
import { items } from '../data/items'
|
|
4
|
+
// @endif
|
|
5
|
+
|
|
6
|
+
/** The mock API: what it answers, by method and path. Add a handler for each call the app makes. */
|
|
7
|
+
export const handlers = [
|
|
8
|
+
http.get('/api/greeting', () => HttpResponse.json({ message: 'Hello from the mock API' })),
|
|
9
|
+
// @if react-hook-form
|
|
10
|
+
http.post('/api/messages', async ({ request }) => {
|
|
11
|
+
const { name } = await request.json()
|
|
12
|
+
return HttpResponse.json({ message: `Thanks, ${name}: the mock API took your message.` })
|
|
13
|
+
}),
|
|
14
|
+
// @endif
|
|
15
|
+
// @if sample-data
|
|
16
|
+
http.get('/api/items', () =>
|
|
17
|
+
HttpResponse.json(items.map(({ id, title, status }) => ({ id, title, status })))
|
|
18
|
+
),
|
|
19
|
+
http.get('/api/items/:id', ({ params }) => {
|
|
20
|
+
const item = items.find(({ id }) => id === params.id)
|
|
21
|
+
return item ? HttpResponse.json(item) : new HttpResponse(null, { status: 404 })
|
|
22
|
+
}),
|
|
23
|
+
// @endif
|
|
24
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeAll } from 'vitest'
|
|
2
|
+
import { server } from './server'
|
|
3
|
+
|
|
4
|
+
// The mock API answers every request a test makes; one it has no handler for fails the test.
|
|
5
|
+
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
|
|
6
|
+
afterEach(() => server.resetHandlers())
|
|
7
|
+
afterAll(() => server.close())
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starts the mock API in the browser while VITE_MSW, in .env, is true. Set it to false once the
|
|
3
|
+
* app's own API answers.
|
|
4
|
+
*/
|
|
5
|
+
export async function startMocks() {
|
|
6
|
+
if (import.meta.env.VITE_MSW !== 'true') return
|
|
7
|
+
const { worker } = await import('./browser')
|
|
8
|
+
// A request the mock API has no handler for - a page the router fetches - goes to the network.
|
|
9
|
+
await worker.start({ onUnhandledFrame: 'bypass' })
|
|
10
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// @if !tanstack-query && !swr
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
// @endif
|
|
4
|
+
import { zodResolver } from '@hookform/resolvers/zod'
|
|
5
|
+
// @if tanstack-query
|
|
6
|
+
import { useMutation } from '@tanstack/react-query'
|
|
7
|
+
// @endif
|
|
8
|
+
import { Controller, useForm } from 'react-hook-form'
|
|
9
|
+
// @if swr
|
|
10
|
+
import useSWRMutation from 'swr/mutation'
|
|
11
|
+
// @endif
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
14
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
15
|
+
import { TextInput } from '@soroush.tech/design-system/TextInput'
|
|
16
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
17
|
+
// @if tanstack-query || swr || msw
|
|
18
|
+
import { sendMessage } from '../../data/api'
|
|
19
|
+
// @endif
|
|
20
|
+
|
|
21
|
+
/** What the form takes, and what it says when a value will not do. */
|
|
22
|
+
const schema = z.object({
|
|
23
|
+
name: z.string().trim().min(1, 'Your name, please.'),
|
|
24
|
+
email: z.email('An email address, please.'),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// @if tanstack-query
|
|
28
|
+
/** A form whose values a Zod schema checks; once they pass, it sends them with a mutation of TanStack Query. */
|
|
29
|
+
export default function Page() {
|
|
30
|
+
const mutation = useMutation({ mutationFn: sendMessage })
|
|
31
|
+
const { control, handleSubmit } = useForm({
|
|
32
|
+
resolver: zodResolver(schema),
|
|
33
|
+
defaultValues: { name: '', email: '' },
|
|
34
|
+
})
|
|
35
|
+
return (
|
|
36
|
+
<Flex gap={2} alignItems="flex-start">
|
|
37
|
+
<Typography variant="h2">Form</Typography>
|
|
38
|
+
<Typography color="secondary">
|
|
39
|
+
React Hook Form holds the values, and a Zod schema checks them when the form is sent.
|
|
40
|
+
</Typography>
|
|
41
|
+
<form noValidate onSubmit={handleSubmit((values) => mutation.mutate(values))}>
|
|
42
|
+
<Flex gap={2} alignItems="flex-start">
|
|
43
|
+
<Controller
|
|
44
|
+
name="name"
|
|
45
|
+
control={control}
|
|
46
|
+
render={({ field, fieldState }) => (
|
|
47
|
+
<Flex gap={1}>
|
|
48
|
+
<TextInput
|
|
49
|
+
name={field.name}
|
|
50
|
+
value={field.value}
|
|
51
|
+
onChange={field.onChange}
|
|
52
|
+
placeholder="Name"
|
|
53
|
+
error={fieldState.invalid}
|
|
54
|
+
inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
|
|
55
|
+
/>
|
|
56
|
+
<Typography variant="caption" color="error">
|
|
57
|
+
{fieldState.error?.message}
|
|
58
|
+
</Typography>
|
|
59
|
+
</Flex>
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
<Controller
|
|
63
|
+
name="email"
|
|
64
|
+
control={control}
|
|
65
|
+
render={({ field, fieldState }) => (
|
|
66
|
+
<Flex gap={1}>
|
|
67
|
+
<TextInput
|
|
68
|
+
name={field.name}
|
|
69
|
+
value={field.value}
|
|
70
|
+
onChange={field.onChange}
|
|
71
|
+
type="email"
|
|
72
|
+
placeholder="Email"
|
|
73
|
+
error={fieldState.invalid}
|
|
74
|
+
inputProps={{
|
|
75
|
+
'aria-label': 'Email',
|
|
76
|
+
autoComplete: 'email',
|
|
77
|
+
onBlur: field.onBlur,
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
<Typography variant="caption" color="error">
|
|
81
|
+
{fieldState.error?.message}
|
|
82
|
+
</Typography>
|
|
83
|
+
</Flex>
|
|
84
|
+
)}
|
|
85
|
+
/>
|
|
86
|
+
<Button type="submit">Send</Button>
|
|
87
|
+
</Flex>
|
|
88
|
+
</form>
|
|
89
|
+
{mutation.data ? <Typography>{mutation.data.message}</Typography> : null}
|
|
90
|
+
</Flex>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
// @elif swr
|
|
94
|
+
/** A form whose values a Zod schema checks; once they pass, it sends them with SWR's mutation. */
|
|
95
|
+
export default function Page() {
|
|
96
|
+
const { trigger, data } = useSWRMutation('messages', (_key, { arg }) => sendMessage(arg))
|
|
97
|
+
const { control, handleSubmit } = useForm({
|
|
98
|
+
resolver: zodResolver(schema),
|
|
99
|
+
defaultValues: { name: '', email: '' },
|
|
100
|
+
})
|
|
101
|
+
return (
|
|
102
|
+
<Flex gap={2} alignItems="flex-start">
|
|
103
|
+
<Typography variant="h2">Form</Typography>
|
|
104
|
+
<Typography color="secondary">
|
|
105
|
+
React Hook Form holds the values, and a Zod schema checks them when the form is sent.
|
|
106
|
+
</Typography>
|
|
107
|
+
<form noValidate onSubmit={handleSubmit((values) => trigger(values))}>
|
|
108
|
+
<Flex gap={2} alignItems="flex-start">
|
|
109
|
+
<Controller
|
|
110
|
+
name="name"
|
|
111
|
+
control={control}
|
|
112
|
+
render={({ field, fieldState }) => (
|
|
113
|
+
<Flex gap={1}>
|
|
114
|
+
<TextInput
|
|
115
|
+
name={field.name}
|
|
116
|
+
value={field.value}
|
|
117
|
+
onChange={field.onChange}
|
|
118
|
+
placeholder="Name"
|
|
119
|
+
error={fieldState.invalid}
|
|
120
|
+
inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
|
|
121
|
+
/>
|
|
122
|
+
<Typography variant="caption" color="error">
|
|
123
|
+
{fieldState.error?.message}
|
|
124
|
+
</Typography>
|
|
125
|
+
</Flex>
|
|
126
|
+
)}
|
|
127
|
+
/>
|
|
128
|
+
<Controller
|
|
129
|
+
name="email"
|
|
130
|
+
control={control}
|
|
131
|
+
render={({ field, fieldState }) => (
|
|
132
|
+
<Flex gap={1}>
|
|
133
|
+
<TextInput
|
|
134
|
+
name={field.name}
|
|
135
|
+
value={field.value}
|
|
136
|
+
onChange={field.onChange}
|
|
137
|
+
type="email"
|
|
138
|
+
placeholder="Email"
|
|
139
|
+
error={fieldState.invalid}
|
|
140
|
+
inputProps={{
|
|
141
|
+
'aria-label': 'Email',
|
|
142
|
+
autoComplete: 'email',
|
|
143
|
+
onBlur: field.onBlur,
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
<Typography variant="caption" color="error">
|
|
147
|
+
{fieldState.error?.message}
|
|
148
|
+
</Typography>
|
|
149
|
+
</Flex>
|
|
150
|
+
)}
|
|
151
|
+
/>
|
|
152
|
+
<Button type="submit">Send</Button>
|
|
153
|
+
</Flex>
|
|
154
|
+
</form>
|
|
155
|
+
{data ? <Typography>{data.message}</Typography> : null}
|
|
156
|
+
</Flex>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
// @elif msw
|
|
160
|
+
/** A form whose values a Zod schema checks; once they pass, it sends them to the API. */
|
|
161
|
+
export default function Page() {
|
|
162
|
+
const [answer, setAnswer] = useState(null)
|
|
163
|
+
const { control, handleSubmit } = useForm({
|
|
164
|
+
resolver: zodResolver(schema),
|
|
165
|
+
defaultValues: { name: '', email: '' },
|
|
166
|
+
})
|
|
167
|
+
return (
|
|
168
|
+
<Flex gap={2} alignItems="flex-start">
|
|
169
|
+
<Typography variant="h2">Form</Typography>
|
|
170
|
+
<Typography color="secondary">
|
|
171
|
+
React Hook Form holds the values, and a Zod schema checks them when the form is sent.
|
|
172
|
+
</Typography>
|
|
173
|
+
<form
|
|
174
|
+
noValidate
|
|
175
|
+
onSubmit={handleSubmit(async (values) => setAnswer((await sendMessage(values)).message))}
|
|
176
|
+
>
|
|
177
|
+
<Flex gap={2} alignItems="flex-start">
|
|
178
|
+
<Controller
|
|
179
|
+
name="name"
|
|
180
|
+
control={control}
|
|
181
|
+
render={({ field, fieldState }) => (
|
|
182
|
+
<Flex gap={1}>
|
|
183
|
+
<TextInput
|
|
184
|
+
name={field.name}
|
|
185
|
+
value={field.value}
|
|
186
|
+
onChange={field.onChange}
|
|
187
|
+
placeholder="Name"
|
|
188
|
+
error={fieldState.invalid}
|
|
189
|
+
inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
|
|
190
|
+
/>
|
|
191
|
+
<Typography variant="caption" color="error">
|
|
192
|
+
{fieldState.error?.message}
|
|
193
|
+
</Typography>
|
|
194
|
+
</Flex>
|
|
195
|
+
)}
|
|
196
|
+
/>
|
|
197
|
+
<Controller
|
|
198
|
+
name="email"
|
|
199
|
+
control={control}
|
|
200
|
+
render={({ field, fieldState }) => (
|
|
201
|
+
<Flex gap={1}>
|
|
202
|
+
<TextInput
|
|
203
|
+
name={field.name}
|
|
204
|
+
value={field.value}
|
|
205
|
+
onChange={field.onChange}
|
|
206
|
+
type="email"
|
|
207
|
+
placeholder="Email"
|
|
208
|
+
error={fieldState.invalid}
|
|
209
|
+
inputProps={{
|
|
210
|
+
'aria-label': 'Email',
|
|
211
|
+
autoComplete: 'email',
|
|
212
|
+
onBlur: field.onBlur,
|
|
213
|
+
}}
|
|
214
|
+
/>
|
|
215
|
+
<Typography variant="caption" color="error">
|
|
216
|
+
{fieldState.error?.message}
|
|
217
|
+
</Typography>
|
|
218
|
+
</Flex>
|
|
219
|
+
)}
|
|
220
|
+
/>
|
|
221
|
+
<Button type="submit">Send</Button>
|
|
222
|
+
</Flex>
|
|
223
|
+
</form>
|
|
224
|
+
{answer ? <Typography>{answer}</Typography> : null}
|
|
225
|
+
</Flex>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
// @else
|
|
229
|
+
/** A form whose values a Zod schema checks; once they pass, it shows them. */
|
|
230
|
+
export default function Page() {
|
|
231
|
+
const [sent, setSent] = useState(null)
|
|
232
|
+
const { control, handleSubmit } = useForm({
|
|
233
|
+
resolver: zodResolver(schema),
|
|
234
|
+
defaultValues: { name: '', email: '' },
|
|
235
|
+
})
|
|
236
|
+
return (
|
|
237
|
+
<Flex gap={2} alignItems="flex-start">
|
|
238
|
+
<Typography variant="h2">Form</Typography>
|
|
239
|
+
<Typography color="secondary">
|
|
240
|
+
React Hook Form holds the values, and a Zod schema checks them when the form is sent.
|
|
241
|
+
</Typography>
|
|
242
|
+
<form noValidate onSubmit={handleSubmit(setSent)}>
|
|
243
|
+
<Flex gap={2} alignItems="flex-start">
|
|
244
|
+
<Controller
|
|
245
|
+
name="name"
|
|
246
|
+
control={control}
|
|
247
|
+
render={({ field, fieldState }) => (
|
|
248
|
+
<Flex gap={1}>
|
|
249
|
+
<TextInput
|
|
250
|
+
name={field.name}
|
|
251
|
+
value={field.value}
|
|
252
|
+
onChange={field.onChange}
|
|
253
|
+
placeholder="Name"
|
|
254
|
+
error={fieldState.invalid}
|
|
255
|
+
inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
|
|
256
|
+
/>
|
|
257
|
+
<Typography variant="caption" color="error">
|
|
258
|
+
{fieldState.error?.message}
|
|
259
|
+
</Typography>
|
|
260
|
+
</Flex>
|
|
261
|
+
)}
|
|
262
|
+
/>
|
|
263
|
+
<Controller
|
|
264
|
+
name="email"
|
|
265
|
+
control={control}
|
|
266
|
+
render={({ field, fieldState }) => (
|
|
267
|
+
<Flex gap={1}>
|
|
268
|
+
<TextInput
|
|
269
|
+
name={field.name}
|
|
270
|
+
value={field.value}
|
|
271
|
+
onChange={field.onChange}
|
|
272
|
+
type="email"
|
|
273
|
+
placeholder="Email"
|
|
274
|
+
error={fieldState.invalid}
|
|
275
|
+
inputProps={{
|
|
276
|
+
'aria-label': 'Email',
|
|
277
|
+
autoComplete: 'email',
|
|
278
|
+
onBlur: field.onBlur,
|
|
279
|
+
}}
|
|
280
|
+
/>
|
|
281
|
+
<Typography variant="caption" color="error">
|
|
282
|
+
{fieldState.error?.message}
|
|
283
|
+
</Typography>
|
|
284
|
+
</Flex>
|
|
285
|
+
)}
|
|
286
|
+
/>
|
|
287
|
+
<Button type="submit">Send</Button>
|
|
288
|
+
</Flex>
|
|
289
|
+
</form>
|
|
290
|
+
{sent ? <Typography>Thanks, {sent.name}: the form was valid.</Typography> : null}
|
|
291
|
+
</Flex>
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
// @endif
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { useDispatch, useSelector } from 'react-redux'
|
|
5
|
+
import { incremented } from '../../state/store'
|
|
6
|
+
|
|
7
|
+
/** A count, held in the Redux store, src/state/store, and the button that adds to it. */
|
|
8
|
+
export function Counter() {
|
|
9
|
+
const count = useSelector((state) => state.count)
|
|
10
|
+
const dispatch = useDispatch()
|
|
11
|
+
const increment = () => dispatch(incremented())
|
|
12
|
+
return (
|
|
13
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
14
|
+
<Button size="sm" variant="outlined" onClick={increment}>
|
|
15
|
+
Count
|
|
16
|
+
</Button>
|
|
17
|
+
<Typography>Count: {count}</Typography>
|
|
18
|
+
</Flex>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { configureStore, createSlice } from '@reduxjs/toolkit'
|
|
2
|
+
|
|
3
|
+
/** The color scheme the app is drawn in: a slice of the store. */
|
|
4
|
+
const schemeSlice = createSlice({
|
|
5
|
+
name: 'scheme',
|
|
6
|
+
initialState: '__SCHEME__',
|
|
7
|
+
reducers: {
|
|
8
|
+
schemeChanged: (_scheme, action) => action.payload,
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/** The home page's count: another slice. */
|
|
13
|
+
const countSlice = createSlice({
|
|
14
|
+
name: 'count',
|
|
15
|
+
initialState: 0,
|
|
16
|
+
reducers: {
|
|
17
|
+
incremented: (count) => count + 1,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const { schemeChanged } = schemeSlice.actions
|
|
22
|
+
export const { incremented } = countSlice.actions
|
|
23
|
+
|
|
24
|
+
/** The app's Redux store, which PageShell provides to every page. */
|
|
25
|
+
export const store = configureStore({
|
|
26
|
+
reducer: { scheme: schemeSlice.reducer, count: countSlice.reducer },
|
|
27
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { useCounter } from '../../state/counter'
|
|
5
|
+
|
|
6
|
+
/** A count, held in a zustand store, src/state/counter, and the button that adds to it. */
|
|
7
|
+
export function Counter() {
|
|
8
|
+
const { count, increment } = useCounter()
|
|
9
|
+
return (
|
|
10
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
11
|
+
<Button size="sm" variant="outlined" onClick={increment}>
|
|
12
|
+
Count
|
|
13
|
+
</Button>
|
|
14
|
+
<Typography>Count: {count}</Typography>
|
|
15
|
+
</Flex>
|
|
16
|
+
)
|
|
17
|
+
}
|