@ultraviolet/form 1.3.5 → 1.4.1

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.
@@ -19,6 +19,7 @@ const CheckboxField = /*#__PURE__*/forwardRef((_ref, ref) => {
19
19
  onBlur,
20
20
  onFocus,
21
21
  value,
22
+ helper,
22
23
  'data-testid': dataTestId
23
24
  } = _ref;
24
25
  const {
@@ -59,6 +60,7 @@ const CheckboxField = /*#__PURE__*/forwardRef((_ref, ref) => {
59
60
  disabled: disabled,
60
61
  checked: input.checked,
61
62
  error: error,
63
+ helper: helper,
62
64
  ref: ref,
63
65
  className: className,
64
66
  value: input.value,
@@ -0,0 +1,55 @@
1
+ import { RadioGroup } from '@ultraviolet/ui';
2
+ import { jsx } from '@emotion/react/jsx-runtime';
3
+ import { useErrors } from '../../providers/ErrorContext/index.js';
4
+ import { useFormField } from '../../hooks/useFormField.js';
5
+
6
+ const RadioGroupField = _ref => {
7
+ let {
8
+ className,
9
+ legend = '',
10
+ name,
11
+ onChange,
12
+ required,
13
+ validate,
14
+ value,
15
+ children,
16
+ error: customError,
17
+ helper,
18
+ direction
19
+ } = _ref;
20
+ const {
21
+ getError
22
+ } = useErrors();
23
+ const {
24
+ input,
25
+ meta
26
+ } = useFormField(name, {
27
+ required,
28
+ validate,
29
+ value
30
+ });
31
+ const error = getError({
32
+ label: legend,
33
+ meta: meta,
34
+ name,
35
+ value: input.value
36
+ });
37
+ return jsx(RadioGroup, {
38
+ className: className,
39
+ name: input.name,
40
+ onChange: event => {
41
+ input.onChange(event);
42
+ onChange?.(event);
43
+ },
44
+ required: required,
45
+ value: input.value,
46
+ legend: legend,
47
+ error: error ?? customError,
48
+ helper: helper,
49
+ direction: direction,
50
+ children: children
51
+ });
52
+ };
53
+ RadioGroupField.Radio = RadioGroup.Radio;
54
+
55
+ export { RadioGroupField };
@@ -14,7 +14,8 @@ const Submit = _ref => {
14
14
  variant = 'filled',
15
15
  sentiment = 'primary',
16
16
  tooltip,
17
- fullWidth
17
+ fullWidth,
18
+ onClick
18
19
  } = _ref;
19
20
  const {
20
21
  invalid,
@@ -44,6 +45,7 @@ const Submit = _ref => {
44
45
  sentiment: sentiment,
45
46
  tooltip: tooltip,
46
47
  fullWidth: fullWidth,
48
+ onClick: onClick,
47
49
  children: children
48
50
  });
49
51
  };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { Field, FormSpy, useField, useForm, useFormState } from 'react-final-for
6
6
  import * as react from 'react';
7
7
  import { ReactNode, ComponentProps, FocusEvent, JSX, ForwardedRef, FocusEventHandler } from 'react';
8
8
  import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
9
- import { DateInput, Radio, SelectInput, SelectableCard, NumberInput, TagInput, TextInput, TimeInput, Toggle, Button } from '@ultraviolet/ui';
9
+ import { DateInput, Radio, SelectInput, SelectableCard, NumberInput, TagInput, TextInput, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
10
10
  import { CSSObject, Theme, css } from '@emotion/react';
11
11
  import Select, { GroupBase, OptionProps, Props, CommonProps } from 'react-select';
12
12
 
@@ -78,6 +78,7 @@ declare const CheckboxField: react.ForwardRefExoticComponent<BaseFieldProps<stri
78
78
  error?: ReactNode;
79
79
  size?: number | undefined;
80
80
  progress?: boolean | undefined;
81
+ helper?: ReactNode;
81
82
  disabled?: boolean | undefined;
82
83
  checked?: boolean | "indeterminate" | undefined;
83
84
  className?: string | undefined;
@@ -92,7 +93,7 @@ declare const CheckboxField: react.ForwardRefExoticComponent<BaseFieldProps<stri
92
93
  children?: undefined;
93
94
  } & {
94
95
  'aria-label': string;
95
- }))) & react.RefAttributes<HTMLInputElement>, "value" | "disabled" | "progress" | "onFocus" | "onBlur" | "onChange" | "size" | "data-testid">> & {
96
+ }))) & react.RefAttributes<HTMLInputElement>, "value" | "disabled" | "progress" | "onFocus" | "onBlur" | "onChange" | "size" | "data-testid" | "helper">> & {
96
97
  name: string;
97
98
  label?: string | undefined;
98
99
  className?: string | undefined;
@@ -135,8 +136,8 @@ type FormProps<FormValues = unknown> = {
135
136
  };
136
137
  declare const Form: <FormValues>({ children, onRawSubmit, errors, initialValues, validateOnBlur, validate, name, render, mutators, keepDirtyOnReinitialize, className, }: FormProps<FormValues>) => JSX.Element;
137
138
 
138
- type RadioValue = NonNullable<ComponentProps<typeof Radio>['value']>;
139
- type RadioFieldProps<T = RadioValue, K = string> = BaseFieldProps<T, K> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'data-testid' | 'label'>> & {
139
+ type RadioValue$1 = NonNullable<ComponentProps<typeof Radio>['value']>;
140
+ type RadioFieldProps<T = RadioValue$1, K = string> = BaseFieldProps<T, K> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'data-testid' | 'label'>> & {
140
141
  className?: string;
141
142
  name: string;
142
143
  required?: boolean;
@@ -635,8 +636,37 @@ type SubmitProps = {
635
636
  sentiment?: ComponentProps<typeof Button>['sentiment'];
636
637
  tooltip?: ComponentProps<typeof Button>['tooltip'];
637
638
  fullWidth?: ComponentProps<typeof Button>['fullWidth'];
639
+ onClick?: ComponentProps<typeof Button>['onClick'];
640
+ };
641
+ declare const Submit: ({ children, className, disabled, icon, iconPosition, size, variant, sentiment, tooltip, fullWidth, onClick, }: SubmitProps) => JSX.Element;
642
+
643
+ type RadioValue = NonNullable<ComponentProps<typeof RadioGroup>['value']>;
644
+ type RadioGroupFieldProps<T = RadioValue, K = string> = BaseFieldProps<T, K> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'onChange' | 'value' | 'legend' | 'children' | 'required' | 'name' | 'error' | 'helper' | 'direction'>> & {
645
+ className?: string;
646
+ name: string;
647
+ required?: boolean;
648
+ };
649
+ declare const RadioGroupField: {
650
+ ({ className, legend, name, onChange, required, validate, value, children, error: customError, helper, direction, }: RadioGroupFieldProps): JSX.Element;
651
+ Radio: ({ onFocus, onBlur, disabled, error, name, value, label, helper, className, autoFocus, onKeyDown, "data-testid": dataTestId, }: {
652
+ error?: react.ReactNode;
653
+ name?: string | undefined;
654
+ value: string | number;
655
+ key?: react.Key | null | undefined;
656
+ disabled?: boolean | undefined;
657
+ label?: react.ReactNode;
658
+ className?: string | undefined;
659
+ ref?: react.Ref<HTMLInputElement> | undefined;
660
+ onFocus?: react.FocusEventHandler<HTMLInputElement> | undefined;
661
+ onBlur?: react.FocusEventHandler<HTMLInputElement> | undefined;
662
+ autoFocus?: boolean | undefined;
663
+ id?: string | undefined;
664
+ 'aria-label'?: string | undefined;
665
+ 'data-testid'?: string | undefined;
666
+ helper?: react.ReactNode;
667
+ onKeyDown?: react.KeyboardEventHandler<HTMLInputElement> | undefined;
668
+ }) => _emotion_react_jsx_runtime.JSX.Element;
638
669
  };
639
- declare const Submit: ({ children, className, disabled, icon, iconPosition, size, variant, sentiment, tooltip, fullWidth, }: SubmitProps) => JSX.Element;
640
670
 
641
671
  type UseValidationParams<FieldValue = unknown> = {
642
672
  validators: ValidatorObject<FieldValue>[];
@@ -665,4 +695,4 @@ type ErrorProviderProps = {
665
695
  declare const ErrorProvider: ({ children, errors, }: ErrorProviderProps) => JSX.Element;
666
696
  declare const useErrors: () => ErrorContextValue;
667
697
 
668
- export { BaseFieldProps, CheckboxField, DateField, ErrorProvider, Form, FormErrors, NumberInputField, RadioField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
698
+ export { BaseFieldProps, CheckboxField, DateField, ErrorProvider, Form, FormErrors, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export { TagInputField } from './components/TagInputField/index.js';
15
15
  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
+ export { RadioGroupField } from './components/RadioGroupField/index.js';
18
19
  export { useValidation } from './hooks/useValidation.js';
19
20
  export { useOnFieldChange } from './hooks/useOnFieldChange.js';
20
21
  export { pickValidators } from './helpers/pickValidators.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "1.3.5",
3
+ "version": "1.4.1",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "react-dom": "18.x"
39
39
  },
40
40
  "devDependencies": {
41
- "@babel/core": "7.22.10",
41
+ "@babel/core": "7.22.11",
42
42
  "@types/final-form-focus": "1.1.3",
43
43
  "@types/react": "18.2.8",
44
44
  "@types/react-dom": "18.2.4",
@@ -46,7 +46,7 @@
46
46
  "react-dom": "18.2.0"
47
47
  },
48
48
  "dependencies": {
49
- "@babel/runtime": "7.22.10",
49
+ "@babel/runtime": "7.22.11",
50
50
  "@emotion/babel-plugin": "11.11.0",
51
51
  "@emotion/react": "11.11.1",
52
52
  "@emotion/styled": "11.11.0",
@@ -55,6 +55,6 @@
55
55
  "react-final-form": "6.5.9",
56
56
  "react-final-form-arrays": "3.1.4",
57
57
  "react-select": "5.7.4",
58
- "@ultraviolet/ui": "1.8.4"
58
+ "@ultraviolet/ui": "1.10.0"
59
59
  }
60
60
  }