@apia/validations2-component 5.0.0 → 5.0.3

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.
@@ -0,0 +1,14 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { ValidationStore } from '@apia/validations2-controller';
5
+
6
+ declare const ValidationContextPrimitive: react.Context<ValidationStore<any> | null>;
7
+ declare const ValidationContext: ({ children, store, }: {
8
+ children: ReactNode;
9
+ store: ValidationStore<any>;
10
+ }) => react_jsx_runtime.JSX.Element;
11
+ declare const useValidations: () => ValidationStore<any>;
12
+
13
+ export { ValidationContext, ValidationContextPrimitive, useValidations };
14
+ //# sourceMappingURL=Context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useContext } from 'react';
3
+
4
+ const ValidationContextPrimitive = createContext(null);
5
+ const ValidationContext = ({
6
+ children,
7
+ store
8
+ }) => /* @__PURE__ */ jsx(ValidationContextPrimitive.Provider, { value: store, children });
9
+ const useValidations = () => useContext(ValidationContextPrimitive);
10
+
11
+ export { ValidationContext, ValidationContextPrimitive, useValidations };
12
+ //# sourceMappingURL=Context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.js","sources":["../src/Context.tsx"],"sourcesContent":["import { ValidationStore } from '@apia/validations2-controller';\r\nimport { createContext, ReactNode, useContext } from 'react';\r\n\r\nexport const ValidationContextPrimitive =\r\n createContext<ValidationStore<any> | null>(null);\r\n\r\nexport const ValidationContext = ({\r\n children,\r\n store,\r\n}: {\r\n children: ReactNode;\r\n store: ValidationStore<any>;\r\n}) => (\r\n <ValidationContextPrimitive.Provider value={store}>\r\n {children}\r\n </ValidationContextPrimitive.Provider>\r\n);\r\n\r\nexport const useValidations = () => useContext(ValidationContextPrimitive)!;\r\n"],"names":[],"mappings":";;;AAGO,MAAM,0BAAA,GACX,cAA2C,IAAI;AAE1C,MAAM,oBAAoB,CAAC;AAAA,EAChC,QAAA;AAAA,EACA;AACF,CAAA,yBAIG,0BAAA,CAA2B,QAAA,EAA3B,EAAoC,KAAA,EAAO,OACzC,QAAA,EACH;AAGK,MAAM,cAAA,GAAiB,MAAM,UAAA,CAAW,0BAA0B;;;;"}
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TFieldLabel, TCheckbox } from '@apia/components';
3
+ import { TLabel, TChangeEventHandler } from '@apia/util';
4
+ import { ReactNode } from 'react';
5
+
6
+ type TValidateCheckbox = {
7
+ path: string;
8
+ label: 'nolabel' | TLabel;
9
+ labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
10
+ hiddenFallback?: ReactNode;
11
+ onChange?: TChangeEventHandler<boolean>;
12
+ } & Omit<TCheckbox, 'value' | 'checked' | 'defaultValue' | 'onChange'>;
13
+ declare const ValidatedCheckbox: (({ className, label, path, labelProps, onChange, defaultChecked, hiddenFallback, ...props }: TValidateCheckbox) => react_jsx_runtime.JSX.Element) & {
14
+ displayName: string;
15
+ };
16
+
17
+ export { type TValidateCheckbox, ValidatedCheckbox };
18
+ //# sourceMappingURL=ValidatedCheckbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedCheckbox.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { observer } from 'mobx-react-lite';
3
+ import { useValidations } from './Context.js';
4
+ import { CheckboxLabel, Checkbox } from '@apia/components';
5
+
6
+ const ValidatedCheckbox = observer(
7
+ ({
8
+ className,
9
+ label,
10
+ path,
11
+ labelProps,
12
+ onChange,
13
+ defaultChecked = false,
14
+ hiddenFallback,
15
+ ...props
16
+ }) => {
17
+ const field = useValidations().useField(path, defaultChecked);
18
+ if (field.hidden) {
19
+ return /* @__PURE__ */ jsx(Fragment, { children: hiddenFallback ?? null });
20
+ }
21
+ return /* @__PURE__ */ jsx(
22
+ CheckboxLabel,
23
+ {
24
+ ...labelProps,
25
+ label: label === "nolabel" ? "" : label.text,
26
+ title: label === "nolabel" ? "" : label.title,
27
+ required: field.required,
28
+ className: `${className || ""} ${field.isTouched ? "field__touched" : ""} checkbox`,
29
+ error: field.error,
30
+ children: /* @__PURE__ */ jsx(
31
+ Checkbox,
32
+ {
33
+ ...props,
34
+ disabled: Boolean(props.disabled || field.disabled),
35
+ ref: field.ref,
36
+ onChange: async (ev) => {
37
+ await onChange?.(ev);
38
+ if (!ev.defaultPrevented) {
39
+ field.setValue(ev.value);
40
+ }
41
+ },
42
+ checked: field.value
43
+ }
44
+ )
45
+ }
46
+ );
47
+ }
48
+ );
49
+
50
+ export { ValidatedCheckbox };
51
+ //# sourceMappingURL=ValidatedCheckbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedCheckbox.js","sources":["../src/ValidatedCheckbox.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { useValidations } from './Context';\r\nimport {\r\n Checkbox,\r\n CheckboxLabel,\r\n TCheckbox,\r\n TFieldLabel,\r\n} from '@apia/components';\r\nimport { TLabel, TChangeEventHandler } from '@apia/util';\r\nimport { ReactNode } from 'react';\r\n\r\nexport type TValidateCheckbox = {\r\n path: string;\r\n label: 'nolabel' | TLabel;\r\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\r\n hiddenFallback?: ReactNode;\r\n onChange?: TChangeEventHandler<boolean>;\r\n} & Omit<TCheckbox, 'value' | 'checked' | 'defaultValue' | 'onChange'>;\r\n\r\nexport const ValidatedCheckbox = observer(\r\n ({\r\n className,\r\n label,\r\n path,\r\n labelProps,\r\n onChange,\r\n defaultChecked = false,\r\n hiddenFallback,\r\n ...props\r\n }: TValidateCheckbox) => {\r\n const field = useValidations().useField(path, defaultChecked);\r\n\r\n if (field.hidden) {\r\n return <>{hiddenFallback ?? null}</>;\r\n }\r\n\r\n return (\r\n <CheckboxLabel\r\n {...labelProps}\r\n label={label === 'nolabel' ? '' : label.text}\r\n title={label === 'nolabel' ? '' : label.title}\r\n required={field.required}\r\n className={`${className || ''} ${field.isTouched ? 'field__touched' : ''} checkbox`}\r\n error={field.error}\r\n >\r\n <Checkbox\r\n {...props}\r\n disabled={Boolean(props.disabled || field.disabled)}\r\n ref={field.ref as any}\r\n onChange={async (ev) => {\r\n await onChange?.(ev);\r\n if (!ev.defaultPrevented) {\r\n field.setValue(ev.value);\r\n }\r\n }}\r\n checked={field.value as any}\r\n />\r\n </CheckboxLabel>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;AAmBO,MAAM,iBAAA,GAAoB,QAAA;AAAA,EAC/B,CAAC;AAAA,IACC,SAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAA,GAAiB,KAAA;AAAA,IACjB,cAAA;AAAA,IACA,GAAG;AAAA,GACL,KAAyB;AACvB,IAAA,MAAM,KAAA,GAAQ,cAAA,EAAe,CAAE,QAAA,CAAS,MAAM,cAAc,CAAA;AAE5D,IAAA,IAAI,MAAM,MAAA,EAAQ;AAChB,MAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,4BAAkB,IAAA,EAAK,CAAA;AAAA;AAGnC,IAAA,uBACE,GAAA;AAAA,MAAC,aAAA;AAAA,MAAA;AAAA,QACE,GAAG,UAAA;AAAA,QACJ,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,IAAA;AAAA,QACxC,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,KAAA;AAAA,QACxC,UAAU,KAAA,CAAM,QAAA;AAAA,QAChB,SAAA,EAAW,GAAG,SAAA,IAAa,EAAE,IAAI,KAAA,CAAM,SAAA,GAAY,mBAAmB,EAAE,CAAA,SAAA,CAAA;AAAA,QACxE,OAAO,KAAA,CAAM,KAAA;AAAA,QAEb,QAAA,kBAAA,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACE,GAAG,KAAA;AAAA,YACJ,QAAA,EAAU,OAAA,CAAQ,KAAA,CAAM,QAAA,IAAY,MAAM,QAAQ,CAAA;AAAA,YAClD,KAAK,KAAA,CAAM,GAAA;AAAA,YACX,QAAA,EAAU,OAAO,EAAA,KAAO;AACtB,cAAA,MAAM,WAAW,EAAE,CAAA;AACnB,cAAA,IAAI,CAAC,GAAG,gBAAA,EAAkB;AACxB,gBAAA,KAAA,CAAM,QAAA,CAAS,GAAG,KAAK,CAAA;AAAA;AACzB,aACF;AAAA,YACA,SAAS,KAAA,CAAM;AAAA;AAAA;AACjB;AAAA,KACF;AAAA;AAGN;;;;"}
@@ -0,0 +1,19 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TFieldLabel } from '@apia/components';
3
+ import { InputProps } from '@apia/theme';
4
+ import { TLabel, TChangeEventHandler } from '@apia/util';
5
+ import { ReactNode } from 'react';
6
+
7
+ type TValidateInput = {
8
+ path: string;
9
+ label: 'nolabel' | TLabel;
10
+ labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
11
+ hiddenFallback?: ReactNode;
12
+ onChange?: TChangeEventHandler<string>;
13
+ } & Omit<InputProps, 'value' | 'onChange'>;
14
+ declare const ValidatedInput: (({ className, label, path, labelProps, defaultValue, hiddenFallback, onChange, ...props }: TValidateInput) => react_jsx_runtime.JSX.Element) & {
15
+ displayName: string;
16
+ };
17
+
18
+ export { type TValidateInput, ValidatedInput };
19
+ //# sourceMappingURL=ValidatedInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedInput.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { observer } from 'mobx-react-lite';
3
+ import { useValidations } from './Context.js';
4
+ import { FieldLabel } from '@apia/components';
5
+ import { Input } from '@apia/theme';
6
+ import { ChangeEvent } from '@apia/util';
7
+
8
+ const ValidatedInput = observer(
9
+ ({
10
+ className,
11
+ label,
12
+ path,
13
+ labelProps,
14
+ defaultValue = "",
15
+ hiddenFallback,
16
+ onChange,
17
+ ...props
18
+ }) => {
19
+ const field = useValidations().useField(path, defaultValue);
20
+ if (field.hidden) {
21
+ return /* @__PURE__ */ jsx(Fragment, { children: hiddenFallback ?? null });
22
+ }
23
+ return /* @__PURE__ */ jsx(
24
+ FieldLabel,
25
+ {
26
+ ...labelProps,
27
+ label: label === "nolabel" ? "" : label.text,
28
+ title: label === "nolabel" ? "" : label.title,
29
+ required: field.required,
30
+ className: `${className || ""} ${field.isTouched ? "field__touched" : ""} input`,
31
+ error: field.error,
32
+ avoidSemicolon: label === "nolabel",
33
+ children: /* @__PURE__ */ jsx(
34
+ Input,
35
+ {
36
+ ...props,
37
+ disabled: Boolean(props.disabled || field.disabled),
38
+ ref: field.ref,
39
+ onChange: async (_ev) => {
40
+ const ev = new ChangeEvent(_ev.target.value);
41
+ await onChange?.(ev);
42
+ if (!ev.defaultPrevented) {
43
+ field.setValue(ev.value);
44
+ }
45
+ },
46
+ value: field.value
47
+ }
48
+ )
49
+ }
50
+ );
51
+ }
52
+ );
53
+
54
+ export { ValidatedInput };
55
+ //# sourceMappingURL=ValidatedInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedInput.js","sources":["../src/ValidatedInput.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { useValidations } from './Context';\r\nimport { FieldLabel, TFieldLabel } from '@apia/components';\r\nimport { Input, InputProps } from '@apia/theme';\r\nimport { ChangeEvent, TLabel, TChangeEventHandler } from '@apia/util';\r\nimport { ReactNode } from 'react';\r\n\r\nexport type TValidateInput = {\r\n path: string;\r\n label: 'nolabel' | TLabel;\r\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\r\n hiddenFallback?: ReactNode;\r\n onChange?: TChangeEventHandler<string>;\r\n} & Omit<InputProps, 'value' | 'onChange'>;\r\n\r\nexport const ValidatedInput = observer(\r\n ({\r\n className,\r\n label,\r\n path,\r\n labelProps,\r\n defaultValue = '',\r\n hiddenFallback,\r\n onChange,\r\n ...props\r\n }: TValidateInput) => {\r\n const field = useValidations().useField(path, defaultValue);\r\n\r\n if (field.hidden) {\r\n return <>{hiddenFallback ?? null}</>;\r\n }\r\n\r\n return (\r\n <FieldLabel\r\n {...labelProps}\r\n label={label === 'nolabel' ? '' : label.text}\r\n title={label === 'nolabel' ? '' : label.title}\r\n required={field.required}\r\n className={`${className || ''} ${field.isTouched ? 'field__touched' : ''} input`}\r\n error={field.error}\r\n avoidSemicolon={label === 'nolabel'}\r\n >\r\n <Input\r\n {...props}\r\n disabled={Boolean(props.disabled || field.disabled)}\r\n ref={field.ref as any}\r\n onChange={async (_ev) => {\r\n const ev = new ChangeEvent(_ev.target.value);\r\n\r\n await onChange?.(ev);\r\n if (!ev.defaultPrevented) {\r\n field.setValue(ev.value);\r\n }\r\n }}\r\n value={field.value as any}\r\n />\r\n </FieldLabel>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;AAeO,MAAM,cAAA,GAAiB,QAAA;AAAA,EAC5B,CAAC;AAAA,IACC,SAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA,GAAe,EAAA;AAAA,IACf,cAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,GACL,KAAsB;AACpB,IAAA,MAAM,KAAA,GAAQ,cAAA,EAAe,CAAE,QAAA,CAAS,MAAM,YAAY,CAAA;AAE1D,IAAA,IAAI,MAAM,MAAA,EAAQ;AAChB,MAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,4BAAkB,IAAA,EAAK,CAAA;AAAA;AAGnC,IAAA,uBACE,GAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACE,GAAG,UAAA;AAAA,QACJ,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,IAAA;AAAA,QACxC,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,KAAA;AAAA,QACxC,UAAU,KAAA,CAAM,QAAA;AAAA,QAChB,SAAA,EAAW,GAAG,SAAA,IAAa,EAAE,IAAI,KAAA,CAAM,SAAA,GAAY,mBAAmB,EAAE,CAAA,MAAA,CAAA;AAAA,QACxE,OAAO,KAAA,CAAM,KAAA;AAAA,QACb,gBAAgB,KAAA,KAAU,SAAA;AAAA,QAE1B,QAAA,kBAAA,GAAA;AAAA,UAAC,KAAA;AAAA,UAAA;AAAA,YACE,GAAG,KAAA;AAAA,YACJ,QAAA,EAAU,OAAA,CAAQ,KAAA,CAAM,QAAA,IAAY,MAAM,QAAQ,CAAA;AAAA,YAClD,KAAK,KAAA,CAAM,GAAA;AAAA,YACX,QAAA,EAAU,OAAO,GAAA,KAAQ;AACvB,cAAA,MAAM,EAAA,GAAK,IAAI,WAAA,CAAY,GAAA,CAAI,OAAO,KAAK,CAAA;AAE3C,cAAA,MAAM,WAAW,EAAE,CAAA;AACnB,cAAA,IAAI,CAAC,GAAG,gBAAA,EAAkB;AACxB,gBAAA,KAAA,CAAM,QAAA,CAAS,GAAG,KAAK,CAAA;AAAA;AACzB,aACF;AAAA,YACA,OAAO,KAAA,CAAM;AAAA;AAAA;AACf;AAAA,KACF;AAAA;AAGN;;;;"}
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TFieldLabel } from '@apia/components';
3
+ import { TLabel, TChangeEventHandler, TOption } from '@apia/util';
4
+ import { ReactNode } from 'react';
5
+
6
+ type TValidateSelect = {
7
+ className?: string;
8
+ disabled?: boolean;
9
+ path: string;
10
+ label: 'nolabel' | TLabel;
11
+ labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
12
+ hiddenFallback?: ReactNode;
13
+ onChange?: TChangeEventHandler<string>;
14
+ options?: TOption[];
15
+ defaultValue?: string;
16
+ };
17
+ declare const ValidatedSelect: (({ className, disabled, label, path, labelProps, hiddenFallback, onChange, options, defaultValue, }: TValidateSelect) => react_jsx_runtime.JSX.Element) & {
18
+ displayName: string;
19
+ };
20
+
21
+ export { type TValidateSelect, ValidatedSelect };
22
+ //# sourceMappingURL=ValidatedSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedSelect.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,82 @@
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { observer } from 'mobx-react-lite';
3
+ import { useValidations } from './Context.js';
4
+ import { FieldLabel, Autocomplete } from '@apia/components';
5
+ import { ChangeEvent } from '@apia/util';
6
+
7
+ function normalizeOptionValue(value) {
8
+ return value == null ? "" : String(value);
9
+ }
10
+ function normalizeSelectValue(value) {
11
+ if (value && typeof value === "object" && "value" in value) {
12
+ return normalizeOptionValue(value.value);
13
+ }
14
+ return normalizeOptionValue(value);
15
+ }
16
+ const ValidatedSelect = observer(
17
+ ({
18
+ className,
19
+ disabled,
20
+ label,
21
+ path,
22
+ labelProps,
23
+ hiddenFallback,
24
+ onChange,
25
+ options,
26
+ defaultValue
27
+ }) => {
28
+ const store = useValidations();
29
+ const field = store.useField(path, defaultValue);
30
+ const effectiveOptions = (options ?? field.options ?? []).map(
31
+ (option) => ({
32
+ ...option,
33
+ value: normalizeOptionValue(option.value)
34
+ })
35
+ );
36
+ const selectedValue = normalizeSelectValue(field.value);
37
+ const firstOptionValue = effectiveOptions[0]?.value;
38
+ const hasEmptyOption = effectiveOptions.some((option) => option.value === "");
39
+ const effectiveValue = firstOptionValue !== void 0 && (field.value === void 0 || selectedValue === "" && !hasEmptyOption) ? firstOptionValue : selectedValue;
40
+ if (field.value !== effectiveValue) {
41
+ field.setValue(effectiveValue, false);
42
+ }
43
+ if (field.hidden) {
44
+ return /* @__PURE__ */ jsx(Fragment, { children: hiddenFallback ?? null });
45
+ }
46
+ return /* @__PURE__ */ jsx(
47
+ FieldLabel,
48
+ {
49
+ ...labelProps,
50
+ label: label === "nolabel" ? "" : label.text,
51
+ title: label === "nolabel" ? "" : label.title,
52
+ required: field.required,
53
+ className: `${className || ""} ${field.isTouched ? "field__touched" : ""} select`,
54
+ error: field.error,
55
+ avoidSemicolon: label === "nolabel",
56
+ children: /* @__PURE__ */ jsx(
57
+ Autocomplete,
58
+ {
59
+ ref: field.ref,
60
+ properties: {
61
+ options: effectiveOptions,
62
+ disabled: Boolean(disabled || field.disabled),
63
+ value: effectiveValue,
64
+ onChange: async (value) => {
65
+ const ev = new ChangeEvent(value);
66
+ await onChange?.(ev);
67
+ if (!ev.defaultPrevented) {
68
+ field.setValue(value);
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ }
74
+ }
75
+ )
76
+ }
77
+ );
78
+ }
79
+ );
80
+
81
+ export { ValidatedSelect };
82
+ //# sourceMappingURL=ValidatedSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedSelect.js","sources":["../src/ValidatedSelect.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { useValidations } from './Context';\r\nimport { Autocomplete, FieldLabel, TFieldLabel } from '@apia/components';\r\nimport { ChangeEvent, TLabel, TChangeEventHandler, TOption } from '@apia/util';\r\nimport { ReactNode } from 'react';\r\n\r\nexport type TValidateSelect = {\r\n className?: string;\r\n disabled?: boolean;\r\n path: string;\r\n label: 'nolabel' | TLabel;\r\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\r\n hiddenFallback?: ReactNode;\r\n onChange?: TChangeEventHandler<string>;\r\n options?: TOption[];\r\n defaultValue?: string;\r\n};\r\n\r\nfunction normalizeOptionValue(value: unknown) {\r\n return value == null ? '' : String(value);\r\n}\r\n\r\nfunction normalizeSelectValue(value: unknown) {\r\n if (value && typeof value === 'object' && 'value' in value) {\r\n return normalizeOptionValue((value as { value?: unknown }).value);\r\n }\r\n\r\n return normalizeOptionValue(value);\r\n}\r\n\r\nexport const ValidatedSelect = observer(\r\n ({\r\n className,\r\n disabled,\r\n label,\r\n path,\r\n labelProps,\r\n hiddenFallback,\r\n onChange,\r\n options,\r\n defaultValue,\r\n }: TValidateSelect) => {\r\n const store = useValidations();\r\n const field = store.useField(path, defaultValue);\r\n const effectiveOptions = ((options ?? field.options ?? []) as TOption[]).map(\r\n (option) => ({\r\n ...option,\r\n value: normalizeOptionValue(option.value),\r\n }),\r\n );\r\n\r\n const selectedValue = normalizeSelectValue(field.value);\r\n const firstOptionValue = effectiveOptions[0]?.value;\r\n const hasEmptyOption = effectiveOptions.some((option) => option.value === '');\r\n const effectiveValue =\r\n firstOptionValue !== undefined &&\r\n (field.value === undefined || (selectedValue === '' && !hasEmptyOption))\r\n ? firstOptionValue\r\n : selectedValue;\r\n\r\n if (field.value !== effectiveValue) {\r\n field.setValue(effectiveValue, false);\r\n }\r\n\r\n if (field.hidden) {\r\n return <>{hiddenFallback ?? null}</>;\r\n }\r\n\r\n return (\r\n <FieldLabel\r\n {...labelProps}\r\n label={label === 'nolabel' ? '' : label.text}\r\n title={label === 'nolabel' ? '' : label.title}\r\n required={field.required}\r\n className={`${className || ''} ${field.isTouched ? 'field__touched' : ''} select`}\r\n error={field.error}\r\n avoidSemicolon={label === 'nolabel'}\r\n >\r\n <Autocomplete\r\n ref={field.ref}\r\n properties={{\r\n options: effectiveOptions,\r\n disabled: Boolean(disabled || field.disabled),\r\n value: effectiveValue,\r\n onChange: async (value) => {\r\n const ev = new ChangeEvent(value);\r\n\r\n await onChange?.(ev);\r\n if (!ev.defaultPrevented) {\r\n field.setValue(value);\r\n return true;\r\n }\r\n\r\n return false;\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BAAA,IAAI,CAAC,GAAG,gBAAA,EAAkB;AACxB,kBAAA,KAAA,CAAM,SAAS,KAAK,CAAA;AACpB,kBAAA,OAAO,IAAA;AAAA;AAGT,gBAAA,OAAO,KAAA;AAAA;AACT;AACF;AAAA;AACF;AAAA,KACF;AAAA;AAGN;;;;"}
@@ -0,0 +1,21 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode, ComponentProps } from 'react';
3
+ import { CardSwitch } from '@apia/components';
4
+ import { TLabel, TChangeEventHandler } from '@apia/util';
5
+
6
+ type TCardSwitchProps = ComponentProps<typeof CardSwitch>;
7
+ type TValidatedSwitch = {
8
+ className?: string;
9
+ defaultChecked?: boolean;
10
+ path: string;
11
+ label: 'nolabel' | TLabel;
12
+ hiddenFallback?: ReactNode;
13
+ onChange?: TChangeEventHandler<boolean>;
14
+ title?: TCardSwitchProps['title'];
15
+ } & Omit<TCardSwitchProps, 'checked' | 'onToggle' | 'title'>;
16
+ declare const ValidatedSwitch: (({ className, defaultChecked, hiddenFallback, label, onChange, path, sx, title, ...props }: TValidatedSwitch) => react_jsx_runtime.JSX.Element) & {
17
+ displayName: string;
18
+ };
19
+
20
+ export { type TValidatedSwitch, ValidatedSwitch };
21
+ //# sourceMappingURL=ValidatedSwitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedSwitch.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
+ import { observer } from 'mobx-react-lite';
3
+ import { CardSwitch, FieldErrorMessage } from '@apia/components';
4
+ import { ChangeEvent } from '@apia/util';
5
+ import { useValidations } from './Context.js';
6
+
7
+ const ValidatedSwitch = observer(
8
+ ({
9
+ className,
10
+ defaultChecked = false,
11
+ hiddenFallback,
12
+ label,
13
+ onChange,
14
+ path,
15
+ sx,
16
+ title,
17
+ ...props
18
+ }) => {
19
+ const field = useValidations().useField(path, defaultChecked);
20
+ const titleText = label === "nolabel" ? "" : label.text;
21
+ const ariaLabel = label === "nolabel" ? void 0 : label.title || label.text;
22
+ if (field.hidden) {
23
+ return /* @__PURE__ */ jsx(Fragment, { children: hiddenFallback ?? null });
24
+ }
25
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
26
+ /* @__PURE__ */ jsx(
27
+ CardSwitch,
28
+ {
29
+ ...props,
30
+ ariaLabel: props.ariaLabel ?? ariaLabel,
31
+ disabled: Boolean(props.disabled || field.disabled),
32
+ sx: {
33
+ ...sx,
34
+ ...field.isTouched ? {
35
+ borderColor: "touchedBorderColor"
36
+ } : {},
37
+ ...field.error ? {
38
+ borderLeftColor: "danger",
39
+ borderLeftStyle: "solid",
40
+ borderLeftWidth: "4px"
41
+ } : {}
42
+ },
43
+ title: title ?? titleText,
44
+ onToggle: async (nextChecked) => {
45
+ const event = new ChangeEvent(nextChecked);
46
+ await onChange?.(event);
47
+ if (!event.defaultPrevented) {
48
+ field.setValue(event.value);
49
+ }
50
+ },
51
+ checked: field.value
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsx(FieldErrorMessage, { name: path, children: field.error })
55
+ ] });
56
+ }
57
+ );
58
+
59
+ export { ValidatedSwitch };
60
+ //# sourceMappingURL=ValidatedSwitch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedSwitch.js","sources":["../src/ValidatedSwitch.tsx"],"sourcesContent":["import { ComponentProps, ReactNode } from 'react';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { CardSwitch, FieldErrorMessage } from '@apia/components';\r\nimport { TChangeEventHandler, TLabel, ChangeEvent } from '@apia/util';\r\nimport { useValidations } from './Context';\r\n\r\ntype TCardSwitchProps = ComponentProps<typeof CardSwitch>;\r\n\r\nexport type TValidatedSwitch = {\r\n className?: string;\r\n defaultChecked?: boolean;\r\n path: string;\r\n label: 'nolabel' | TLabel;\r\n hiddenFallback?: ReactNode;\r\n onChange?: TChangeEventHandler<boolean>;\r\n title?: TCardSwitchProps['title'];\r\n} & Omit<TCardSwitchProps, 'checked' | 'onToggle' | 'title'>;\r\n\r\nexport const ValidatedSwitch = observer(\r\n ({\r\n className,\r\n defaultChecked = false,\r\n hiddenFallback,\r\n label,\r\n onChange,\r\n path,\r\n sx,\r\n title,\r\n ...props\r\n }: TValidatedSwitch) => {\r\n const field = useValidations().useField(path, defaultChecked);\r\n const titleText = label === 'nolabel' ? '' : label.text;\r\n const ariaLabel =\r\n label === 'nolabel' ? undefined : label.title || label.text;\r\n\r\n if (field.hidden) {\r\n return <>{hiddenFallback ?? null}</>;\r\n }\r\n\r\n return (\r\n <>\r\n <CardSwitch\r\n {...props}\r\n ariaLabel={props.ariaLabel ?? ariaLabel}\r\n disabled={Boolean(props.disabled || field.disabled)}\r\n sx={{\r\n ...sx,\r\n ...(field.isTouched\r\n ? {\r\n borderColor: 'touchedBorderColor',\r\n }\r\n : {}),\r\n ...(field.error\r\n ? {\r\n borderLeftColor: 'danger',\r\n borderLeftStyle: 'solid',\r\n borderLeftWidth: '4px',\r\n }\r\n : {}),\r\n }}\r\n title={title ?? titleText}\r\n onToggle={async (nextChecked) => {\r\n const event = new ChangeEvent(nextChecked);\r\n\r\n await onChange?.(event);\r\n if (!event.defaultPrevented) {\r\n field.setValue(event.value);\r\n }\r\n }}\r\n checked={field.value as boolean}\r\n />\r\n <FieldErrorMessage name={path}>{field.error}</FieldErrorMessage>\r\n </>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;AAkBO,MAAM,eAAA,GAAkB,QAAA;AAAA,EAC7B,CAAC;AAAA,IACC,SAAA;AAAA,IACA,cAAA,GAAiB,KAAA;AAAA,IACjB,cAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,EAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAG;AAAA,GACL,KAAwB;AACtB,IAAA,MAAM,KAAA,GAAQ,cAAA,EAAe,CAAE,QAAA,CAAS,MAAM,cAA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A,EAAM,IAAA,EAAO,gBAAM,KAAA,EAAM;AAAA,KAAA,EAC9C,CAAA;AAAA;AAGN;;;;"}
@@ -0,0 +1,19 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TFieldLabel } from '@apia/components';
3
+ import { TextareaProps } from '@apia/theme';
4
+ import { TLabel, TChangeEventHandler } from '@apia/util';
5
+ import { ReactNode } from 'react';
6
+
7
+ type TValidateTextarea = {
8
+ path: string;
9
+ label: TLabel | 'nolabel';
10
+ labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
11
+ hiddenFallback?: ReactNode;
12
+ onChange?: TChangeEventHandler<string>;
13
+ } & Omit<TextareaProps, 'value' | 'onChange'>;
14
+ declare const ValidatedTextarea: (({ className, label, path, labelProps, defaultValue, hiddenFallback, onChange, ...props }: TValidateTextarea) => react_jsx_runtime.JSX.Element) & {
15
+ displayName: string;
16
+ };
17
+
18
+ export { type TValidateTextarea, ValidatedTextarea };
19
+ //# sourceMappingURL=ValidatedTextarea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedTextarea.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { observer } from 'mobx-react-lite';
3
+ import { useValidations } from './Context.js';
4
+ import { FieldLabel } from '@apia/components';
5
+ import { Textarea } from '@apia/theme';
6
+ import { ChangeEvent } from '@apia/util';
7
+
8
+ const ValidatedTextarea = observer(
9
+ ({
10
+ className,
11
+ label,
12
+ path,
13
+ labelProps,
14
+ defaultValue = "",
15
+ hiddenFallback,
16
+ onChange,
17
+ ...props
18
+ }) => {
19
+ const field = useValidations().useField(path, defaultValue);
20
+ if (field.hidden) {
21
+ return /* @__PURE__ */ jsx(Fragment, { children: hiddenFallback ?? null });
22
+ }
23
+ return /* @__PURE__ */ jsx(
24
+ FieldLabel,
25
+ {
26
+ ...labelProps,
27
+ label: label === "nolabel" ? "" : label.text,
28
+ title: label === "nolabel" ? "" : label.title,
29
+ required: field.required,
30
+ className: `${className || ""} ${field.isTouched ? "field__touched" : ""} textarea`,
31
+ error: field.error,
32
+ avoidSemicolon: label === "nolabel",
33
+ children: /* @__PURE__ */ jsx(
34
+ Textarea,
35
+ {
36
+ ...props,
37
+ disabled: Boolean(props.disabled || field.disabled),
38
+ ref: field.ref,
39
+ onChange: async (_ev) => {
40
+ const ev = new ChangeEvent(_ev.target.value);
41
+ await onChange?.(ev);
42
+ if (!ev.defaultPrevented) {
43
+ field.setValue(ev.value);
44
+ }
45
+ },
46
+ value: field.value
47
+ }
48
+ )
49
+ }
50
+ );
51
+ }
52
+ );
53
+
54
+ export { ValidatedTextarea };
55
+ //# sourceMappingURL=ValidatedTextarea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedTextarea.js","sources":["../src/ValidatedTextarea.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { useValidations } from './Context';\r\nimport { FieldLabel, TFieldLabel } from '@apia/components';\r\nimport { Textarea, TextareaProps } from '@apia/theme';\r\nimport { ChangeEvent, TLabel, TChangeEventHandler } from '@apia/util';\r\nimport { ReactNode } from 'react';\r\n\r\nexport type TValidateTextarea = {\r\n path: string;\r\n label: TLabel | 'nolabel';\r\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\r\n hiddenFallback?: ReactNode;\r\n onChange?: TChangeEventHandler<string>;\r\n} & Omit<TextareaProps, 'value' | 'onChange'>;\r\n\r\nexport const ValidatedTextarea = observer(\r\n ({\r\n className,\r\n label,\r\n path,\r\n labelProps,\r\n defaultValue = '',\r\n hiddenFallback,\r\n onChange,\r\n ...props\r\n }: TValidateTextarea) => {\r\n const field = useValidations().useField(path, defaultValue);\r\n\r\n if (field.hidden) {\r\n return <>{hiddenFallback ?? null}</>;\r\n }\r\n\r\n return (\r\n <FieldLabel\r\n {...labelProps}\r\n label={label === 'nolabel' ? '' : label.text}\r\n title={label === 'nolabel' ? '' : label.title}\r\n required={field.required}\r\n className={`${className || ''} ${field.isTouched ? 'field__touched' : ''} textarea`}\r\n error={field.error}\r\n avoidSemicolon={label === 'nolabel'}\r\n >\r\n <Textarea\r\n {...props}\r\n disabled={Boolean(props.disabled || field.disabled)}\r\n ref={field.ref as any}\r\n onChange={async (_ev) => {\r\n const ev = new ChangeEvent(_ev.target.value);\r\n\r\n await onChange?.(ev);\r\n if (!ev.defaultPrevented) {\r\n field.setValue(ev.value);\r\n }\r\n }}\r\n value={field.value as any}\r\n />\r\n </FieldLabel>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;AAeO,MAAM,iBAAA,GAAoB,QAAA;AAAA,EAC/B,CAAC;AAAA,IACC,SAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA,GAAe,EAAA;AAAA,IACf,cAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,GACL,KAAyB;AACvB,IAAA,MAAM,KAAA,GAAQ,cAAA,EAAe,CAAE,QAAA,CAAS,MAAM,YAAY,CAAA;AAE1D,IAAA,IAAI,MAAM,MAAA,EAAQ;AAChB,MAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,4BAAkB,IAAA,EAAK,CAAA;AAAA;AAGnC,IAAA,uBACE,GAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACE,GAAG,UAAA;AAAA,QACJ,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,IAAA;AAAA,QACxC,KAAA,EAAO,KAAA,KAAU,SAAA,GAAY,EAAA,GAAK,KAAA,CAAM,KAAA;AAAA,QACxC,UAAU,KAAA,CAAM,QAAA;AAAA,QAChB,SAAA,EAAW,GAAG,SAAA,IAAa,EAAE,IAAI,KAAA,CAAM,SAAA,GAAY,mBAAmB,EAAE,CAAA,SAAA,CAAA;AAAA,QACxE,OAAO,KAAA,CAAM,KAAA;AAAA,QACb,gBAAgB,KAAA,KAAU,SAAA;AAAA,QAE1B,QAAA,kBAAA,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACE,GAAG,KAAA;AAAA,YACJ,QAAA,EAAU,OAAA,CAAQ,KAAA,CAAM,QAAA,IAAY,MAAM,QAAQ,CAAA;AAAA,YAClD,KAAK,KAAA,CAAM,GAAA;AAAA,YACX,QAAA,EAAU,OAAO,GAAA,KAAQ;AACvB,cAAA,MAAM,EAAA,GAAK,IAAI,WAAA,CAAY,GAAA,CAAI,OAAO,KAAK,CAAA;AAE3C,cAAA,MAAM,WAAW,EAAE,CAAA;AACnB,cAAA,IAAI,CAAC,GAAG,gBAAA,EAAkB;AACxB,gBAAA,KAAA,CAAM,QAAA,CAAS,GAAG,KAAK,CAAA;AAAA;AACzB,aACF;AAAA,YACA,OAAO,KAAA,CAAM;AAAA;AAAA;AACf;AAAA,KACF;AAAA;AAGN;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,56 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
- import { ReactNode } from 'react';
4
- import { ValidationStore } from '@apia/validations2-controller';
5
- import { TFieldLabel, TCheckbox } from '@apia/components';
6
- import { InputProps, TextareaProps } from '@apia/theme';
7
- import { TOption } from '@apia/util';
8
-
9
- declare const ValidationContextPrimitive: react.Context<ValidationStore<any> | null>;
10
- declare const ValidationContext: ({ children, store, }: {
11
- children: ReactNode;
12
- store: ValidationStore<any>;
13
- }) => react_jsx_runtime.JSX.Element;
14
- declare const useValidations: () => ValidationStore<any>;
15
-
16
- type TValidateCheckbox = {
17
- path: string;
18
- label: string;
19
- labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
20
- } & Omit<TCheckbox, 'value' | 'checked'>;
21
- declare const ValidatedCheckbox: (({ className, label, path, labelProps, onChange, ...props }: TValidateCheckbox) => react_jsx_runtime.JSX.Element) & {
22
- displayName: string;
23
- };
24
-
25
- type TValidateInput = {
26
- path: string;
27
- label: string;
28
- labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
29
- } & Omit<InputProps, 'value'>;
30
- declare const ValidatedInput: (({ className, label, path, labelProps, onChange, ...props }: TValidateInput) => react_jsx_runtime.JSX.Element) & {
31
- displayName: string;
32
- };
33
-
34
- type TValidateSelect = {
35
- className?: string;
36
- path: string;
37
- label: string;
38
- labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
39
- onChange?: (value: string) => unknown;
40
- options: TOption[];
41
- };
42
- declare const ValidatedSelect: (({ className, label, path, labelProps, onChange, options, }: TValidateSelect) => react_jsx_runtime.JSX.Element) & {
43
- displayName: string;
44
- };
45
-
46
- type TValidateTextarea = {
47
- path: string;
48
- label: string;
49
- labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;
50
- } & Omit<TextareaProps, 'value'>;
51
- declare const ValidatedTextarea: (({ className, label, path, labelProps, onChange, ...props }: TValidateTextarea) => react_jsx_runtime.JSX.Element) & {
52
- displayName: string;
53
- };
54
-
55
- export { type TValidateCheckbox, type TValidateInput, type TValidateSelect, type TValidateTextarea, ValidatedCheckbox, ValidatedInput, ValidatedSelect, ValidatedTextarea, ValidationContext, ValidationContextPrimitive, useValidations };
1
+ export { ValidationContext, ValidationContextPrimitive, useValidations } from './Context.js';
2
+ export { TValidateCheckbox, ValidatedCheckbox } from './ValidatedCheckbox.js';
3
+ export { TValidateInput, ValidatedInput } from './ValidatedInput.js';
4
+ export { TValidateSelect, ValidatedSelect } from './ValidatedSelect.js';
5
+ export { TValidatedSwitch, ValidatedSwitch } from './ValidatedSwitch.js';
6
+ export { TValidateTextarea, ValidatedTextarea } from './ValidatedTextarea.js';
56
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,157 +1,7 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { createContext, useContext } from 'react';
3
- import { observer } from 'mobx-react-lite';
4
- import { FieldLabel, Checkbox, Autocomplete } from '@apia/components';
5
- import { Input, Textarea } from '@apia/theme';
6
-
7
- const ValidationContextPrimitive = createContext(null);
8
- const ValidationContext = ({
9
- children,
10
- store
11
- }) => /* @__PURE__ */ jsx(ValidationContextPrimitive.Provider, { value: store, children });
12
- const useValidations = () => useContext(ValidationContextPrimitive);
13
-
14
- const ValidatedCheckbox = observer(
15
- ({
16
- className,
17
- label,
18
- path,
19
- labelProps,
20
- onChange,
21
- ...props
22
- }) => {
23
- const field = useValidations().useField(path);
24
- return /* @__PURE__ */ jsx(
25
- FieldLabel,
26
- {
27
- avoidSemicolon: true,
28
- ...labelProps,
29
- label,
30
- required: field.required,
31
- className: `${className || ""} checkbox`,
32
- error: field.error,
33
- children: /* @__PURE__ */ jsx(
34
- Checkbox,
35
- {
36
- ...props,
37
- ref: field.ref,
38
- onChange: (ev) => {
39
- field.setValue(ev.target.value);
40
- onChange?.(ev);
41
- },
42
- value: field.value
43
- }
44
- )
45
- }
46
- );
47
- }
48
- );
49
-
50
- const ValidatedInput = observer(
51
- ({
52
- className,
53
- label,
54
- path,
55
- labelProps,
56
- onChange,
57
- ...props
58
- }) => {
59
- const field = useValidations().useField(path);
60
- return /* @__PURE__ */ jsx(
61
- FieldLabel,
62
- {
63
- ...labelProps,
64
- label,
65
- required: field.required,
66
- className: `${className || ""} input`,
67
- error: field.error,
68
- children: /* @__PURE__ */ jsx(
69
- Input,
70
- {
71
- ...props,
72
- ref: field.ref,
73
- onChange: (ev) => {
74
- field.setValue(ev.target.value);
75
- onChange?.(ev);
76
- },
77
- value: field.value
78
- }
79
- )
80
- }
81
- );
82
- }
83
- );
84
-
85
- const ValidatedSelect = observer(
86
- ({
87
- className,
88
- label,
89
- path,
90
- labelProps,
91
- onChange,
92
- options
93
- }) => {
94
- const field = useValidations().useField(path);
95
- return /* @__PURE__ */ jsx(
96
- FieldLabel,
97
- {
98
- ...labelProps,
99
- label,
100
- required: field.required,
101
- className: `${className || ""} select`,
102
- error: field.error,
103
- children: /* @__PURE__ */ jsx(
104
- Autocomplete,
105
- {
106
- ref: field.ref,
107
- properties: {
108
- options,
109
- onChange(value) {
110
- field.setValue(value);
111
- onChange?.(value);
112
- }
113
- }
114
- }
115
- )
116
- }
117
- );
118
- }
119
- );
120
-
121
- const ValidatedTextarea = observer(
122
- ({
123
- className,
124
- label,
125
- path,
126
- labelProps,
127
- onChange,
128
- ...props
129
- }) => {
130
- const field = useValidations().useField(path);
131
- return /* @__PURE__ */ jsx(
132
- FieldLabel,
133
- {
134
- ...labelProps,
135
- label,
136
- required: field.required,
137
- className: `${className || ""} textarea`,
138
- error: field.error,
139
- children: /* @__PURE__ */ jsx(
140
- Textarea,
141
- {
142
- ...props,
143
- ref: field.ref,
144
- onChange: (ev) => {
145
- field.setValue(ev.target.value);
146
- onChange?.(ev);
147
- },
148
- value: field.value
149
- }
150
- )
151
- }
152
- );
153
- }
154
- );
155
-
156
- export { ValidatedCheckbox, ValidatedInput, ValidatedSelect, ValidatedTextarea, ValidationContext, ValidationContextPrimitive, useValidations };
1
+ export { ValidationContext, ValidationContextPrimitive, useValidations } from './Context.js';
2
+ export { ValidatedCheckbox } from './ValidatedCheckbox.js';
3
+ export { ValidatedInput } from './ValidatedInput.js';
4
+ export { ValidatedSelect } from './ValidatedSelect.js';
5
+ export { ValidatedSwitch } from './ValidatedSwitch.js';
6
+ export { ValidatedTextarea } from './ValidatedTextarea.js';
157
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/Context.tsx","../src/ValidatedCheckbox.tsx","../src/ValidatedInput.tsx","../src/ValidatedSelect.tsx","../src/ValidatedTextarea.tsx"],"sourcesContent":["import { ValidationStore } from '@apia/validations2-controller';\nimport { createContext, ReactNode, useContext } from 'react';\n\nexport const ValidationContextPrimitive =\n createContext<ValidationStore<any> | null>(null);\n\nexport const ValidationContext = ({\n children,\n store,\n}: {\n children: ReactNode;\n store: ValidationStore<any>;\n}) => (\n <ValidationContextPrimitive.Provider value={store}>\n {children}\n </ValidationContextPrimitive.Provider>\n);\n\nexport const useValidations = () => useContext(ValidationContextPrimitive)!;\n","import { observer } from 'mobx-react-lite';\nimport { useValidations } from './Context';\nimport { Checkbox, FieldLabel, TCheckbox, TFieldLabel } from '@apia/components';\n\nexport type TValidateCheckbox = {\n path: string;\n label: string;\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\n} & Omit<TCheckbox, 'value' | 'checked'>;\n\nexport const ValidatedCheckbox = observer(\n ({\n className,\n label,\n path,\n labelProps,\n onChange,\n ...props\n }: TValidateCheckbox) => {\n const field = useValidations().useField(path);\n\n return (\n <FieldLabel\n avoidSemicolon\n {...labelProps}\n label={label}\n required={field.required}\n className={`${className || ''} checkbox`}\n error={field.error}\n >\n <Checkbox\n {...props}\n ref={field.ref}\n onChange={(ev) => {\n field.setValue(ev.target.value);\n onChange?.(ev);\n }}\n value={field.value as any}\n />\n </FieldLabel>\n );\n },\n);\n","import { observer } from 'mobx-react-lite';\nimport { useValidations } from './Context';\nimport { FieldLabel, TFieldLabel } from '@apia/components';\nimport { Input, InputProps } from '@apia/theme';\n\nexport type TValidateInput = {\n path: string;\n label: string;\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\n} & Omit<InputProps, 'value'>;\n\nexport const ValidatedInput = observer(\n ({\n className,\n label,\n path,\n labelProps,\n onChange,\n ...props\n }: TValidateInput) => {\n const field = useValidations().useField(path);\n\n return (\n <FieldLabel\n {...labelProps}\n label={label}\n required={field.required}\n className={`${className || ''} input`}\n error={field.error}\n >\n <Input\n {...props}\n ref={field.ref}\n onChange={(ev) => {\n field.setValue(ev.target.value);\n onChange?.(ev);\n }}\n value={field.value as any}\n />\n </FieldLabel>\n );\n },\n);\n","import { observer } from 'mobx-react-lite';\nimport { useValidations } from './Context';\nimport { Autocomplete, FieldLabel, TFieldLabel } from '@apia/components';\nimport { TOption } from '@apia/util';\n\nexport type TValidateSelect = {\n className?: string;\n path: string;\n label: string;\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\n onChange?: (value: string) => unknown;\n options: TOption[];\n};\n\nexport const ValidatedSelect = observer(\n ({\n className,\n label,\n path,\n labelProps,\n onChange,\n options,\n }: TValidateSelect) => {\n const field = useValidations().useField(path);\n\n return (\n <FieldLabel\n {...labelProps}\n label={label}\n required={field.required}\n className={`${className || ''} select`}\n error={field.error}\n >\n <Autocomplete\n ref={field.ref}\n properties={{\n options,\n onChange(value) {\n field.setValue(value);\n onChange?.(value);\n },\n }}\n />\n </FieldLabel>\n );\n },\n);\n","import { observer } from 'mobx-react-lite';\nimport { useValidations } from './Context';\nimport { FieldLabel, TFieldLabel } from '@apia/components';\nimport { Textarea, TextareaProps } from '@apia/theme';\n\nexport type TValidateTextarea = {\n path: string;\n label: string;\n labelProps?: Pick<TFieldLabel, 'avoidSemicolon' | 'requiredMarkPosition'>;\n} & Omit<TextareaProps, 'value'>;\n\nexport const ValidatedTextarea = observer(\n ({\n className,\n label,\n path,\n labelProps,\n onChange,\n ...props\n }: TValidateTextarea) => {\n const field = useValidations().useField(path);\n\n return (\n <FieldLabel\n {...labelProps}\n label={label}\n required={field.required}\n className={`${className || ''} textarea`}\n error={field.error}\n >\n <Textarea\n {...props}\n ref={field.ref}\n onChange={(ev) => {\n field.setValue(ev.target.value);\n onChange?.(ev);\n }}\n value={field.value as any}\n />\n </FieldLabel>\n );\n },\n);\n"],"names":[],"mappings":";;;;;;AAGO,MAAM,0BAAA,GACX,cAA2C,IAAI;AAE1C,MAAM,oBAAoB,CAAC;AAAA,EAChC,QAAA;AAAA,EACA;AACF,CAAA,yBAIG,0BAAA,CAA2B,QAAA,EAA3B,EAAoC,KAAA,EAAO,OACzC,QAAA,EACH;AAGK,MAAM,cAAA,GAAiB,MAAM,UAAA,CAAW,0BAA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KACF;AAAA;AAGN;;ACnCO,MAAM,iBAAA,GAAoB,QAAA;AAAA,EAC/B,CAAC;AAAA,IACC,SAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,GACL,KAAyB;AACvB,IAAA,MAAM,KAAA,GAAQ,cAAA,EAAe,CAAE,QAAA,CAAS,IAAI,CAAA;AAE5C,IAAA,uBACE,GAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACE,GAAG,UAAA;AAAA,QACJ,KAAA;AAAA,QACA,UAAU,KAAA,CAAM,QAAA;AAAA,QAChB,SAAA,EAAW,CAAA,EAAG,SAAA,IAAa,EAAE,CAAA,SAAA,CAAA;AAAA,QAC7B,OAAO,KAAA,CAAM,KAAA;AAAA,QAEb,QAAA,kBAAA,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACE,GAAG,KAAA;AAAA,YACJ,KAAK,KAAA,CAAM,GAAA;AAAA,YACX,QAAA,EAAU,CAAC,EAAA,KAAO;AAChB,cAAA,KAAA,CAAM,QAAA,CAAS,EAAA,CAAG,MAAA,CAAO,KAAK,CAAA;AAC9B,cAAA,QAAA,GAAW,EAAE,CAAA;AAAA,aACf;AAAA,YACA,OAAO,KAAA,CAAM;AAAA;AAAA;AACf;AAAA,KACF;AAAA;AAGN;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apia/validations2-component",
3
- "version": "5.0.0",
3
+ "version": "5.0.3",
4
4
  "sideEffects": false,
5
5
  "author": "Alexis Leite <alexisleite@live.com>",
6
6
  "main": "dist/index.js",
@@ -30,11 +30,11 @@
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
32
  "dependencies": {
33
- "@apia/components": "^5.0.0",
34
- "@apia/theme": "^5.0.0",
35
- "@apia/validations2-controller": "^5.0.0",
36
- "mobx": "^6.15.0",
37
- "mobx-react-lite": "^4.1.1"
33
+ "@apia/components": "^5.0.3",
34
+ "@apia/theme": "^5.0.3",
35
+ "@apia/validations2-controller": "^5.0.3",
36
+ "mobx": "6.12.3",
37
+ "mobx-react-lite": "3.4.3"
38
38
  },
39
- "gitHead": "985b675635fb9d3dc5e26a90a6d9898864418b84"
39
+ "gitHead": "f45775979bc2be3fdb389ab24155446758840c14"
40
40
  }