@ultraviolet/form 2.13.11 → 2.14.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.
- package/dist/components/UnitInputField/index.cjs +65 -0
- package/dist/components/UnitInputField/index.d.ts +11 -0
- package/dist/components/UnitInputField/index.js +65 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +3 -3
- package/package.json +6 -6
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const UnitInputField = ({
|
|
8
|
+
id,
|
|
9
|
+
name,
|
|
10
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
11
|
+
min = 0,
|
|
12
|
+
size,
|
|
13
|
+
placeholder,
|
|
14
|
+
placeholderUnit,
|
|
15
|
+
onChange,
|
|
16
|
+
onChangeUnitValue,
|
|
17
|
+
disabled,
|
|
18
|
+
options,
|
|
19
|
+
className,
|
|
20
|
+
label,
|
|
21
|
+
required,
|
|
22
|
+
width,
|
|
23
|
+
selectInputWidth,
|
|
24
|
+
helper,
|
|
25
|
+
rules,
|
|
26
|
+
shouldUnregister = false,
|
|
27
|
+
validate
|
|
28
|
+
}) => {
|
|
29
|
+
const {
|
|
30
|
+
getError
|
|
31
|
+
} = index.useErrors();
|
|
32
|
+
const {
|
|
33
|
+
field: unitField
|
|
34
|
+
} = reactHookForm.useController({
|
|
35
|
+
name: `${name}-unit`,
|
|
36
|
+
shouldUnregister,
|
|
37
|
+
rules: {
|
|
38
|
+
required
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const {
|
|
42
|
+
field: valueField,
|
|
43
|
+
fieldState: valueFieldState
|
|
44
|
+
} = reactHookForm.useController({
|
|
45
|
+
name,
|
|
46
|
+
shouldUnregister,
|
|
47
|
+
rules: {
|
|
48
|
+
required,
|
|
49
|
+
min,
|
|
50
|
+
max,
|
|
51
|
+
...rules,
|
|
52
|
+
...validate
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.UnitInput, { id, name, required, max, min, error: getError({
|
|
56
|
+
label
|
|
57
|
+
}, valueFieldState.error), size, placeholder, helper, onChange: (event) => {
|
|
58
|
+
valueField.onChange(event);
|
|
59
|
+
onChange?.(event);
|
|
60
|
+
}, onChangeUnitValue: (event) => {
|
|
61
|
+
unitField.onChange(event);
|
|
62
|
+
onChangeUnitValue?.(event);
|
|
63
|
+
}, value: valueField.value, unitValue: unitField.value, selectInputWidth, disabled, options, label, className, width, placeholderUnit });
|
|
64
|
+
};
|
|
65
|
+
exports.UnitInputField = UnitInputField;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UnitInput } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type UnitInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Pick<ComponentProps<typeof UnitInput>, 'id' | 'name' | 'className' | 'data-testid' | 'disabled' | 'value' | 'max' | 'min' | 'options' | 'placeholder' | 'placeholderUnit' | 'size' | 'unitValue' | 'required' | 'width' | 'helper' | 'selectInputWidth'> & {
|
|
6
|
+
onChange?: ComponentProps<typeof UnitInput>['onChange'];
|
|
7
|
+
onChangeUnitValue?: ComponentProps<typeof UnitInput>['onChangeUnitValue'];
|
|
8
|
+
label: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const UnitInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ id, name, max, min, size, placeholder, placeholderUnit, onChange, onChangeUnitValue, disabled, options, className, label, required, width, selectInputWidth, helper, rules, shouldUnregister, validate, }: UnitInputFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { UnitInput } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
5
|
+
const UnitInputField = ({
|
|
6
|
+
id,
|
|
7
|
+
name,
|
|
8
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
9
|
+
min = 0,
|
|
10
|
+
size,
|
|
11
|
+
placeholder,
|
|
12
|
+
placeholderUnit,
|
|
13
|
+
onChange,
|
|
14
|
+
onChangeUnitValue,
|
|
15
|
+
disabled,
|
|
16
|
+
options,
|
|
17
|
+
className,
|
|
18
|
+
label,
|
|
19
|
+
required,
|
|
20
|
+
width,
|
|
21
|
+
selectInputWidth,
|
|
22
|
+
helper,
|
|
23
|
+
rules,
|
|
24
|
+
shouldUnregister = false,
|
|
25
|
+
validate
|
|
26
|
+
}) => {
|
|
27
|
+
const {
|
|
28
|
+
getError
|
|
29
|
+
} = useErrors();
|
|
30
|
+
const {
|
|
31
|
+
field: unitField
|
|
32
|
+
} = useController({
|
|
33
|
+
name: `${name}-unit`,
|
|
34
|
+
shouldUnregister,
|
|
35
|
+
rules: {
|
|
36
|
+
required
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const {
|
|
40
|
+
field: valueField,
|
|
41
|
+
fieldState: valueFieldState
|
|
42
|
+
} = useController({
|
|
43
|
+
name,
|
|
44
|
+
shouldUnregister,
|
|
45
|
+
rules: {
|
|
46
|
+
required,
|
|
47
|
+
min,
|
|
48
|
+
max,
|
|
49
|
+
...rules,
|
|
50
|
+
...validate
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return /* @__PURE__ */ jsx(UnitInput, { id, name, required, max, min, error: getError({
|
|
54
|
+
label
|
|
55
|
+
}, valueFieldState.error), size, placeholder, helper, onChange: (event) => {
|
|
56
|
+
valueField.onChange(event);
|
|
57
|
+
onChange?.(event);
|
|
58
|
+
}, onChangeUnitValue: (event) => {
|
|
59
|
+
unitField.onChange(event);
|
|
60
|
+
onChangeUnitValue?.(event);
|
|
61
|
+
}, value: valueField.value, unitValue: unitField.value, selectInputWidth, disabled, options, label, className, width, placeholderUnit });
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
UnitInputField
|
|
65
|
+
};
|
|
@@ -20,3 +20,4 @@ export { RadioGroupField } from './RadioGroupField';
|
|
|
20
20
|
export { KeyValueField } from './KeyValueField';
|
|
21
21
|
export { SelectableCardGroupField } from './SelectableCardGroupField';
|
|
22
22
|
export { SelectInputFieldV2 } from './SelectInputFieldV2';
|
|
23
|
+
export { UnitInputField } from './UnitInputField';
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ const index$i = require("./components/RadioGroupField/index.cjs");
|
|
|
29
29
|
const index$j = require("./components/KeyValueField/index.cjs");
|
|
30
30
|
const index$k = require("./components/SelectableCardGroupField/index.cjs");
|
|
31
31
|
const index$l = require("./components/SelectInputFieldV2/index.cjs");
|
|
32
|
+
const index$m = require("./components/UnitInputField/index.cjs");
|
|
32
33
|
exports.FORM_ERROR = constants.FORM_ERROR;
|
|
33
34
|
exports.ErrorProvider = index.ErrorProvider;
|
|
34
35
|
exports.useErrors = index.useErrors;
|
|
@@ -82,3 +83,4 @@ exports.RadioGroupField = index$i.RadioGroupField;
|
|
|
82
83
|
exports.KeyValueField = index$j.KeyValueField;
|
|
83
84
|
exports.SelectableCardGroupField = index$k.SelectableCardGroupField;
|
|
84
85
|
exports.SelectInputFieldV2 = index$l.SelectInputFieldV2;
|
|
86
|
+
exports.UnitInputField = index$m.UnitInputField;
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { RadioGroupField } from "./components/RadioGroupField/index.js";
|
|
|
27
27
|
import { KeyValueField } from "./components/KeyValueField/index.js";
|
|
28
28
|
import { SelectableCardGroupField } from "./components/SelectableCardGroupField/index.js";
|
|
29
29
|
import { SelectInputFieldV2 } from "./components/SelectInputFieldV2/index.js";
|
|
30
|
+
import { UnitInputField } from "./components/UnitInputField/index.js";
|
|
30
31
|
export {
|
|
31
32
|
CheckboxField,
|
|
32
33
|
CheckboxGroupField,
|
|
@@ -51,6 +52,7 @@ export {
|
|
|
51
52
|
TextInputField2 as TextInputFieldV2,
|
|
52
53
|
TimeField,
|
|
53
54
|
ToggleField,
|
|
55
|
+
UnitInputField,
|
|
54
56
|
useController,
|
|
55
57
|
useErrors,
|
|
56
58
|
useFieldArray,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldError, FieldPath, FieldValues, Path, PathValue, UseControllerProps, Validate } from 'react-hook-form';
|
|
1
|
+
import type { FieldError, FieldPath, FieldPathValue, FieldValues, Path, PathValue, UseControllerProps, Validate } from 'react-hook-form';
|
|
2
2
|
export type MetaField = {
|
|
3
3
|
min?: number | string;
|
|
4
4
|
max?: number | string;
|
|
@@ -19,10 +19,10 @@ export type FormErrors = {
|
|
|
19
19
|
export type BaseFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = {
|
|
20
20
|
name: TName;
|
|
21
21
|
required?: boolean;
|
|
22
|
+
validate?: Record<string, Validate<FieldPathValue<TFieldValues, TName>, TFieldValues>>;
|
|
22
23
|
/**
|
|
23
|
-
* @deprecated
|
|
24
|
+
* @deprecated Use individual props instead
|
|
24
25
|
*/
|
|
25
|
-
validate?: Validate<PathValue<TFieldValues, Path<TFieldValues>>, TFieldValues>;
|
|
26
26
|
rules?: UseControllerProps<TFieldValues>['rules'];
|
|
27
27
|
defaultValue?: PathValue<TFieldValues, Path<TFieldValues>>;
|
|
28
28
|
label?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@emotion/styled": "11.11.5",
|
|
56
56
|
"react": "18.x",
|
|
57
57
|
"react-dom": "18.x",
|
|
58
|
-
"react-hook-form": "7.51.
|
|
58
|
+
"react-hook-form": "7.51.5"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/core": "7.24.5",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"@emotion/react": "11.11.4",
|
|
72
72
|
"@emotion/styled": "11.11.5",
|
|
73
73
|
"react-select": "5.8.0",
|
|
74
|
-
"react-hook-form": "7.51.
|
|
75
|
-
"@ultraviolet/ui": "1.
|
|
76
|
-
"@ultraviolet/themes": "1.
|
|
74
|
+
"react-hook-form": "7.51.5",
|
|
75
|
+
"@ultraviolet/ui": "1.54.0",
|
|
76
|
+
"@ultraviolet/themes": "1.11.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"prebuild": "shx rm -rf dist",
|
|
82
82
|
"size": "pnpm run build && size-limit",
|
|
83
83
|
"test:unit:coverage": "pnpm test:unit --coverage",
|
|
84
|
-
"test:unit": "vitest --run --config vite.config.ts",
|
|
84
|
+
"test:unit": "LC_ALL=en_US.UTF-8 pnpm vitest --run --config vite.config.ts",
|
|
85
85
|
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
86
86
|
"typecheck": "tsc --noEmit",
|
|
87
87
|
"watch:build": "vite build --config vite.config.ts --watch",
|