@soroush.design/cli 0.2.0-alpha.3 → 0.2.0-alpha.4

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 (183) hide show
  1. package/dist/bin.mjs +1 -1
  2. package/dist/index.d.mts +4 -4
  3. package/dist/index.mjs +1 -1
  4. package/dist/{io-Bybgct-f.mjs → io-C_8_JerZ.mjs} +368 -1039
  5. package/package.json +13 -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/templates.md +66 -0
  86. package/templates/vike/js/base/README.md +87 -0
  87. package/templates/vike/js/base/_gitignore +4 -0
  88. package/templates/vike/js/base/src/data/api.js +76 -0
  89. package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
  90. package/templates/vike/js/base/src/pages/+config.js +12 -0
  91. package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
  92. package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
  93. package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
  94. package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
  95. package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
  96. package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
  97. package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
  98. package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
  99. package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
  100. package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
  101. package/templates/vike/js/base/vite.config.js +14 -0
  102. package/templates/vike/js/base/vitest.config.js +13 -0
  103. package/templates/vike/js/sample-data/src/data/items.js +58 -0
  104. package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
  105. package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
  106. package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
  107. package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
  108. package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
  109. package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  110. package/templates/vike/js/spa/src/pages/+config.js +12 -0
  111. package/templates/vike/js/spa/src/pages/+onRenderClient.jsx +25 -0
  112. package/templates/vike/js/spa/src/pages/+onRenderHtml.jsx +16 -0
  113. package/templates/vike/js/spa/src/pages/about/+Page.jsx +14 -0
  114. package/templates/vike/js/ssg/src/pages/+config.js +11 -0
  115. package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
  116. package/templates/vike/js/ssr/src/pages/+config.js +12 -0
  117. package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
  118. package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
  119. package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  120. package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
  121. package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
  122. package/templates/vike/js/with/msw/_env +3 -0
  123. package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
  124. package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
  125. package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
  126. package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
  127. package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
  128. package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
  129. package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  130. package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
  131. package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  132. package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
  133. package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
  134. package/templates/vike/ts/base/README.md +87 -0
  135. package/templates/vike/ts/base/_gitignore +4 -0
  136. package/templates/vike/ts/base/src/data/api.ts +84 -0
  137. package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
  138. package/templates/vike/ts/base/src/pages/+config.ts +14 -0
  139. package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
  140. package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
  141. package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
  142. package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
  143. package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
  144. package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
  145. package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
  146. package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
  147. package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
  148. package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
  149. package/templates/vike/ts/base/src/vike.d.ts +20 -0
  150. package/templates/vike/ts/base/tsconfig.json +18 -0
  151. package/templates/vike/ts/base/vite.config.ts +14 -0
  152. package/templates/vike/ts/base/vitest.config.ts +13 -0
  153. package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
  154. package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
  155. package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
  156. package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
  157. package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
  158. package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
  159. package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  160. package/templates/vike/ts/spa/src/pages/+config.ts +14 -0
  161. package/templates/vike/ts/spa/src/pages/+onRenderClient.tsx +27 -0
  162. package/templates/vike/ts/spa/src/pages/+onRenderHtml.tsx +17 -0
  163. package/templates/vike/ts/spa/src/pages/about/+Page.tsx +14 -0
  164. package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
  165. package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
  166. package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
  167. package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
  168. package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
  169. package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  170. package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
  171. package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
  172. package/templates/vike/ts/with/msw/_env +3 -0
  173. package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
  174. package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
  175. package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
  176. package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
  177. package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
  178. package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
  179. package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  180. package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
  181. package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  182. package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
  183. package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
@@ -0,0 +1,298 @@
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
+ type Values = z.infer<typeof schema>
28
+
29
+ // @if tanstack-query
30
+ /** A form whose values a Zod schema checks; once they pass, it sends them with a mutation of TanStack Query. */
31
+ export default function Page() {
32
+ const mutation = useMutation({ mutationFn: sendMessage })
33
+ const { control, handleSubmit } = useForm<Values>({
34
+ resolver: zodResolver(schema),
35
+ defaultValues: { name: '', email: '' },
36
+ })
37
+ return (
38
+ <Flex gap={2} alignItems="flex-start">
39
+ <Typography variant="h2">Form</Typography>
40
+ <Typography color="secondary">
41
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
42
+ </Typography>
43
+ <form noValidate onSubmit={handleSubmit((values) => mutation.mutate(values))}>
44
+ <Flex gap={2} alignItems="flex-start">
45
+ <Controller
46
+ name="name"
47
+ control={control}
48
+ render={({ field, fieldState }) => (
49
+ <Flex gap={1}>
50
+ <TextInput
51
+ name={field.name}
52
+ value={field.value}
53
+ onChange={field.onChange}
54
+ placeholder="Name"
55
+ error={fieldState.invalid}
56
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
57
+ />
58
+ <Typography variant="caption" color="error">
59
+ {fieldState.error?.message}
60
+ </Typography>
61
+ </Flex>
62
+ )}
63
+ />
64
+ <Controller
65
+ name="email"
66
+ control={control}
67
+ render={({ field, fieldState }) => (
68
+ <Flex gap={1}>
69
+ <TextInput
70
+ name={field.name}
71
+ value={field.value}
72
+ onChange={field.onChange}
73
+ type="email"
74
+ placeholder="Email"
75
+ error={fieldState.invalid}
76
+ inputProps={{
77
+ 'aria-label': 'Email',
78
+ autoComplete: 'email',
79
+ onBlur: field.onBlur,
80
+ }}
81
+ />
82
+ <Typography variant="caption" color="error">
83
+ {fieldState.error?.message}
84
+ </Typography>
85
+ </Flex>
86
+ )}
87
+ />
88
+ <Button type="submit">Send</Button>
89
+ </Flex>
90
+ </form>
91
+ {mutation.data ? <Typography>{mutation.data.message}</Typography> : null}
92
+ </Flex>
93
+ )
94
+ }
95
+ // @elif swr
96
+ /** A form whose values a Zod schema checks; once they pass, it sends them with SWR's mutation. */
97
+ export default function Page() {
98
+ const { trigger, data } = useSWRMutation('messages', (_key: string, { arg }: { arg: Values }) =>
99
+ sendMessage(arg)
100
+ )
101
+ const { control, handleSubmit } = useForm<Values>({
102
+ resolver: zodResolver(schema),
103
+ defaultValues: { name: '', email: '' },
104
+ })
105
+ return (
106
+ <Flex gap={2} alignItems="flex-start">
107
+ <Typography variant="h2">Form</Typography>
108
+ <Typography color="secondary">
109
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
110
+ </Typography>
111
+ <form noValidate onSubmit={handleSubmit((values) => trigger(values))}>
112
+ <Flex gap={2} alignItems="flex-start">
113
+ <Controller
114
+ name="name"
115
+ control={control}
116
+ render={({ field, fieldState }) => (
117
+ <Flex gap={1}>
118
+ <TextInput
119
+ name={field.name}
120
+ value={field.value}
121
+ onChange={field.onChange}
122
+ placeholder="Name"
123
+ error={fieldState.invalid}
124
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
125
+ />
126
+ <Typography variant="caption" color="error">
127
+ {fieldState.error?.message}
128
+ </Typography>
129
+ </Flex>
130
+ )}
131
+ />
132
+ <Controller
133
+ name="email"
134
+ control={control}
135
+ render={({ field, fieldState }) => (
136
+ <Flex gap={1}>
137
+ <TextInput
138
+ name={field.name}
139
+ value={field.value}
140
+ onChange={field.onChange}
141
+ type="email"
142
+ placeholder="Email"
143
+ error={fieldState.invalid}
144
+ inputProps={{
145
+ 'aria-label': 'Email',
146
+ autoComplete: 'email',
147
+ onBlur: field.onBlur,
148
+ }}
149
+ />
150
+ <Typography variant="caption" color="error">
151
+ {fieldState.error?.message}
152
+ </Typography>
153
+ </Flex>
154
+ )}
155
+ />
156
+ <Button type="submit">Send</Button>
157
+ </Flex>
158
+ </form>
159
+ {data ? <Typography>{data.message}</Typography> : null}
160
+ </Flex>
161
+ )
162
+ }
163
+ // @elif msw
164
+ /** A form whose values a Zod schema checks; once they pass, it sends them to the API. */
165
+ export default function Page() {
166
+ const [answer, setAnswer] = useState<string | null>(null)
167
+ const { control, handleSubmit } = useForm<Values>({
168
+ resolver: zodResolver(schema),
169
+ defaultValues: { name: '', email: '' },
170
+ })
171
+ return (
172
+ <Flex gap={2} alignItems="flex-start">
173
+ <Typography variant="h2">Form</Typography>
174
+ <Typography color="secondary">
175
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
176
+ </Typography>
177
+ <form
178
+ noValidate
179
+ onSubmit={handleSubmit(async (values) => setAnswer((await sendMessage(values)).message))}
180
+ >
181
+ <Flex gap={2} alignItems="flex-start">
182
+ <Controller
183
+ name="name"
184
+ control={control}
185
+ render={({ field, fieldState }) => (
186
+ <Flex gap={1}>
187
+ <TextInput
188
+ name={field.name}
189
+ value={field.value}
190
+ onChange={field.onChange}
191
+ placeholder="Name"
192
+ error={fieldState.invalid}
193
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
194
+ />
195
+ <Typography variant="caption" color="error">
196
+ {fieldState.error?.message}
197
+ </Typography>
198
+ </Flex>
199
+ )}
200
+ />
201
+ <Controller
202
+ name="email"
203
+ control={control}
204
+ render={({ field, fieldState }) => (
205
+ <Flex gap={1}>
206
+ <TextInput
207
+ name={field.name}
208
+ value={field.value}
209
+ onChange={field.onChange}
210
+ type="email"
211
+ placeholder="Email"
212
+ error={fieldState.invalid}
213
+ inputProps={{
214
+ 'aria-label': 'Email',
215
+ autoComplete: 'email',
216
+ onBlur: field.onBlur,
217
+ }}
218
+ />
219
+ <Typography variant="caption" color="error">
220
+ {fieldState.error?.message}
221
+ </Typography>
222
+ </Flex>
223
+ )}
224
+ />
225
+ <Button type="submit">Send</Button>
226
+ </Flex>
227
+ </form>
228
+ {answer ? <Typography>{answer}</Typography> : null}
229
+ </Flex>
230
+ )
231
+ }
232
+ // @else
233
+ /** A form whose values a Zod schema checks; once they pass, it shows them. */
234
+ export default function Page() {
235
+ const [sent, setSent] = useState<Values | null>(null)
236
+ const { control, handleSubmit } = useForm<Values>({
237
+ resolver: zodResolver(schema),
238
+ defaultValues: { name: '', email: '' },
239
+ })
240
+ return (
241
+ <Flex gap={2} alignItems="flex-start">
242
+ <Typography variant="h2">Form</Typography>
243
+ <Typography color="secondary">
244
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
245
+ </Typography>
246
+ <form noValidate onSubmit={handleSubmit(setSent)}>
247
+ <Flex gap={2} alignItems="flex-start">
248
+ <Controller
249
+ name="name"
250
+ control={control}
251
+ render={({ field, fieldState }) => (
252
+ <Flex gap={1}>
253
+ <TextInput
254
+ name={field.name}
255
+ value={field.value}
256
+ onChange={field.onChange}
257
+ placeholder="Name"
258
+ error={fieldState.invalid}
259
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
260
+ />
261
+ <Typography variant="caption" color="error">
262
+ {fieldState.error?.message}
263
+ </Typography>
264
+ </Flex>
265
+ )}
266
+ />
267
+ <Controller
268
+ name="email"
269
+ control={control}
270
+ render={({ field, fieldState }) => (
271
+ <Flex gap={1}>
272
+ <TextInput
273
+ name={field.name}
274
+ value={field.value}
275
+ onChange={field.onChange}
276
+ type="email"
277
+ placeholder="Email"
278
+ error={fieldState.invalid}
279
+ inputProps={{
280
+ 'aria-label': 'Email',
281
+ autoComplete: 'email',
282
+ onBlur: field.onBlur,
283
+ }}
284
+ />
285
+ <Typography variant="caption" color="error">
286
+ {fieldState.error?.message}
287
+ </Typography>
288
+ </Flex>
289
+ )}
290
+ />
291
+ <Button type="submit">Send</Button>
292
+ </Flex>
293
+ </form>
294
+ {sent ? <Typography>Thanks, {sent.name}: the form was valid.</Typography> : null}
295
+ </Flex>
296
+ )
297
+ }
298
+ // @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, type RootState } 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: RootState) => 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,29 @@
1
+ import { configureStore, createSlice, type PayloadAction } 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__' as 'light' | 'dark',
7
+ reducers: {
8
+ schemeChanged: (_scheme, action: PayloadAction<'light' | 'dark'>) => 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
+ })
28
+
29
+ export type RootState = ReturnType<typeof store.getState>
@@ -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
+ }
@@ -0,0 +1,19 @@
1
+ import { create } from 'zustand'
2
+
3
+ interface CounterState {
4
+ count: number
5
+ increment: () => void
6
+ }
7
+
8
+ /** The home page's count: a zustand store, which any component can read. */
9
+ // @if ts
10
+ export const useCounter = create<CounterState>()((set) => ({
11
+ count: 0,
12
+ increment: () => set((state) => ({ count: state.count + 1 })),
13
+ }))
14
+ // @else
15
+ export const useCounter = create((set) => ({
16
+ count: 0,
17
+ increment: () => set((state) => ({ count: state.count + 1 })),
18
+ }))
19
+ // @endif
@@ -0,0 +1,19 @@
1
+ import { create } from 'zustand'
2
+
3
+ interface SchemeState {
4
+ scheme: 'light' | 'dark'
5
+ setScheme: (scheme: 'light' | 'dark') => void
6
+ }
7
+
8
+ /** The color scheme the app is drawn in: a zustand store, which any component can read. */
9
+ // @if ts
10
+ export const useScheme = create<SchemeState>()((set) => ({
11
+ scheme: '__SCHEME__',
12
+ setScheme: (scheme) => set({ scheme }),
13
+ }))
14
+ // @else
15
+ export const useScheme = create((set) => ({
16
+ scheme: '__SCHEME__',
17
+ setScheme: (scheme) => set({ scheme }),
18
+ }))
19
+ // @endif