@manafishrov/ui 1.3.1 → 1.3.2
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/dist/components/form/NumberInputField.js +100 -73
- package/dist/components/form/NumberInputField.js.map +1 -1
- package/dist/components/form/SubmitButton.js +12 -9
- package/dist/components/form/SubmitButton.js.map +1 -1
- package/package.json +1 -1
- package/src/components/form/NumberInputField.tsx +111 -35
- package/src/components/form/SubmitButton.tsx +2 -1
|
@@ -1,81 +1,108 @@
|
|
|
1
|
-
import { createComponent as
|
|
2
|
-
import { Field as
|
|
3
|
-
import { NumberInput as
|
|
4
|
-
import { useFieldContext as
|
|
5
|
-
import { splitProps as
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createComponent as r, mergeProps as o, Show as d } from "solid-js/web";
|
|
2
|
+
import { Field as m, FieldLabel as g, FieldContent as c, FieldError as s, FieldDescription as h } from "../Field.js";
|
|
3
|
+
import { NumberInput as b, NumberInputControl as V, NumberInputInput as f, NumberInputTriggers as C } from "../NumberInput.js";
|
|
4
|
+
import { useFieldContext as N } from "./context.js";
|
|
5
|
+
import { splitProps as F, createSignal as I, createEffect as v } from "solid-js";
|
|
6
|
+
const a = (e) => typeof e != "number" || !Number.isFinite(e) ? "" : String(e), B = (e) => {
|
|
7
|
+
const [u, t] = I(a(e().state.value));
|
|
8
|
+
return v(() => {
|
|
9
|
+
t(a(e().state.value));
|
|
10
|
+
}), {
|
|
11
|
+
inputValue: u,
|
|
12
|
+
onValueChange: (l) => {
|
|
13
|
+
t(l.value);
|
|
11
14
|
},
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
onValueCommit: (l) => {
|
|
16
|
+
t(l.value), Number.isFinite(l.valueAsNumber) && e().handleChange(l.valueAsNumber);
|
|
14
17
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
get readOnly() {
|
|
19
|
-
return r.readOnly ?? !1;
|
|
20
|
-
},
|
|
21
|
-
get children() {
|
|
22
|
-
return [e(a, {
|
|
23
|
-
get children() {
|
|
24
|
-
return r.label;
|
|
25
|
-
}
|
|
26
|
-
}), e(o, {
|
|
27
|
-
get children() {
|
|
28
|
-
return [e(m, {
|
|
29
|
-
get value() {
|
|
30
|
-
return String(t().state.value);
|
|
31
|
-
},
|
|
32
|
-
onValueChange: (i) => {
|
|
33
|
-
t().handleChange(i.valueAsNumber);
|
|
34
|
-
},
|
|
35
|
-
onBlur: () => {
|
|
36
|
-
t().handleBlur();
|
|
37
|
-
},
|
|
38
|
-
get invalid() {
|
|
39
|
-
return t().state.meta.errors.length > 0;
|
|
40
|
-
},
|
|
41
|
-
get disabled() {
|
|
42
|
-
return r.disabled ?? !1;
|
|
43
|
-
},
|
|
44
|
-
get readOnly() {
|
|
45
|
-
return r.readOnly ?? !1;
|
|
46
|
-
},
|
|
47
|
-
get required() {
|
|
48
|
-
return r.required ?? !1;
|
|
49
|
-
},
|
|
50
|
-
get children() {
|
|
51
|
-
return e(h, {
|
|
52
|
-
get children() {
|
|
53
|
-
return [e(p, l), e(u, {
|
|
54
|
-
get when() {
|
|
55
|
-
return r.showTriggers !== !1;
|
|
56
|
-
},
|
|
57
|
-
get children() {
|
|
58
|
-
return e(c, {});
|
|
59
|
-
}
|
|
60
|
-
})];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}), e(s, {
|
|
65
|
-
get errors() {
|
|
66
|
-
return t().state.meta.errors;
|
|
67
|
-
}
|
|
68
|
-
}), e(g, {
|
|
69
|
-
get children() {
|
|
70
|
-
return r.description;
|
|
71
|
-
}
|
|
72
|
-
})];
|
|
73
|
-
}
|
|
74
|
-
})];
|
|
18
|
+
onBlur: () => {
|
|
19
|
+
t(a(e().state.value)), e().handleBlur();
|
|
75
20
|
}
|
|
21
|
+
};
|
|
22
|
+
}, y = (e) => r(m, {
|
|
23
|
+
get invalid() {
|
|
24
|
+
return e.field().state.meta.errors.length > 0;
|
|
25
|
+
},
|
|
26
|
+
get required() {
|
|
27
|
+
return e.local.required ?? !1;
|
|
28
|
+
},
|
|
29
|
+
get disabled() {
|
|
30
|
+
return e.local.disabled ?? !1;
|
|
31
|
+
},
|
|
32
|
+
get readOnly() {
|
|
33
|
+
return e.local.readOnly ?? !1;
|
|
34
|
+
},
|
|
35
|
+
get children() {
|
|
36
|
+
return [r(g, {
|
|
37
|
+
get children() {
|
|
38
|
+
return e.local.label;
|
|
39
|
+
}
|
|
40
|
+
}), r(c, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [r(b, {
|
|
43
|
+
get value() {
|
|
44
|
+
return e.inputValue();
|
|
45
|
+
},
|
|
46
|
+
get onValueChange() {
|
|
47
|
+
return e.onValueChange;
|
|
48
|
+
},
|
|
49
|
+
get onValueCommit() {
|
|
50
|
+
return e.onValueCommit;
|
|
51
|
+
},
|
|
52
|
+
get onBlur() {
|
|
53
|
+
return e.onBlur;
|
|
54
|
+
},
|
|
55
|
+
get invalid() {
|
|
56
|
+
return e.field().state.meta.errors.length > 0;
|
|
57
|
+
},
|
|
58
|
+
get disabled() {
|
|
59
|
+
return e.local.disabled ?? !1;
|
|
60
|
+
},
|
|
61
|
+
get readOnly() {
|
|
62
|
+
return e.local.readOnly ?? !1;
|
|
63
|
+
},
|
|
64
|
+
get required() {
|
|
65
|
+
return e.local.required ?? !1;
|
|
66
|
+
},
|
|
67
|
+
get children() {
|
|
68
|
+
return r(V, {
|
|
69
|
+
get children() {
|
|
70
|
+
return [r(f, o(() => e.others)), r(d, {
|
|
71
|
+
get when() {
|
|
72
|
+
return e.local.showTriggers !== !1;
|
|
73
|
+
},
|
|
74
|
+
get children() {
|
|
75
|
+
return r(C, {});
|
|
76
|
+
}
|
|
77
|
+
})];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}), r(s, {
|
|
82
|
+
get errors() {
|
|
83
|
+
return e.field().state.meta.errors;
|
|
84
|
+
}
|
|
85
|
+
}), r(h, {
|
|
86
|
+
get children() {
|
|
87
|
+
return e.local.description;
|
|
88
|
+
}
|
|
89
|
+
})];
|
|
90
|
+
}
|
|
91
|
+
})];
|
|
92
|
+
}
|
|
93
|
+
}), A = (e) => {
|
|
94
|
+
const u = N(), [t, i] = F(e, ["label", "description", "required", "disabled", "readOnly", "showTriggers"]), n = B(u);
|
|
95
|
+
return y({
|
|
96
|
+
field: u,
|
|
97
|
+
local: t,
|
|
98
|
+
others: i,
|
|
99
|
+
inputValue: n.inputValue,
|
|
100
|
+
onValueChange: n.onValueChange,
|
|
101
|
+
onValueCommit: n.onValueCommit,
|
|
102
|
+
onBlur: n.onBlur
|
|
76
103
|
});
|
|
77
104
|
};
|
|
78
105
|
export {
|
|
79
|
-
|
|
106
|
+
A as NumberInputField
|
|
80
107
|
};
|
|
81
108
|
//# sourceMappingURL=NumberInputField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInputField.js","sources":["../../../src/components/form/NumberInputField.tsx"],"sourcesContent":["import type { Component, ComponentProps } from 'solid-js';\n\nimport { Field, FieldLabel, FieldContent, FieldError, FieldDescription } from '@/components/Field';\nimport {\n NumberInput,\n NumberInputControl,\n NumberInputInput,\n NumberInputTriggers,\n} from '@/components/NumberInput';\n\nimport { useFieldContext } from './context';\n\nexport type NumberInputFieldProps = ComponentProps<typeof NumberInputInput> & {\n label?: string;\n description?: string;\n showTriggers?: boolean;\n};\n\
|
|
1
|
+
{"version":3,"file":"NumberInputField.js","sources":["../../../src/components/form/NumberInputField.tsx"],"sourcesContent":["import type { Component, ComponentProps, JSX } from 'solid-js';\n\nimport { Field, FieldLabel, FieldContent, FieldError, FieldDescription } from '@/components/Field';\nimport {\n NumberInput,\n NumberInputControl,\n NumberInputInput,\n NumberInputTriggers,\n} from '@/components/NumberInput';\n\nimport { useFieldContext } from './context';\n\nexport type NumberInputFieldProps = ComponentProps<typeof NumberInputInput> & {\n label?: string;\n description?: string;\n showTriggers?: boolean;\n};\n\nconst toNumberInputValue = (value: number | undefined): string => {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n return '';\n }\n\n return String(value);\n};\n\ntype NumberInputFieldLocalProps = Pick<\n NumberInputFieldProps,\n 'label' | 'description' | 'required' | 'disabled' | 'readOnly' | 'showTriggers'\n>;\n\ntype RenderNumberInputFieldProps = {\n field: ReturnType<typeof useFieldContext<number>>;\n local: NumberInputFieldLocalProps;\n others: Omit<NumberInputFieldProps, keyof NumberInputFieldLocalProps>;\n inputValue: () => string;\n onValueChange: NonNullable<ComponentProps<typeof NumberInput>['onValueChange']>;\n onValueCommit: NonNullable<ComponentProps<typeof NumberInput>['onValueCommit']>;\n onBlur: () => void;\n};\n\ntype NumberInputFieldState = Pick<\n RenderNumberInputFieldProps,\n 'inputValue' | 'onValueChange' | 'onValueCommit' | 'onBlur'\n>;\n\nconst createNumberInputFieldState = (\n field: ReturnType<typeof useFieldContext<number>>,\n): NumberInputFieldState => {\n const [inputValue, setInputValue] = createSignal(toNumberInputValue(field().state.value));\n\n createEffect(() => {\n setInputValue(toNumberInputValue(field().state.value));\n });\n\n const onValueChange: NonNullable<ComponentProps<typeof NumberInput>['onValueChange']> = (\n details,\n ) => {\n setInputValue(details.value);\n };\n\n const onValueCommit: NonNullable<ComponentProps<typeof NumberInput>['onValueCommit']> = (\n details,\n ) => {\n setInputValue(details.value);\n\n if (!Number.isFinite(details.valueAsNumber)) {\n return;\n }\n\n field().handleChange(details.valueAsNumber);\n };\n\n const onBlur = (): void => {\n setInputValue(toNumberInputValue(field().state.value));\n field().handleBlur();\n };\n\n return {\n inputValue,\n onValueChange,\n onValueCommit,\n onBlur,\n };\n};\n\nconst renderNumberInputField = (props: RenderNumberInputFieldProps): JSX.Element => (\n <Field\n invalid={props.field().state.meta.errors.length > 0}\n required={props.local.required ?? false}\n disabled={props.local.disabled ?? false}\n readOnly={props.local.readOnly ?? false}\n >\n <FieldLabel>{props.local.label}</FieldLabel>\n <FieldContent>\n <NumberInput\n value={props.inputValue()}\n onValueChange={props.onValueChange}\n onValueCommit={props.onValueCommit}\n onBlur={props.onBlur}\n invalid={props.field().state.meta.errors.length > 0}\n disabled={props.local.disabled ?? false}\n readOnly={props.local.readOnly ?? false}\n required={props.local.required ?? false}\n >\n <NumberInputControl>\n <NumberInputInput {...props.others} />\n <Show when={props.local.showTriggers !== false}>\n <NumberInputTriggers />\n </Show>\n </NumberInputControl>\n </NumberInput>\n <FieldError errors={props.field().state.meta.errors} />\n <FieldDescription>{props.local.description}</FieldDescription>\n </FieldContent>\n </Field>\n);\n\nexport const NumberInputField: Component<NumberInputFieldProps> = (props) => {\n const field = useFieldContext<number>();\n const [local, others] = splitProps(props, [\n 'label',\n 'description',\n 'required',\n 'disabled',\n 'readOnly',\n 'showTriggers',\n ]);\n const state = createNumberInputFieldState(field);\n\n return renderNumberInputField({\n field,\n local,\n others,\n inputValue: state.inputValue,\n onValueChange: state.onValueChange,\n onValueCommit: state.onValueCommit,\n onBlur: state.onBlur,\n });\n};\n"],"names":["toNumberInputValue","value","Number","isFinite","String","createNumberInputFieldState","field","inputValue","setInputValue","createSignal","state","createEffect","onValueChange","details","onValueCommit","valueAsNumber","handleChange","onBlur","handleBlur","renderNumberInputField","props","_$createComponent","Field","invalid","meta","errors","length","required","local","disabled","readOnly","children","FieldLabel","label","FieldContent","NumberInput","NumberInputControl","NumberInputInput","_$mergeProps","others","_$Show","when","showTriggers","NumberInputTriggers","FieldError","FieldDescription","description","NumberInputField","useFieldContext","splitProps"],"mappings":";;;;;AAkBA,MAAMA,IAAqBA,CAACC,MACtB,OAAOA,KAAU,YAAY,CAACC,OAAOC,SAASF,CAAK,IAC9C,KAGFG,OAAOH,CAAK,GAuBfI,IAA8BA,CAClCC,MAC0B;AAC1B,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAaT,EAAmBM,EAAAA,EAAQI,MAAMT,KAAK,CAAC;AAExFU,SAAAA,EAAa,MAAM;AACj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AAO,CACxC,SACA,eACA,YACA,YACA,YACA,cAAc,CACf,GACKV,IAAQL,EAA4BC,CAAK;AAE/C,SAAOa,EAAuB;AAAA,IAC5Bb,OAAAA;AAAAA,IACAsB,OAAAA;AAAAA,IACAW,QAAAA;AAAAA,IACAhC,YAAYG,EAAMH;AAAAA,IAClBK,eAAeF,EAAME;AAAAA,IACrBE,eAAeJ,EAAMI;AAAAA,IACrBG,QAAQP,EAAMO;AAAAA,EAAAA,CACf;AACH;"}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { createComponent as
|
|
1
|
+
import { createComponent as s, mergeProps as n } from "solid-js/web";
|
|
2
2
|
import { Button as a } from "../Button.js";
|
|
3
|
-
import { useFormContext as
|
|
4
|
-
import { splitProps as
|
|
5
|
-
const p = (
|
|
6
|
-
const
|
|
7
|
-
return
|
|
3
|
+
import { useFormContext as l } from "./context.js";
|
|
4
|
+
import { splitProps as m } from "solid-js";
|
|
5
|
+
const p = (r) => {
|
|
6
|
+
const e = l(), [t, o] = m(r, ["children", "loading", "disabled", "class"]), i = () => e.state.isSubmitting || e.state.isValidating || (t.loading ?? !1);
|
|
7
|
+
return s(a, n({
|
|
8
8
|
type: "submit",
|
|
9
9
|
get loading() {
|
|
10
10
|
return i();
|
|
11
11
|
},
|
|
12
12
|
get disabled() {
|
|
13
|
-
return
|
|
13
|
+
return t.disabled ?? !e.state.canSubmit;
|
|
14
|
+
},
|
|
15
|
+
get class() {
|
|
16
|
+
return `min-w-24 ${t.class ?? ""}`;
|
|
14
17
|
}
|
|
15
|
-
},
|
|
18
|
+
}, o, {
|
|
16
19
|
get children() {
|
|
17
|
-
return
|
|
20
|
+
return t.children;
|
|
18
21
|
}
|
|
19
22
|
}));
|
|
20
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubmitButton.js","sources":["../../../src/components/form/SubmitButton.tsx"],"sourcesContent":["import type { Component, ComponentProps } from 'solid-js';\n\nimport { Button } from '@/components/Button';\n\nimport { useFormContext } from './context';\n\nexport type SubmitButtonProps = ComponentProps<typeof Button> & {\n loading?: boolean;\n};\n\nexport const SubmitButton: Component<SubmitButtonProps> = (props) => {\n const form = useFormContext();\n const [local, others] = splitProps(props, ['children', 'loading', 'disabled']);\n\n const isLoading = (): boolean =>\n form.state.isSubmitting || form.state.isValidating || (local.loading ?? false);\n\n return (\n <Button\n type='submit'\n loading={isLoading()}\n disabled={local.disabled ?? !form.state.canSubmit}\n {...others}\n >\n {local.children}\n </Button>\n );\n};\n"],"names":["SubmitButton","props","form","useFormContext","local","others","splitProps","isLoading","state","isSubmitting","isValidating","loading","_$createComponent","Button","_$mergeProps","type","disabled","canSubmit","children"],"mappings":";;;;AAUO,MAAMA,IAA8CC,CAAAA,MAAU;AACnE,QAAMC,IAAOC,EAAAA,GACP,CAACC,GAAOC,CAAM,IAAIC,EAAWL,GAAO,CAAC,YAAY,WAAW,
|
|
1
|
+
{"version":3,"file":"SubmitButton.js","sources":["../../../src/components/form/SubmitButton.tsx"],"sourcesContent":["import type { Component, ComponentProps } from 'solid-js';\n\nimport { Button } from '@/components/Button';\n\nimport { useFormContext } from './context';\n\nexport type SubmitButtonProps = ComponentProps<typeof Button> & {\n loading?: boolean;\n};\n\nexport const SubmitButton: Component<SubmitButtonProps> = (props) => {\n const form = useFormContext();\n const [local, others] = splitProps(props, ['children', 'loading', 'disabled', 'class']);\n\n const isLoading = (): boolean =>\n form.state.isSubmitting || form.state.isValidating || (local.loading ?? false);\n\n return (\n <Button\n type='submit'\n loading={isLoading()}\n disabled={local.disabled ?? !form.state.canSubmit}\n class={`min-w-24 ${local.class ?? ''}`}\n {...others}\n >\n {local.children}\n </Button>\n );\n};\n"],"names":["SubmitButton","props","form","useFormContext","local","others","splitProps","isLoading","state","isSubmitting","isValidating","loading","_$createComponent","Button","_$mergeProps","type","disabled","canSubmit","class","children"],"mappings":";;;;AAUO,MAAMA,IAA8CC,CAAAA,MAAU;AACnE,QAAMC,IAAOC,EAAAA,GACP,CAACC,GAAOC,CAAM,IAAIC,EAAWL,GAAO,CAAC,YAAY,WAAW,YAAY,OAAO,CAAC,GAEhFM,IAAYA,MAChBL,EAAKM,MAAMC,gBAAgBP,EAAKM,MAAME,iBAAiBN,EAAMO,WAAW;AAE1E,SAAAC,EACGC,GAAMC,EAAA;AAAA,IACLC,MAAI;AAAA,IAAA,IACJJ,UAAO;AAAA,aAAEJ,EAAAA;AAAAA,IAAW;AAAA,IAAA,IACpBS,WAAQ;AAAA,aAAEZ,EAAMY,YAAY,CAACd,EAAKM,MAAMS;AAAAA,IAAS;AAAA,IAAA,IAAA,QAAA;AAAA,aAC1C,YAAYb,EAAMc,SAAS,EAAE;AAAA,IAAE;AAAA,EAAA,GAClCb,GAAM;AAAA,IAAA,IAAAc,WAAA;AAAA,aAETf,EAAMe;AAAAA,IAAQ;AAAA,EAAA,CAAA,CAAA;AAGrB;"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Component, ComponentProps } from 'solid-js';
|
|
1
|
+
import type { Component, ComponentProps, JSX } from 'solid-js';
|
|
2
2
|
|
|
3
3
|
import { Field, FieldLabel, FieldContent, FieldError, FieldDescription } from '@/components/Field';
|
|
4
4
|
import {
|
|
@@ -16,6 +16,106 @@ export type NumberInputFieldProps = ComponentProps<typeof NumberInputInput> & {
|
|
|
16
16
|
showTriggers?: boolean;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
const toNumberInputValue = (value: number | undefined): string => {
|
|
20
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return String(value);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type NumberInputFieldLocalProps = Pick<
|
|
28
|
+
NumberInputFieldProps,
|
|
29
|
+
'label' | 'description' | 'required' | 'disabled' | 'readOnly' | 'showTriggers'
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
type RenderNumberInputFieldProps = {
|
|
33
|
+
field: ReturnType<typeof useFieldContext<number>>;
|
|
34
|
+
local: NumberInputFieldLocalProps;
|
|
35
|
+
others: Omit<NumberInputFieldProps, keyof NumberInputFieldLocalProps>;
|
|
36
|
+
inputValue: () => string;
|
|
37
|
+
onValueChange: NonNullable<ComponentProps<typeof NumberInput>['onValueChange']>;
|
|
38
|
+
onValueCommit: NonNullable<ComponentProps<typeof NumberInput>['onValueCommit']>;
|
|
39
|
+
onBlur: () => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type NumberInputFieldState = Pick<
|
|
43
|
+
RenderNumberInputFieldProps,
|
|
44
|
+
'inputValue' | 'onValueChange' | 'onValueCommit' | 'onBlur'
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
const createNumberInputFieldState = (
|
|
48
|
+
field: ReturnType<typeof useFieldContext<number>>,
|
|
49
|
+
): NumberInputFieldState => {
|
|
50
|
+
const [inputValue, setInputValue] = createSignal(toNumberInputValue(field().state.value));
|
|
51
|
+
|
|
52
|
+
createEffect(() => {
|
|
53
|
+
setInputValue(toNumberInputValue(field().state.value));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const onValueChange: NonNullable<ComponentProps<typeof NumberInput>['onValueChange']> = (
|
|
57
|
+
details,
|
|
58
|
+
) => {
|
|
59
|
+
setInputValue(details.value);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const onValueCommit: NonNullable<ComponentProps<typeof NumberInput>['onValueCommit']> = (
|
|
63
|
+
details,
|
|
64
|
+
) => {
|
|
65
|
+
setInputValue(details.value);
|
|
66
|
+
|
|
67
|
+
if (!Number.isFinite(details.valueAsNumber)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
field().handleChange(details.valueAsNumber);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const onBlur = (): void => {
|
|
75
|
+
setInputValue(toNumberInputValue(field().state.value));
|
|
76
|
+
field().handleBlur();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
inputValue,
|
|
81
|
+
onValueChange,
|
|
82
|
+
onValueCommit,
|
|
83
|
+
onBlur,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const renderNumberInputField = (props: RenderNumberInputFieldProps): JSX.Element => (
|
|
88
|
+
<Field
|
|
89
|
+
invalid={props.field().state.meta.errors.length > 0}
|
|
90
|
+
required={props.local.required ?? false}
|
|
91
|
+
disabled={props.local.disabled ?? false}
|
|
92
|
+
readOnly={props.local.readOnly ?? false}
|
|
93
|
+
>
|
|
94
|
+
<FieldLabel>{props.local.label}</FieldLabel>
|
|
95
|
+
<FieldContent>
|
|
96
|
+
<NumberInput
|
|
97
|
+
value={props.inputValue()}
|
|
98
|
+
onValueChange={props.onValueChange}
|
|
99
|
+
onValueCommit={props.onValueCommit}
|
|
100
|
+
onBlur={props.onBlur}
|
|
101
|
+
invalid={props.field().state.meta.errors.length > 0}
|
|
102
|
+
disabled={props.local.disabled ?? false}
|
|
103
|
+
readOnly={props.local.readOnly ?? false}
|
|
104
|
+
required={props.local.required ?? false}
|
|
105
|
+
>
|
|
106
|
+
<NumberInputControl>
|
|
107
|
+
<NumberInputInput {...props.others} />
|
|
108
|
+
<Show when={props.local.showTriggers !== false}>
|
|
109
|
+
<NumberInputTriggers />
|
|
110
|
+
</Show>
|
|
111
|
+
</NumberInputControl>
|
|
112
|
+
</NumberInput>
|
|
113
|
+
<FieldError errors={props.field().state.meta.errors} />
|
|
114
|
+
<FieldDescription>{props.local.description}</FieldDescription>
|
|
115
|
+
</FieldContent>
|
|
116
|
+
</Field>
|
|
117
|
+
);
|
|
118
|
+
|
|
19
119
|
export const NumberInputField: Component<NumberInputFieldProps> = (props) => {
|
|
20
120
|
const field = useFieldContext<number>();
|
|
21
121
|
const [local, others] = splitProps(props, [
|
|
@@ -26,39 +126,15 @@ export const NumberInputField: Component<NumberInputFieldProps> = (props) => {
|
|
|
26
126
|
'readOnly',
|
|
27
127
|
'showTriggers',
|
|
28
128
|
]);
|
|
129
|
+
const state = createNumberInputFieldState(field);
|
|
29
130
|
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<NumberInput
|
|
40
|
-
value={String(field().state.value)}
|
|
41
|
-
onValueChange={(details) => {
|
|
42
|
-
field().handleChange(details.valueAsNumber);
|
|
43
|
-
}}
|
|
44
|
-
onBlur={() => {
|
|
45
|
-
field().handleBlur();
|
|
46
|
-
}}
|
|
47
|
-
invalid={field().state.meta.errors.length > 0}
|
|
48
|
-
disabled={local.disabled ?? false}
|
|
49
|
-
readOnly={local.readOnly ?? false}
|
|
50
|
-
required={local.required ?? false}
|
|
51
|
-
>
|
|
52
|
-
<NumberInputControl>
|
|
53
|
-
<NumberInputInput {...others} />
|
|
54
|
-
<Show when={local.showTriggers !== false}>
|
|
55
|
-
<NumberInputTriggers />
|
|
56
|
-
</Show>
|
|
57
|
-
</NumberInputControl>
|
|
58
|
-
</NumberInput>
|
|
59
|
-
<FieldError errors={field().state.meta.errors} />
|
|
60
|
-
<FieldDescription>{local.description}</FieldDescription>
|
|
61
|
-
</FieldContent>
|
|
62
|
-
</Field>
|
|
63
|
-
);
|
|
131
|
+
return renderNumberInputField({
|
|
132
|
+
field,
|
|
133
|
+
local,
|
|
134
|
+
others,
|
|
135
|
+
inputValue: state.inputValue,
|
|
136
|
+
onValueChange: state.onValueChange,
|
|
137
|
+
onValueCommit: state.onValueCommit,
|
|
138
|
+
onBlur: state.onBlur,
|
|
139
|
+
});
|
|
64
140
|
};
|
|
@@ -10,7 +10,7 @@ export type SubmitButtonProps = ComponentProps<typeof Button> & {
|
|
|
10
10
|
|
|
11
11
|
export const SubmitButton: Component<SubmitButtonProps> = (props) => {
|
|
12
12
|
const form = useFormContext();
|
|
13
|
-
const [local, others] = splitProps(props, ['children', 'loading', 'disabled']);
|
|
13
|
+
const [local, others] = splitProps(props, ['children', 'loading', 'disabled', 'class']);
|
|
14
14
|
|
|
15
15
|
const isLoading = (): boolean =>
|
|
16
16
|
form.state.isSubmitting || form.state.isValidating || (local.loading ?? false);
|
|
@@ -20,6 +20,7 @@ export const SubmitButton: Component<SubmitButtonProps> = (props) => {
|
|
|
20
20
|
type='submit'
|
|
21
21
|
loading={isLoading()}
|
|
22
22
|
disabled={local.disabled ?? !form.state.canSubmit}
|
|
23
|
+
class={`min-w-24 ${local.class ?? ''}`}
|
|
23
24
|
{...others}
|
|
24
25
|
>
|
|
25
26
|
{local.children}
|