@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.
Files changed (250) hide show
  1. package/dist/bin.mjs +2 -15
  2. package/dist/index.d.mts +4 -4
  3. package/dist/index.mjs +1 -1
  4. package/dist/{io-Bybgct-f.mjs → io-CqI2BTaP.mjs} +430 -1032
  5. package/package.json +14 -5
  6. package/templates/astro/js/base/README.md +93 -0
  7. package/templates/astro/js/base/_gitignore +5 -0
  8. package/templates/astro/js/base/astro.config.mjs +23 -0
  9. package/templates/astro/js/base/src/components/About.jsx +24 -0
  10. package/templates/astro/js/base/src/components/Counter.jsx +26 -0
  11. package/templates/astro/js/base/src/components/Greeting.jsx +60 -0
  12. package/templates/astro/js/base/src/components/Header.jsx +99 -0
  13. package/templates/astro/js/base/src/components/Home.jsx +32 -0
  14. package/templates/astro/js/base/src/components/Home.test.jsx +39 -0
  15. package/templates/astro/js/base/src/components/NotFound.jsx +17 -0
  16. package/templates/astro/js/base/src/data/api.js +84 -0
  17. package/templates/astro/js/base/src/layouts/Layout.astro +52 -0
  18. package/templates/astro/js/base/src/pages/404.astro +12 -0
  19. package/templates/astro/js/base/src/pages/about.astro +12 -0
  20. package/templates/astro/js/base/src/pages/index.astro +23 -0
  21. package/templates/astro/js/base/src/theme/Island.jsx +89 -0
  22. package/templates/astro/js/base/src/theme/scheme.js +32 -0
  23. package/templates/astro/js/base/vitest.config.js +12 -0
  24. package/templates/astro/js/sample-data/src/components/ItemDetails.jsx +64 -0
  25. package/templates/astro/js/sample-data/src/components/ItemList.jsx +100 -0
  26. package/templates/astro/js/sample-data/src/components/StatusChip.jsx +8 -0
  27. package/templates/astro/js/sample-data/src/data/items.js +65 -0
  28. package/templates/astro/js/sample-data/src/pages/items/[id].astro +37 -0
  29. package/templates/astro/js/sample-data/src/pages/items/index.astro +20 -0
  30. package/templates/astro/js/with/jotai/src/components/Counter.jsx +26 -0
  31. package/templates/astro/js/with/jotai/src/state/counter.js +4 -0
  32. package/templates/astro/js/with/msw/_env +3 -0
  33. package/templates/astro/js/with/msw/src/mocks/browser.js +5 -0
  34. package/templates/astro/js/with/msw/src/mocks/handlers.js +24 -0
  35. package/templates/astro/js/with/msw/src/mocks/server.js +5 -0
  36. package/templates/astro/js/with/msw/src/mocks/setupTests.js +7 -0
  37. package/templates/astro/js/with/msw/src/mocks/start.js +14 -0
  38. package/templates/astro/js/with/react-hook-form/src/components/Form.jsx +313 -0
  39. package/templates/astro/js/with/react-hook-form/src/pages/form.astro +8 -0
  40. package/templates/astro/js/with/redux-toolkit/src/components/Counter.jsx +27 -0
  41. package/templates/astro/js/with/redux-toolkit/src/state/store.js +18 -0
  42. package/templates/astro/js/with/tanstack-query/src/data/queryClient.js +13 -0
  43. package/templates/astro/js/with/zustand/src/components/Counter.jsx +24 -0
  44. package/templates/astro/js/with/zustand/src/state/counter.js +14 -0
  45. package/templates/astro/ts/base/README.md +93 -0
  46. package/templates/astro/ts/base/_gitignore +5 -0
  47. package/templates/astro/ts/base/astro.config.mjs +23 -0
  48. package/templates/astro/ts/base/src/components/About.tsx +24 -0
  49. package/templates/astro/ts/base/src/components/Counter.tsx +26 -0
  50. package/templates/astro/ts/base/src/components/Greeting.tsx +61 -0
  51. package/templates/astro/ts/base/src/components/Header.tsx +99 -0
  52. package/templates/astro/ts/base/src/components/Home.test.tsx +39 -0
  53. package/templates/astro/ts/base/src/components/Home.tsx +33 -0
  54. package/templates/astro/ts/base/src/components/NotFound.tsx +17 -0
  55. package/templates/astro/ts/base/src/data/api.ts +92 -0
  56. package/templates/astro/ts/base/src/layouts/Layout.astro +52 -0
  57. package/templates/astro/ts/base/src/pages/404.astro +12 -0
  58. package/templates/astro/ts/base/src/pages/about.astro +12 -0
  59. package/templates/astro/ts/base/src/pages/index.astro +23 -0
  60. package/templates/astro/ts/base/src/theme/Island.tsx +90 -0
  61. package/templates/astro/ts/base/src/theme/scheme.ts +34 -0
  62. package/templates/astro/ts/base/tsconfig.json +9 -0
  63. package/templates/astro/ts/base/vitest.config.ts +12 -0
  64. package/templates/astro/ts/sample-data/src/components/ItemDetails.tsx +65 -0
  65. package/templates/astro/ts/sample-data/src/components/ItemList.tsx +109 -0
  66. package/templates/astro/ts/sample-data/src/components/StatusChip.tsx +9 -0
  67. package/templates/astro/ts/sample-data/src/data/items.ts +71 -0
  68. package/templates/astro/ts/sample-data/src/pages/items/[id].astro +39 -0
  69. package/templates/astro/ts/sample-data/src/pages/items/index.astro +20 -0
  70. package/templates/astro/ts/with/jotai/src/components/Counter.tsx +26 -0
  71. package/templates/astro/ts/with/jotai/src/state/counter.ts +4 -0
  72. package/templates/astro/ts/with/msw/_env +3 -0
  73. package/templates/astro/ts/with/msw/src/mocks/browser.ts +5 -0
  74. package/templates/astro/ts/with/msw/src/mocks/handlers.ts +24 -0
  75. package/templates/astro/ts/with/msw/src/mocks/server.ts +5 -0
  76. package/templates/astro/ts/with/msw/src/mocks/setupTests.ts +7 -0
  77. package/templates/astro/ts/with/msw/src/mocks/start.ts +14 -0
  78. package/templates/astro/ts/with/react-hook-form/src/components/Form.tsx +317 -0
  79. package/templates/astro/ts/with/react-hook-form/src/pages/form.astro +8 -0
  80. package/templates/astro/ts/with/redux-toolkit/src/components/Counter.tsx +27 -0
  81. package/templates/astro/ts/with/redux-toolkit/src/state/store.ts +19 -0
  82. package/templates/astro/ts/with/tanstack-query/src/data/queryClient.ts +13 -0
  83. package/templates/astro/ts/with/zustand/src/components/Counter.tsx +24 -0
  84. package/templates/astro/ts/with/zustand/src/state/counter.ts +19 -0
  85. package/templates/react-router/js/base/README.md +67 -0
  86. package/templates/react-router/js/base/_gitignore +4 -0
  87. package/templates/react-router/js/base/index.html +12 -0
  88. package/templates/react-router/js/base/src/components/RouterLink.jsx +12 -0
  89. package/templates/react-router/js/base/src/data/api.js +76 -0
  90. package/templates/react-router/js/base/src/main.jsx +38 -0
  91. package/templates/react-router/js/base/src/pages/ErrorPage.jsx +14 -0
  92. package/templates/react-router/js/base/src/pages/Layout.jsx +141 -0
  93. package/templates/react-router/js/base/src/pages/about/Page.jsx +14 -0
  94. package/templates/react-router/js/base/src/pages/index/Counter.jsx +18 -0
  95. package/templates/react-router/js/base/src/pages/index/Greeting.jsx +48 -0
  96. package/templates/react-router/js/base/src/pages/index/Page.jsx +29 -0
  97. package/templates/react-router/js/base/src/pages/index/Page.test.jsx +61 -0
  98. package/templates/react-router/js/base/src/routes.jsx +46 -0
  99. package/templates/react-router/js/base/vite.config.js +13 -0
  100. package/templates/react-router/js/base/vitest.config.js +13 -0
  101. package/templates/react-router/js/sample-data/src/data/items.js +55 -0
  102. package/templates/react-router/js/sample-data/src/pages/item/Page.jsx +49 -0
  103. package/templates/react-router/js/sample-data/src/pages/item/loader.js +14 -0
  104. package/templates/react-router/js/sample-data/src/pages/items/Page.jsx +48 -0
  105. package/templates/react-router/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  106. package/templates/react-router/js/sample-data/src/pages/items/loader.js +11 -0
  107. package/templates/react-router/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  108. package/templates/react-router/js/with/jotai/src/state/counter.js +4 -0
  109. package/templates/react-router/js/with/jotai/src/state/scheme.js +4 -0
  110. package/templates/react-router/js/with/msw/_env +3 -0
  111. package/templates/react-router/js/with/msw/src/mocks/browser.js +5 -0
  112. package/templates/react-router/js/with/msw/src/mocks/handlers.js +24 -0
  113. package/templates/react-router/js/with/msw/src/mocks/server.js +5 -0
  114. package/templates/react-router/js/with/msw/src/mocks/setupTests.js +7 -0
  115. package/templates/react-router/js/with/msw/src/mocks/start.js +10 -0
  116. package/templates/react-router/js/with/react-hook-form/src/pages/form/Page.jsx +294 -0
  117. package/templates/react-router/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  118. package/templates/react-router/js/with/redux-toolkit/src/state/store.js +27 -0
  119. package/templates/react-router/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  120. package/templates/react-router/js/with/zustand/src/state/counter.js +14 -0
  121. package/templates/react-router/js/with/zustand/src/state/scheme.js +14 -0
  122. package/templates/react-router/ts/base/README.md +67 -0
  123. package/templates/react-router/ts/base/_gitignore +4 -0
  124. package/templates/react-router/ts/base/index.html +12 -0
  125. package/templates/react-router/ts/base/src/components/RouterLink.tsx +12 -0
  126. package/templates/react-router/ts/base/src/data/api.ts +84 -0
  127. package/templates/react-router/ts/base/src/main.tsx +38 -0
  128. package/templates/react-router/ts/base/src/pages/ErrorPage.tsx +14 -0
  129. package/templates/react-router/ts/base/src/pages/Layout.tsx +141 -0
  130. package/templates/react-router/ts/base/src/pages/about/Page.tsx +14 -0
  131. package/templates/react-router/ts/base/src/pages/index/Counter.tsx +18 -0
  132. package/templates/react-router/ts/base/src/pages/index/Greeting.tsx +49 -0
  133. package/templates/react-router/ts/base/src/pages/index/Page.test.tsx +61 -0
  134. package/templates/react-router/ts/base/src/pages/index/Page.tsx +29 -0
  135. package/templates/react-router/ts/base/src/routes.tsx +47 -0
  136. package/templates/react-router/ts/base/tsconfig.json +18 -0
  137. package/templates/react-router/ts/base/vite.config.ts +13 -0
  138. package/templates/react-router/ts/base/vitest.config.ts +13 -0
  139. package/templates/react-router/ts/sample-data/src/data/items.ts +61 -0
  140. package/templates/react-router/ts/sample-data/src/pages/item/Page.tsx +50 -0
  141. package/templates/react-router/ts/sample-data/src/pages/item/loader.ts +14 -0
  142. package/templates/react-router/ts/sample-data/src/pages/items/Page.tsx +49 -0
  143. package/templates/react-router/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  144. package/templates/react-router/ts/sample-data/src/pages/items/loader.ts +11 -0
  145. package/templates/react-router/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  146. package/templates/react-router/ts/with/jotai/src/state/counter.ts +4 -0
  147. package/templates/react-router/ts/with/jotai/src/state/scheme.ts +4 -0
  148. package/templates/react-router/ts/with/msw/_env +3 -0
  149. package/templates/react-router/ts/with/msw/src/mocks/browser.ts +5 -0
  150. package/templates/react-router/ts/with/msw/src/mocks/handlers.ts +24 -0
  151. package/templates/react-router/ts/with/msw/src/mocks/server.ts +5 -0
  152. package/templates/react-router/ts/with/msw/src/mocks/setupTests.ts +7 -0
  153. package/templates/react-router/ts/with/msw/src/mocks/start.ts +10 -0
  154. package/templates/react-router/ts/with/react-hook-form/src/pages/form/Page.tsx +298 -0
  155. package/templates/react-router/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  156. package/templates/react-router/ts/with/redux-toolkit/src/state/store.ts +29 -0
  157. package/templates/react-router/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  158. package/templates/react-router/ts/with/zustand/src/state/counter.ts +19 -0
  159. package/templates/react-router/ts/with/zustand/src/state/scheme.ts +19 -0
  160. package/templates/templates.md +67 -0
  161. package/templates/vike/js/base/README.md +83 -0
  162. package/templates/vike/js/base/_gitignore +4 -0
  163. package/templates/vike/js/base/src/data/api.js +76 -0
  164. package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
  165. package/templates/vike/js/base/src/pages/+config.js +12 -0
  166. package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
  167. package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
  168. package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
  169. package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
  170. package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
  171. package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
  172. package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
  173. package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
  174. package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
  175. package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
  176. package/templates/vike/js/base/vite.config.js +14 -0
  177. package/templates/vike/js/base/vitest.config.js +13 -0
  178. package/templates/vike/js/sample-data/src/data/items.js +58 -0
  179. package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
  180. package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
  181. package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
  182. package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
  183. package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
  184. package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  185. package/templates/vike/js/ssg/src/pages/+config.js +11 -0
  186. package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
  187. package/templates/vike/js/ssr/src/pages/+config.js +12 -0
  188. package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
  189. package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
  190. package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  191. package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
  192. package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
  193. package/templates/vike/js/with/msw/_env +3 -0
  194. package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
  195. package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
  196. package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
  197. package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
  198. package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
  199. package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
  200. package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  201. package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
  202. package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  203. package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
  204. package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
  205. package/templates/vike/ts/base/README.md +83 -0
  206. package/templates/vike/ts/base/_gitignore +4 -0
  207. package/templates/vike/ts/base/src/data/api.ts +84 -0
  208. package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
  209. package/templates/vike/ts/base/src/pages/+config.ts +14 -0
  210. package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
  211. package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
  212. package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
  213. package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
  214. package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
  215. package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
  216. package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
  217. package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
  218. package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
  219. package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
  220. package/templates/vike/ts/base/src/vike.d.ts +20 -0
  221. package/templates/vike/ts/base/tsconfig.json +18 -0
  222. package/templates/vike/ts/base/vite.config.ts +14 -0
  223. package/templates/vike/ts/base/vitest.config.ts +13 -0
  224. package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
  225. package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
  226. package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
  227. package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
  228. package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
  229. package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
  230. package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  231. package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
  232. package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
  233. package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
  234. package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
  235. package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
  236. package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  237. package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
  238. package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
  239. package/templates/vike/ts/with/msw/_env +3 -0
  240. package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
  241. package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
  242. package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
  243. package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
  244. package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
  245. package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
  246. package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  247. package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
  248. package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  249. package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
  250. package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
@@ -0,0 +1,99 @@
1
+ // @if !ssg
2
+ import { Button } from '@soroush.tech/design-system/Button'
3
+ // @endif
4
+ import { Flex } from '@soroush.tech/design-system/Flex'
5
+ import { Link } from '@soroush.tech/design-system/Link'
6
+ import { Typography } from '@soroush.tech/design-system/Typography'
7
+ import { Providers } from '../theme/Providers'
8
+ // @if !ssg
9
+ import { setScheme, useScheme } from '../theme/scheme'
10
+ // @endif
11
+
12
+ /**
13
+ // @if ssg
14
+ * The header of every page. Its Providers draw the base styles, once a
15
+ * page.
16
+ // @else
17
+ * 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.
19
+ // @endif
20
+ */
21
+ // @if ssg
22
+ export default function Header() {
23
+ return (
24
+ <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>
52
+ </Providers>
53
+ )
54
+ }
55
+ // @else
56
+ export default function Header() {
57
+ const scheme = useScheme()
58
+ const otherScheme = scheme === 'light' ? 'dark' : 'light'
59
+ return (
60
+ <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>
96
+ </Providers>
97
+ )
98
+ }
99
+ // @endif
@@ -0,0 +1,39 @@
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
+ import { afterEach, describe, expect, it } from 'vitest'
7
+ // @if !ssg
8
+ import Counter from './Counter'
9
+ // @endif
10
+ // @if msw
11
+ import Greeting from './Greeting'
12
+ // @endif
13
+ import Home from './Home'
14
+
15
+ // Each island renders inside its own providers, so a test renders it as it is.
16
+ describe('the home page', () => {
17
+ // Vitest has no globals here, so Testing Library cannot clean up on its own.
18
+ afterEach(cleanup)
19
+
20
+ it('shows the app title', () => {
21
+ render(<Home />)
22
+ expect(screen.getByRole('heading', { name: '__TITLE_STRING__' })).toBeTruthy()
23
+ })
24
+ // @if !ssg
25
+
26
+ it('counts each press of its button', () => {
27
+ render(<Counter />)
28
+ fireEvent.click(screen.getByRole('button', { name: 'Count' }))
29
+ expect(screen.getByText('Count: 1')).toBeTruthy()
30
+ })
31
+ // @endif
32
+ // @if msw
33
+
34
+ it('shows the greeting the mock API answers', async () => {
35
+ render(<Greeting />)
36
+ expect(await screen.findByText('Hello from the mock API')).toBeTruthy()
37
+ })
38
+ // @endif
39
+ })
@@ -0,0 +1,33 @@
1
+ import type { ReactNode } from 'react'
2
+ import { Button } from '@soroush.tech/design-system/Button'
3
+ import { Flex } from '@soroush.tech/design-system/Flex'
4
+ import { Typography } from '@soroush.tech/design-system/Typography'
5
+ import { withIsland } from '../theme/Island'
6
+
7
+ // @if ssg
8
+ /** The home page. */
9
+ // @elif tanstack-query || swr || msw
10
+ /** The home page. Its children are the islands of its greeting and its counter. */
11
+ // @else
12
+ /** The home page. Its child is the island of its counter. */
13
+ // @endif
14
+ function Home({ children }: { readonly children?: ReactNode }) {
15
+ return (
16
+ <Flex gap={2} alignItems="flex-start" px={3} py={4}>
17
+ <Typography variant="h2">__TITLE__</Typography>
18
+ <Typography color="secondary">
19
+ An Astro app on the design system. Edit src/components/Home.tsx, and make the themes your
20
+ own in src/theme/themes.ts.
21
+ </Typography>
22
+ {children}
23
+ <Flex flexDirection="row" gap={1}>
24
+ <Button href="https://docs.soroush.tech">Components</Button>
25
+ <Button href="https://astro.build" variant="outlined">
26
+ Astro
27
+ </Button>
28
+ </Flex>
29
+ </Flex>
30
+ )
31
+ }
32
+
33
+ export default withIsland(Home)
@@ -0,0 +1,17 @@
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
+ import { withIsland } from '../theme/Island'
5
+
6
+ /** Shown for a page that does not exist. */
7
+ function NotFound() {
8
+ return (
9
+ <Flex gap={2} alignItems="flex-start" px={3} py={4}>
10
+ <Typography variant="h2">Page not found</Typography>
11
+ <Typography color="secondary">This page does not exist.</Typography>
12
+ <Link href="/">Back home</Link>
13
+ </Flex>
14
+ )
15
+ }
16
+
17
+ export default withIsland(NotFound)
@@ -0,0 +1,92 @@
1
+ // @if tanstack-query || swr || msw
2
+ // @if ts && sample-data && msw && (tanstack-query || swr)
3
+ import type { Item } from './items'
4
+
5
+ // @elif sample-data && !msw && (tanstack-query || swr)
6
+ import { items } from './items'
7
+
8
+ // @endif
9
+ // @if msw
10
+ import { mocks } from '../mocks/start'
11
+
12
+ // @endif
13
+ // @if ts
14
+ /** What the API says to the app. */
15
+ export interface Greeting {
16
+ message: string
17
+ }
18
+ // @if react-hook-form
19
+
20
+ /** What the form sends. */
21
+ export interface Message {
22
+ name: string
23
+ email: string
24
+ }
25
+ // @endif
26
+
27
+ // @endif
28
+ // @if msw
29
+ /** A greeting, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
30
+ export async function fetchGreeting(): Promise<Greeting> {
31
+ await mocks
32
+ const response = await fetch('/api/greeting')
33
+ if (!response.ok) throw new Error(`GET /api/greeting answered ${response.status}`)
34
+ return response.json()
35
+ }
36
+ // @else
37
+ /** A greeting, as an API would answer: make it fetch from yours. */
38
+ export function fetchGreeting(): Promise<Greeting> {
39
+ return Promise.resolve({ message: 'Hello from src/data/api: make it fetch from your API.' })
40
+ }
41
+ // @endif
42
+ // @if react-hook-form && msw
43
+
44
+ /** Sends the form's values to the API, which answers what it made of them. */
45
+ export async function sendMessage(message: Message): Promise<Greeting> {
46
+ await mocks
47
+ const response = await fetch('/api/messages', {
48
+ method: 'POST',
49
+ headers: { 'Content-Type': 'application/json' },
50
+ body: JSON.stringify(message),
51
+ })
52
+ if (!response.ok) throw new Error(`POST /api/messages answered ${response.status}`)
53
+ return response.json()
54
+ }
55
+ // @elif react-hook-form
56
+
57
+ /** Sends the form's values, as an API would take them: make it post to yours. */
58
+ export function sendMessage(message: Message): Promise<Greeting> {
59
+ return Promise.resolve({ message: `Thanks, ${message.name}: your message was sent.` })
60
+ }
61
+ // @endif
62
+ // @if sample-data && msw && (tanstack-query || swr)
63
+
64
+ /** The items, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
65
+ export async function fetchItems(): Promise<Pick<Item, 'id' | 'title' | 'status'>[]> {
66
+ await mocks
67
+ const response = await fetch('/api/items')
68
+ if (!response.ok) throw new Error(`GET /api/items answered ${response.status}`)
69
+ return response.json()
70
+ }
71
+
72
+ /** One item, from the API. */
73
+ export async function fetchItem(id: string): Promise<Item> {
74
+ await mocks
75
+ const response = await fetch(`/api/items/${id}`)
76
+ if (!response.ok) throw new Error(`GET /api/items/${id} answered ${response.status}`)
77
+ return response.json()
78
+ }
79
+ // @elif sample-data && (tanstack-query || swr)
80
+
81
+ /** The items, as an API would answer: make it fetch from yours. */
82
+ export function fetchItems() {
83
+ return Promise.resolve(items.map(({ id, title, status }) => ({ id, title, status })))
84
+ }
85
+
86
+ /** One item, as an API would answer: make it fetch from yours. */
87
+ export function fetchItem(id: string) {
88
+ const item = items.find((candidate) => candidate.id === id)
89
+ return item ? Promise.resolve(item) : Promise.reject(new Error(`There is no item ${id}.`))
90
+ }
91
+ // @endif
92
+ // @endif
@@ -0,0 +1,52 @@
1
+ ---
2
+ // @if !ssg
3
+ import { ClientRouter } from 'astro:transitions'
4
+ // @endif
5
+ import Header from '../components/Header'
6
+ ---
7
+
8
+ <html lang="en">
9
+ <head>
10
+ <meta charset="UTF-8" />
11
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
12
+ <title>__TITLE__</title>
13
+ {/* @if !ssg */}
14
+ <ClientRouter />
15
+ {/* @endif */}
16
+ </head>
17
+ <body>
18
+ {/* @if ssg */}
19
+ <Header />
20
+ {/* @else */}
21
+ <Header client:load transition:persist />
22
+ {/* @endif */}
23
+ <main>
24
+ <slot />
25
+ </main>
26
+ {/* @if !ssg */}
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.
33
+ document.addEventListener('astro:before-swap', ({ newDocument }) => {
34
+ const kept = new Set()
35
+ document.head.querySelectorAll('style[data-emotion]').forEach((style, index) => {
36
+ const id = `soroush-styles-${index}`
37
+ style.setAttribute('data-astro-transition-persist', id)
38
+ const placeholder = newDocument.createElement('style')
39
+ placeholder.setAttribute('data-astro-transition-persist', id)
40
+ newDocument.head.append(placeholder)
41
+ kept.add(style.getAttribute('data-emotion'))
42
+ })
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)
47
+ })
48
+ })
49
+ </script>
50
+ {/* @endif */}
51
+ </body>
52
+ </html>
@@ -0,0 +1,12 @@
1
+ ---
2
+ import NotFound from '../components/NotFound'
3
+ import Layout from '../layouts/Layout.astro'
4
+ ---
5
+
6
+ <Layout>
7
+ {/* @if ssg */}
8
+ <NotFound />
9
+ {/* @else */}
10
+ <NotFound client:load />
11
+ {/* @endif */}
12
+ </Layout>
@@ -0,0 +1,12 @@
1
+ ---
2
+ import About from '../components/About'
3
+ import Layout from '../layouts/Layout.astro'
4
+ ---
5
+
6
+ <Layout>
7
+ {/* @if ssg */}
8
+ <About />
9
+ {/* @else */}
10
+ <About client:load />
11
+ {/* @endif */}
12
+ </Layout>
@@ -0,0 +1,23 @@
1
+ ---
2
+ // @if !ssg
3
+ import Counter from '../components/Counter'
4
+ // @endif
5
+ // @if tanstack-query || swr || msw
6
+ import Greeting from '../components/Greeting'
7
+ // @endif
8
+ import Home from '../components/Home'
9
+ import Layout from '../layouts/Layout.astro'
10
+ ---
11
+
12
+ <Layout>
13
+ {/* @if ssg */}
14
+ <Home />
15
+ {/* @else */}
16
+ <Home client:load>
17
+ {/* @if tanstack-query || swr || msw */}
18
+ <Greeting client:only="react" />
19
+ {/* @endif */}
20
+ <Counter client:only="react" />
21
+ </Home>
22
+ {/* @endif */}
23
+ </Layout>
@@ -0,0 +1,90 @@
1
+ // @if tanstack-query
2
+ import { useState, type ComponentType, type ReactNode } from 'react'
3
+ import { QueryClientProvider } from '@tanstack/react-query'
4
+ // @else
5
+ import type { ComponentType, ReactNode } from 'react'
6
+ // @endif
7
+ // @if redux-toolkit
8
+ import { Provider as StoreProvider } from 'react-redux'
9
+ // @endif
10
+ import { ThemeProvider } from '@soroush.tech/design-system/theme'
11
+ // @if tanstack-query
12
+ import { getQueryClient } from '../data/queryClient'
13
+ // @endif
14
+ // @if redux-toolkit
15
+ import { store } from '../state/store'
16
+ // @endif
17
+ // @if !ssg
18
+ import { useScheme } from './scheme'
19
+ // @endif
20
+ import themes from './themes'
21
+
22
+ /**
23
+ // @if tanstack-query && redux-toolkit
24
+ * What every island renders inside: its theme, the query client and the Redux store. Astro
25
+ * renders each island as a React root of its own, so each one renders inside Island, and in the
26
+ * browser they share one client and one store; the header's Providers draw the base styles.
27
+ // @elif tanstack-query
28
+ * What every island renders inside: its theme and the query client. Astro renders each island as
29
+ * a React root of its own, so each one renders inside Island, and in the browser they share one
30
+ * client; the header's Providers draw the base styles.
31
+ // @elif redux-toolkit
32
+ * What every island renders inside: its theme and the Redux store. Astro renders each island as a
33
+ * React root of its own, so each one renders inside Island, and they share one store; the
34
+ * header's Providers draw the base styles.
35
+ // @else
36
+ * What every island renders inside: its theme. Astro renders each island as a React root of its
37
+ * own, so each one renders inside Island; the header's Providers draw the base styles, once a page.
38
+ // @endif
39
+ */
40
+ // @if ssg
41
+ function Island({ children }: { readonly children: ReactNode }) {
42
+ return <ThemeProvider theme={themes.__SCHEME__}>{children}</ThemeProvider>
43
+ }
44
+ // @elif tanstack-query && redux-toolkit
45
+ function Island({ children }: { readonly children: ReactNode }) {
46
+ const [queryClient] = useState(getQueryClient)
47
+ return (
48
+ <QueryClientProvider client={queryClient}>
49
+ <StoreProvider store={store}>
50
+ <ThemeProvider theme={themes[useScheme()]}>{children}</ThemeProvider>
51
+ </StoreProvider>
52
+ </QueryClientProvider>
53
+ )
54
+ }
55
+ // @elif tanstack-query
56
+ function Island({ children }: { readonly children: ReactNode }) {
57
+ const [queryClient] = useState(getQueryClient)
58
+ return (
59
+ <QueryClientProvider client={queryClient}>
60
+ <ThemeProvider theme={themes[useScheme()]}>{children}</ThemeProvider>
61
+ </QueryClientProvider>
62
+ )
63
+ }
64
+ // @elif redux-toolkit
65
+ function Island({ children }: { readonly children: ReactNode }) {
66
+ return (
67
+ <StoreProvider store={store}>
68
+ <ThemeProvider theme={themes[useScheme()]}>{children}</ThemeProvider>
69
+ </StoreProvider>
70
+ )
71
+ }
72
+ // @else
73
+ function Island({ children }: { readonly children: ReactNode }) {
74
+ return <ThemeProvider theme={themes[useScheme()]}>{children}</ThemeProvider>
75
+ }
76
+ // @endif
77
+
78
+ /**
79
+ * `Component` as an island: rendered inside Island, so its hooks find what Island provides. Every
80
+ * island of the app is exported this way.
81
+ */
82
+ export function withIsland<Props extends object>(Component: ComponentType<Props>) {
83
+ return function InIsland(props: Props) {
84
+ return (
85
+ <Island>
86
+ <Component {...props} />
87
+ </Island>
88
+ )
89
+ }
90
+ }
@@ -0,0 +1,34 @@
1
+ // @if !ssg
2
+ import { useSyncExternalStore } from 'react'
3
+
4
+ type Scheme = 'light' | 'dark'
5
+
6
+ let current: Scheme = '__SCHEME__'
7
+ const listeners = new Set<() => void>()
8
+
9
+ /** Switches the color scheme of every island, on this page and the pages the app moves to. */
10
+ export function setScheme(scheme: Scheme) {
11
+ current = scheme
12
+ for (const listener of listeners) listener()
13
+ }
14
+
15
+ function subscribe(listener: () => void) {
16
+ listeners.add(listener)
17
+ return () => {
18
+ listeners.delete(listener)
19
+ }
20
+ }
21
+
22
+ /**
23
+ * The color scheme every island draws in. Each island is a React root of its own, so they share
24
+ * it here, not through context. An island first draws the default, as the server did, so it
25
+ * hydrates on the HTML it was given, then the scheme picked.
26
+ */
27
+ export function useScheme(): Scheme {
28
+ return useSyncExternalStore(
29
+ subscribe,
30
+ () => current,
31
+ () => '__SCHEME__'
32
+ )
33
+ }
34
+ // @endif
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "astro/tsconfigs/strict",
3
+ "include": [".astro/types.d.ts", "**/*"],
4
+ "exclude": ["dist"],
5
+ "compilerOptions": {
6
+ "jsx": "react-jsx",
7
+ "jsxImportSource": "react"
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="vitest/config" />
2
+ import { getViteConfig } from 'astro/config'
3
+
4
+ // The tests render components in jsdom, through the app's own Vite settings, as Astro builds them.
5
+ export default getViteConfig({
6
+ // @if msw
7
+ // The mock API answers the tests' requests, from Node, as it answers the app's in the browser.
8
+ test: { environment: 'jsdom', setupFiles: ['./src/mocks/setupTests.ts'] },
9
+ // @else
10
+ test: { environment: 'jsdom' },
11
+ // @endif
12
+ })
@@ -0,0 +1,65 @@
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 type { Item } from '../data/items'
12
+ import { withIsland } from '../theme/Island'
13
+ import { StatusChip } from './StatusChip'
14
+
15
+ // @if ssr
16
+ /** One item, as src/pages/items/[id].astro reads it on each request. */
17
+ // @else
18
+ /** One item, as src/pages/items/[id].astro reads it at build time. */
19
+ // @endif
20
+ // @if tanstack-query
21
+ function ItemDetails({ item: initialItem }: { readonly item: Item }) {
22
+ const { data: item } = useQuery({
23
+ queryKey: ['items', initialItem.id],
24
+ queryFn: () => fetchItem(initialItem.id),
25
+ initialData: initialItem,
26
+ })
27
+ return (
28
+ <Flex gap={2} alignItems="flex-start" px={3} py={4}>
29
+ <Typography variant="h2">{item.title}</Typography>
30
+ <StatusChip status={item.status} />
31
+ <Typography color="secondary">{item.summary}</Typography>
32
+ <Link href="/items">All items</Link>
33
+ </Flex>
34
+ )
35
+ }
36
+ // @elif swr
37
+ function ItemDetails({ item: initialItem }: { readonly item: Item }) {
38
+ const { data: item = initialItem } = useSWR(
39
+ ['items', initialItem.id],
40
+ () => fetchItem(initialItem.id),
41
+ { fallbackData: initialItem }
42
+ )
43
+ return (
44
+ <Flex gap={2} alignItems="flex-start" px={3} py={4}>
45
+ <Typography variant="h2">{item.title}</Typography>
46
+ <StatusChip status={item.status} />
47
+ <Typography color="secondary">{item.summary}</Typography>
48
+ <Link href="/items">All items</Link>
49
+ </Flex>
50
+ )
51
+ }
52
+ // @else
53
+ function ItemDetails({ item }: { readonly item: Item }) {
54
+ return (
55
+ <Flex gap={2} alignItems="flex-start" px={3} py={4}>
56
+ <Typography variant="h2">{item.title}</Typography>
57
+ <StatusChip status={item.status} />
58
+ <Typography color="secondary">{item.summary}</Typography>
59
+ <Link href="/items">All items</Link>
60
+ </Flex>
61
+ )
62
+ }
63
+ // @endif
64
+
65
+ export default withIsland(ItemDetails)