@ultraviolet/form 3.1.1 → 3.2.0
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.
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
4
|
const ui = require("@ultraviolet/ui");
|
|
5
5
|
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const validateRegex = require("../../utils/validateRegex.cjs");
|
|
6
7
|
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
8
|
const TagInputField = ({
|
|
9
|
+
regex: regexes,
|
|
8
10
|
className,
|
|
9
11
|
disabled,
|
|
10
12
|
id,
|
|
@@ -39,13 +41,19 @@ const TagInputField = ({
|
|
|
39
41
|
rules: {
|
|
40
42
|
required,
|
|
41
43
|
shouldUnregister,
|
|
42
|
-
validate
|
|
44
|
+
validate: {
|
|
45
|
+
...regexes ? {
|
|
46
|
+
pattern: (value) => validateRegex.validateRegex(value, regexes)
|
|
47
|
+
} : {},
|
|
48
|
+
...validate
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
});
|
|
45
52
|
return /* @__PURE__ */ jsxRuntime.jsx(ui.TagInput, { name: field.name, className, disabled, id, onChange: (newTags) => {
|
|
46
53
|
field.onChange(newTags);
|
|
47
54
|
onChange?.(newTags);
|
|
48
55
|
}, placeholder, variant, value: field.value, "data-testid": dataTestId, clearable, label, labelDescription, size, success, error: getError({
|
|
56
|
+
regex: regexes,
|
|
49
57
|
label: label ?? ""
|
|
50
58
|
}, error), readOnly, tooltip });
|
|
51
59
|
};
|
|
@@ -2,5 +2,7 @@ import { TagInput } from '@ultraviolet/ui';
|
|
|
2
2
|
import type { ComponentProps } from 'react';
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
|
-
export type TagInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Partial<Pick<ComponentProps<typeof TagInput>, 'variant' | 'placeholder' | 'disabled' | 'className' | 'id' | 'data-testid' | 'clearable' | 'label' | 'labelDescription' | 'size' | 'success' | 'readOnly' | 'tooltip'
|
|
6
|
-
|
|
5
|
+
export type TagInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Partial<Pick<ComponentProps<typeof TagInput>, 'variant' | 'placeholder' | 'disabled' | 'className' | 'id' | 'data-testid' | 'clearable' | 'label' | 'labelDescription' | 'size' | 'success' | 'readOnly' | 'tooltip'>> & {
|
|
6
|
+
regex?: (RegExp | RegExp[])[];
|
|
7
|
+
};
|
|
8
|
+
export declare const TagInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ regex: regexes, className, disabled, id, control, name, onChange, placeholder, required, variant, shouldUnregister, "data-testid": dataTestId, clearable, label, labelDescription, size, success, readOnly, tooltip, validate, }: TagInputFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { TagInput } from "@ultraviolet/ui";
|
|
3
3
|
import { useController } from "react-hook-form";
|
|
4
|
+
import { validateRegex } from "../../utils/validateRegex.js";
|
|
4
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
5
6
|
const TagInputField = ({
|
|
7
|
+
regex: regexes,
|
|
6
8
|
className,
|
|
7
9
|
disabled,
|
|
8
10
|
id,
|
|
@@ -37,13 +39,19 @@ const TagInputField = ({
|
|
|
37
39
|
rules: {
|
|
38
40
|
required,
|
|
39
41
|
shouldUnregister,
|
|
40
|
-
validate
|
|
42
|
+
validate: {
|
|
43
|
+
...regexes ? {
|
|
44
|
+
pattern: (value) => validateRegex(value, regexes)
|
|
45
|
+
} : {},
|
|
46
|
+
...validate
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
});
|
|
43
50
|
return /* @__PURE__ */ jsx(TagInput, { name: field.name, className, disabled, id, onChange: (newTags) => {
|
|
44
51
|
field.onChange(newTags);
|
|
45
52
|
onChange?.(newTags);
|
|
46
53
|
}, placeholder, variant, value: field.value, "data-testid": dataTestId, clearable, label, labelDescription, size, success, error: getError({
|
|
54
|
+
regex: regexes,
|
|
47
55
|
label: label ?? ""
|
|
48
56
|
}, error), readOnly, tooltip });
|
|
49
57
|
};
|