@strictly/react-form 0.0.5 → 0.0.7

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 (68) hide show
  1. package/.out/core/mobx/hooks.d.ts +10 -0
  2. package/.out/core/mobx/hooks.js +47 -0
  3. package/.out/core/mobx/specs/form_presenter.tests.js +3 -6
  4. package/.out/core/mobx/specs/{merge_field_adapters_with_two_way_converter.js → merge_field_adapters_with_two_way_converter.tests.js} +15 -16
  5. package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +78 -10
  6. package/.out/core/mobx/sub_form_field_adapters.d.ts +6 -4
  7. package/.out/core/mobx/sub_form_field_adapters.js +23 -2
  8. package/.out/core/props.d.ts +2 -2
  9. package/.out/index.d.ts +1 -0
  10. package/.out/index.js +1 -0
  11. package/.out/mantine/create_fields_view.d.ts +7 -0
  12. package/.out/mantine/{create_sub_form.js → create_fields_view.js} +4 -5
  13. package/.out/mantine/create_form.d.ts +7 -0
  14. package/.out/mantine/create_form.js +13 -0
  15. package/.out/mantine/hooks.d.ts +6 -4
  16. package/.out/mantine/hooks.js +17 -7
  17. package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -2
  18. package/.out/mantine/specs/checkbox_hooks.stories.js +2 -2
  19. package/.out/mantine/specs/{sub_form_hooks.stories.d.ts → fields_view_hooks.stories.d.ts} +2 -2
  20. package/.out/mantine/specs/{sub_form_hooks.stories.js → fields_view_hooks.stories.js} +9 -8
  21. package/.out/mantine/specs/fields_view_hooks.tests.d.ts +1 -0
  22. package/.out/mantine/specs/fields_view_hooks.tests.js +12 -0
  23. package/.out/mantine/specs/form_hooks.stories.d.ts +12 -0
  24. package/.out/mantine/specs/form_hooks.stories.js +60 -0
  25. package/.out/mantine/specs/form_hooks.tests.d.ts +1 -0
  26. package/.out/mantine/specs/form_hooks.tests.js +12 -0
  27. package/.out/mantine/specs/list_hooks.stories.d.ts +2 -2
  28. package/.out/mantine/specs/list_hooks.stories.js +2 -2
  29. package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -2
  30. package/.out/mantine/specs/radio_group_hooks.stories.js +2 -2
  31. package/.out/mantine/specs/select_hooks.stories.d.ts +2 -2
  32. package/.out/mantine/specs/select_hooks.stories.js +2 -2
  33. package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -2
  34. package/.out/mantine/specs/text_input_hooks.stories.js +2 -2
  35. package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -2
  36. package/.out/mantine/specs/value_input_hooks.stories.js +2 -2
  37. package/.out/tsconfig.tsbuildinfo +1 -1
  38. package/.turbo/turbo-build.log +8 -8
  39. package/.turbo/turbo-check-types.log +1 -1
  40. package/core/mobx/hooks.ts +94 -0
  41. package/core/mobx/specs/form_presenter.tests.ts +6 -6
  42. package/core/mobx/specs/{merge_field_adapters_with_two_way_converter.ts → merge_field_adapters_with_two_way_converter.tests.ts} +16 -16
  43. package/core/mobx/specs/sub_form_field_adapters.tests.ts +93 -10
  44. package/core/mobx/sub_form_field_adapters.ts +54 -7
  45. package/core/props.ts +2 -2
  46. package/dist/index.cjs +200 -90
  47. package/dist/index.d.cts +43 -34
  48. package/dist/index.d.ts +43 -34
  49. package/dist/index.js +186 -70
  50. package/index.ts +1 -0
  51. package/mantine/{create_sub_form.tsx → create_fields_view.tsx} +27 -16
  52. package/mantine/create_form.tsx +43 -0
  53. package/mantine/hooks.tsx +48 -14
  54. package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +460 -0
  55. package/mantine/specs/__snapshots__/form_hooks.tests.tsx.snap +273 -0
  56. package/mantine/specs/checkbox_hooks.stories.tsx +4 -4
  57. package/mantine/specs/{sub_form_hooks.stories.tsx → fields_view_hooks.stories.tsx} +23 -11
  58. package/mantine/specs/fields_view_hooks.tests.tsx +15 -0
  59. package/mantine/specs/form_hooks.stories.tsx +107 -0
  60. package/mantine/specs/form_hooks.tests.tsx +15 -0
  61. package/mantine/specs/list_hooks.stories.tsx +4 -4
  62. package/mantine/specs/radio_group_hooks.stories.tsx +4 -4
  63. package/mantine/specs/select_hooks.stories.tsx +4 -4
  64. package/mantine/specs/text_input_hooks.stories.tsx +4 -4
  65. package/mantine/specs/value_input_hooks.stories.tsx +4 -4
  66. package/package.json +1 -1
  67. package/.out/mantine/create_sub_form.d.ts +0 -6
  68. /package/.out/core/mobx/specs/{merge_field_adapters_with_two_way_converter.d.ts → merge_field_adapters_with_two_way_converter.tests.d.ts} +0 -0
@@ -0,0 +1,273 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`form hooks > renders Empty 1`] = `
4
+ <div>
5
+ <style
6
+ data-mantine-styles="classes"
7
+ >
8
+ @media (max-width: 35.99375em) {.mantine-visible-from-xs {display: none !important;}}@media (min-width: 36em) {.mantine-hidden-from-xs {display: none !important;}}@media (max-width: 47.99375em) {.mantine-visible-from-sm {display: none !important;}}@media (min-width: 48em) {.mantine-hidden-from-sm {display: none !important;}}@media (max-width: 61.99375em) {.mantine-visible-from-md {display: none !important;}}@media (min-width: 62em) {.mantine-hidden-from-md {display: none !important;}}@media (max-width: 74.99375em) {.mantine-visible-from-lg {display: none !important;}}@media (min-width: 75em) {.mantine-hidden-from-lg {display: none !important;}}@media (max-width: 87.99375em) {.mantine-visible-from-xl {display: none !important;}}@media (min-width: 88em) {.mantine-hidden-from-xl {display: none !important;}}
9
+ </style>
10
+ <div
11
+ class="m_6d731127 mantine-Stack-root"
12
+ style="--stack-gap: var(--mantine-spacing-md); --stack-align: stretch; --stack-justify: flex-start;"
13
+ >
14
+ <div
15
+ class="m_46b77525 mantine-InputWrapper-root mantine-TextInput-root"
16
+ >
17
+ <label
18
+ class="m_8fdc1311 mantine-InputWrapper-label mantine-TextInput-label"
19
+ for="mantine-0px4bipx4"
20
+ id="mantine-0px4bipx4-label"
21
+ >
22
+ fields view
23
+ </label>
24
+ <div
25
+ class="m_6c018570 mantine-Input-wrapper mantine-TextInput-wrapper"
26
+ data-variant="default"
27
+ >
28
+ <input
29
+ aria-invalid="false"
30
+ class="m_8fb7ebe7 mantine-Input-input mantine-TextInput-input"
31
+ data-variant="default"
32
+ id="mantine-0px4bipx4"
33
+ name="$"
34
+ value=""
35
+ />
36
+ </div>
37
+ </div>
38
+ <div
39
+ class="m_6d731127 mantine-Stack-root"
40
+ style="--stack-gap: var(--mantine-spacing-md); --stack-align: stretch; --stack-justify: flex-start;"
41
+ >
42
+ <div
43
+ class="m_e2f5cd4e m_46b77525 mantine-InputWrapper-root mantine-NumberInput-root"
44
+ >
45
+ <label
46
+ class="m_8fdc1311 mantine-InputWrapper-label mantine-NumberInput-label"
47
+ for="mantine-12voha2vo"
48
+ id="mantine-12voha2vo-label"
49
+ >
50
+ sub form
51
+ </label>
52
+ <div
53
+ class="m_6c018570 mantine-Input-wrapper mantine-NumberInput-wrapper"
54
+ data-variant="default"
55
+ data-with-right-section="true"
56
+ style="--input-right-section-width: var(--ni-right-section-width-sm);"
57
+ >
58
+ <input
59
+ aria-invalid="false"
60
+ class="m_8fb7ebe7 mantine-Input-input mantine-NumberInput-input"
61
+ data-variant="default"
62
+ id="mantine-12voha2vo"
63
+ inputmode="numeric"
64
+ type="text"
65
+ value="0"
66
+ />
67
+ <div
68
+ class="m_82577fc2 mantine-Input-section mantine-NumberInput-section"
69
+ data-position="right"
70
+ >
71
+ <div
72
+ class="m_95e17d22 mantine-NumberInput-controls"
73
+ >
74
+ <button
75
+ aria-hidden="true"
76
+ class="mantine-focus-auto m_80b4b171 mantine-NumberInput-control m_87cf2631 mantine-UnstyledButton-root"
77
+ data-direction="up"
78
+ tabindex="-1"
79
+ type="button"
80
+ >
81
+ <svg
82
+ fill="none"
83
+ style="transform: rotate(180deg);"
84
+ viewBox="0 0 15 15"
85
+ xmlns="http://www.w3.org/2000/svg"
86
+ >
87
+ <path
88
+ clip-rule="evenodd"
89
+ d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z"
90
+ fill="currentColor"
91
+ fill-rule="evenodd"
92
+ />
93
+ </svg>
94
+ </button>
95
+ <button
96
+ aria-hidden="true"
97
+ class="mantine-focus-auto m_80b4b171 mantine-NumberInput-control m_87cf2631 mantine-UnstyledButton-root"
98
+ data-direction="down"
99
+ tabindex="-1"
100
+ type="button"
101
+ >
102
+ <svg
103
+ fill="none"
104
+ viewBox="0 0 15 15"
105
+ xmlns="http://www.w3.org/2000/svg"
106
+ >
107
+ <path
108
+ clip-rule="evenodd"
109
+ d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z"
110
+ fill="currentColor"
111
+ fill-rule="evenodd"
112
+ />
113
+ </svg>
114
+ </button>
115
+ </div>
116
+ </div>
117
+ </div>
118
+ </div>
119
+ <button
120
+ class="mantine-focus-auto mantine-active m_77c9d27d mantine-Button-root m_87cf2631 mantine-UnstyledButton-root"
121
+ style="--button-color: var(--mantine-color-white);"
122
+ type="button"
123
+ >
124
+ <span
125
+ class="m_80f1301b mantine-Button-inner"
126
+ >
127
+ <span
128
+ class="m_811560b9 mantine-Button-label"
129
+ >
130
+ Cancel
131
+ </span>
132
+ </span>
133
+ </button>
134
+ </div>
135
+ </div>
136
+ </div>
137
+ `;
138
+
139
+ exports[`form hooks > renders Populated 1`] = `
140
+ <div>
141
+ <style
142
+ data-mantine-styles="classes"
143
+ >
144
+ @media (max-width: 35.99375em) {.mantine-visible-from-xs {display: none !important;}}@media (min-width: 36em) {.mantine-hidden-from-xs {display: none !important;}}@media (max-width: 47.99375em) {.mantine-visible-from-sm {display: none !important;}}@media (min-width: 48em) {.mantine-hidden-from-sm {display: none !important;}}@media (max-width: 61.99375em) {.mantine-visible-from-md {display: none !important;}}@media (min-width: 62em) {.mantine-hidden-from-md {display: none !important;}}@media (max-width: 74.99375em) {.mantine-visible-from-lg {display: none !important;}}@media (min-width: 75em) {.mantine-hidden-from-lg {display: none !important;}}@media (max-width: 87.99375em) {.mantine-visible-from-xl {display: none !important;}}@media (min-width: 88em) {.mantine-hidden-from-xl {display: none !important;}}
145
+ </style>
146
+ <div
147
+ class="m_6d731127 mantine-Stack-root"
148
+ style="--stack-gap: var(--mantine-spacing-md); --stack-align: stretch; --stack-justify: flex-start;"
149
+ >
150
+ <div
151
+ class="m_46b77525 mantine-InputWrapper-root mantine-TextInput-root"
152
+ >
153
+ <label
154
+ class="m_8fdc1311 mantine-InputWrapper-label mantine-TextInput-label"
155
+ for="mantine-0cyk5rcyk"
156
+ id="mantine-0cyk5rcyk-label"
157
+ >
158
+ fields view
159
+ </label>
160
+ <div
161
+ class="m_6c018570 mantine-Input-wrapper mantine-TextInput-wrapper"
162
+ data-variant="default"
163
+ >
164
+ <input
165
+ aria-invalid="false"
166
+ class="m_8fb7ebe7 mantine-Input-input mantine-TextInput-input"
167
+ data-variant="default"
168
+ id="mantine-0cyk5rcyk"
169
+ name="$"
170
+ value="Hello"
171
+ />
172
+ </div>
173
+ </div>
174
+ <div
175
+ class="m_6d731127 mantine-Stack-root"
176
+ style="--stack-gap: var(--mantine-spacing-md); --stack-align: stretch; --stack-justify: flex-start;"
177
+ >
178
+ <div
179
+ class="m_e2f5cd4e m_46b77525 mantine-InputWrapper-root mantine-NumberInput-root"
180
+ >
181
+ <label
182
+ class="m_8fdc1311 mantine-InputWrapper-label mantine-NumberInput-label"
183
+ for="mantine-0px4bipx4"
184
+ id="mantine-0px4bipx4-label"
185
+ >
186
+ sub form
187
+ </label>
188
+ <div
189
+ class="m_6c018570 mantine-Input-wrapper mantine-NumberInput-wrapper"
190
+ data-variant="default"
191
+ data-with-right-section="true"
192
+ style="--input-right-section-width: var(--ni-right-section-width-sm);"
193
+ >
194
+ <input
195
+ aria-invalid="false"
196
+ class="m_8fb7ebe7 mantine-Input-input mantine-NumberInput-input"
197
+ data-variant="default"
198
+ id="mantine-0px4bipx4"
199
+ inputmode="numeric"
200
+ type="text"
201
+ value="2"
202
+ />
203
+ <div
204
+ class="m_82577fc2 mantine-Input-section mantine-NumberInput-section"
205
+ data-position="right"
206
+ >
207
+ <div
208
+ class="m_95e17d22 mantine-NumberInput-controls"
209
+ >
210
+ <button
211
+ aria-hidden="true"
212
+ class="mantine-focus-auto m_80b4b171 mantine-NumberInput-control m_87cf2631 mantine-UnstyledButton-root"
213
+ data-direction="up"
214
+ tabindex="-1"
215
+ type="button"
216
+ >
217
+ <svg
218
+ fill="none"
219
+ style="transform: rotate(180deg);"
220
+ viewBox="0 0 15 15"
221
+ xmlns="http://www.w3.org/2000/svg"
222
+ >
223
+ <path
224
+ clip-rule="evenodd"
225
+ d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z"
226
+ fill="currentColor"
227
+ fill-rule="evenodd"
228
+ />
229
+ </svg>
230
+ </button>
231
+ <button
232
+ aria-hidden="true"
233
+ class="mantine-focus-auto m_80b4b171 mantine-NumberInput-control m_87cf2631 mantine-UnstyledButton-root"
234
+ data-direction="down"
235
+ tabindex="-1"
236
+ type="button"
237
+ >
238
+ <svg
239
+ fill="none"
240
+ viewBox="0 0 15 15"
241
+ xmlns="http://www.w3.org/2000/svg"
242
+ >
243
+ <path
244
+ clip-rule="evenodd"
245
+ d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z"
246
+ fill="currentColor"
247
+ fill-rule="evenodd"
248
+ />
249
+ </svg>
250
+ </button>
251
+ </div>
252
+ </div>
253
+ </div>
254
+ </div>
255
+ <button
256
+ class="mantine-focus-auto mantine-active m_77c9d27d mantine-Button-root m_87cf2631 mantine-UnstyledButton-root"
257
+ style="--button-color: var(--mantine-color-white);"
258
+ type="button"
259
+ >
260
+ <span
261
+ class="m_80f1301b mantine-Button-inner"
262
+ >
263
+ <span
264
+ class="m_811560b9 mantine-Button-label"
265
+ >
266
+ Cancel
267
+ </span>
268
+ </span>
269
+ </button>
270
+ </div>
271
+ </div>
272
+ </div>
273
+ `;
@@ -3,21 +3,21 @@ import {
3
3
  type Meta,
4
4
  type StoryObj,
5
5
  } from '@storybook/react'
6
- import { type FormProps } from 'core/props'
6
+ import { type FieldsViewProps } from 'core/props'
7
7
  import { type ErrorRenderer } from 'mantine/error_renderer'
8
- import { useMantineForm } from 'mantine/hooks'
8
+ import { useMantineFormFields } from 'mantine/hooks'
9
9
  import { type Field } from 'types/field'
10
10
  import { CHECKBOX_LABEL } from './checkbox_constants'
11
11
 
12
12
  function Component({
13
13
  ErrorRenderer,
14
14
  ...props
15
- }: FormProps<{
15
+ }: FieldsViewProps<{
16
16
  $: Field<boolean, string>,
17
17
  }> & {
18
18
  ErrorRenderer?: ErrorRenderer,
19
19
  }) {
20
- const inputProps = useMantineForm(props)
20
+ const inputProps = useMantineFormFields(props)
21
21
  const CheckboxComponent = inputProps.checkbox('$')
22
22
  return (
23
23
  <CheckboxComponent
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Button,
2
3
  Stack,
3
4
  } from '@mantine/core'
4
5
  import { action } from '@storybook/addon-actions'
@@ -6,29 +7,40 @@ import {
6
7
  type Meta,
7
8
  type StoryObj,
8
9
  } from '@storybook/react'
9
- import { type FormProps } from 'core/props'
10
- import { useMantineForm } from 'mantine/hooks'
10
+ import { type FieldsViewProps } from 'core/props'
11
+ import { useMantineFormFields } from 'mantine/hooks'
11
12
  import { type Field } from 'types/field'
12
13
 
13
- function SubFormImpl(props: FormProps<{
14
+ const onClick = action('some button clicked')
15
+
16
+ function SubFieldsView(props: FieldsViewProps<{
14
17
  $: Field<string, string>,
15
- }>) {
16
- const form = useMantineForm(props)
18
+ }> & {
19
+ onClick: () => void,
20
+ }) {
21
+ const form = useMantineFormFields(props)
17
22
  const TextInput = form.textInput('$')
18
- return <TextInput label='sub form' />
23
+ return (
24
+ <Stack>
25
+ <TextInput label='sub fields view' />
26
+ <Button onClick={props.onClick}>
27
+ Bonus Button
28
+ </Button>
29
+ </Stack>
30
+ )
19
31
  }
20
32
 
21
- function Component(props: FormProps<{
33
+ function Component(props: FieldsViewProps<{
22
34
  $: Field<string, string>,
23
35
  '$.a': Field<string, string>,
24
36
  }>) {
25
- const form = useMantineForm(props)
26
- const SubForm = form.subForm('$.a', SubFormImpl)
37
+ const form = useMantineFormFields(props)
38
+ const FieldsView = form.fieldsView('$.a', SubFieldsView)
27
39
  const TextInput = form.textInput('$')
28
40
  return (
29
41
  <Stack>
30
- <TextInput label='form' />
31
- <SubForm />
42
+ <TextInput label='fields view' />
43
+ <FieldsView onClick={onClick} />
32
44
  </Stack>
33
45
  )
34
46
  }
@@ -0,0 +1,15 @@
1
+ import { composeStories } from '@storybook/react'
2
+ import { toArray } from '@strictly/base'
3
+ import {
4
+ render,
5
+ } from '@testing-library/react'
6
+ import * as stories from './fields_view_hooks.stories'
7
+
8
+ const composedStories = composeStories(stories)
9
+
10
+ describe('field view hooks', function () {
11
+ it.each(toArray(composedStories))('renders %s', function (_name, Story) {
12
+ const wrapper = render(<Story />)
13
+ expect(wrapper.container).toMatchSnapshot()
14
+ })
15
+ })
@@ -0,0 +1,107 @@
1
+ import {
2
+ Button,
3
+ NumberInput,
4
+ Stack,
5
+ } from '@mantine/core'
6
+ import { action } from '@storybook/addon-actions'
7
+ import {
8
+ type Meta,
9
+ type StoryObj,
10
+ } from '@storybook/react'
11
+ import {
12
+ type FieldsViewProps,
13
+ type FormProps,
14
+ } from 'core/props'
15
+ import { useMantineFormFields } from 'mantine/hooks'
16
+ import { useCallback } from 'react'
17
+ import { type Field } from 'types/field'
18
+
19
+ const onCancel = action('canceled')
20
+
21
+ function SubForm({
22
+ value,
23
+ onValueChange,
24
+ onCancel,
25
+ }: FormProps<number> & {
26
+ onCancel: () => void,
27
+ }) {
28
+ const onChange = useCallback((v: number | string) => {
29
+ onValueChange(Number.parseInt(`${v}`))
30
+ }, [onValueChange])
31
+ return (
32
+ <Stack>
33
+ <NumberInput
34
+ allowDecimal={false}
35
+ label='sub form'
36
+ onChange={onChange}
37
+ value={value}
38
+ />
39
+ <Button onClick={onCancel}>
40
+ Cancel
41
+ </Button>
42
+ </Stack>
43
+ )
44
+ }
45
+
46
+ function Component(props: FieldsViewProps<{
47
+ $: Field<string>,
48
+ '$.a': Field<number>,
49
+ }>) {
50
+ const form = useMantineFormFields(props)
51
+ const Form = form.form('$.a', SubForm)
52
+ const TextInput = form.textInput('$')
53
+ return (
54
+ <Stack>
55
+ <TextInput label='fields view' />
56
+ <Form onCancel={onCancel} />
57
+ </Stack>
58
+ )
59
+ }
60
+
61
+ const meta: Meta<typeof Component> = {
62
+ component: Component,
63
+ args: {
64
+ onFieldBlur: action('onFieldBlur'),
65
+ onFieldFocus: action('onFieldFocus'),
66
+ onFieldSubmit: action('onFieldSubmit'),
67
+ onFieldValueChange: action('onFieldValueChange'),
68
+ },
69
+ }
70
+
71
+ export default meta
72
+
73
+ type Story = StoryObj<typeof Component>
74
+
75
+ export const Empty: Story = {
76
+ args: {
77
+ fields: {
78
+ $: {
79
+ readonly: false,
80
+ required: false,
81
+ value: '',
82
+ },
83
+ '$.a': {
84
+ readonly: false,
85
+ required: false,
86
+ value: 0,
87
+ },
88
+ },
89
+ },
90
+ }
91
+
92
+ export const Populated: Story = {
93
+ args: {
94
+ fields: {
95
+ $: {
96
+ readonly: false,
97
+ required: false,
98
+ value: 'Hello',
99
+ },
100
+ '$.a': {
101
+ readonly: false,
102
+ required: false,
103
+ value: 2,
104
+ },
105
+ },
106
+ },
107
+ }
@@ -0,0 +1,15 @@
1
+ import { composeStories } from '@storybook/react'
2
+ import { toArray } from '@strictly/base'
3
+ import {
4
+ render,
5
+ } from '@testing-library/react'
6
+ import * as stories from './form_hooks.stories'
7
+
8
+ const composedStories = composeStories(stories)
9
+
10
+ describe('form hooks', function () {
11
+ it.each(toArray(composedStories))('renders %s', function (_name, Story) {
12
+ const wrapper = render(<Story />)
13
+ expect(wrapper.container).toMatchSnapshot()
14
+ })
15
+ })
@@ -8,16 +8,16 @@ import {
8
8
  type Meta,
9
9
  type StoryObj,
10
10
  } from '@storybook/react'
11
- import { type FormProps } from 'core/props'
12
- import { useMantineForm } from 'mantine/hooks'
11
+ import { type FieldsViewProps } from 'core/props'
12
+ import { useMantineFormFields } from 'mantine/hooks'
13
13
  import { type Field } from 'types/field'
14
14
 
15
15
  type ListPath = `$.${number}`
16
16
 
17
- function Component(props: FormProps<{
17
+ function Component(props: FieldsViewProps<{
18
18
  $: Field<string[], string>,
19
19
  }>) {
20
- const form = useMantineForm(props)
20
+ const form = useMantineFormFields(props)
21
21
  const List = form.list('$')
22
22
  return (
23
23
  <Paper
@@ -6,11 +6,11 @@ import {
6
6
  type Meta,
7
7
  type StoryObj,
8
8
  } from '@storybook/react'
9
- import { type FormProps } from 'core/props'
9
+ import { type FieldsViewProps } from 'core/props'
10
10
  import {
11
11
  type ErrorRenderer,
12
12
  } from 'mantine/error_renderer'
13
- import { useMantineForm } from 'mantine/hooks'
13
+ import { useMantineFormFields } from 'mantine/hooks'
14
14
  import { type Field } from 'types/field'
15
15
  import {
16
16
  RADIO_GROUP_LABEL,
@@ -22,12 +22,12 @@ import {
22
22
  function Component({
23
23
  ErrorRenderer,
24
24
  ...props
25
- }: FormProps<{
25
+ }: FieldsViewProps<{
26
26
  $: Field<RadioValue | null, string>,
27
27
  }> & {
28
28
  ErrorRenderer?: ErrorRenderer,
29
29
  }) {
30
- const form = useMantineForm(props)
30
+ const form = useMantineFormFields(props)
31
31
  const RadioGroupComponent = form.radioGroup('$')
32
32
 
33
33
  return (
@@ -3,21 +3,21 @@ import {
3
3
  type Meta,
4
4
  type StoryObj,
5
5
  } from '@storybook/react'
6
- import { type FormProps } from 'core/props'
6
+ import { type FieldsViewProps } from 'core/props'
7
7
  import { type ErrorRenderer } from 'mantine/error_renderer'
8
- import { useMantineForm } from 'mantine/hooks'
8
+ import { useMantineFormFields } from 'mantine/hooks'
9
9
  import { type Field } from 'types/field'
10
10
  import { SELECT_LABEL } from './select_hooks_constant'
11
11
 
12
12
  function Component({
13
13
  ErrorRenderer,
14
14
  ...props
15
- }: FormProps<{
15
+ }: FieldsViewProps<{
16
16
  $: Field<string | null, string>,
17
17
  }> & {
18
18
  ErrorRenderer?: ErrorRenderer,
19
19
  }) {
20
- const form = useMantineForm(props)
20
+ const form = useMantineFormFields(props)
21
21
  const SelectComponent = form.select('$')
22
22
  return (
23
23
  <SelectComponent
@@ -8,13 +8,13 @@ import {
8
8
  type Meta,
9
9
  type StoryObj,
10
10
  } from '@storybook/react'
11
- import { type FormProps } from 'core/props'
11
+ import { type FieldsViewProps } from 'core/props'
12
12
  import {
13
13
  type SuppliedTextInputProps,
14
14
  type TextInputTarget,
15
15
  } from 'mantine/create_text_input'
16
16
  import { type ErrorRenderer } from 'mantine/error_renderer'
17
- import { useMantineForm } from 'mantine/hooks'
17
+ import { useMantineFormFields } from 'mantine/hooks'
18
18
  import { type ComponentType } from 'react'
19
19
  import { type Field } from 'types/field'
20
20
  import { TEXT_INPUT_LABEL } from './text_input_constants'
@@ -25,14 +25,14 @@ function Component<T extends TextInputTarget>({
25
25
  TextInput,
26
26
  ErrorRenderer,
27
27
  ...props
28
- }: FormProps<{
28
+ }: FieldsViewProps<{
29
29
  $: Field<string, string>,
30
30
  }> & {
31
31
  TextInput?: ComponentType<StoryTextInputProps<T>>,
32
32
  } & {
33
33
  ErrorRenderer?: ErrorRenderer,
34
34
  }) {
35
- const form = useMantineForm(props)
35
+ const form = useMantineFormFields(props)
36
36
  const TextInputComponent = form.textInput<'$', StoryTextInputProps<T>>('$', TextInput)
37
37
  return (
38
38
  <TextInputComponent
@@ -13,10 +13,10 @@ import {
13
13
  type Meta,
14
14
  type StoryObj,
15
15
  } from '@storybook/react'
16
- import { type FormProps } from 'core/props'
16
+ import { type FieldsViewProps } from 'core/props'
17
17
  import { type SuppliedValueInputProps } from 'mantine/create_value_input'
18
18
  import { type ErrorRenderer } from 'mantine/error_renderer'
19
- import { useMantineForm } from 'mantine/hooks'
19
+ import { useMantineFormFields } from 'mantine/hooks'
20
20
  import {
21
21
  type ComponentType,
22
22
  } from 'react'
@@ -37,7 +37,7 @@ function Component<
37
37
  ErrorRenderer,
38
38
  inputProps,
39
39
  ...props
40
- }: FormProps<{
40
+ }: FieldsViewProps<{
41
41
  $: Field<V, string>,
42
42
  }> & {
43
43
  ValueInput: ComponentType<P>,
@@ -46,7 +46,7 @@ function Component<
46
46
  } & {
47
47
  ErrorRenderer?: ErrorRenderer,
48
48
  }) {
49
- const form = useMantineForm(props)
49
+ const form = useMantineFormFields(props)
50
50
  const ValueInputComponent = form.valueInput<'$', P>('$', ValueInput)
51
51
  return (
52
52
  <ValueInputComponent
package/package.json CHANGED
@@ -69,7 +69,7 @@
69
69
  "test:watch": "vitest"
70
70
  },
71
71
  "type": "module",
72
- "version": "0.0.5",
72
+ "version": "0.0.7",
73
73
  "exports": {
74
74
  ".": {
75
75
  "import": {
@@ -1,6 +0,0 @@
1
- import type { FormProps } from 'core/props';
2
- import type { ComponentType } from 'react';
3
- import type { AllFieldsOfFields } from 'types/all_fields_of_fields';
4
- import type { Fields } from 'types/field';
5
- import type { SubFormFields } from 'types/sub_form_fields';
6
- export declare function createSubForm<F extends Fields, K extends keyof AllFieldsOfFields<F>, S extends Fields = SubFormFields<F, K>>(valuePath: K, SubForm: ComponentType<FormProps<S>>, observableProps: FormProps<F>): () => import("react/jsx-runtime").JSX.Element;