@ultraviolet/form 1.4.2 → 1.5.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.
- package/dist/components/CheckboxGroupField/index.js +58 -0
- package/dist/index.d.ts +30 -2
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CheckboxGroup } from '@ultraviolet/ui';
|
|
2
|
+
import { useFieldArray } from 'react-final-form-arrays';
|
|
3
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
4
|
+
import { useErrors } from '../../providers/ErrorContext/index.js';
|
|
5
|
+
|
|
6
|
+
const CheckboxGroupField = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
legend,
|
|
9
|
+
value,
|
|
10
|
+
className,
|
|
11
|
+
helper,
|
|
12
|
+
direction,
|
|
13
|
+
children,
|
|
14
|
+
onChange,
|
|
15
|
+
error: customError,
|
|
16
|
+
name,
|
|
17
|
+
required = false
|
|
18
|
+
} = _ref;
|
|
19
|
+
const {
|
|
20
|
+
getError
|
|
21
|
+
} = useErrors();
|
|
22
|
+
const {
|
|
23
|
+
fields,
|
|
24
|
+
meta
|
|
25
|
+
} = useFieldArray(name, {
|
|
26
|
+
type: 'checkbox',
|
|
27
|
+
value,
|
|
28
|
+
validate: localValue => required && localValue?.length === 0 ? 'Required' : undefined
|
|
29
|
+
});
|
|
30
|
+
const error = getError({
|
|
31
|
+
label: legend,
|
|
32
|
+
meta,
|
|
33
|
+
value: fields.value,
|
|
34
|
+
name
|
|
35
|
+
});
|
|
36
|
+
return jsx(CheckboxGroup, {
|
|
37
|
+
legend: legend,
|
|
38
|
+
name: fields.name,
|
|
39
|
+
value: fields.value,
|
|
40
|
+
onChange: event => {
|
|
41
|
+
if (fields.value?.includes(event.currentTarget.value)) {
|
|
42
|
+
fields.remove(fields.value.indexOf(event.currentTarget?.value));
|
|
43
|
+
} else {
|
|
44
|
+
fields.push(event.currentTarget.value);
|
|
45
|
+
}
|
|
46
|
+
onChange?.(event);
|
|
47
|
+
},
|
|
48
|
+
error: error ?? customError,
|
|
49
|
+
className: className,
|
|
50
|
+
direction: direction,
|
|
51
|
+
helper: helper,
|
|
52
|
+
required: required,
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
CheckboxGroupField.Checkbox = CheckboxGroup.Checkbox;
|
|
57
|
+
|
|
58
|
+
export { CheckboxGroupField };
|
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, RadioGroup } from '@ultraviolet/ui';
|
|
9
|
+
import { CheckboxGroup, 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
|
|
|
@@ -101,6 +101,34 @@ declare const CheckboxField: react.ForwardRefExoticComponent<BaseFieldProps<stri
|
|
|
101
101
|
required?: boolean | undefined;
|
|
102
102
|
} & react.RefAttributes<HTMLInputElement>>;
|
|
103
103
|
|
|
104
|
+
type CheckboxGroupValue = string[];
|
|
105
|
+
type CheckboxGroupFieldProps<T = CheckboxGroupValue, K = string> = BaseFieldProps<T, K> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'onChange' | 'required' | 'direction' | 'children' | 'value' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend' | 'name'>>;
|
|
106
|
+
declare const CheckboxGroupField: {
|
|
107
|
+
({ legend, value, className, helper, direction, children, onChange, error: customError, name, required, }: CheckboxGroupFieldProps): _emotion_react_jsx_runtime.JSX.Element;
|
|
108
|
+
Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, }: Omit<({
|
|
109
|
+
error?: react.ReactNode;
|
|
110
|
+
size?: number | undefined;
|
|
111
|
+
progress?: boolean | undefined;
|
|
112
|
+
helper?: react.ReactNode;
|
|
113
|
+
disabled?: boolean | undefined;
|
|
114
|
+
checked?: boolean | "indeterminate" | undefined;
|
|
115
|
+
className?: string | undefined;
|
|
116
|
+
"data-visibility"?: string | undefined;
|
|
117
|
+
required?: boolean | undefined;
|
|
118
|
+
'data-testid'?: string | undefined;
|
|
119
|
+
} & Pick<react.InputHTMLAttributes<HTMLInputElement>, "name" | "value" | "onFocus" | "onBlur" | "autoFocus" | "id" | "onChange"> & (({
|
|
120
|
+
"aria-label"?: undefined;
|
|
121
|
+
} & {
|
|
122
|
+
children: react.ReactNode;
|
|
123
|
+
}) | ({
|
|
124
|
+
children?: undefined;
|
|
125
|
+
} & {
|
|
126
|
+
'aria-label': string;
|
|
127
|
+
}))) & react.RefAttributes<HTMLInputElement>, "required" | "onChange" | "checked"> & {
|
|
128
|
+
value: string;
|
|
129
|
+
}) => _emotion_react_jsx_runtime.JSX.Element;
|
|
130
|
+
};
|
|
131
|
+
|
|
104
132
|
type DateFieldProps = BaseFieldProps<Date> & Omit<ComponentProps<typeof DateInput>, 'maxDate' | 'minDate' | 'disabled' | 'required' | 'locale' | 'name' | 'onChange' | 'onFocus' | 'onBlur' | 'autoFocus'> & {
|
|
105
133
|
name: string;
|
|
106
134
|
maxDate?: Date;
|
|
@@ -700,4 +728,4 @@ type ErrorProviderProps = {
|
|
|
700
728
|
declare const ErrorProvider: ({ children, errors, }: ErrorProviderProps) => JSX.Element;
|
|
701
729
|
declare const useErrors: () => ErrorContextValue;
|
|
702
730
|
|
|
703
|
-
export { BaseFieldProps, CheckboxField, DateField, ErrorProvider, Form, FormErrors, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
|
|
731
|
+
export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, Form, type FormErrors, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { FORM_ERROR } from 'final-form';
|
|
|
3
3
|
export { Field, FormSpy, useField, useForm, useFormState } from 'react-final-form';
|
|
4
4
|
export { ErrorProvider, useErrors } from './providers/ErrorContext/index.js';
|
|
5
5
|
export { CheckboxField } from './components/CheckboxField/index.js';
|
|
6
|
+
export { CheckboxGroupField } from './components/CheckboxGroupField/index.js';
|
|
6
7
|
export { DateField } from './components/DateField/index.js';
|
|
7
8
|
export { Form } from './components/Form/index.js';
|
|
8
9
|
export { RadioField } from './components/RadioField/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -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.
|
|
58
|
+
"@ultraviolet/ui": "1.11.0"
|
|
59
59
|
}
|
|
60
60
|
}
|