@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.
- package/.out/core/mobx/hooks.d.ts +10 -0
- package/.out/core/mobx/hooks.js +47 -0
- package/.out/core/mobx/specs/form_presenter.tests.js +3 -6
- package/.out/core/mobx/specs/{merge_field_adapters_with_two_way_converter.js → merge_field_adapters_with_two_way_converter.tests.js} +15 -16
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +78 -10
- package/.out/core/mobx/sub_form_field_adapters.d.ts +6 -4
- package/.out/core/mobx/sub_form_field_adapters.js +23 -2
- package/.out/core/props.d.ts +2 -2
- package/.out/index.d.ts +1 -0
- package/.out/index.js +1 -0
- package/.out/mantine/create_fields_view.d.ts +7 -0
- package/.out/mantine/{create_sub_form.js → create_fields_view.js} +4 -5
- package/.out/mantine/create_form.d.ts +7 -0
- package/.out/mantine/create_form.js +13 -0
- package/.out/mantine/hooks.d.ts +6 -4
- package/.out/mantine/hooks.js +17 -7
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/checkbox_hooks.stories.js +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.d.ts → fields_view_hooks.stories.d.ts} +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.js → fields_view_hooks.stories.js} +9 -8
- package/.out/mantine/specs/fields_view_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/fields_view_hooks.tests.js +12 -0
- package/.out/mantine/specs/form_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/form_hooks.stories.js +60 -0
- package/.out/mantine/specs/form_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/form_hooks.tests.js +12 -0
- package/.out/mantine/specs/list_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/list_hooks.stories.js +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.js +2 -2
- package/.out/mantine/specs/select_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/select_hooks.stories.js +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.js +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.js +2 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/hooks.ts +94 -0
- package/core/mobx/specs/form_presenter.tests.ts +6 -6
- package/core/mobx/specs/{merge_field_adapters_with_two_way_converter.ts → merge_field_adapters_with_two_way_converter.tests.ts} +16 -16
- package/core/mobx/specs/sub_form_field_adapters.tests.ts +93 -10
- package/core/mobx/sub_form_field_adapters.ts +54 -7
- package/core/props.ts +2 -2
- package/dist/index.cjs +200 -90
- package/dist/index.d.cts +43 -34
- package/dist/index.d.ts +43 -34
- package/dist/index.js +186 -70
- package/index.ts +1 -0
- package/mantine/{create_sub_form.tsx → create_fields_view.tsx} +27 -16
- package/mantine/create_form.tsx +43 -0
- package/mantine/hooks.tsx +48 -14
- package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +460 -0
- package/mantine/specs/__snapshots__/form_hooks.tests.tsx.snap +273 -0
- package/mantine/specs/checkbox_hooks.stories.tsx +4 -4
- package/mantine/specs/{sub_form_hooks.stories.tsx → fields_view_hooks.stories.tsx} +23 -11
- package/mantine/specs/fields_view_hooks.tests.tsx +15 -0
- package/mantine/specs/form_hooks.stories.tsx +107 -0
- package/mantine/specs/form_hooks.tests.tsx +15 -0
- package/mantine/specs/list_hooks.stories.tsx +4 -4
- package/mantine/specs/radio_group_hooks.stories.tsx +4 -4
- package/mantine/specs/select_hooks.stories.tsx +4 -4
- package/mantine/specs/text_input_hooks.stories.tsx +4 -4
- package/mantine/specs/value_input_hooks.stories.tsx +4 -4
- package/package.json +1 -1
- package/.out/mantine/create_sub_form.d.ts +0 -6
- /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,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, NumberInput, Stack, } from '@mantine/core';
|
|
3
|
+
import { action } from '@storybook/addon-actions';
|
|
4
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
const onCancel = action('canceled');
|
|
7
|
+
function SubForm({ value, onValueChange, onCancel, }) {
|
|
8
|
+
const onChange = useCallback((v) => {
|
|
9
|
+
onValueChange(Number.parseInt(`${v}`));
|
|
10
|
+
}, [onValueChange]);
|
|
11
|
+
return (_jsxs(Stack, { children: [_jsx(NumberInput, { allowDecimal: false, label: 'sub form', onChange: onChange, value: value }), _jsx(Button, { onClick: onCancel, children: "Cancel" })] }));
|
|
12
|
+
}
|
|
13
|
+
function Component(props) {
|
|
14
|
+
const form = useMantineFormFields(props);
|
|
15
|
+
const Form = form.form('$.a', SubForm);
|
|
16
|
+
const TextInput = form.textInput('$');
|
|
17
|
+
return (_jsxs(Stack, { children: [_jsx(TextInput, { label: 'fields view' }), _jsx(Form, { onCancel: onCancel })] }));
|
|
18
|
+
}
|
|
19
|
+
const meta = {
|
|
20
|
+
component: Component,
|
|
21
|
+
args: {
|
|
22
|
+
onFieldBlur: action('onFieldBlur'),
|
|
23
|
+
onFieldFocus: action('onFieldFocus'),
|
|
24
|
+
onFieldSubmit: action('onFieldSubmit'),
|
|
25
|
+
onFieldValueChange: action('onFieldValueChange'),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export default meta;
|
|
29
|
+
export const Empty = {
|
|
30
|
+
args: {
|
|
31
|
+
fields: {
|
|
32
|
+
$: {
|
|
33
|
+
readonly: false,
|
|
34
|
+
required: false,
|
|
35
|
+
value: '',
|
|
36
|
+
},
|
|
37
|
+
'$.a': {
|
|
38
|
+
readonly: false,
|
|
39
|
+
required: false,
|
|
40
|
+
value: 0,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
export const Populated = {
|
|
46
|
+
args: {
|
|
47
|
+
fields: {
|
|
48
|
+
$: {
|
|
49
|
+
readonly: false,
|
|
50
|
+
required: false,
|
|
51
|
+
value: 'Hello',
|
|
52
|
+
},
|
|
53
|
+
'$.a': {
|
|
54
|
+
readonly: false,
|
|
55
|
+
required: false,
|
|
56
|
+
value: 2,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { composeStories } from '@storybook/react';
|
|
3
|
+
import { toArray } from '@strictly/base';
|
|
4
|
+
import { render, } from '@testing-library/react';
|
|
5
|
+
import * as stories from './form_hooks.stories';
|
|
6
|
+
const composedStories = composeStories(stories);
|
|
7
|
+
describe('form hooks', function () {
|
|
8
|
+
it.each(toArray(composedStories))('renders %s', function (_name, Story) {
|
|
9
|
+
const wrapper = render(_jsx(Story, {}));
|
|
10
|
+
expect(wrapper.container).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FieldsViewProps } from 'core/props';
|
|
3
3
|
import { type Field } from 'types/field';
|
|
4
|
-
declare function Component(props:
|
|
4
|
+
declare function Component(props: FieldsViewProps<{
|
|
5
5
|
$: Field<string[], string>;
|
|
6
6
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
declare const meta: Meta<typeof Component>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Code, Paper, Stack, } from '@mantine/core';
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import {
|
|
4
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
5
5
|
function Component(props) {
|
|
6
|
-
const form =
|
|
6
|
+
const form = useMantineFormFields(props);
|
|
7
7
|
const List = form.list('$');
|
|
8
8
|
return (_jsx(Paper, { p: 'sm', withBorder: true, children: _jsx(Stack, { children: _jsx(List, { children: function (valuePath, value, index) {
|
|
9
9
|
return (_jsxs(Code, { children: [_jsxs("span", { children: ["ValuePath: ", valuePath] }), _jsx("br", {}), _jsxs("span", { children: ["Value: ", value] }), _jsx("br", {}), _jsxs("span", { children: ["Index: ", index] })] }, valuePath));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FieldsViewProps } from 'core/props';
|
|
3
3
|
import { type ErrorRenderer } from 'mantine/error_renderer';
|
|
4
4
|
import { type Field } from 'types/field';
|
|
5
5
|
import { type RadioValue } from './radio_group_constants';
|
|
6
|
-
declare function Component({ ErrorRenderer, ...props }:
|
|
6
|
+
declare function Component({ ErrorRenderer, ...props }: FieldsViewProps<{
|
|
7
7
|
$: Field<RadioValue | null, string>;
|
|
8
8
|
}> & {
|
|
9
9
|
ErrorRenderer?: ErrorRenderer;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Stack, } from '@mantine/core';
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import {
|
|
4
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
5
5
|
import { RADIO_GROUP_LABEL, RADIO_LABELS, RADIO_VALUES, } from './radio_group_constants';
|
|
6
6
|
function Component({ ErrorRenderer, ...props }) {
|
|
7
|
-
const form =
|
|
7
|
+
const form = useMantineFormFields(props);
|
|
8
8
|
const RadioGroupComponent = form.radioGroup('$');
|
|
9
9
|
return (_jsx(RadioGroupComponent, { ErrorRenderer: ErrorRenderer, label: RADIO_GROUP_LABEL, children: _jsx(Stack, { children: RADIO_VALUES.map(function (value) {
|
|
10
10
|
const label = RADIO_LABELS[value];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FieldsViewProps } from 'core/props';
|
|
3
3
|
import { type ErrorRenderer } from 'mantine/error_renderer';
|
|
4
4
|
import { type Field } from 'types/field';
|
|
5
|
-
declare function Component({ ErrorRenderer, ...props }:
|
|
5
|
+
declare function Component({ ErrorRenderer, ...props }: FieldsViewProps<{
|
|
6
6
|
$: Field<string | null, string>;
|
|
7
7
|
}> & {
|
|
8
8
|
ErrorRenderer?: ErrorRenderer;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { action } from '@storybook/addon-actions';
|
|
3
|
-
import {
|
|
3
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
4
4
|
import { SELECT_LABEL } from './select_hooks_constant';
|
|
5
5
|
function Component({ ErrorRenderer, ...props }) {
|
|
6
|
-
const form =
|
|
6
|
+
const form = useMantineFormFields(props);
|
|
7
7
|
const SelectComponent = form.select('$');
|
|
8
8
|
return (_jsx(SelectComponent, { ErrorRenderer: ErrorRenderer, data: [
|
|
9
9
|
'a',
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type TextInputProps } from '@mantine/core';
|
|
2
2
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
3
|
-
import { type
|
|
3
|
+
import { type FieldsViewProps } from 'core/props';
|
|
4
4
|
import { type SuppliedTextInputProps, type TextInputTarget } from 'mantine/create_text_input';
|
|
5
5
|
import { type ErrorRenderer } from 'mantine/error_renderer';
|
|
6
6
|
import { type ComponentType } from 'react';
|
|
7
7
|
import { type Field } from 'types/field';
|
|
8
8
|
type StoryTextInputProps<T extends TextInputTarget> = SuppliedTextInputProps<T> & Pick<TextInputProps, 'label'>;
|
|
9
|
-
declare function Component<T extends TextInputTarget>({ TextInput, ErrorRenderer, ...props }:
|
|
9
|
+
declare function Component<T extends TextInputTarget>({ TextInput, ErrorRenderer, ...props }: FieldsViewProps<{
|
|
10
10
|
$: Field<string, string>;
|
|
11
11
|
}> & {
|
|
12
12
|
TextInput?: ComponentType<StoryTextInputProps<T>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PillsInputField, Textarea, } from '@mantine/core';
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import {
|
|
4
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
5
5
|
import { TEXT_INPUT_LABEL } from './text_input_constants';
|
|
6
6
|
function Component({ TextInput, ErrorRenderer, ...props }) {
|
|
7
|
-
const form =
|
|
7
|
+
const form = useMantineFormFields(props);
|
|
8
8
|
const TextInputComponent = form.textInput('$', TextInput);
|
|
9
9
|
return (_jsx(TextInputComponent, { ErrorRenderer: ErrorRenderer, label: TEXT_INPUT_LABEL }));
|
|
10
10
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type JsonInputProps, type NumberInputProps, type RatingProps, type SliderProps } from '@mantine/core';
|
|
2
2
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
3
|
-
import { type
|
|
3
|
+
import { type FieldsViewProps } from 'core/props';
|
|
4
4
|
import { type SuppliedValueInputProps } from 'mantine/create_value_input';
|
|
5
5
|
import { type ErrorRenderer } from 'mantine/error_renderer';
|
|
6
6
|
import { type ComponentType } from 'react';
|
|
7
7
|
import { type Field } from 'types/field';
|
|
8
8
|
type StoryValueInputProps<V> = SuppliedValueInputProps<V, any>;
|
|
9
|
-
declare function Component<V, P extends StoryValueInputProps<V>>({ ValueInput, ErrorRenderer, inputProps, ...props }:
|
|
9
|
+
declare function Component<V, P extends StoryValueInputProps<V>>({ ValueInput, ErrorRenderer, inputProps, ...props }: FieldsViewProps<{
|
|
10
10
|
$: Field<V, string>;
|
|
11
11
|
}> & {
|
|
12
12
|
ValueInput: ComponentType<P>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { JsonInput, NumberInput, Rating, Slider, } from '@mantine/core';
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import {
|
|
4
|
+
import { useMantineFormFields } from 'mantine/hooks';
|
|
5
5
|
import { NUMBER_INPUT_LABEL, SLIDER_LABEL, } from './value_input_constants';
|
|
6
6
|
function Component({ ValueInput, ErrorRenderer, inputProps, ...props }) {
|
|
7
|
-
const form =
|
|
7
|
+
const form = useMantineFormFields(props);
|
|
8
8
|
const ValueInputComponent = form.valueInput('$', ValueInput);
|
|
9
9
|
return (_jsx(ValueInputComponent, { ...inputProps, ErrorRenderer: ErrorRenderer }));
|
|
10
10
|
}
|