@ultraviolet/form 2.10.8 → 2.11.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.
@@ -0,0 +1,115 @@
1
+ import { SelectInputV2 } from '@ultraviolet/ui';
2
+ import { useCallback } from 'react';
3
+ import { useController } from 'react-hook-form';
4
+ import { jsx } from '@emotion/react/jsx-runtime';
5
+ import { useErrors } from '../../providers/ErrorContext/index.js';
6
+
7
+ const SelectInputFieldV2 = ({
8
+ autofocus,
9
+ className,
10
+ id,
11
+ label = '',
12
+ onFocus,
13
+ onBlur,
14
+ placeholder,
15
+ readOnly,
16
+ required,
17
+ size,
18
+ 'data-testid': dataTestId,
19
+ disabled,
20
+ placeholderSearch,
21
+ helper,
22
+ options,
23
+ emptyState,
24
+ onChange,
25
+ searchable,
26
+ clearable,
27
+ multiselect,
28
+ descriptionDirection,
29
+ footer,
30
+ labelDescription,
31
+ success,
32
+ loadMore,
33
+ isLoading,
34
+ selectAll,
35
+ selectAllGroup,
36
+ name,
37
+ 'aria-label': ariaLabel,
38
+ optionalInfoPlacement,
39
+ rules,
40
+ shouldUnregister = false
41
+ }) => {
42
+ const {
43
+ field,
44
+ fieldState: {
45
+ error
46
+ }
47
+ } = useController({
48
+ name,
49
+ shouldUnregister,
50
+ rules: {
51
+ required,
52
+ ...rules
53
+ }
54
+ });
55
+ const {
56
+ getError
57
+ } = useErrors();
58
+ const format = useCallback(val => {
59
+ if (!Array.isArray(options)) {
60
+ let formattedValue;
61
+ Object.keys(options).forEach(group => options[group].forEach(option => {
62
+ if (option.value === val) {
63
+ formattedValue = option;
64
+ }
65
+ }));
66
+ return formattedValue;
67
+ }
68
+ return options.find(option => option.value === val);
69
+ }, [options]);
70
+ return jsx(SelectInputV2, {
71
+ name: field.name,
72
+ options: options,
73
+ required: required,
74
+ size: size,
75
+ "data-testid": dataTestId,
76
+ className: className,
77
+ disabled: disabled,
78
+ id: id,
79
+ label: label,
80
+ onFocus: onFocus,
81
+ onBlur: event => {
82
+ field.onBlur();
83
+ onBlur?.(event);
84
+ },
85
+ placeholder: placeholder,
86
+ readOnly: readOnly,
87
+ value: format(field.value),
88
+ placeholderSearch: placeholderSearch,
89
+ helper: helper,
90
+ emptyState: emptyState,
91
+ searchable: searchable,
92
+ clearable: clearable,
93
+ multiselect: multiselect,
94
+ descriptionDirection: descriptionDirection,
95
+ footer: footer,
96
+ labelDescription: labelDescription,
97
+ error: getError({
98
+ label
99
+ }, error),
100
+ success: success,
101
+ loadMore: loadMore,
102
+ isLoading: isLoading,
103
+ selectAll: selectAll,
104
+ selectAllGroup: selectAllGroup,
105
+ autofocus: autofocus,
106
+ optionalInfoPlacement: optionalInfoPlacement,
107
+ "aria-label": ariaLabel,
108
+ onChange: value => {
109
+ field.onChange(value);
110
+ onChange?.(value);
111
+ }
112
+ });
113
+ };
114
+
115
+ export { SelectInputFieldV2 };
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, TextArea, TextInput, TextInputV2, TimeInput, Toggle, Button, RadioGroup, SelectableCardGroup } from '@ultraviolet/ui';
2
+ import { Checkbox, CheckboxGroup, DateInput, Radio, SelectInput, SelectableCard, NumberInput, NumberInputV2, TagInput, TextArea, TextInput, TextInputV2, TimeInput, Toggle, Button, RadioGroup, SelectableCardGroup, SelectInputV2 } 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';
@@ -215,6 +215,9 @@ type SelectInputProps = Partial<SelectProps & SelectStyleProps & Pick<ComponentP
215
215
  children: ReactNode;
216
216
  emptyState?: ComponentProps<Select>['noOptionsMessage'];
217
217
  }>;
218
+ /**
219
+ * @deprecated This component is deprecated, please use `SelectInputFieldV2` instead
220
+ */
218
221
  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'>> & {
219
222
  multiple?: boolean;
220
223
  parse?: (value: unknown, name?: string) => unknown;
@@ -420,6 +423,9 @@ declare const SelectableCardGroupField: {
420
423
  }) => _emotion_react_jsx_runtime.JSX.Element;
421
424
  };
422
425
 
426
+ type SelectInputFieldV2Props<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Pick<ComponentProps<typeof SelectInputV2>, 'placeholder' | 'placeholderSearch' | 'label' | 'helper' | 'options' | 'emptyState' | 'searchable' | 'readOnly' | 'clearable' | 'size' | 'multiselect' | 'required' | 'descriptionDirection' | 'footer' | 'labelDescription' | 'success' | 'loadMore' | 'isLoading' | 'selectAll' | 'selectAllGroup' | 'autofocus' | 'data-testid' | 'onChange' | 'id' | 'onBlur' | 'aria-label' | 'className' | 'onFocus' | 'optionalInfoPlacement' | 'disabled'>;
427
+ declare const SelectInputFieldV2: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autofocus, className, id, label, onFocus, onBlur, placeholder, readOnly, required, size, "data-testid": dataTestId, disabled, placeholderSearch, helper, options, emptyState, onChange, searchable, clearable, multiselect, descriptionDirection, footer, labelDescription, success, loadMore, isLoading, selectAll, selectAllGroup, name, "aria-label": ariaLabel, optionalInfoPlacement, rules, shouldUnregister, }: SelectInputFieldV2Props<TFieldValues, TName>) => _emotion_react_jsx_runtime.JSX.Element;
428
+
423
429
  type ErrorContextValue = {
424
430
  errors: RequiredErrors;
425
431
  getError: (meta: MetaField, error?: FieldError) => string | undefined;
@@ -546,4 +552,4 @@ declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = Fi
546
552
  };
547
553
  };
548
554
 
549
- export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, KeyValueField, NumberInputField, NumberInputFieldV2, RadioField, RadioGroupField, SelectInputField, SelectableCardField, SelectableCardGroupField, Submit, SubmitErrorAlert, TagInputField, TextAreaField, TextInputField$1 as TextInputField, TextInputField as TextInputFieldV2, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
555
+ export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, KeyValueField, NumberInputField, NumberInputFieldV2, RadioField, RadioGroupField, SelectInputField, SelectInputFieldV2, SelectableCardField, SelectableCardGroupField, Submit, SubmitErrorAlert, TagInputField, TextAreaField, TextInputField$1 as TextInputField, TextInputField as TextInputFieldV2, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
package/dist/index.js CHANGED
@@ -26,3 +26,4 @@ export { Submit } from './components/Submit/index.js';
26
26
  export { RadioGroupField } from './components/RadioGroupField/index.js';
27
27
  export { KeyValueField } from './components/KeyValueField/index.js';
28
28
  export { SelectableCardGroupField } from './components/SelectableCardGroupField/index.js';
29
+ export { SelectInputFieldV2 } from './components/SelectInputFieldV2/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "2.10.8",
3
+ "version": "2.11.0",
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.5",
54
54
  "react-select": "5.8.0",
55
55
  "react-hook-form": "7.51.3",
56
- "@ultraviolet/ui": "1.48.0"
56
+ "@ultraviolet/ui": "1.48.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rollup -c ../../rollup.config.mjs",