@ultraviolet/form 2.0.0-next.2 → 2.0.0-next.3

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.
@@ -1,17 +1,16 @@
1
- import { useFormContext } from 'react-hook-form';
1
+ import { useFormContext, useWatch } from 'react-hook-form';
2
2
 
3
3
  /**
4
4
  * @deprecated
5
5
  */
6
6
  const useFormStateDeprecated = _params => {
7
7
  const {
8
- formState,
9
- watch
8
+ formState
10
9
  } = useFormContext();
11
10
  return {
12
11
  dirtySinceLastSubmit: formState.isDirty,
13
12
  submitErrors: formState.errors.root,
14
- values: watch(),
13
+ values: useWatch(),
15
14
  hasValidationErrors: !formState.isValid,
16
15
  pristine: !formState.isDirty,
17
16
  errors: formState.errors,
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
2
2
  import { Checkbox, CheckboxGroup, DateInput, Radio, SelectableCard, NumberInput, TagInput, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
3
3
  import * as react from 'react';
4
- import { ComponentProps, ReactNode, FocusEvent, JSX, ForwardedRef, FocusEventHandler } from 'react';
4
+ import { ComponentProps, ReactNode, FocusEvent, ForwardedRef, FocusEventHandler, JSX } from 'react';
5
5
  import * as react_hook_form from 'react-hook-form';
6
- import { FieldValues, FieldPath, Validate, PathValue, Path, UseControllerProps, FieldError, UseFormReturn, DefaultValues, FieldErrors, DeepPartial, FieldPathValue, ArrayPath, FieldArray } from 'react-hook-form';
7
- export * from 'react-hook-form';
8
- import * as Select from 'react-select';
9
- import Select__default, { Props, CommonProps, GroupBase } from 'react-select';
6
+ import { FieldValues, FieldPath, Validate, PathValue, Path, UseControllerProps, FieldError, UseFormReturn, DefaultValues, FieldErrors, FieldPathValue, DeepPartial, ArrayPath, FieldArray } from 'react-hook-form';
7
+ export { ControllerRenderProps, DeepPartial, FieldErrors, FieldPath, FieldValues, Path, PathValue, UseFieldArrayMove, UseFieldArrayRemove, UseFormReturn, UseFormSetValue, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
10
8
  import { CSSObject, Theme, css } from '@emotion/react';
9
+ import Select, { OptionProps, GroupBase, Props, CommonProps } from 'react-select';
11
10
 
12
11
  declare const FORM_ERROR = "FINAL_FORM/form-error";
13
12
 
@@ -39,14 +38,12 @@ type BaseFieldProps<TFieldValues extends FieldValues = FieldValues> = {
39
38
  };
40
39
 
41
40
  type CheckboxFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof Checkbox>, 'disabled' | 'onBlur' | 'onChange' | 'onFocus' | 'progress' | 'size' | 'data-testid' | 'helper' | 'tooltip'>> & {
42
- label?: string;
43
41
  className?: string;
44
42
  children?: ReactNode;
45
- required?: boolean;
46
43
  };
47
44
  declare const CheckboxField: <TFieldValues extends FieldValues>({ name, label, size, progress, disabled, required, className, children, onChange, onBlur, onFocus, rules, helper, tooltip, "data-testid": dataTestId, value, }: CheckboxFieldProps<TFieldValues>) => _emotion_react_jsx_runtime.JSX.Element;
48
45
 
49
- type CheckboxGroupFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'onChange' | 'required' | 'direction' | 'children' | 'value' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend' | 'name'>>;
46
+ type CheckboxGroupFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'onChange' | 'required' | 'direction' | 'children' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend'>>;
50
47
  declare const CheckboxGroupField: {
51
48
  <TFieldValues extends FieldValues>({ legend, className, helper, direction, children, onChange, label, error: customError, name, required, }: CheckboxGroupFieldProps<TFieldValues>): _emotion_react_jsx_runtime.JSX.Element;
52
49
  Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, }: Omit<({
@@ -75,7 +72,6 @@ declare const CheckboxGroupField: {
75
72
  };
76
73
 
77
74
  type DateFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Omit<ComponentProps<typeof DateInput>, 'maxDate' | 'minDate' | 'disabled' | 'required' | 'locale' | 'name' | 'onChange' | 'onFocus' | 'onBlur' | 'autoFocus' | 'stardDate' | 'endDate'> & {
78
- name: string;
79
75
  maxDate?: Date;
80
76
  minDate?: Date;
81
77
  disabled?: boolean;
@@ -122,10 +118,10 @@ type FormProps<TFormValues extends FieldValues = FieldValues> = {
122
118
  change: UseFormReturn<TFormValues>['setValue'];
123
119
  }) => Promise<OnRawSubmitReturn> | OnRawSubmitReturn;
124
120
  } & XOR<[
125
- /**
126
- * @deprecated
127
- */
128
121
  {
122
+ /**
123
+ * @deprecated
124
+ */
129
125
  initialValues?: DefaultValues<TFormValues>;
130
126
  },
131
127
  {
@@ -134,12 +130,10 @@ type FormProps<TFormValues extends FieldValues = FieldValues> = {
134
130
  ]>;
135
131
  declare const Form: <TFormValues extends FieldValues>({ children, methods: methodsProp, initialValues, errors, onRawSubmit, name, }: FormProps<TFormValues>) => _emotion_react_jsx_runtime.JSX.Element;
136
132
 
137
- type RadioFieldProps<TFieldValues extends FieldValues> = Omit<BaseFieldProps<TFieldValues>, 'label'> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'data-testid' | 'label' | 'tooltip'>> & {
133
+ type RadioFieldProps<TFieldValues extends FieldValues> = Omit<BaseFieldProps<TFieldValues>, 'label'> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'data-testid' | 'tooltip' | 'label'>> & {
138
134
  className?: string;
139
- name: string;
140
- required?: boolean;
141
135
  };
142
- declare const RadioField: <TFieldValues extends FieldValues>({ className, "data-testid": dataTestId, disabled, id, name, onBlur, label, onChange, onFocus, required, value, rules, tooltip, }: RadioFieldProps<TFieldValues>) => JSX.Element;
136
+ declare const RadioField: <TFieldValues extends FieldValues>({ className, "data-testid": dataTestId, disabled, id, name, onBlur, label, onChange, onFocus, required, value, rules, tooltip, }: RadioFieldProps<TFieldValues>) => _emotion_react_jsx_runtime.JSX.Element;
143
137
 
144
138
  type SelectOption = {
145
139
  value: string;
@@ -180,7 +174,7 @@ type SelectProps = StyledContainerProps & Omit<Props<SelectOption>, 'value'> & C
180
174
  required?: boolean;
181
175
  time?: boolean;
182
176
  };
183
- type StateManagedSelect = typeof Select__default;
177
+ type StateManagedSelect = typeof Select;
184
178
  type SelectInputProps = Partial<SelectProps & SelectStyleProps & {
185
179
  /**
186
180
  * Name of the animation
@@ -198,26 +192,24 @@ type SelectInputProps = Partial<SelectProps & SelectStyleProps & {
198
192
  */
199
193
  customComponents?: SelectProps['components'];
200
194
  children: ReactNode;
201
- emptyState?: ComponentProps<Select__default>['noOptionsMessage'];
195
+ emptyState?: ComponentProps<Select>['noOptionsMessage'];
202
196
  }>;
203
197
  type SelectInputFieldProps<TFieldValues extends FieldValues = FieldValues> = BaseFieldProps<TFieldValues> & 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'>> & {
204
- label?: string;
205
198
  multiple?: boolean;
206
199
  parse?: (value: unknown, name?: string) => unknown;
207
200
  format?: (value: unknown, name: string) => unknown;
208
201
  maxLength?: number;
209
202
  minLength?: number;
210
- name: string;
211
203
  };
212
204
  declare const SelectInputField: {
213
205
  <TFieldValues extends FieldValues>({ 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, }: SelectInputFieldProps<TFieldValues>): _emotion_react_jsx_runtime.JSX.Element;
214
- Option: (props: Partial<Select.OptionProps<{
206
+ Option: (props: Partial<OptionProps<{
215
207
  value: string;
216
208
  label: ReactNode;
217
209
  disabled?: boolean | undefined;
218
210
  description?: string | undefined;
219
211
  inlineDescription?: string | undefined;
220
- }, boolean, Select.GroupBase<{
212
+ }, boolean, GroupBase<{
221
213
  value: string;
222
214
  label: ReactNode;
223
215
  disabled?: boolean | undefined;
@@ -232,12 +224,12 @@ declare const SelectInputField: {
232
224
  }>) => react.JSX.Element;
233
225
  };
234
226
 
235
- type SelectableCardFieldProps<TFieldValues extends FieldValues> = Omit<BaseFieldProps<TFieldValues>, 'label'> & Partial<Pick<ComponentProps<typeof SelectableCard>, 'disabled' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'showTick' | 'type' | 'id' | 'children' | 'name' | 'tooltip' | 'label'>> & {
227
+ type SelectableCardFieldProps<TFieldValues extends FieldValues> = Omit<BaseFieldProps<TFieldValues>, 'label'> & Partial<Pick<ComponentProps<typeof SelectableCard>, 'disabled' | 'onBlur' | 'onChange' | 'onFocus' | 'showTick' | 'type' | 'id' | 'children' | 'tooltip' | 'label'>> & {
236
228
  className?: string;
237
229
  };
238
230
  declare const SelectableCardField: <TFieldValues extends FieldValues>({ name, value, onChange, showTick, type, disabled, children, className, onFocus, onBlur, required, tooltip, id, label, rules, }: SelectableCardFieldProps<TFieldValues>) => _emotion_react_jsx_runtime.JSX.Element;
239
231
 
240
- type NumberInputValueFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof NumberInput>, 'disabled' | 'maxValue' | 'minValue' | 'onMaxCrossed' | 'onMinCrossed' | 'size' | 'step' | 'text' | 'value' | 'onChange' | 'className'>> & {
232
+ type NumberInputValueFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof NumberInput>, 'disabled' | 'maxValue' | 'minValue' | 'onMaxCrossed' | 'onMinCrossed' | 'size' | 'step' | 'text' | 'onChange' | 'className'>> & {
241
233
  onBlur?: FocusEventHandler<HTMLInputElement>;
242
234
  onFocus?: FocusEventHandler<HTMLInputElement>;
243
235
  };
@@ -321,7 +313,7 @@ declare const TextInputField: react.ForwardRefExoticComponent<BaseFieldProps<Fie
321
313
  suppressContentEditableWarning?: boolean | undefined;
322
314
  suppressHydrationWarning?: boolean | undefined;
323
315
  accessKey?: string | undefined;
324
- contentEditable?: (boolean | "false" | "true") | "inherit" | undefined;
316
+ contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only" | undefined;
325
317
  contextMenu?: string | undefined;
326
318
  dir?: string | undefined;
327
319
  draggable?: (boolean | "false" | "true") | undefined;
@@ -597,7 +589,7 @@ declare const TextInputField: react.ForwardRefExoticComponent<BaseFieldProps<Fie
597
589
  } | undefined;
598
590
  max?: string | number | undefined;
599
591
  min?: string | number | undefined;
600
- } & (Omit<react.InputHTMLAttributes<HTMLInputElement>, "onChange"> | Omit<react.TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange">)) & react.RefAttributes<HTMLInputElement | HTMLTextAreaElement | null>, "type" | "required" | "min" | "max" | "maxLength" | "minLength" | "onChange" | "onBlur" | "disabled" | "label" | "onFocus" | "autoFocus" | "id" | "size" | "autoComplete" | "placeholder" | "autoCapitalize" | "autoCorrect" | "autoSave" | "onKeyDown" | "onKeyUp" | "readOnly" | "noTopLabel" | "cols" | "rows" | "fillAvailable" | "generated" | "multiline" | "notice" | "random" | "resizable" | "unit" | "valid">> & {
592
+ } & (Omit<react.InputHTMLAttributes<HTMLInputElement>, "onChange"> | Omit<react.TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange">)) & react.RefAttributes<HTMLInputElement | HTMLTextAreaElement | null>, "type" | "min" | "max" | "maxLength" | "minLength" | "onChange" | "onBlur" | "disabled" | "onFocus" | "autoFocus" | "id" | "size" | "autoComplete" | "placeholder" | "autoCapitalize" | "autoCorrect" | "autoSave" | "onKeyDown" | "onKeyUp" | "readOnly" | "noTopLabel" | "cols" | "rows" | "fillAvailable" | "generated" | "multiline" | "notice" | "random" | "resizable" | "unit" | "valid">> & {
601
593
  className?: string | undefined;
602
594
  /**
603
595
  * @deprecated Use rules instead
@@ -614,8 +606,6 @@ type TimeFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldVal
614
606
  declare const TimeField: <TFieldValues extends FieldValues>({ required, name, schedule, placeholder, disabled, readOnly, onBlur, onFocus, onChange, isLoading, isClearable, inputId, id, animation, animationDuration, animationOnChange, className, isSearchable, rules, options, "data-testid": dataTestId, }: TimeFieldProps<TFieldValues>) => _emotion_react_jsx_runtime.JSX.Element;
615
607
 
616
608
  type ToggleFieldProps<TFieldValues extends FieldValues> = Omit<BaseFieldProps<TFieldValues>, 'label'> & Pick<ComponentProps<typeof Toggle>, 'disabled' | 'label' | 'onChange' | 'size' | 'tooltip' | 'labelPosition' | 'className' | 'data-testid'> & {
617
- name: string;
618
- required?: boolean;
619
609
  parse?: (value: boolean) => any;
620
610
  format?: (value: any) => boolean;
621
611
  };
@@ -636,10 +626,8 @@ type SubmitProps = {
636
626
  };
637
627
  declare const Submit: ({ children, className, disabled, icon, iconPosition, size, variant, sentiment, tooltip, fullWidth, onClick, }: SubmitProps) => _emotion_react_jsx_runtime.JSX.Element;
638
628
 
639
- type RadioGroupFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'onChange' | 'value' | 'legend' | 'children' | 'required' | 'name' | 'error' | 'helper' | 'direction'>> & {
629
+ type RadioGroupFieldProps<TFieldValues extends FieldValues> = BaseFieldProps<TFieldValues> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'onChange' | 'legend' | 'children' | 'error' | 'helper' | 'direction'>> & {
640
630
  className?: string;
641
- name: string;
642
- required?: boolean;
643
631
  };
644
632
  declare const RadioGroupField: {
645
633
  <TFieldValues extends FieldValues>({ className, legend, name, onChange, required, rules, children, label, error: customError, helper, direction, }: RadioGroupFieldProps<TFieldValues>): JSX.Element;
@@ -664,16 +652,6 @@ declare const RadioGroupField: {
664
652
  }) => _emotion_react_jsx_runtime.JSX.Element;
665
653
  };
666
654
 
667
- type FormSpyProps<TFieldValues extends FieldValues> = {
668
- onChange?: (values: {
669
- values: DeepPartial<TFieldValues>;
670
- }) => void;
671
- };
672
- /**
673
- * @deprecated
674
- */
675
- declare const FormSpy: <TFieldValues extends FieldValues>({ onChange, }: FormSpyProps<TFieldValues>) => null;
676
-
677
655
  type ErrorContextValue = {
678
656
  errors: RequiredErrors;
679
657
  getError: (meta: MetaField, error?: FieldError) => string | undefined;
@@ -685,11 +663,11 @@ type ErrorProviderProps = {
685
663
  declare const ErrorProvider: ({ children, errors }: ErrorProviderProps) => _emotion_react_jsx_runtime.JSX.Element;
686
664
  declare const useErrors: () => ErrorContextValue;
687
665
 
688
- type CallbackFn<TFieldValues extends FieldValues, T> = (value: T, values: DeepPartial<TFieldValues>) => void | Promise<void>;
666
+ type CallbackFn<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = (value: FieldPathValue<TFieldValues, TFieldName>, values: DeepPartial<TFieldValues>) => void | Promise<void>;
689
667
  /**
690
668
  * @deprecated
691
669
  */
692
- declare const useOnFieldChange: <T, TFieldValues extends FieldValues = FieldValues>(fieldName: FieldPath<TFieldValues>, callback: CallbackFn<TFieldValues, T>, enabled?: boolean) => void;
670
+ declare const useOnFieldChange: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>>(fieldName: TFieldName, callback: CallbackFn<TFieldValues, TFieldName>, enabled?: boolean) => void;
693
671
 
694
672
  type UseFormStateParams = {
695
673
  subscription?: Record<string, boolean>;
@@ -769,4 +747,4 @@ declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = Fi
769
747
  };
770
748
  };
771
749
 
772
- export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, FormSpy, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
750
+ export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, FORM_ERROR, Form, type FormErrors, type FormProps, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, useErrors, useFieldArrayDeprecated, useFieldDeprecated, useFormDeprecated, useFormStateDeprecated, useOnFieldChange };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { FORM_ERROR } from './constants.js';
2
2
  export { ErrorProvider, useErrors } from './providers/ErrorContext/index.js';
3
- export * from 'react-hook-form';
3
+ export { useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
4
4
  export { CheckboxField } from './components/CheckboxField/index.js';
5
5
  export { CheckboxGroupField } from './components/CheckboxGroupField/index.js';
6
6
  export { DateField } from './components/DateField/index.js';
@@ -16,7 +16,6 @@ export { TextInputField } from './components/TextInputField/index.js';
16
16
  export { TimeField } from './components/TimeField/index.js';
17
17
  export { ToggleField } from './components/ToggleField/index.js';
18
18
  export { RadioGroupField } from './components/RadioGroupField/index.js';
19
- export { FormSpy } from './components/FormSpy/index.js';
20
19
  export { useFormStateDeprecated } from './hooks/useFormState.js';
21
20
  export { useFieldDeprecated } from './hooks/useField.js';
22
21
  export { useFormDeprecated } from './hooks/useForm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "2.0.0-next.2",
3
+ "version": "2.0.0-next.3",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -35,24 +35,25 @@
35
35
  "@emotion/react": "11.11.1",
36
36
  "@emotion/styled": "11.11.0",
37
37
  "react": "18.x",
38
- "react-dom": "18.x"
38
+ "react-dom": "18.x",
39
+ "react-hook-form": "7.47.0"
39
40
  },
40
41
  "devDependencies": {
41
- "@babel/core": "7.23.2",
42
- "@types/final-form-focus": "1.1.6",
43
- "@types/react": "18.2.34",
44
- "@types/react-dom": "18.2.14",
42
+ "@babel/core": "7.23.3",
43
+ "@types/final-form-focus": "1.1.7",
44
+ "@types/react": "18.2.37",
45
+ "@types/react-dom": "18.2.15",
45
46
  "react": "18.2.0",
46
47
  "react-dom": "18.2.0"
47
48
  },
48
49
  "dependencies": {
49
- "@babel/runtime": "7.23.2",
50
+ "@babel/runtime": "7.23.4",
50
51
  "@emotion/babel-plugin": "11.11.0",
51
52
  "@emotion/react": "11.11.1",
52
53
  "@emotion/styled": "11.11.0",
54
+ "react-select": "5.8.0",
53
55
  "react-hook-form": "^7.47.0",
54
- "react-select": "5.7.5",
55
- "@ultraviolet/ui": "1.24.0"
56
+ "@ultraviolet/ui": "1.26.1"
56
57
  },
57
58
  "scripts": {
58
59
  "build": "rollup -c ../../rollup.config.mjs"