@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.
@@ -1,81 +1,108 @@
1
- import { createComponent as e, Show as u } from "solid-js/web";
2
- import { Field as d, FieldLabel as a, FieldContent as o, FieldError as s, FieldDescription as g } from "../Field.js";
3
- import { NumberInput as m, NumberInputControl as h, NumberInputInput as p, NumberInputTriggers as c } from "../NumberInput.js";
4
- import { useFieldContext as b } from "./context.js";
5
- import { splitProps as f } from "solid-js";
6
- const v = (n) => {
7
- const t = b(), [r, l] = f(n, ["label", "description", "required", "disabled", "readOnly", "showTriggers"]);
8
- return e(d, {
9
- get invalid() {
10
- return t().state.meta.errors.length > 0;
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
- get required() {
13
- return r.required ?? !1;
15
+ onValueCommit: (l) => {
16
+ t(l.value), Number.isFinite(l.valueAsNumber) && e().handleChange(l.valueAsNumber);
14
17
  },
15
- get disabled() {
16
- return r.disabled ?? !1;
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
- v as NumberInputField
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\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\n return (\n <Field\n invalid={field().state.meta.errors.length > 0}\n required={local.required ?? false}\n disabled={local.disabled ?? false}\n readOnly={local.readOnly ?? false}\n >\n <FieldLabel>{local.label}</FieldLabel>\n <FieldContent>\n <NumberInput\n value={String(field().state.value)}\n onValueChange={(details) => {\n field().handleChange(details.valueAsNumber);\n }}\n onBlur={() => {\n field().handleBlur();\n }}\n invalid={field().state.meta.errors.length > 0}\n disabled={local.disabled ?? false}\n readOnly={local.readOnly ?? false}\n required={local.required ?? false}\n >\n <NumberInputControl>\n <NumberInputInput {...others} />\n <Show when={local.showTriggers !== false}>\n <NumberInputTriggers />\n </Show>\n </NumberInputControl>\n </NumberInput>\n <FieldError errors={field().state.meta.errors} />\n <FieldDescription>{local.description}</FieldDescription>\n </FieldContent>\n </Field>\n );\n};\n"],"names":["NumberInputField","props","field","useFieldContext","local","others","splitProps","_$createComponent","Field","invalid","state","meta","errors","length","required","disabled","readOnly","children","FieldLabel","label","FieldContent","NumberInput","value","String","onValueChange","details","handleChange","valueAsNumber","onBlur","handleBlur","NumberInputControl","NumberInputInput","_$Show","when","showTriggers","NumberInputTriggers","FieldError","FieldDescription","description"],"mappings":";;;;;AAkBO,MAAMA,IAAsDC,CAAAA,MAAU;AAC3E,QAAMC,IAAQC,EAAAA,GACR,CAACC,GAAOC,CAAM,IAAIC,EAAWL,GAAO,CACxC,SACA,eACA,YACA,YACA,YACA,cAAc,CACf;AAED,SAAAM,EACGC,GAAK;AAAA,IAAA,IACJC,UAAO;AAAA,aAAEP,EAAAA,EAAQQ,MAAMC,KAAKC,OAAOC,SAAS;AAAA,IAAC;AAAA,IAAA,IAC7CC,WAAQ;AAAA,aAAEV,EAAMU,YAAY;AAAA,IAAK;AAAA,IAAA,IACjCC,WAAQ;AAAA,aAAEX,EAAMW,YAAY;AAAA,IAAK;AAAA,IAAA,IACjCC,WAAQ;AAAA,aAAEZ,EAAMY,YAAY;AAAA,IAAK;AAAA,IAAA,IAAAC,WAAA;AAAA,aAAA,CAAAV,EAEhCW,GAAU;AAAA,QAAA,IAAAD,WAAA;AAAA,iBAAEb,EAAMe;AAAAA,QAAK;AAAA,MAAA,CAAA,GAAAZ,EACvBa,GAAY;AAAA,QAAA,IAAAH,WAAA;AAAA,iBAAA,CAAAV,EACVc,GAAW;AAAA,YAAA,IACVC,QAAK;AAAA,qBAAEC,OAAOrB,IAAQQ,M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umberInputField.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,MA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,IAAAd,WAAA;AAAA,mBAAEX,EAAMQ,MAAMkB;AAAAA,UAAW;AAAA,QAAA,CAAA,CAAA;AAAA,MAAA;AAAA,IAAA,CAAA,CAAA;AAAA,EAAA;AAAA,CAAA,GAKnCC,IAAsD3B,CAAAA,MAAU;AAC3E,QAAMd,IAAQ0C,EAAAA,GACR,CAACpB,GAAOW,CAAM,IAAIU,EAAW7B,GAAO,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 n, mergeProps as s } from "solid-js/web";
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 m } from "./context.js";
4
- import { splitProps as d } from "solid-js";
5
- const p = (e) => {
6
- const t = m(), [o, r] = d(e, ["children", "loading", "disabled"]), i = () => t.state.isSubmitting || t.state.isValidating || (o.loading ?? !1);
7
- return n(a, s({
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 o.disabled ?? !t.state.canSubmit;
13
+ return t.disabled ?? !e.state.canSubmit;
14
+ },
15
+ get class() {
16
+ return `min-w-24 ${t.class ?? ""}`;
14
17
  }
15
- }, r, {
18
+ }, o, {
16
19
  get children() {
17
- return o.children;
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,UAAU,CAAC,GAEvEM,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,EAAA,GAC7CZ,GAAM;AAAA,IAAA,IAAAa,WAAA;AAAA,aAETd,EAAMc;AAAAA,IAAQ;AAAA,EAAA,CAAA,CAAA;AAGrB;"}
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,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@manafishrov/ui",
4
- "version": "1.3.1",
4
+ "version": "1.3.2",
5
5
  "description": "Styled component library for Manafish interfaces ",
6
6
  "license": "AGPL-3.0-or-later",
7
7
  "repository": {
@@ -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
- <Field
32
- invalid={field().state.meta.errors.length > 0}
33
- required={local.required ?? false}
34
- disabled={local.disabled ?? false}
35
- readOnly={local.readOnly ?? false}
36
- >
37
- <FieldLabel>{local.label}</FieldLabel>
38
- <FieldContent>
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}