@uxf/form 11.71.0 → 11.72.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.
- package/checkbox-list/checkbox-list.d.ts +3 -2
- package/checkbox-list/checkbox-list.js +0 -1
- package/form-renderer/field/base-field.js +2 -2
- package/money-input/money-input.d.ts +6 -2
- package/money-input/money-input.js +28 -3
- package/money-input/money-input.stories.js +1 -1
- package/number-input/number-input.js +2 -2
- package/package.json +2 -2
- package/password-input/password-input.d.ts +3 -2
- package/password-input/password-input.js +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { CheckboxInputProps as UICheckboxInputProps } from "@uxf/ui/checkbox-input";
|
|
2
2
|
import { FormControlProps } from "@uxf/ui/types";
|
|
3
3
|
import React, { ReactNode } from "react";
|
|
4
|
-
import { FieldValues
|
|
4
|
+
import { FieldValues } from "react-hook-form";
|
|
5
|
+
import { ControlProps } from "../types";
|
|
5
6
|
type ValueType = string | number;
|
|
6
7
|
export type CheckboxListOption = {
|
|
7
8
|
id: ValueType;
|
|
@@ -9,7 +10,7 @@ export type CheckboxListOption = {
|
|
|
9
10
|
isDisabled?: boolean;
|
|
10
11
|
};
|
|
11
12
|
export type CheckboxListValue<T> = T[] | null;
|
|
12
|
-
type CheckboxListProps<FormData extends FieldValues> =
|
|
13
|
+
type CheckboxListProps<FormData extends FieldValues> = ControlProps<FormData> & Omit<UICheckboxInputProps, "isInvalid" | "name" | "onChange" | "value"> & {
|
|
13
14
|
onChange?: FormControlProps<CheckboxListValue<string | number>>["onChange"];
|
|
14
15
|
options: CheckboxListOption[];
|
|
15
16
|
requiredMessage?: string;
|
|
@@ -15,7 +15,6 @@ function CheckboxList(props) {
|
|
|
15
15
|
const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formContext.formId}__${props.name}`;
|
|
16
16
|
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
17
17
|
control: props.control,
|
|
18
|
-
defaultValue: props.defaultValue,
|
|
19
18
|
name: props.name,
|
|
20
19
|
rules: {
|
|
21
20
|
required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
|
|
@@ -51,9 +51,9 @@ function BaseField(props) {
|
|
|
51
51
|
case "files":
|
|
52
52
|
case "images":
|
|
53
53
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
54
|
-
react_1.default.createElement(label_1.Label,
|
|
54
|
+
react_1.default.createElement(label_1.Label, { isRequired: isRequired }, label),
|
|
55
55
|
react_1.default.createElement("div", { className: "mb-3" },
|
|
56
|
-
react_1.default.createElement(dropzone_input_1.DropzoneInput, { control: props.control, label: label, name: fieldName, onUploadFile: uploadHandler })),
|
|
56
|
+
react_1.default.createElement(dropzone_input_1.DropzoneInput, { control: props.control, isRequired: isRequired, label: label, name: fieldName, onUploadFile: uploadHandler })),
|
|
57
57
|
react_1.default.createElement(dropzone_list_1.DropzoneList, { control: props.control, errorText: "Soubor se nepoda\u0159ilo nahr\u00E1t.", name: fieldName, onRemoveConfirm: (_g = props.overrides) === null || _g === void 0 ? void 0 : _g.onRemoveConfirm })));
|
|
58
58
|
case "manyToMany":
|
|
59
59
|
return (react_1.default.createElement(multi_combobox_1.MultiCombobox, { control: props.control, isDisabled: isDisabled, isRequired: isRequired, label: label, loadOptions: (term) => { var _a; return autocompleteHandler((_a = props.fieldSchema.autocomplete) !== null && _a !== void 0 ? _a : "", term); }, name: fieldName }));
|
|
@@ -5,13 +5,17 @@ import { FieldValues } from "react-hook-form";
|
|
|
5
5
|
import { ControlProps } from "../types";
|
|
6
6
|
export type MoneyInputValue = Money | null;
|
|
7
7
|
export type MoneyInputProps<FormData extends FieldValues> = Omit<ControlProps<FormData>, "defaultValue"> & Omit<FormControlProps<MoneyInputValue>, "value" | "onChange"> & {
|
|
8
|
-
id?: string;
|
|
9
|
-
requiredMessage?: string;
|
|
10
8
|
defaultCurrency?: Currency;
|
|
9
|
+
id?: string;
|
|
11
10
|
label?: string;
|
|
12
11
|
leftAddon?: ReactNode;
|
|
13
12
|
leftElement?: ReactNode;
|
|
13
|
+
max?: number;
|
|
14
|
+
maxMessage?: (value: MoneyInputValue) => string;
|
|
15
|
+
min?: number;
|
|
16
|
+
minMessage?: (value: MoneyInputValue) => string;
|
|
14
17
|
onChange?: FormControlProps<MoneyInputValue>["onChange"];
|
|
18
|
+
requiredMessage?: string;
|
|
15
19
|
rightAddon?: ReactNode;
|
|
16
20
|
};
|
|
17
21
|
export declare function MoneyInput<FormData extends FieldValues>(props: MoneyInputProps<FormData>): React.JSX.Element;
|
|
@@ -38,7 +38,7 @@ const CONTROL_KEYS = ["v", "V", "c", "C", "x", "X", "a", "A"];
|
|
|
38
38
|
// Allow digits and decimal point (.,)
|
|
39
39
|
const ALLOWED_KEYS = /[0-9+\-.,]/;
|
|
40
40
|
function MoneyInput(props) {
|
|
41
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
41
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
42
42
|
const formContext = (0, form_context_1.useFormContext)();
|
|
43
43
|
const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formContext.formId}__${props.name}`;
|
|
44
44
|
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
@@ -46,11 +46,36 @@ function MoneyInput(props) {
|
|
|
46
46
|
name: props.name,
|
|
47
47
|
rules: {
|
|
48
48
|
required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
|
|
49
|
+
validate: {
|
|
50
|
+
validMinNumber: (value) => {
|
|
51
|
+
if (!value) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof props.min === "number" && !isNaN(props.min) && value.amount < props.min) {
|
|
55
|
+
return props.minMessage
|
|
56
|
+
? props.minMessage(value)
|
|
57
|
+
: `Hodnota musí být větší nebo rovna ${props.min}.`;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
validMaxNumber: (value) => {
|
|
61
|
+
if (!value) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof props.max === "number" && !isNaN(props.max) && value.amount > props.max) {
|
|
65
|
+
return props.maxMessage
|
|
66
|
+
? props.maxMessage(value)
|
|
67
|
+
: `Hodnota musí být menší nebo rovna ${props.max}.`;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
...(typeof ((_b = props.rules) === null || _b === void 0 ? void 0 : _b.validate) === "function"
|
|
71
|
+
? { custom: props.rules.validate }
|
|
72
|
+
: (_c = props.rules) === null || _c === void 0 ? void 0 : _c.validate),
|
|
73
|
+
},
|
|
49
74
|
...props.rules,
|
|
50
75
|
},
|
|
51
76
|
shouldUnregister: props.shouldUnregister,
|
|
52
77
|
});
|
|
53
|
-
const [lastCurrency, setLastCurrency] = (0, react_1.useState)((
|
|
78
|
+
const [lastCurrency, setLastCurrency] = (0, react_1.useState)((_f = (_e = (_d = field.value) === null || _d === void 0 ? void 0 : _d.currency) !== null && _e !== void 0 ? _e : props.defaultCurrency) !== null && _f !== void 0 ? _f : "CZK");
|
|
54
79
|
(0, react_1.useEffect)(() => {
|
|
55
80
|
var _a;
|
|
56
81
|
if ((0, is_not_nil_1.isNotNil)(field.value) && ((_a = field.value) === null || _a === void 0 ? void 0 : _a.currency) !== lastCurrency) {
|
|
@@ -78,6 +103,6 @@ function MoneyInput(props) {
|
|
|
78
103
|
field.onChange(newValue);
|
|
79
104
|
(_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, newValue, event);
|
|
80
105
|
};
|
|
81
|
-
return (react_1.default.createElement(text_input_1.TextInput, { className: "uxf-money-input uxf-input--no-spin-buttons", helperText: (
|
|
106
|
+
return (react_1.default.createElement(text_input_1.TextInput, { className: "uxf-money-input uxf-input--no-spin-buttons", helperText: (_g = fieldState.error) === null || _g === void 0 ? void 0 : _g.message, id: id, inputMode: "decimal", isDisabled: formContext.isFormDisabled || props.isDisabled, isInvalid: Boolean(fieldState.error), isReadOnly: formContext.isFormReadOnly || props.isReadOnly, isRequired: props.isRequired, label: props.label, leftAddon: props.leftAddon, leftElement: props.leftElement, name: field.name, onChange: changeHandler, onKeyDown: keyDownHandler, ref: field.ref, rightAddon: props.rightAddon, rightElement: currencies_1.currencies[(_j = (_h = field.value) === null || _h === void 0 ? void 0 : _h.currency) !== null && _j !== void 0 ? _j : lastCurrency].symbol, step: 2, type: "number", value: (_l = (_k = field.value) === null || _k === void 0 ? void 0 : _k.amount) !== null && _l !== void 0 ? _l : "" }));
|
|
82
107
|
}
|
|
83
108
|
MoneyInput.displayName = "UxfFormMoneyInput";
|
|
@@ -9,7 +9,7 @@ const storybook_form_1 = require("../storybook/storybook-form");
|
|
|
9
9
|
const money_input_1 = require("./money-input");
|
|
10
10
|
function Default() {
|
|
11
11
|
return (react_1.default.createElement(storybook_form_1.StorybookForm, { className: "space-y-4 p-4", defaultValues: { "default-value": { amount: "100", currency: "USD" } } }, ({ control }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
12
|
-
react_1.default.createElement(money_input_1.MoneyInput, { control: control, label: "Default money input", name: "default" }),
|
|
12
|
+
react_1.default.createElement(money_input_1.MoneyInput, { control: control, label: "Default money input min100 max200", max: 200, min: 100, name: "default" }),
|
|
13
13
|
react_1.default.createElement(money_input_1.MoneyInput, { control: control, defaultCurrency: "EUR", label: "Money input with default currency", name: "default-currency" }),
|
|
14
14
|
react_1.default.createElement(money_input_1.MoneyInput, { control: control, label: "Money input with default value", name: "default-value" })))));
|
|
15
15
|
}
|
|
@@ -21,13 +21,13 @@ function NumberInput(props) {
|
|
|
21
21
|
max: typeof props.max === "number" && !isNaN(props.max)
|
|
22
22
|
? {
|
|
23
23
|
value: props.max,
|
|
24
|
-
message: (_b = props.maxMessage) !== null && _b !== void 0 ? _b : `Hodnota musí být menší nebo rovna
|
|
24
|
+
message: (_b = props.maxMessage) !== null && _b !== void 0 ? _b : `Hodnota musí být menší nebo rovna ${props.max}.`,
|
|
25
25
|
}
|
|
26
26
|
: undefined,
|
|
27
27
|
min: typeof props.min === "number" && !isNaN(props.min)
|
|
28
28
|
? {
|
|
29
29
|
value: props.min,
|
|
30
|
-
message: (_c = props.minMessage) !== null && _c !== void 0 ? _c : `Hodnota musí být větší nebo rovna
|
|
30
|
+
message: (_c = props.minMessage) !== null && _c !== void 0 ? _c : `Hodnota musí být větší nebo rovna ${props.min}.`,
|
|
31
31
|
}
|
|
32
32
|
: undefined,
|
|
33
33
|
required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/form",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.72.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@uxf/ui": "11.
|
|
19
|
+
"@uxf/ui": "11.72.3",
|
|
20
20
|
"coordinate-parser": "1.0.7",
|
|
21
21
|
"dayjs": "1.11.13",
|
|
22
22
|
"react-hook-form": "7.53.0"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { TextInputProps as UITextInputProps } from "@uxf/ui/text-input";
|
|
2
2
|
import { FormControlProps } from "@uxf/ui/types";
|
|
3
3
|
import React, { ReactNode } from "react";
|
|
4
|
-
import { FieldValues
|
|
5
|
-
|
|
4
|
+
import { FieldValues } from "react-hook-form";
|
|
5
|
+
import { ControlProps } from "../types";
|
|
6
|
+
export type PasswordInputProps<FormData extends FieldValues> = ControlProps<FormData> & Omit<UITextInputProps, "isFocused" | "isInvalid" | "max" | "min" | "name" | "onChange" | "value" | "type"> & {
|
|
6
7
|
minLengthMessage?: string;
|
|
7
8
|
onChange?: FormControlProps<string | null>["onChange"];
|
|
8
9
|
renderVisibilitySetter?: (isVisible: boolean, onToggle: () => void) => ReactNode;
|
|
@@ -62,7 +62,6 @@ function PasswordInput(props) {
|
|
|
62
62
|
const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formContext.formId}__${props.name}`;
|
|
63
63
|
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
64
64
|
control: props.control,
|
|
65
|
-
defaultValue: props.defaultValue,
|
|
66
65
|
name: props.name,
|
|
67
66
|
shouldUnregister: props.shouldUnregister,
|
|
68
67
|
rules: {
|