@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,183 @@
|
|
|
1
|
+
// @if !ssg && (tanstack-query || (!zustand && !jotai && !redux-toolkit))
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
// @else
|
|
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
|
+
import { View } from '@soroush.tech/design-system/View'
|
|
12
|
+
// @if tanstack-query
|
|
13
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
14
|
+
// @endif
|
|
15
|
+
// @if zustand
|
|
16
|
+
import { useScheme } from '../state/scheme'
|
|
17
|
+
// @elif jotai
|
|
18
|
+
import { useAtom } from 'jotai'
|
|
19
|
+
import { schemeAtom } from '../state/scheme'
|
|
20
|
+
// @elif redux-toolkit
|
|
21
|
+
import { useDispatch, useSelector } from 'react-redux'
|
|
22
|
+
import { schemeChanged } from '../state/store'
|
|
23
|
+
// @endif
|
|
24
|
+
import { Providers } from '../theme/Providers'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
// @if ssg
|
|
28
|
+
* The frame every page renders in, inside the app's providers. A page has no JavaScript in the
|
|
29
|
+
* browser, so it is drawn in the default scheme, which src/theme/Providers.js sets.
|
|
30
|
+
// @elif zustand || jotai
|
|
31
|
+
* The frame every page renders in. The app's providers live here, in the app itself, so the
|
|
32
|
+
* scheme, held in src/state/scheme.js, can switch the theme.
|
|
33
|
+
// @elif redux-toolkit
|
|
34
|
+
* The frame every page renders in. The app's providers live here, in the app itself, so the
|
|
35
|
+
* scheme, held in src/state/store.js, can switch the theme.
|
|
36
|
+
// @else
|
|
37
|
+
* The frame every page renders in. The app's providers live here, in the app itself, so the
|
|
38
|
+
* scheme it holds can switch the theme.
|
|
39
|
+
// @endif
|
|
40
|
+
*/
|
|
41
|
+
export default function Layout({ children }) {
|
|
42
|
+
// @if tanstack-query
|
|
43
|
+
const [queryClient] = useState(() => new QueryClient())
|
|
44
|
+
// @endif
|
|
45
|
+
// @if zustand
|
|
46
|
+
const { scheme, setScheme } = useScheme()
|
|
47
|
+
// @elif jotai
|
|
48
|
+
const [scheme, setScheme] = useAtom(schemeAtom)
|
|
49
|
+
// @elif redux-toolkit
|
|
50
|
+
const scheme = useSelector((state) => state.scheme)
|
|
51
|
+
const dispatch = useDispatch()
|
|
52
|
+
const setScheme = (next) => dispatch(schemeChanged(next))
|
|
53
|
+
// @elif !ssg
|
|
54
|
+
const [scheme, setScheme] = useState('__SCHEME__')
|
|
55
|
+
// @endif
|
|
56
|
+
// @if !ssg
|
|
57
|
+
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
58
|
+
// @endif
|
|
59
|
+
// @if ssg
|
|
60
|
+
return (
|
|
61
|
+
<Providers>
|
|
62
|
+
<Flex
|
|
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>
|
|
89
|
+
<View as="main" px={3} py={4}>
|
|
90
|
+
{children}
|
|
91
|
+
</View>
|
|
92
|
+
</Providers>
|
|
93
|
+
)
|
|
94
|
+
// @elif tanstack-query
|
|
95
|
+
return (
|
|
96
|
+
<QueryClientProvider client={queryClient}>
|
|
97
|
+
<Providers scheme={scheme}>
|
|
98
|
+
<Flex
|
|
99
|
+
as="header"
|
|
100
|
+
flexDirection="row"
|
|
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>
|
|
133
|
+
<View as="main" px={3} py={4}>
|
|
134
|
+
{children}
|
|
135
|
+
</View>
|
|
136
|
+
</Providers>
|
|
137
|
+
</QueryClientProvider>
|
|
138
|
+
)
|
|
139
|
+
// @else
|
|
140
|
+
return (
|
|
141
|
+
<Providers scheme={scheme}>
|
|
142
|
+
<Flex
|
|
143
|
+
as="header"
|
|
144
|
+
flexDirection="row"
|
|
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>
|
|
177
|
+
<View as="main" px={3} py={4}>
|
|
178
|
+
{children}
|
|
179
|
+
</View>
|
|
180
|
+
</Providers>
|
|
181
|
+
)
|
|
182
|
+
// @endif
|
|
183
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The settings of every page: https://vike.dev/config
|
|
2
|
+
export default {
|
|
3
|
+
// Isomorphic: every page is HTML at build time, then the app moves between pages in the
|
|
4
|
+
// browser, with no reload.
|
|
5
|
+
prerender: 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,39 @@
|
|
|
1
|
+
// @if !ssg
|
|
2
|
+
import { createRoot, hydrateRoot } from 'react-dom/client'
|
|
3
|
+
// @if msw
|
|
4
|
+
import { startMocks } from '../mocks/start'
|
|
5
|
+
// @else
|
|
6
|
+
// @endif
|
|
7
|
+
import { PageShell } from './PageShell'
|
|
8
|
+
|
|
9
|
+
let root
|
|
10
|
+
// @if msw
|
|
11
|
+
const mocks = startMocks()
|
|
12
|
+
// @endif
|
|
13
|
+
|
|
14
|
+
/** Takes over the page the server drew, then draws each page the app moves to. */
|
|
15
|
+
// @if msw
|
|
16
|
+
export const onRenderClient = async (pageContext) => {
|
|
17
|
+
await mocks
|
|
18
|
+
const page = <PageShell pageContext={pageContext} />
|
|
19
|
+
const container = document.getElementById('root')
|
|
20
|
+
if (pageContext.isHydration) {
|
|
21
|
+
root = hydrateRoot(container, page)
|
|
22
|
+
} else {
|
|
23
|
+
root ??= createRoot(container)
|
|
24
|
+
root.render(page)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// @else
|
|
28
|
+
export const onRenderClient = (pageContext) => {
|
|
29
|
+
const page = <PageShell pageContext={pageContext} />
|
|
30
|
+
const container = document.getElementById('root')
|
|
31
|
+
if (pageContext.isHydration) {
|
|
32
|
+
root = hydrateRoot(container, page)
|
|
33
|
+
} else {
|
|
34
|
+
root ??= createRoot(container)
|
|
35
|
+
root.render(page)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// @endif
|
|
39
|
+
// @endif
|
|
@@ -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 - at build time, as the app is prerendered - with the styles it uses
|
|
9
|
+
* in the 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,47 @@
|
|
|
1
|
+
import { StrictMode } from 'react'
|
|
2
|
+
import { CacheProvider, styleCache } from '@soroush.tech/design-system/engine'
|
|
3
|
+
// @if redux-toolkit
|
|
4
|
+
import { Provider as StoreProvider } from 'react-redux'
|
|
5
|
+
// @endif
|
|
6
|
+
// @if redux-toolkit
|
|
7
|
+
import { store } from '../state/store'
|
|
8
|
+
// @endif
|
|
9
|
+
import { PageContextProvider } from './usePageContext'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The page inside its +Layout. The Emotion cache is the design system's, so the styles the page
|
|
13
|
+
* uses are found where it is drawn, and every component of the page can read its pageContext.
|
|
14
|
+
*/
|
|
15
|
+
export function PageShell({ pageContext }) {
|
|
16
|
+
const { Page, config } = pageContext
|
|
17
|
+
const { Layout } = config
|
|
18
|
+
return (
|
|
19
|
+
<StrictMode>
|
|
20
|
+
<CacheProvider value={styleCache}>
|
|
21
|
+
{/* @if redux-toolkit */}
|
|
22
|
+
<StoreProvider store={store}>
|
|
23
|
+
<PageContextProvider pageContext={pageContext}>
|
|
24
|
+
{Layout ? (
|
|
25
|
+
<Layout>
|
|
26
|
+
<Page />
|
|
27
|
+
</Layout>
|
|
28
|
+
) : (
|
|
29
|
+
<Page />
|
|
30
|
+
)}
|
|
31
|
+
</PageContextProvider>
|
|
32
|
+
</StoreProvider>
|
|
33
|
+
{/* @else */}
|
|
34
|
+
<PageContextProvider pageContext={pageContext}>
|
|
35
|
+
{Layout ? (
|
|
36
|
+
<Layout>
|
|
37
|
+
<Page />
|
|
38
|
+
</Layout>
|
|
39
|
+
) : (
|
|
40
|
+
<Page />
|
|
41
|
+
)}
|
|
42
|
+
</PageContextProvider>
|
|
43
|
+
{/* @endif */}
|
|
44
|
+
</CacheProvider>
|
|
45
|
+
</StrictMode>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
|
|
5
|
+
/** Shown for a page that does not exist, and when a page fails to render. */
|
|
6
|
+
export default function Page() {
|
|
7
|
+
return (
|
|
8
|
+
<Flex gap={2} alignItems="flex-start">
|
|
9
|
+
<Typography variant="h2">Page not found</Typography>
|
|
10
|
+
<Typography color="secondary">This page does not exist, or it could not be shown.</Typography>
|
|
11
|
+
<Link href="/">Back home</Link>
|
|
12
|
+
</Flex>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -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: it is HTML with its styles from the build, and the app moves to it without a
|
|
10
|
+
reload.
|
|
11
|
+
</Typography>
|
|
12
|
+
</Flex>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
// @if !ssg
|
|
5
|
+
import { Counter } from './Counter'
|
|
6
|
+
// @endif
|
|
7
|
+
// @if tanstack-query || swr || msw
|
|
8
|
+
import { Greeting } from './Greeting'
|
|
9
|
+
// @endif
|
|
10
|
+
|
|
11
|
+
export default function Page() {
|
|
12
|
+
return (
|
|
13
|
+
<Flex gap={2} alignItems="flex-start">
|
|
14
|
+
<Typography variant="h2">__TITLE__</Typography>
|
|
15
|
+
<Typography color="secondary">
|
|
16
|
+
A Vike app on the design system. Edit src/pages/index/+Page.jsx, and make the themes your
|
|
17
|
+
own in src/theme/themes.js.
|
|
18
|
+
</Typography>
|
|
19
|
+
{/* @if tanstack-query || swr || msw */}
|
|
20
|
+
<Greeting />
|
|
21
|
+
{/* @endif */}
|
|
22
|
+
{/* @if !ssg */}
|
|
23
|
+
<Counter />
|
|
24
|
+
{/* @endif */}
|
|
25
|
+
<Flex flexDirection="row" gap={1}>
|
|
26
|
+
<Button href="https://docs.soroush.tech">Components</Button>
|
|
27
|
+
<Button href="https://vike.dev" variant="outlined">
|
|
28
|
+
Vike
|
|
29
|
+
</Button>
|
|
30
|
+
</Flex>
|
|
31
|
+
</Flex>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @if !ssg
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
4
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
5
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
6
|
+
|
|
7
|
+
/** A count, held in the component's own state, and the button that adds to it. */
|
|
8
|
+
export function Counter() {
|
|
9
|
+
const [count, setCount] = useState(0)
|
|
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
|
+
}
|
|
20
|
+
// @endif
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @if tanstack-query || swr || msw
|
|
2
|
+
// @if tanstack-query
|
|
3
|
+
import { useQuery } from '@tanstack/react-query'
|
|
4
|
+
// @elif swr
|
|
5
|
+
import useSWR from 'swr'
|
|
6
|
+
// @else
|
|
7
|
+
import { useEffect, useState } from 'react'
|
|
8
|
+
// @endif
|
|
9
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
10
|
+
// @if !tanstack-query && !swr
|
|
11
|
+
// @endif
|
|
12
|
+
import { fetchGreeting } from '../../data/api'
|
|
13
|
+
|
|
14
|
+
// @if tanstack-query
|
|
15
|
+
/** What the API says, read with a query of TanStack Query. */
|
|
16
|
+
export function Greeting() {
|
|
17
|
+
const { data } = useQuery({ queryKey: ['greeting'], queryFn: fetchGreeting })
|
|
18
|
+
return (
|
|
19
|
+
<Typography color="secondary">
|
|
20
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
21
|
+
</Typography>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
// @elif swr
|
|
25
|
+
/** What the API says, read with SWR. */
|
|
26
|
+
export function Greeting() {
|
|
27
|
+
const { data } = useSWR('greeting', fetchGreeting)
|
|
28
|
+
return (
|
|
29
|
+
<Typography color="secondary">
|
|
30
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
31
|
+
</Typography>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
// @else
|
|
35
|
+
/** What the API says, read with fetch, as the page loads. */
|
|
36
|
+
export function Greeting() {
|
|
37
|
+
const [data, setData] = useState()
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
fetchGreeting().then(setData, () => setData({ message: 'The API did not answer.' }))
|
|
40
|
+
}, [])
|
|
41
|
+
return (
|
|
42
|
+
<Typography color="secondary">
|
|
43
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
44
|
+
</Typography>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
// @endif
|
|
48
|
+
// @endif
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @if ssg
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
3
|
+
// @else
|
|
4
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
5
|
+
// @endif
|
|
6
|
+
// @if tanstack-query
|
|
7
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
8
|
+
// @endif
|
|
9
|
+
// @if redux-toolkit
|
|
10
|
+
import { Provider as StoreProvider } from 'react-redux'
|
|
11
|
+
// @endif
|
|
12
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
13
|
+
// @if redux-toolkit
|
|
14
|
+
import { store } from '../../state/store'
|
|
15
|
+
// @endif
|
|
16
|
+
import { Providers } from '../../theme/Providers'
|
|
17
|
+
import Page from './+Page'
|
|
18
|
+
|
|
19
|
+
/** The home page, inside the providers the app gives it. */
|
|
20
|
+
function renderPage() {
|
|
21
|
+
render(
|
|
22
|
+
<Providers>
|
|
23
|
+
{/* @if tanstack-query && redux-toolkit */}
|
|
24
|
+
<QueryClientProvider client={new QueryClient()}>
|
|
25
|
+
<StoreProvider store={store}>
|
|
26
|
+
<Page />
|
|
27
|
+
</StoreProvider>
|
|
28
|
+
</QueryClientProvider>
|
|
29
|
+
{/* @elif tanstack-query */}
|
|
30
|
+
<QueryClientProvider client={new QueryClient()}>
|
|
31
|
+
<Page />
|
|
32
|
+
</QueryClientProvider>
|
|
33
|
+
{/* @elif redux-toolkit */}
|
|
34
|
+
<StoreProvider store={store}>
|
|
35
|
+
<Page />
|
|
36
|
+
</StoreProvider>
|
|
37
|
+
{/* @else */}
|
|
38
|
+
<Page />
|
|
39
|
+
{/* @endif */}
|
|
40
|
+
</Providers>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('the home page', () => {
|
|
45
|
+
// Vitest has no globals here, so Testing Library cannot clean up on its own.
|
|
46
|
+
afterEach(cleanup)
|
|
47
|
+
|
|
48
|
+
it('shows the app title', () => {
|
|
49
|
+
renderPage()
|
|
50
|
+
expect(screen.getByRole('heading', { name: '__TITLE_STRING__' })).toBeTruthy()
|
|
51
|
+
})
|
|
52
|
+
// @if !ssg
|
|
53
|
+
|
|
54
|
+
it('counts each press of its button', () => {
|
|
55
|
+
renderPage()
|
|
56
|
+
fireEvent.click(screen.getByRole('button', { name: 'Count' }))
|
|
57
|
+
expect(screen.getByText('Count: 1')).toBeTruthy()
|
|
58
|
+
})
|
|
59
|
+
// @endif
|
|
60
|
+
// @if msw
|
|
61
|
+
|
|
62
|
+
it('shows the greeting the mock API answers', async () => {
|
|
63
|
+
renderPage()
|
|
64
|
+
expect(await screen.findByText('Hello from the mock API')).toBeTruthy()
|
|
65
|
+
})
|
|
66
|
+
// @endif
|
|
67
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
const Context = createContext(undefined)
|
|
4
|
+
|
|
5
|
+
/** Gives every component of the page its pageContext: https://vike.dev/pageContext */
|
|
6
|
+
export function PageContextProvider({ pageContext, children }) {
|
|
7
|
+
return <Context.Provider value={pageContext}>{children}</Context.Provider>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The pageContext of the page on screen: its URL, its route's parameters, its data. */
|
|
11
|
+
export function usePageContext() {
|
|
12
|
+
const pageContext = useContext(Context)
|
|
13
|
+
if (!pageContext) throw new Error('usePageContext runs only inside a page.')
|
|
14
|
+
return pageContext
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** What the page's +data returned: https://vike.dev/data */
|
|
18
|
+
export function useData() {
|
|
19
|
+
return usePageContext().data
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react'
|
|
2
|
+
// @if msw
|
|
3
|
+
import { msw } from 'msw/vite'
|
|
4
|
+
// @endif
|
|
5
|
+
import vike from 'vike/plugin'
|
|
6
|
+
import { defineConfig } from 'vite'
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
// @if msw
|
|
10
|
+
plugins: [react(), vike(), msw({ mode: 'worker-only' })],
|
|
11
|
+
// @else
|
|
12
|
+
plugins: [react(), vike()],
|
|
13
|
+
// @endif
|
|
14
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react'
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
// The tests render components in jsdom, with no Vike: a page is a component like any other.
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
// @if msw
|
|
8
|
+
// The mock API answers the tests' requests, from Node, as it answers the app's in the browser.
|
|
9
|
+
test: { environment: 'jsdom', setupFiles: ['./src/mocks/setupTests.js'] },
|
|
10
|
+
// @else
|
|
11
|
+
test: { environment: 'jsdom' },
|
|
12
|
+
// @endif
|
|
13
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @if ts
|
|
2
|
+
/** One sample item. */
|
|
3
|
+
|
|
4
|
+
// @endif
|
|
5
|
+
/**
|
|
6
|
+
* Sample data, so the items pages have something to show: each page's +data reads it at build
|
|
7
|
+
* time. Make the +data hooks fetch your own data instead, and remove this file.
|
|
8
|
+
*/
|
|
9
|
+
export const items = [
|
|
10
|
+
{
|
|
11
|
+
id: 'theme',
|
|
12
|
+
title: 'Make the theme your own',
|
|
13
|
+
summary: 'Change the colors and fonts of both themes in src/theme/themes.js.',
|
|
14
|
+
status: 'doing',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'fonts',
|
|
18
|
+
title: 'Load the fonts',
|
|
19
|
+
summary: 'The theme names Space Grotesk and JetBrains Mono, and does not load them.',
|
|
20
|
+
status: 'todo',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'pages',
|
|
24
|
+
title: 'Add a page',
|
|
25
|
+
summary: 'A folder in src/pages with a +Page in it is a new route.',
|
|
26
|
+
status: 'todo',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'data',
|
|
30
|
+
title: 'Read your own data',
|
|
31
|
+
// @if ssr
|
|
32
|
+
summary: 'Each +data here reads this file. Make it fetch from your API, on each request.',
|
|
33
|
+
// @else
|
|
34
|
+
summary: 'Each +data here reads this file. Make it fetch from your API, at build time.',
|
|
35
|
+
// @endif
|
|
36
|
+
status: 'todo',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'build',
|
|
40
|
+
title: 'Build it',
|
|
41
|
+
// @if ssr
|
|
42
|
+
summary: 'The server renders every page, these items among them, to HTML with its styles.',
|
|
43
|
+
// @else
|
|
44
|
+
summary: 'The build prerenders every page, these items among them, to HTML with its styles.',
|
|
45
|
+
// @endif
|
|
46
|
+
status: 'done',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'deploy',
|
|
50
|
+
title: 'Deploy it',
|
|
51
|
+
// @if ssr
|
|
52
|
+
summary: 'npm start runs the server the build wrote, on any Node host.',
|
|
53
|
+
// @else
|
|
54
|
+
summary: 'The build is static files in dist/client, which any static host serves.',
|
|
55
|
+
// @endif
|
|
56
|
+
status: 'todo',
|
|
57
|
+
},
|
|
58
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { fetchItems } from '../../data/api'
|
|
7
|
+
// @elif swr
|
|
8
|
+
import useSWR from 'swr'
|
|
9
|
+
import { fetchItems } 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 { data: items } = useQuery({
|
|
17
|
+
queryKey: ['items'],
|
|
18
|
+
queryFn: fetchItems,
|
|
19
|
+
initialData: useData(),
|
|
20
|
+
})
|
|
21
|
+
// @elif swr
|
|
22
|
+
const initialItems = useData()
|
|
23
|
+
const { data: items = initialItems } = useSWR('items', fetchItems, {
|
|
24
|
+
fallbackData: initialItems,
|
|
25
|
+
})
|
|
26
|
+
// @else
|
|
27
|
+
const items = useData()
|
|
28
|
+
// @endif
|
|
29
|
+
return (
|
|
30
|
+
<Flex gap={2}>
|
|
31
|
+
<Typography variant="h2">Items</Typography>
|
|
32
|
+
<Typography color="secondary">
|
|
33
|
+
{/* @if ssr */}
|
|
34
|
+
Sample data from src/data/items.js, which this page's +data reads on each request.
|
|
35
|
+
{/* @else */}
|
|
36
|
+
Sample data from src/data/items.js, which this page's +data reads at build time.
|
|
37
|
+
{/* @endif */}
|
|
38
|
+
</Typography>
|
|
39
|
+
<Flex gap={1}>
|
|
40
|
+
{items.map((item) => (
|
|
41
|
+
<Flex key={item.id} flexDirection="row" alignItems="center" gap={2}>
|
|
42
|
+
<Link href={`/items/${item.id}`}>{item.title}</Link>
|
|
43
|
+
<StatusChip status={item.status} />
|
|
44
|
+
</Flex>
|
|
45
|
+
))}
|
|
46
|
+
</Flex>
|
|
47
|
+
</Flex>
|
|
48
|
+
)
|
|
49
|
+
}
|