@ultraviolet/form 2.3.2 → 2.3.4

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,88 @@
1
+ import { NumberInputV2 } from '@ultraviolet/ui';
2
+ import { useController } from 'react-hook-form';
3
+ import { jsx } from '@emotion/react/jsx-runtime';
4
+ import { useErrors } from '../../providers/ErrorContext/index.js';
5
+
6
+ const NumberInputFieldV2 = ({
7
+ disabled,
8
+ max,
9
+ min,
10
+ name,
11
+ onChange,
12
+ onBlur,
13
+ size,
14
+ step,
15
+ unit,
16
+ tooltip,
17
+ className,
18
+ label,
19
+ labelDescription,
20
+ id,
21
+ placeholder,
22
+ success,
23
+ helper,
24
+ rules,
25
+ 'aria-label': ariaLabel,
26
+ 'data-testid': dataTestId,
27
+ required,
28
+ autoFocus,
29
+ readOnly,
30
+ shouldUnregister = false
31
+ }) => {
32
+ const {
33
+ getError
34
+ } = useErrors();
35
+ const {
36
+ field,
37
+ fieldState: {
38
+ error
39
+ }
40
+ } = useController({
41
+ name,
42
+ shouldUnregister,
43
+ rules: {
44
+ max,
45
+ min,
46
+ required,
47
+ ...rules
48
+ }
49
+ });
50
+ return jsx(NumberInputV2, {
51
+ name: field.name,
52
+ value: field.value,
53
+ disabled: disabled,
54
+ onBlur: event => {
55
+ field.onBlur();
56
+ onBlur?.(event);
57
+ },
58
+ onChange: event => {
59
+ // React hook form doesnt allow undefined values after definition https://react-hook-form.com/docs/usecontroller/controller (that make sense)
60
+ field.onChange(event ?? null);
61
+ onChange?.(event);
62
+ },
63
+ max: max,
64
+ min: min,
65
+ size: size,
66
+ step: step,
67
+ className: className,
68
+ "data-testid": dataTestId,
69
+ id: id,
70
+ label: label,
71
+ labelDescription: labelDescription,
72
+ placeholder: placeholder,
73
+ error: getError({
74
+ label: label ?? '',
75
+ max,
76
+ min
77
+ }, error),
78
+ success: success,
79
+ helper: helper,
80
+ tooltip: tooltip,
81
+ unit: unit,
82
+ "aria-label": ariaLabel,
83
+ autoFocus: autoFocus,
84
+ readOnly: readOnly
85
+ });
86
+ };
87
+
88
+ export { NumberInputFieldV2 };
@@ -0,0 +1,95 @@
1
+ import { TextInputV2 } from '@ultraviolet/ui';
2
+ import { useController } from 'react-hook-form';
3
+ import { jsx } from '@emotion/react/jsx-runtime';
4
+ import { useErrors } from '../../providers/ErrorContext/index.js';
5
+
6
+ /**
7
+ * This component offers a form field based on Ultraviolet UI TextInputV2 component
8
+ */
9
+ const TextInputField = ({
10
+ autoFocus,
11
+ clearable,
12
+ className,
13
+ tabIndex,
14
+ 'data-testid': dataTestId,
15
+ disabled,
16
+ helper,
17
+ label,
18
+ labelDescription,
19
+ onChange,
20
+ minLength,
21
+ maxLength,
22
+ name,
23
+ onFocus,
24
+ onBlur,
25
+ placeholder,
26
+ readOnly,
27
+ required,
28
+ success,
29
+ tooltip,
30
+ validate,
31
+ regex: regexes
32
+ }) => {
33
+ const {
34
+ getError
35
+ } = useErrors();
36
+ const {
37
+ field,
38
+ fieldState: {
39
+ error
40
+ }
41
+ } = useController({
42
+ name,
43
+ rules: {
44
+ required,
45
+ validate: {
46
+ ...(regexes ? {
47
+ pattern: value => regexes.every(regex => value === undefined || value === '' || (Array.isArray(regex) ? regex.some(regexOr => regexOr.test(value)) : regex.test(value)))
48
+ } : {}),
49
+ ...validate
50
+ },
51
+ minLength,
52
+ maxLength
53
+ }
54
+ });
55
+ return jsx(TextInputV2, {
56
+ autoFocus: autoFocus,
57
+ className: className,
58
+ clearable: clearable,
59
+ "data-testid": dataTestId,
60
+ disabled: disabled,
61
+ error: getError({
62
+ regex: regexes,
63
+ // minLength,
64
+ // maxLength,
65
+ label,
66
+ value: field.value
67
+ }, error),
68
+ helper: helper,
69
+ label: label,
70
+ labelDescription: labelDescription,
71
+ minLength: minLength,
72
+ maxLength: maxLength,
73
+ name: name,
74
+ onBlur: event => {
75
+ onBlur?.(event);
76
+ field.onBlur();
77
+ },
78
+ onChange: event => {
79
+ field.onChange(event);
80
+ onChange?.(event);
81
+ },
82
+ onFocus: event => {
83
+ onFocus?.(event);
84
+ },
85
+ placeholder: placeholder,
86
+ readOnly: readOnly,
87
+ required: required,
88
+ success: success,
89
+ tabIndex: tabIndex,
90
+ tooltip: tooltip,
91
+ value: field.value
92
+ });
93
+ };
94
+
95
+ export { TextInputField };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
2
- import { Checkbox, CheckboxGroup, DateInput, Radio, SelectInput, SelectableCard, NumberInput, TagInput, TextInput, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
2
+ import { Checkbox, CheckboxGroup, DateInput, Radio, SelectInput, SelectableCard, NumberInput, NumberInputV2, TagInput, TextInput, TextInputV2, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
3
3
  import * as react from 'react';
4
4
  import { ComponentProps, ReactNode, FocusEvent, ForwardedRef, FocusEventHandler, Ref, JSX } from 'react';
5
5
  import * as react_hook_form from 'react-hook-form';
@@ -253,6 +253,13 @@ type NumberInputValueFieldProps<TFieldValues extends FieldValues, TName extends
253
253
  };
254
254
  declare const NumberInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, maxValue, minValue, name, onChange, onBlur, onFocus, onMaxCrossed, onMinCrossed, required, size, step, text, rules, className, label, shouldUnregister, }: NumberInputValueFieldProps<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
255
255
 
256
+ type NumberInputV2Props<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof NumberInputV2>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'data-testid' | 'label' | 'tooltip' | 'unit' | 'size' | 'step' | 'className' | 'placeholder' | 'error' | 'success' | 'helper' | 'labelDescription' | 'aria-label' | 'autoFocus' | 'readOnly' | 'min' | 'max'>> & {
257
+ className?: string;
258
+ name: string;
259
+ required?: boolean;
260
+ };
261
+ declare const NumberInputFieldV2: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, max, min, name, onChange, onBlur, size, step, unit, tooltip, className, label, labelDescription, id, placeholder, success, helper, rules, "aria-label": ariaLabel, "data-testid": dataTestId, required, autoFocus, readOnly, shouldUnregister, }: NumberInputV2Props<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
262
+
256
263
  declare const SubmitErrorAlert: ({ className }: {
257
264
  className?: string | undefined;
258
265
  }) => _emotion_react_jsx_runtime.JSX.Element | null;
@@ -260,7 +267,7 @@ declare const SubmitErrorAlert: ({ className }: {
260
267
  type TagInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof TagInput>, 'tags' | 'variant' | 'placeholder' | 'disabled' | 'className' | 'id' | 'data-testid'>>;
261
268
  declare const TagInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, disabled, id, name, onChange, placeholder, required, rules, variant, shouldUnregister, "data-testid": dataTestId, }: TagInputFieldProps<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
262
269
 
263
- type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof TextInput>, 'autoCapitalize' | 'autoComplete' | 'autoCorrect' | 'autoFocus' | 'autoSave' | 'cols' | 'disabled' | 'fillAvailable' | 'generated' | 'id' | 'multiline' | 'notice' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'placeholder' | 'random' | 'readOnly' | 'resizable' | 'rows' | 'type' | 'noTopLabel' | 'unit' | 'valid' | 'size' | 'maxLength' | 'minLength' | 'min' | 'max' | 'data-testid'>> & {
270
+ type TextInputFieldProps$1<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof TextInput>, 'autoCapitalize' | 'autoComplete' | 'autoCorrect' | 'autoFocus' | 'autoSave' | 'cols' | 'disabled' | 'fillAvailable' | 'generated' | 'id' | 'multiline' | 'notice' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'placeholder' | 'random' | 'readOnly' | 'resizable' | 'rows' | 'type' | 'noTopLabel' | 'unit' | 'valid' | 'size' | 'maxLength' | 'minLength' | 'min' | 'max' | 'data-testid'>> & {
264
271
  className?: string;
265
272
  regex?: (RegExp | RegExp[])[];
266
273
  format?: (value: unknown) => PathValue<TFieldValues, Path<TFieldValues>>;
@@ -269,7 +276,15 @@ type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPa
269
276
  formatOnBlur?: boolean;
270
277
  innerRef?: Ref<HTMLInputElement>;
271
278
  };
272
- declare const TextInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoCapitalize, autoComplete, autoCorrect, autoFocus, autoSave, className, cols, disabled, fillAvailable, generated, id, label, multiline, name, noTopLabel, notice, onChange, onFocus, onKeyDown, onKeyUp, onBlur, placeholder, random, readOnly, required, resizable, rows, type, unit, size, rules, valid, parse, format, formatOnBlur, regex: regexes, min, max, minLength, maxLength, validate, defaultValue, customError, innerRef, shouldUnregister, "data-testid": dataTestId, }: TextInputFieldProps<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
279
+ declare const TextInputField$1: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoCapitalize, autoComplete, autoCorrect, autoFocus, autoSave, className, cols, disabled, fillAvailable, generated, id, label, multiline, name, noTopLabel, notice, onChange, onFocus, onKeyDown, onKeyUp, onBlur, placeholder, random, readOnly, required, resizable, rows, type, unit, size, rules, valid, parse, format, formatOnBlur, regex: regexes, min, max, minLength, maxLength, validate, defaultValue, customError, innerRef, shouldUnregister, "data-testid": dataTestId, }: TextInputFieldProps$1<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
280
+
281
+ type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name' | 'onChange'> & {
282
+ regex?: (RegExp | RegExp[])[];
283
+ };
284
+ /**
285
+ * This component offers a form field based on Ultraviolet UI TextInputV2 component
286
+ */
287
+ declare const TextInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoFocus, clearable, className, tabIndex, "data-testid": dataTestId, disabled, helper, label, labelDescription, onChange, minLength, maxLength, name, onFocus, onBlur, placeholder, readOnly, required, success, tooltip, validate, regex: regexes, }: TextInputFieldProps<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
273
288
 
274
289
  type TimeFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TimeInput>, 'onChange'> & {
275
290
  name: string;
@@ -324,13 +339,13 @@ declare const RadioGroupField: {
324
339
  };
325
340
 
326
341
  type InputKeyProps = {
327
- label: ComponentProps<typeof TextInputField>['label'];
328
- required?: ComponentProps<typeof TextInputField>['required'];
329
- regex?: ComponentProps<typeof TextInputField>['regex'];
342
+ label: ComponentProps<typeof TextInputField$1>['label'];
343
+ required?: ComponentProps<typeof TextInputField$1>['required'];
344
+ regex?: ComponentProps<typeof TextInputField$1>['regex'];
330
345
  };
331
346
  type InputValueProps = {
332
- type?: ComponentProps<typeof TextInputField>['type'];
333
- placeholder?: ComponentProps<typeof TextInputField>['placeholder'];
347
+ type?: ComponentProps<typeof TextInputField$1>['type'];
348
+ placeholder?: ComponentProps<typeof TextInputField$1>['placeholder'];
334
349
  } & InputKeyProps;
335
350
  type AddButtonProps = {
336
351
  name: ComponentProps<typeof Button>['children'];
@@ -478,4 +493,4 @@ declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = Fi
478
493
  };
479
494
  };
480
495
 
481
- export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, KeyValueField, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
496
+ export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, KeyValueField, NumberInputField, NumberInputFieldV2, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField$1 as TextInputField, TextInputField as TextInputFieldV2, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
package/dist/index.js CHANGED
@@ -17,6 +17,8 @@ export { TextInputField } from './components/TextInputField/index.js';
17
17
  export { TimeField } from './components/TimeField/index.js';
18
18
  export { ToggleField } from './components/ToggleField/index.js';
19
19
  export { RadioGroupField } from './components/RadioGroupField/index.js';
20
+ export { NumberInputFieldV2 } from './components/NumberInputFieldV2/index.js';
21
+ export { TextInputField as TextInputFieldV2 } from './components/TextInputFieldV2/index.js';
20
22
  export { useFormStateDeprecated } from './hooks/useFormState.js';
21
23
  export { useFieldDeprecated } from './hooks/useField.js';
22
24
  export { useFormDeprecated } from './hooks/useForm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@babel/core": "7.23.7",
43
43
  "@types/final-form-focus": "1.1.7",
44
- "@types/react": "18.2.45",
44
+ "@types/react": "18.2.48",
45
45
  "@types/react-dom": "18.2.18",
46
46
  "react": "18.2.0",
47
47
  "react-dom": "18.2.0"
@@ -53,7 +53,7 @@
53
53
  "@emotion/styled": "11.11.0",
54
54
  "react-select": "5.8.0",
55
55
  "react-hook-form": "7.49.3",
56
- "@ultraviolet/ui": "1.31.2"
56
+ "@ultraviolet/ui": "1.31.4"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rollup -c ../../rollup.config.mjs",