@strictly/react-form 0.0.6 → 0.0.8

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 (77) hide show
  1. package/.out/core/mobx/hooks.d.ts +5 -1
  2. package/.out/core/mobx/hooks.js +13 -3
  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 +127 -12
  6. package/.out/core/mobx/sub_form_field_adapters.d.ts +6 -4
  7. package/.out/core/mobx/sub_form_field_adapters.js +28 -4
  8. package/.out/field_converters/nullable_to_boolean_converter.d.ts +2 -2
  9. package/.out/mantine/create_checkbox.js +1 -0
  10. package/.out/mantine/create_fields_view.d.ts +1 -1
  11. package/.out/mantine/create_fields_view.js +4 -4
  12. package/.out/mantine/create_form.d.ts +1 -1
  13. package/.out/mantine/create_list.d.ts +1 -1
  14. package/.out/mantine/create_pill.d.ts +1 -1
  15. package/.out/mantine/create_radio.d.ts +1 -1
  16. package/.out/mantine/create_radio_group.js +1 -0
  17. package/.out/mantine/create_text_input.js +7 -2
  18. package/.out/mantine/create_value_input.js +1 -0
  19. package/.out/mantine/error_renderer.d.ts +1 -1
  20. package/.out/mantine/error_renderer.js +1 -1
  21. package/.out/mantine/hooks.d.ts +9 -9
  22. package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -6
  23. package/.out/mantine/specs/checkbox_hooks.stories.js +4 -16
  24. package/.out/mantine/specs/fields_view_hooks.stories.d.ts +1 -1
  25. package/.out/mantine/specs/fields_view_hooks.stories.js +6 -3
  26. package/.out/mantine/specs/form_hooks.stories.d.ts +2 -2
  27. package/.out/mantine/specs/form_hooks.stories.js +4 -1
  28. package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -6
  29. package/.out/mantine/specs/radio_group_hooks.stories.js +5 -17
  30. package/.out/mantine/specs/select_hooks.stories.d.ts +2 -6
  31. package/.out/mantine/specs/select_hooks.stories.js +4 -16
  32. package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -5
  33. package/.out/mantine/specs/text_input_hooks.stories.js +5 -5
  34. package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -5
  35. package/.out/mantine/specs/value_input_hooks.stories.js +5 -5
  36. package/.out/mantine/types.d.ts +4 -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/.turbo/turbo-release$colon$exports.log +1 -1
  41. package/core/mobx/hooks.ts +24 -6
  42. package/core/mobx/specs/form_presenter.tests.ts +6 -6
  43. package/core/mobx/specs/{merge_field_adapters_with_two_way_converter.ts → merge_field_adapters_with_two_way_converter.tests.ts} +16 -16
  44. package/core/mobx/specs/sub_form_field_adapters.tests.ts +193 -17
  45. package/core/mobx/sub_form_field_adapters.ts +74 -11
  46. package/dist/index.cjs +77 -32
  47. package/dist/index.d.cts +25 -18
  48. package/dist/index.d.ts +25 -18
  49. package/dist/index.js +68 -21
  50. package/field_converters/nullable_to_boolean_converter.ts +2 -3
  51. package/mantine/create_checkbox.tsx +2 -1
  52. package/mantine/create_fields_view.tsx +17 -14
  53. package/mantine/create_form.tsx +2 -2
  54. package/mantine/create_list.tsx +1 -1
  55. package/mantine/create_pill.tsx +1 -1
  56. package/mantine/create_radio.tsx +1 -1
  57. package/mantine/create_radio_group.tsx +6 -2
  58. package/mantine/create_text_input.tsx +9 -3
  59. package/mantine/create_value_input.tsx +2 -1
  60. package/mantine/error_renderer.ts +1 -1
  61. package/mantine/hooks.tsx +19 -14
  62. package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +1 -64
  63. package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +52 -52
  64. package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +1 -179
  65. package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +1 -83
  66. package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +27 -27
  67. package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +31 -31
  68. package/mantine/specs/checkbox_hooks.stories.tsx +5 -21
  69. package/mantine/specs/fields_view_hooks.stories.tsx +16 -4
  70. package/mantine/specs/form_hooks.stories.tsx +10 -3
  71. package/mantine/specs/radio_group_hooks.stories.tsx +6 -20
  72. package/mantine/specs/select_hooks.stories.tsx +5 -21
  73. package/mantine/specs/text_input_hooks.stories.tsx +5 -8
  74. package/mantine/specs/value_input_hooks.stories.tsx +5 -8
  75. package/mantine/types.ts +7 -3
  76. package/package.json +2 -1
  77. /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
@@ -13,6 +13,10 @@ import { type Field } from 'types/field'
13
13
 
14
14
  const onClick = action('some button clicked')
15
15
 
16
+ function ErrorRenderer({ error }: { error: string }) {
17
+ return `error ${error}`
18
+ }
19
+
16
20
  function SubFieldsView(props: FieldsViewProps<{
17
21
  $: Field<string, string>,
18
22
  }> & {
@@ -22,7 +26,10 @@ function SubFieldsView(props: FieldsViewProps<{
22
26
  const TextInput = form.textInput('$')
23
27
  return (
24
28
  <Stack>
25
- <TextInput label='sub fields view' />
29
+ <TextInput
30
+ ErrorRenderer={ErrorRenderer}
31
+ label='sub fields view'
32
+ />
26
33
  <Button onClick={props.onClick}>
27
34
  Bonus Button
28
35
  </Button>
@@ -39,8 +46,13 @@ function Component(props: FieldsViewProps<{
39
46
  const TextInput = form.textInput('$')
40
47
  return (
41
48
  <Stack>
42
- <TextInput label='fields view' />
43
- <FieldsView onClick={onClick} />
49
+ <TextInput
50
+ ErrorRenderer={ErrorRenderer}
51
+ label='fields view'
52
+ />
53
+ <FieldsView
54
+ onClick={onClick}
55
+ />
44
56
  </Stack>
45
57
  )
46
58
  }
@@ -127,7 +139,7 @@ export const Disabled: Story = {
127
139
  },
128
140
  }
129
141
 
130
- export const CustomError: Story = {
142
+ export const Errors: Story = {
131
143
  args: {
132
144
  fields: {
133
145
  $: {
@@ -18,6 +18,10 @@ import { type Field } from 'types/field'
18
18
 
19
19
  const onCancel = action('canceled')
20
20
 
21
+ function ErrorRenderer({ error }: { error: string }) {
22
+ return `error ${error}`
23
+ }
24
+
21
25
  function SubForm({
22
26
  value,
23
27
  onValueChange,
@@ -44,15 +48,18 @@ function SubForm({
44
48
  }
45
49
 
46
50
  function Component(props: FieldsViewProps<{
47
- $: Field<string>,
48
- '$.a': Field<number>,
51
+ $: Field<string, string>,
52
+ '$.a': Field<number, string>,
49
53
  }>) {
50
54
  const form = useMantineFormFields(props)
51
55
  const Form = form.form('$.a', SubForm)
52
56
  const TextInput = form.textInput('$')
53
57
  return (
54
58
  <Stack>
55
- <TextInput label='fields view' />
59
+ <TextInput
60
+ ErrorRenderer={ErrorRenderer}
61
+ label='fields view'
62
+ />
56
63
  <Form onCancel={onCancel} />
57
64
  </Stack>
58
65
  )
@@ -19,14 +19,15 @@ import {
19
19
  type RadioValue,
20
20
  } from './radio_group_constants'
21
21
 
22
+ function ErrorRenderer({ error }: { error: string }) {
23
+ return `custom error ${error}`
24
+ }
25
+
22
26
  function Component({
23
- ErrorRenderer,
24
27
  ...props
25
28
  }: FieldsViewProps<{
26
29
  $: Field<RadioValue | null, string>,
27
- }> & {
28
- ErrorRenderer?: ErrorRenderer,
29
- }) {
30
+ }>) {
30
31
  const form = useMantineFormFields(props)
31
32
  const RadioGroupComponent = form.radioGroup('$')
32
33
 
@@ -41,6 +42,7 @@ function Component({
41
42
  const RadioComponent = form.radio('$', value)
42
43
  return (
43
44
  <RadioComponent
45
+ ErrorRenderer={ErrorRenderer}
44
46
  key={label}
45
47
  label={label}
46
48
  />
@@ -125,19 +127,3 @@ export const Error: Story = {
125
127
  },
126
128
  },
127
129
  }
128
-
129
- export const CustomError: Story = {
130
- args: {
131
- fields: {
132
- $: {
133
- readonly: false,
134
- required: false,
135
- value: '2',
136
- error: 'error',
137
- },
138
- },
139
- ErrorRenderer: function () {
140
- return 'custom error'
141
- },
142
- },
143
- }
@@ -4,19 +4,19 @@ import {
4
4
  type StoryObj,
5
5
  } from '@storybook/react'
6
6
  import { type FieldsViewProps } from 'core/props'
7
- import { type ErrorRenderer } from 'mantine/error_renderer'
8
7
  import { useMantineFormFields } from 'mantine/hooks'
9
8
  import { type Field } from 'types/field'
10
9
  import { SELECT_LABEL } from './select_hooks_constant'
11
10
 
11
+ function ErrorRenderer({ error }: { error: string }) {
12
+ return `Error ${error}`
13
+ }
14
+
12
15
  function Component({
13
- ErrorRenderer,
14
16
  ...props
15
17
  }: FieldsViewProps<{
16
18
  $: Field<string | null, string>,
17
- }> & {
18
- ErrorRenderer?: ErrorRenderer,
19
- }) {
19
+ }>) {
20
20
  const form = useMantineFormFields(props)
21
21
  const SelectComponent = form.select('$')
22
22
  return (
@@ -106,19 +106,3 @@ export const DisabledSelect: Story = {
106
106
  },
107
107
  },
108
108
  }
109
-
110
- export const CustomErrorSelect: Story = {
111
- args: {
112
- fields: {
113
- $: {
114
- readonly: false,
115
- required: true,
116
- value: 'c',
117
- error: 'error',
118
- },
119
- },
120
- ErrorRenderer: function () {
121
- return 'custom error'
122
- },
123
- },
124
- }
@@ -13,7 +13,6 @@ import {
13
13
  type SuppliedTextInputProps,
14
14
  type TextInputTarget,
15
15
  } from 'mantine/create_text_input'
16
- import { type ErrorRenderer } from 'mantine/error_renderer'
17
16
  import { useMantineFormFields } from 'mantine/hooks'
18
17
  import { type ComponentType } from 'react'
19
18
  import { type Field } from 'types/field'
@@ -21,16 +20,17 @@ import { TEXT_INPUT_LABEL } from './text_input_constants'
21
20
 
22
21
  type StoryTextInputProps<T extends TextInputTarget> = SuppliedTextInputProps<T> & Pick<TextInputProps, 'label'>
23
22
 
23
+ function ErrorRenderer({ error }: { error: string }) {
24
+ return `error ${error}`
25
+ }
26
+
24
27
  function Component<T extends TextInputTarget>({
25
28
  TextInput,
26
- ErrorRenderer,
27
29
  ...props
28
30
  }: FieldsViewProps<{
29
31
  $: Field<string, string>,
30
32
  }> & {
31
33
  TextInput?: ComponentType<StoryTextInputProps<T>>,
32
- } & {
33
- ErrorRenderer?: ErrorRenderer,
34
34
  }) {
35
35
  const form = useMantineFormFields(props)
36
36
  const TextInputComponent = form.textInput<'$', StoryTextInputProps<T>>('$', TextInput)
@@ -106,7 +106,7 @@ export const Disabled: Story = {
106
106
  },
107
107
  }
108
108
 
109
- export const CustomError: Story = {
109
+ export const Error: Story = {
110
110
  args: {
111
111
  fields: {
112
112
  $: {
@@ -116,9 +116,6 @@ export const CustomError: Story = {
116
116
  error: 'error',
117
117
  },
118
118
  },
119
- ErrorRenderer: function () {
120
- return 'custom error'
121
- },
122
119
  },
123
120
  }
124
121
 
@@ -15,7 +15,6 @@ import {
15
15
  } from '@storybook/react'
16
16
  import { type FieldsViewProps } from 'core/props'
17
17
  import { type SuppliedValueInputProps } from 'mantine/create_value_input'
18
- import { type ErrorRenderer } from 'mantine/error_renderer'
19
18
  import { useMantineFormFields } from 'mantine/hooks'
20
19
  import {
21
20
  type ComponentType,
@@ -26,6 +25,10 @@ import {
26
25
  SLIDER_LABEL,
27
26
  } from './value_input_constants'
28
27
 
28
+ function ErrorRenderer({ error }: { error: string }) {
29
+ return `error ${error}`
30
+ }
31
+
29
32
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
33
  type StoryValueInputProps<V> = SuppliedValueInputProps<V, any>
31
34
 
@@ -34,7 +37,6 @@ function Component<
34
37
  P extends StoryValueInputProps<V>,
35
38
  >({
36
39
  ValueInput,
37
- ErrorRenderer,
38
40
  inputProps,
39
41
  ...props
40
42
  }: FieldsViewProps<{
@@ -43,8 +45,6 @@ function Component<
43
45
  ValueInput: ComponentType<P>,
44
46
  } & {
45
47
  inputProps: P,
46
- } & {
47
- ErrorRenderer?: ErrorRenderer,
48
48
  }) {
49
49
  const form = useMantineFormFields(props)
50
50
  const ValueInputComponent = form.valueInput<'$', P>('$', ValueInput)
@@ -124,7 +124,7 @@ export const RequiredNumberInput: Story<number | string, NumberInputProps> = {
124
124
  },
125
125
  }
126
126
 
127
- export const CustomErrorNumberInput: Story<number | string, NumberInputProps> = {
127
+ export const ErrorNumberInput: Story<number | string, NumberInputProps> = {
128
128
  args: {
129
129
  fields: {
130
130
  $: {
@@ -135,9 +135,6 @@ export const CustomErrorNumberInput: Story<number | string, NumberInputProps> =
135
135
  },
136
136
  },
137
137
  ValueInput: NumberInput,
138
- ErrorRenderer: function () {
139
- return 'a custom error'
140
- },
141
138
  inputProps: {
142
139
  label: NUMBER_INPUT_LABEL,
143
140
  },
package/mantine/types.ts CHANGED
@@ -12,6 +12,10 @@ export type MantineForm<F extends Fields> = {
12
12
  }
13
13
 
14
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- export type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, {
16
- ErrorRenderer?: ErrorRenderer<E>,
17
- }>
15
+ export type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<
16
+ ComponentType<P>,
17
+ T,
18
+ // escape hatch for never comparisons `E extends never` will not work, always returning never
19
+ // https://github.com/microsoft/TypeScript/issues/31751
20
+ [E] extends [never] ? {} : { ErrorRenderer: ErrorRenderer<E> }
21
+ >
package/package.json CHANGED
@@ -22,6 +22,7 @@
22
22
  "@storybook/builder-vite": "^8.4.5",
23
23
  "@storybook/react": "^8.4.5",
24
24
  "@storybook/react-vite": "^8.4.5",
25
+ "@storybook/test": "^8.4.5",
25
26
  "@storybook/test-runner": "^0.21.0",
26
27
  "@strictly/support-vite": "*",
27
28
  "@testing-library/dom": "^10.4.0",
@@ -69,7 +70,7 @@
69
70
  "test:watch": "vitest"
70
71
  },
71
72
  "type": "module",
72
- "version": "0.0.6",
73
+ "version": "0.0.8",
73
74
  "exports": {
74
75
  ".": {
75
76
  "import": {