react-hook-form-cloudscape 1.3.0 → 1.3.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.
- package/README.md +3 -0
- package/components/components/multiselect/multiselect.d.ts +3 -5
- package/components/components/multiselect/utils.d.ts +3 -1
- package/components/multiselect/multiselect.d.ts +3 -5
- package/components/multiselect/multiselect.js +10 -12
- package/components/multiselect/multiselect.js.map +1 -1
- package/components/multiselect/utils.d.ts +3 -1
- package/components/multiselect/utils.js +3 -6
- package/components/multiselect/utils.js.map +1 -1
- package/package.json +1 -1
- package/react-hook-form-cloudscape.es.js +308 -315
- package/react-hook-form-cloudscape.es.js.map +1 -1
- package/react-hook-form-cloudscape.umd.js +8 -8
- package/react-hook-form-cloudscape.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,9 @@ function App {
|
|
|
50
50
|
|
|
51
51
|
You can [create bug reports or feature requests](https://github.com/abudayah/react-hook-form-cloudscape/issues/new/choose), or [start a discussion](https://github.com/abudayah/react-hook-form-cloudscape/discussions) to ask a question. To minimize duplicates, we recommend that you search for existing bug reports, feature requests, or discussions before initiating a new thread.
|
|
52
52
|
|
|
53
|
+
## Articles and guides
|
|
54
|
+
- [Cloudscape Form Validation Made Easy: A Step-by-Step Guide with React-hook-form-cloudscape](https://medium.com/@abudayah/cloudscape-form-validation-made-easy-a-step-by-step-guide-with-react-hook-form-cloudscape-f2238225f125)
|
|
55
|
+
|
|
53
56
|
## License
|
|
54
57
|
|
|
55
58
|
This project is licensed under the [MIT License](/LICENSE).
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Control, FieldValues, FieldPathValue, FieldPath, RegisterOptions } from 'react-hook-form';
|
|
3
3
|
import { MultiselectProps } from '@cloudscape-design/components';
|
|
4
|
-
export interface
|
|
4
|
+
export interface ControlledMultiselectProps<T extends FieldValues> extends Omit<MultiselectProps, 'selectedOptions'> {
|
|
5
5
|
name: FieldPath<T>;
|
|
6
6
|
control?: Control<T>;
|
|
7
|
-
options
|
|
7
|
+
options?: MultiselectProps.Options;
|
|
8
8
|
defaultValue?: FieldPathValue<T, FieldPath<T>>;
|
|
9
9
|
rules?: Omit<RegisterOptions<T, FieldPath<T>>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
10
10
|
shouldUnregister?: boolean;
|
|
11
|
-
onBlur?: MultiselectProps['onBlur'];
|
|
12
|
-
onChange?: MultiselectProps['onChange'];
|
|
13
11
|
}
|
|
14
|
-
declare const CMultiselect: <TFieldValues extends FieldValues>({ name, control, options, defaultValue, rules, onBlur, onChange, shouldUnregister, ...props }:
|
|
12
|
+
declare const CMultiselect: <TFieldValues extends FieldValues>({ name, control, options, defaultValue, rules, onBlur, onChange, shouldUnregister, ...props }: ControlledMultiselectProps<TFieldValues>) => React.JSX.Element;
|
|
15
13
|
export default CMultiselect;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { MultiselectProps } from '@cloudscape-design/components';
|
|
1
|
+
import { MultiselectProps } from '@cloudscape-design/components/multiselect/interfaces';
|
|
2
|
+
export declare const transformMultiselectOptionsToArray: (selectedOptions?: MultiselectProps.Options) => string[];
|
|
3
|
+
export declare const mapSelectedOptionsWithOptions: (options?: MultiselectProps.Options, selectedOptions?: string[]) => Array<MultiselectProps.Option | MultiselectProps.OptionGroup>;
|
|
2
4
|
declare const MultiSelectUtils: {
|
|
3
5
|
transformMultiselectOptionsToArray: (selectedOptions?: MultiselectProps.Options) => string[];
|
|
4
6
|
mapSelectedOptionsWithOptions: (options?: MultiselectProps.Options, selectedOptions?: string[]) => Array<MultiselectProps.Option | MultiselectProps.OptionGroup>;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Control, FieldValues, FieldPathValue, FieldPath, RegisterOptions } from 'react-hook-form';
|
|
3
3
|
import { MultiselectProps } from '@cloudscape-design/components';
|
|
4
|
-
export interface
|
|
4
|
+
export interface ControlledMultiselectProps<T extends FieldValues> extends Omit<MultiselectProps, 'selectedOptions'> {
|
|
5
5
|
name: FieldPath<T>;
|
|
6
6
|
control?: Control<T>;
|
|
7
|
-
options
|
|
7
|
+
options?: MultiselectProps.Options;
|
|
8
8
|
defaultValue?: FieldPathValue<T, FieldPath<T>>;
|
|
9
9
|
rules?: Omit<RegisterOptions<T, FieldPath<T>>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
10
10
|
shouldUnregister?: boolean;
|
|
11
|
-
onBlur?: MultiselectProps['onBlur'];
|
|
12
|
-
onChange?: MultiselectProps['onChange'];
|
|
13
11
|
}
|
|
14
|
-
declare const CMultiselect: <TFieldValues extends FieldValues>({ name, control, options, defaultValue, rules, onBlur, onChange, shouldUnregister, ...props }:
|
|
12
|
+
declare const CMultiselect: <TFieldValues extends FieldValues>({ name, control, options, defaultValue, rules, onBlur, onChange, shouldUnregister, ...props }: ControlledMultiselectProps<TFieldValues>) => React.JSX.Element;
|
|
15
13
|
export default CMultiselect;
|
|
@@ -2,22 +2,20 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
3
|
import { Controller } from 'react-hook-form';
|
|
4
4
|
import { Multiselect } from '@cloudscape-design/components';
|
|
5
|
-
import
|
|
5
|
+
import { transformMultiselectOptionsToArray, mapSelectedOptionsWithOptions } from './utils';
|
|
6
6
|
const CMultiselect = (_a) => {
|
|
7
7
|
var { name, control, options, defaultValue, rules, onBlur, onChange, shouldUnregister = false } = _a, props = __rest(_a, ["name", "control", "options", "defaultValue", "rules", "onBlur", "onChange", "shouldUnregister"]);
|
|
8
|
-
const handleOnBlur = useCallback((
|
|
9
|
-
|
|
8
|
+
const handleOnBlur = useCallback((formOnBlur, e) => {
|
|
9
|
+
formOnBlur();
|
|
10
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
10
11
|
}, [onBlur]);
|
|
11
|
-
const handleOnChange = useCallback((
|
|
12
|
-
|
|
12
|
+
const handleOnChange = useCallback((formOnChange, e) => {
|
|
13
|
+
formOnChange(transformMultiselectOptionsToArray(e.detail.selectedOptions));
|
|
14
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
13
15
|
}, [onChange]);
|
|
14
|
-
return (React.createElement(Controller, { name: name, control: control, defaultValue: defaultValue, rules: rules, shouldUnregister: shouldUnregister, render: ({ field: { ref,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, onChange: (e) => {
|
|
18
|
-
formOnChange(MultiSelectUtils.transformMultiselectOptionsToArray(e.detail.selectedOptions)); // Transform selectedOptions
|
|
19
|
-
handleOnChange(e);
|
|
20
|
-
}, selectedOptions: value }, props))) }));
|
|
16
|
+
return (React.createElement(Controller, { name: name, control: control, defaultValue: defaultValue, rules: rules, shouldUnregister: shouldUnregister, render: ({ field: { ref, onChange, onBlur, value } }) => {
|
|
17
|
+
return (React.createElement(Multiselect, Object.assign({ ref: ref, options: options, onBlur: () => handleOnBlur.bind(null, onBlur), onChange: handleOnChange.bind(null, onChange), selectedOptions: mapSelectedOptionsWithOptions(options, value) }, props)));
|
|
18
|
+
} }));
|
|
21
19
|
};
|
|
22
20
|
export default CMultiselect;
|
|
23
21
|
//# sourceMappingURL=multiselect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiselect.js","sourceRoot":"","sources":["../../src/components/multiselect/multiselect.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAW,UAAU,EAA2D,MAAM,iBAAiB,CAAC;AAC/G,OAAO,
|
|
1
|
+
{"version":3,"file":"multiselect.js","sourceRoot":"","sources":["../../src/components/multiselect/multiselect.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAW,UAAU,EAA2D,MAA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,CAAC,EAC7C,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,EAC7C,eAAe,EAAE,6BAA6B,CAAC,OAAO,EAAE,KAAK,CAAC,IAC1D,KAAK,EACT,CACH,CAAC;QACJ,CAAC,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { MultiselectProps } from '@cloudscape-design/components';
|
|
1
|
+
import { MultiselectProps } from '@cloudscape-design/components/multiselect/interfaces';
|
|
2
|
+
export declare const transformMultiselectOptionsToArray: (selectedOptions?: MultiselectProps.Options) => string[];
|
|
3
|
+
export declare const mapSelectedOptionsWithOptions: (options?: MultiselectProps.Options, selectedOptions?: string[]) => Array<MultiselectProps.Option | MultiselectProps.OptionGroup>;
|
|
2
4
|
declare const MultiSelectUtils: {
|
|
3
5
|
transformMultiselectOptionsToArray: (selectedOptions?: MultiselectProps.Options) => string[];
|
|
4
6
|
mapSelectedOptionsWithOptions: (options?: MultiselectProps.Options, selectedOptions?: string[]) => Array<MultiselectProps.Option | MultiselectProps.OptionGroup>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const transformMultiselectOptionsToArray = (selectedOptions = []) => {
|
|
1
|
+
export const transformMultiselectOptionsToArray = (selectedOptions = []) => {
|
|
2
2
|
if (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.length) {
|
|
3
3
|
return selectedOptions
|
|
4
4
|
.map((option) => {
|
|
@@ -11,7 +11,7 @@ const transformMultiselectOptionsToArray = (selectedOptions = []) => {
|
|
|
11
11
|
}
|
|
12
12
|
return [];
|
|
13
13
|
};
|
|
14
|
-
const mapSelectedOptionsWithOptions = (options = [], selectedOptions = []) => {
|
|
14
|
+
export const mapSelectedOptionsWithOptions = (options = [], selectedOptions = []) => {
|
|
15
15
|
if ((options === null || options === void 0 ? void 0 : options.length) && (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.length)) {
|
|
16
16
|
return options
|
|
17
17
|
.reduce((accOptions, currentOption) => {
|
|
@@ -34,9 +34,6 @@ const mapSelectedOptionsWithOptions = (options = [], selectedOptions = []) => {
|
|
|
34
34
|
}
|
|
35
35
|
return [];
|
|
36
36
|
};
|
|
37
|
-
const MultiSelectUtils = {
|
|
38
|
-
transformMultiselectOptionsToArray,
|
|
39
|
-
mapSelectedOptionsWithOptions,
|
|
40
|
-
};
|
|
37
|
+
const MultiSelectUtils = { transformMultiselectOptionsToArray, mapSelectedOptionsWithOptions };
|
|
41
38
|
export default MultiSelectUtils;
|
|
42
39
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/components/multiselect/utils.ts"],"names":[],"mappings":"AAEA,MAAM,kCAAkC,GAAG,CAAC,kBAA4C,EAAE,EAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/components/multiselect/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,kBAA4C,EAAE,EAAY,EAAE;IAC7G,IAAI,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,EAAE,CAAC;QAC5B,OAAO,eAAe;aACnB,GAAG,CAAC,CAAC,MAA8D,EAAE,EAAE;YACtE,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;gBACxB,OAAO,kCAAkC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5D,CAAC;YAED,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC;aACD,IAAI,EAAc,CAAC;IACxB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,UAAoC,EAAE,EACtC,kBAA4B,EAAE,EACiC,EAAE;IACjE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAA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