@ultraviolet/form 2.4.0 → 2.4.2

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.
@@ -38,7 +38,7 @@ const SelectInputField = ({
38
38
  required,
39
39
  rules,
40
40
  noTopLabel,
41
- noOptionsMessage,
41
+ emptyState,
42
42
  customStyle,
43
43
  shouldUnregister = false,
44
44
  'data-testid': dataTestId
@@ -122,7 +122,7 @@ const SelectInputField = ({
122
122
  noTopLabel: noTopLabel,
123
123
  required: required,
124
124
  value: format(field.value),
125
- noOptionsMessage: noOptionsMessage,
125
+ emptyState: emptyState,
126
126
  "data-testid": dataTestId,
127
127
  children: children
128
128
  });
@@ -0,0 +1,97 @@
1
+ import { TextArea } 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 TextArea component
8
+ */
9
+ const TextAreaField = ({
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
+ rows,
29
+ success,
30
+ tooltip,
31
+ validate,
32
+ regex: regexes
33
+ }) => {
34
+ const {
35
+ getError
36
+ } = useErrors();
37
+ const {
38
+ field,
39
+ fieldState: {
40
+ error
41
+ }
42
+ } = useController({
43
+ name,
44
+ rules: {
45
+ required,
46
+ validate: {
47
+ ...(regexes ? {
48
+ pattern: value => regexes.every(regex => value === undefined || value === '' || (Array.isArray(regex) ? regex.some(regexOr => regexOr.test(value)) : regex.test(value)))
49
+ } : {}),
50
+ ...validate
51
+ },
52
+ minLength,
53
+ maxLength
54
+ }
55
+ });
56
+ return jsx(TextArea, {
57
+ autoFocus: autoFocus,
58
+ className: className,
59
+ clearable: clearable,
60
+ "data-testid": dataTestId,
61
+ disabled: disabled,
62
+ error: getError({
63
+ regex: regexes,
64
+ minLength,
65
+ maxLength,
66
+ label,
67
+ value: field.value
68
+ }, error),
69
+ helper: helper,
70
+ label: label,
71
+ labelDescription: labelDescription,
72
+ minLength: minLength,
73
+ maxLength: maxLength,
74
+ name: name,
75
+ onBlur: event => {
76
+ onBlur?.(event);
77
+ field.onBlur();
78
+ },
79
+ onChange: event => {
80
+ field.onChange(event);
81
+ onChange?.(event);
82
+ },
83
+ onFocus: event => {
84
+ onFocus?.(event);
85
+ },
86
+ placeholder: placeholder,
87
+ readOnly: readOnly,
88
+ required: required,
89
+ rows: rows,
90
+ success: success,
91
+ tabIndex: tabIndex,
92
+ tooltip: tooltip,
93
+ value: field.value
94
+ });
95
+ };
96
+
97
+ export { TextAreaField };
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, NumberInputV2, TagInput, TextInput, TextInputV2, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
2
+ import { Checkbox, CheckboxGroup, DateInput, Radio, SelectInput, SelectableCard, NumberInput, NumberInputV2, TagInput, TextArea, 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';
@@ -212,7 +212,7 @@ type SelectInputProps = Partial<SelectProps & SelectStyleProps & Pick<ComponentP
212
212
  children: ReactNode;
213
213
  emptyState?: ComponentProps<Select>['noOptionsMessage'];
214
214
  }>;
215
- type SelectInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'onChange'> & Partial<Pick<SelectInputProps, 'animation' | 'animationDuration' | 'animationOnChange' | 'children' | 'className' | 'disabled' | 'error' | 'id' | 'inputId' | 'isClearable' | 'isLoading' | 'isSearchable' | 'menuPortalTarget' | 'onBlur' | 'onChange' | 'onFocus' | 'options' | 'placeholder' | 'readOnly' | 'required' | 'value' | 'noTopLabel' | 'noOptionsMessage' | 'customStyle' | 'data-testid'>> & {
215
+ type SelectInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'onChange'> & Partial<Pick<SelectInputProps, 'animation' | 'animationDuration' | 'animationOnChange' | 'children' | 'className' | 'disabled' | 'error' | 'id' | 'inputId' | 'isClearable' | 'isLoading' | 'isSearchable' | 'menuPortalTarget' | 'onBlur' | 'onChange' | 'onFocus' | 'options' | 'placeholder' | 'readOnly' | 'required' | 'value' | 'noTopLabel' | 'emptyState' | 'customStyle' | 'data-testid'>> & {
216
216
  multiple?: boolean;
217
217
  parse?: (value: unknown, name?: string) => unknown;
218
218
  format?: (value: unknown, name: string) => unknown;
@@ -220,7 +220,7 @@ type SelectInputFieldProps<TFieldValues extends FieldValues, TName extends Field
220
220
  minLength?: number;
221
221
  };
222
222
  declare const SelectInputField: {
223
- <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ animation, animationDuration, animationOnChange, children, className, disabled, format: formatProp, id, inputId, isClearable, isLoading, isSearchable, label, maxLength, menuPortalTarget, minLength, multiple, name, onBlur, onChange, onFocus, options: optionsProp, parse: parseProp, placeholder, readOnly, required, rules, noTopLabel, noOptionsMessage, customStyle, shouldUnregister, "data-testid": dataTestId, }: SelectInputFieldProps<TFieldValues, TName>): _emotion_react_jsx_runtime.JSX.Element;
223
+ <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ animation, animationDuration, animationOnChange, children, className, disabled, format: formatProp, id, inputId, isClearable, isLoading, isSearchable, label, maxLength, menuPortalTarget, minLength, multiple, name, onBlur, onChange, onFocus, options: optionsProp, parse: parseProp, placeholder, readOnly, required, rules, noTopLabel, emptyState, customStyle, shouldUnregister, "data-testid": dataTestId, }: SelectInputFieldProps<TFieldValues, TName>): _emotion_react_jsx_runtime.JSX.Element;
224
224
  Option: (props: Partial<OptionProps<{
225
225
  value: string;
226
226
  label: ReactNode;
@@ -267,6 +267,14 @@ declare const SubmitErrorAlert: ({ className }: {
267
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'>>;
268
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;
269
269
 
270
+ type TextAreaFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TextArea>, 'value' | 'error' | 'name' | 'onChange'> & {
271
+ regex?: (RegExp | RegExp[])[];
272
+ };
273
+ /**
274
+ * This component offers a form field based on Ultraviolet UI TextArea component
275
+ */
276
+ declare const TextAreaField: <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, rows, success, tooltip, validate, regex: regexes, }: TextAreaFieldProps<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
277
+
270
278
  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'>> & {
271
279
  className?: string;
272
280
  regex?: (RegExp | RegExp[])[];
@@ -493,4 +501,4 @@ declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = Fi
493
501
  };
494
502
  };
495
503
 
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 };
504
+ export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, KeyValueField, NumberInputField, NumberInputFieldV2, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextAreaField, TextInputField$1 as TextInputField, TextInputField as TextInputFieldV2, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
package/dist/index.js CHANGED
@@ -1,26 +1,27 @@
1
1
  export { FORM_ERROR } from './constants.js';
2
2
  export { ErrorProvider, useErrors } from './providers/ErrorContext/index.js';
3
3
  export { useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
4
+ export { useFormStateDeprecated } from './hooks/useFormState.js';
5
+ export { useFieldDeprecated } from './hooks/useField.js';
6
+ export { useFormDeprecated } from './hooks/useForm.js';
7
+ export { useFieldArrayDeprecated } from './hooks/useFieldArray.js';
8
+ export { useOnFieldChange } from './hooks/useOnFieldChange.js';
4
9
  export { CheckboxField } from './components/CheckboxField/index.js';
5
10
  export { CheckboxGroupField } from './components/CheckboxGroupField/index.js';
6
11
  export { DateField } from './components/DateField/index.js';
7
12
  export { Form } from './components/Form/index.js';
8
- export { KeyValueField } from './components/KeyValueField/index.js';
9
13
  export { RadioField } from './components/RadioField/index.js';
10
- export { SelectableCardField } from './components/SelectableCardField/index.js';
11
14
  export { SelectInputField } from './components/SelectInputField/index.js';
15
+ export { SelectableCardField } from './components/SelectableCardField/index.js';
12
16
  export { NumberInputField } from './components/NumberInputField/index.js';
13
- export { Submit } from './components/Submit/index.js';
17
+ export { NumberInputFieldV2 } from './components/NumberInputFieldV2/index.js';
14
18
  export { SubmitErrorAlert } from './components/SubmitErrorAlert/index.js';
15
19
  export { TagInputField } from './components/TagInputField/index.js';
20
+ export { TextAreaField } from './components/TextAreaField/index.js';
16
21
  export { TextInputField } from './components/TextInputField/index.js';
22
+ export { TextInputField as TextInputFieldV2 } from './components/TextInputFieldV2/index.js';
17
23
  export { TimeField } from './components/TimeField/index.js';
18
24
  export { ToggleField } from './components/ToggleField/index.js';
25
+ export { Submit } from './components/Submit/index.js';
19
26
  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';
22
- export { useFormStateDeprecated } from './hooks/useFormState.js';
23
- export { useFieldDeprecated } from './hooks/useField.js';
24
- export { useFormDeprecated } from './hooks/useForm.js';
25
- export { useFieldArrayDeprecated } from './hooks/useFieldArray.js';
26
- export { useOnFieldChange } from './hooks/useOnFieldChange.js';
27
+ export { KeyValueField } from './components/KeyValueField/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -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.32.0"
56
+ "@ultraviolet/ui": "1.32.2"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rollup -c ../../rollup.config.mjs",