@dhis2/ui-forms 8.2.0 → 8.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/CheckboxFieldFF/CheckboxFieldFF.js +24 -21
- package/build/cjs/CheckboxFieldFF/CheckboxFieldFF.stories.js +3 -27
- package/build/cjs/FieldGroupFF/FieldGroupFF.js +7 -6
- package/build/cjs/FieldGroupFF/FieldGroupFF.stories.js +3 -13
- package/build/cjs/FileInputFieldFF/FileInputFieldFF.js +17 -18
- package/build/cjs/FileInputFieldFF/FileInputFieldFF.stories.e2e.js +12 -8
- package/build/cjs/FileInputFieldFF/FileInputFieldFF.stories.js +3 -27
- package/build/cjs/InputFieldFF/InputFieldFF.js +27 -24
- package/build/cjs/InputFieldFF/InputFieldFF.stories.js +3 -27
- package/build/cjs/MultiSelectFieldFF/MultiSelectFieldFF.js +15 -14
- package/build/cjs/MultiSelectFieldFF/MultiSelectFieldFF.stories.e2e.js +13 -10
- package/build/cjs/MultiSelectFieldFF/MultiSelectFieldFF.stories.js +3 -29
- package/build/cjs/RadioFieldFF/RadioFieldFF.js +24 -21
- package/build/cjs/RadioFieldFF/RadioFieldFF.stories.js +3 -27
- package/build/cjs/SingleSelectFieldFF/SingleSelectFieldFF.js +15 -14
- package/build/cjs/SingleSelectFieldFF/SingleSelectFieldFF.stories.e2e.js +13 -10
- package/build/cjs/SingleSelectFieldFF/SingleSelectFieldFF.stories.js +3 -29
- package/build/cjs/SwitchFieldFF/SwitchFieldFF.js +24 -21
- package/build/cjs/SwitchFieldFF/SwitchFieldFF.stories.js +3 -27
- package/build/cjs/TextAreaFieldFF/TextAreaFieldFF.js +26 -23
- package/build/cjs/TextAreaFieldFF/TextAreaFieldFF.stories.js +3 -27
- package/build/cjs/formDecorator.js +6 -5
- package/build/cjs/index.js +12 -11
- package/build/cjs/locales/en/translations.json +0 -1
- package/build/cjs/shared/helpers/createChangeHandler.js +19 -16
- package/build/cjs/shared/helpers/createSelectChangeHandler.js +10 -6
- package/build/cjs/shared/propTypes.js +1 -1
- package/build/cjs/transformers/arrayWithIdObjects.js +6 -3
- package/build/cjs/validators/__tests__/createPattern.test.js +1 -1
- package/build/cjs/validators/composeValidators.js +10 -2
- package/build/cjs/validators/helpers/index.js +1 -1
- package/build/cjs/validators/number.js +1 -1
- package/build/cjs/validators/string.js +1 -1
- package/build/cjs/validators/test-helpers/index.js +2 -2
- package/build/cjs/validators/url.js +1 -1
- package/build/es/CheckboxFieldFF/CheckboxFieldFF.js +24 -21
- package/build/es/CheckboxFieldFF/CheckboxFieldFF.stories.js +2 -26
- package/build/es/FieldGroupFF/FieldGroupFF.js +7 -6
- package/build/es/FieldGroupFF/FieldGroupFF.stories.js +2 -12
- package/build/es/FileInputFieldFF/FileInputFieldFF.js +17 -18
- package/build/es/FileInputFieldFF/FileInputFieldFF.stories.e2e.js +12 -8
- package/build/es/FileInputFieldFF/FileInputFieldFF.stories.js +2 -26
- package/build/es/InputFieldFF/InputFieldFF.js +27 -24
- package/build/es/InputFieldFF/InputFieldFF.stories.js +2 -26
- package/build/es/MultiSelectFieldFF/MultiSelectFieldFF.js +15 -14
- package/build/es/MultiSelectFieldFF/MultiSelectFieldFF.stories.e2e.js +13 -10
- package/build/es/MultiSelectFieldFF/MultiSelectFieldFF.stories.js +2 -28
- package/build/es/RadioFieldFF/RadioFieldFF.js +24 -21
- package/build/es/RadioFieldFF/RadioFieldFF.stories.js +2 -26
- package/build/es/SingleSelectFieldFF/SingleSelectFieldFF.js +15 -14
- package/build/es/SingleSelectFieldFF/SingleSelectFieldFF.stories.e2e.js +13 -10
- package/build/es/SingleSelectFieldFF/SingleSelectFieldFF.stories.js +2 -28
- package/build/es/SwitchFieldFF/SwitchFieldFF.js +24 -21
- package/build/es/SwitchFieldFF/SwitchFieldFF.stories.js +2 -26
- package/build/es/TextAreaFieldFF/TextAreaFieldFF.js +26 -23
- package/build/es/TextAreaFieldFF/TextAreaFieldFF.stories.js +2 -26
- package/build/es/formDecorator.js +6 -5
- package/build/es/locales/en/translations.json +0 -1
- package/build/es/shared/helpers/createChangeHandler.js +19 -16
- package/build/es/shared/helpers/createSelectChangeHandler.js +10 -6
- package/build/es/transformers/arrayWithIdObjects.js +6 -3
- package/build/es/validators/__tests__/createPattern.test.js +1 -1
- package/build/es/validators/composeValidators.js +10 -2
- package/build/es/validators/test-helpers/index.js +1 -1
- package/package.json +10 -10
@@ -5,27 +5,30 @@ import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
6
6
|
import { createToggleChangeHandler, createFocusHandler, createBlurHandler, hasError, isValid, getValidationText } from '../shared/helpers.js';
|
7
7
|
import { metaPropType, inputPropType } from '../shared/propTypes.js';
|
8
|
-
export const CheckboxFieldFF =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
export const CheckboxFieldFF = _ref => {
|
9
|
+
let {
|
10
|
+
error,
|
11
|
+
input,
|
12
|
+
meta,
|
13
|
+
showValidStatus,
|
14
|
+
valid,
|
15
|
+
validationText,
|
16
|
+
onBlur,
|
17
|
+
onFocus,
|
18
|
+
...rest
|
19
|
+
} = _ref;
|
20
|
+
return /*#__PURE__*/React.createElement(CheckboxField, _extends({}, rest, {
|
21
|
+
name: input.name,
|
22
|
+
checked: input.checked,
|
23
|
+
value: input.value,
|
24
|
+
error: hasError(meta, error),
|
25
|
+
valid: isValid(meta, valid, showValidStatus),
|
26
|
+
validationText: getValidationText(meta, validationText, error),
|
27
|
+
onFocus: createFocusHandler(input, onFocus),
|
28
|
+
onChange: createToggleChangeHandler(input),
|
29
|
+
onBlur: createBlurHandler(input, onBlur)
|
30
|
+
}));
|
31
|
+
};
|
29
32
|
CheckboxFieldFF.propTypes = {
|
30
33
|
/** Provided by Final Form `Field` */
|
31
34
|
input: inputPropType.isRequired,
|
@@ -4,33 +4,9 @@ import { formDecorator } from '../formDecorator.js';
|
|
4
4
|
import { inputArgType, metaArgType } from '../shared/propTypes.js';
|
5
5
|
import { hasValue } from '../validators/index.js';
|
6
6
|
import { CheckboxFieldFF } from './CheckboxFieldFF.js';
|
7
|
-
const description = `
|
8
|
-
The \`CheckboxFieldFF\` is a wrapper around a \`CheckboxField\` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.
|
9
|
-
|
10
|
-
#### Final Form
|
11
|
-
|
12
|
-
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
|
13
|
-
|
14
|
-
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={CheckboxFieldFF} />\`. See the code samples below for examples.
|
15
|
-
|
16
|
-
#### Props
|
17
|
-
|
18
|
-
The props shown in the table below are generally provided to the \`CheckboxFieldFF\` wrapper by the Final Form \`Field\`.
|
19
|
-
|
20
|
-
Note that any props beyond the API of the \`Field\` component will be spread to the \`CheckboxFieldFF\`, which passes any extra props to the underlying \`CheckboxField\` using \`{...rest}\`.
|
21
|
-
|
22
|
-
Therefore, to add any props to the \`CheckboxFieldFF\` or \`CheckboxField\`, add those props to the parent Final Form \`Field\` component.
|
23
|
-
|
24
|
-
Also see \`Checkbox\` and \`CheckboxField\` for notes about props and implementation.
|
25
|
-
|
26
|
-
\`\`\`js
|
27
|
-
import { CheckboxFieldFF } from '@dhis2/ui'
|
28
|
-
\`\`\`
|
29
|
-
|
30
|
-
Press **Submit** to see the form values logged to the console.
|
31
|
-
`;
|
7
|
+
const description = "\nThe `CheckboxFieldFF` is a wrapper around a `CheckboxField` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.\n\n#### Final Form\n\nSee how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).\n\nInside a Final Form `<Form>` component, these 'FF' UI components are intended to be used in the `component` prop of the [Final Form `<Field>` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. `<Field component={CheckboxFieldFF} />`. See the code samples below for examples.\n\n#### Props\n\nThe props shown in the table below are generally provided to the `CheckboxFieldFF` wrapper by the Final Form `Field`.\n\nNote that any props beyond the API of the `Field` component will be spread to the `CheckboxFieldFF`, which passes any extra props to the underlying `CheckboxField` using `{...rest}`.\n\nTherefore, to add any props to the `CheckboxFieldFF` or `CheckboxField`, add those props to the parent Final Form `Field` component.\n\nAlso see `Checkbox` and `CheckboxField` for notes about props and implementation.\n\n```js\nimport { CheckboxFieldFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n";
|
32
8
|
export default {
|
33
|
-
title: '
|
9
|
+
title: 'Checkbox Field (Final Form)',
|
34
10
|
component: CheckboxFieldFF,
|
35
11
|
decorators: [formDecorator],
|
36
12
|
parameters: {
|
@@ -2,12 +2,13 @@ import { FieldGroup } from '@dhis2-ui/field';
|
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import React from 'react';
|
4
4
|
import { useField } from 'react-final-form';
|
5
|
-
export const FieldGroupFF =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
export const FieldGroupFF = _ref => {
|
6
|
+
let {
|
7
|
+
name,
|
8
|
+
label,
|
9
|
+
children,
|
10
|
+
required
|
11
|
+
} = _ref;
|
11
12
|
const {
|
12
13
|
meta: {
|
13
14
|
error,
|
@@ -4,19 +4,9 @@ import { CheckboxFieldFF } from '../CheckboxFieldFF/CheckboxFieldFF.js';
|
|
4
4
|
import { formDecorator } from '../formDecorator.js';
|
5
5
|
import { hasValue } from '../validators/index.js';
|
6
6
|
import { FieldGroupFF } from './FieldGroupFF.js';
|
7
|
-
const description = `
|
8
|
-
This component is intended for use with [Final Form](https://final-form.org/docs/react-final-form/getting-started), the preferred library for form validation and utilities in DHIS 2 apps.
|
9
|
-
|
10
|
-
\`FieldGroupFF\` groups related fields (using the Final Form \`<Field>\`), like checkboxes, and adds a label and name.
|
11
|
-
|
12
|
-
\`\`\`js
|
13
|
-
import { FieldGroupFF } from '@dhis2/ui'
|
14
|
-
\`\`\`
|
15
|
-
|
16
|
-
Press **Submit** to see the form values logged to the console.
|
17
|
-
`;
|
7
|
+
const description = "\nThis component is intended for use with [Final Form](https://final-form.org/docs/react-final-form/getting-started), the preferred library for form validation and utilities in DHIS 2 apps.\n\n`FieldGroupFF` groups related fields (using the Final Form `<Field>`), like checkboxes, and adds a label and name.\n\n```js\nimport { FieldGroupFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n";
|
18
8
|
export default {
|
19
|
-
title: '
|
9
|
+
title: 'Field Group (Final Form)',
|
20
10
|
component: FieldGroupFF,
|
21
11
|
decorators: [formDecorator],
|
22
12
|
parameters: {
|
@@ -23,9 +23,10 @@ const dedupeAndConcat = (currentFiles, newFileList) => {
|
|
23
23
|
}).files;
|
24
24
|
};
|
25
25
|
|
26
|
-
const createChangeHandler = (input, multifile) =>
|
27
|
-
|
28
|
-
|
26
|
+
const createChangeHandler = (input, multifile) => _ref => {
|
27
|
+
let {
|
28
|
+
files
|
29
|
+
} = _ref;
|
29
30
|
// A JavaScript FileList instance is read-only, so we cannot add files to it
|
30
31
|
// FileList also doesn't have a .map method so by destructuring the FileList
|
31
32
|
// instance into an array we can add, remove and map
|
@@ -40,18 +41,19 @@ const createRemoveHandler = (input, fileToDelete) => () => {
|
|
40
41
|
input.onChange(value);
|
41
42
|
};
|
42
43
|
|
43
|
-
export const FileInputFieldFF =
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
export const FileInputFieldFF = _ref2 => {
|
45
|
+
let {
|
46
|
+
buttonLabel,
|
47
|
+
disabled,
|
48
|
+
error,
|
49
|
+
input,
|
50
|
+
meta,
|
51
|
+
multifile,
|
52
|
+
showValidStatus,
|
53
|
+
valid,
|
54
|
+
validationText,
|
55
|
+
...rest
|
56
|
+
} = _ref2;
|
55
57
|
const files = input.value || [];
|
56
58
|
return /*#__PURE__*/React.createElement(FileInputField, _extends({}, rest, {
|
57
59
|
onChange: createChangeHandler(input, multifile),
|
@@ -69,9 +71,6 @@ export const FileInputFieldFF = ({
|
|
69
71
|
removeText: i18n.t('Remove')
|
70
72
|
})));
|
71
73
|
};
|
72
|
-
FileInputFieldFF.defaultProps = {
|
73
|
-
placeholder: i18n.t('No file(s) selected yet')
|
74
|
-
};
|
75
74
|
FileInputFieldFF.propTypes = {
|
76
75
|
/** `input` props provided by Final Form `Field` */
|
77
76
|
input: inputPropType.isRequired,
|
@@ -13,9 +13,10 @@ import { TextAreaFieldFF } from '../TextAreaFieldFF/TextAreaFieldFF.js';
|
|
13
13
|
import { composeValidators, email, hasValue } from '../validators/index.js';
|
14
14
|
import { FileInputFieldFF } from './FileInputFieldFF.js';
|
15
15
|
|
16
|
-
const StandardForm =
|
17
|
-
|
18
|
-
|
16
|
+
const StandardForm = _ref => {
|
17
|
+
let {
|
18
|
+
values
|
19
|
+
} = _ref;
|
19
20
|
return /*#__PURE__*/React.createElement("div", {
|
20
21
|
style: {
|
21
22
|
maxWidth: 830
|
@@ -197,7 +198,7 @@ const StandardForm = ({
|
|
197
198
|
const [file] = files;
|
198
199
|
|
199
200
|
if (file.type !== 'text/plain') {
|
200
|
-
return
|
201
|
+
return "The file you provided is not a txt file, received \"".concat(file.type, "\"");
|
201
202
|
}
|
202
203
|
},
|
203
204
|
component: FileInputFieldFF
|
@@ -217,7 +218,7 @@ const StandardForm = ({
|
|
217
218
|
}
|
218
219
|
|
219
220
|
if (file.type !== 'application/jpg') {
|
220
|
-
return
|
221
|
+
return "One of the files is not a jpg, received \"".concat(file.type, "\"");
|
221
222
|
}
|
222
223
|
}, undefined);
|
223
224
|
},
|
@@ -237,6 +238,9 @@ storiesOf('Testing:FileInput', module).addDecorator(formDecorator).addParameters
|
|
237
238
|
options: {
|
238
239
|
showPanel: false
|
239
240
|
}
|
240
|
-
}).add('Standard form', (_, {
|
241
|
-
|
242
|
-
|
241
|
+
}).add('Standard form', (_, _ref2) => {
|
242
|
+
let {
|
243
|
+
formRenderProps
|
244
|
+
} = _ref2;
|
245
|
+
return /*#__PURE__*/React.createElement(StandardForm, formRenderProps);
|
246
|
+
});
|
@@ -4,34 +4,10 @@ import { formDecorator } from '../formDecorator.js';
|
|
4
4
|
import { inputArgType, metaArgType } from '../shared/propTypes.js';
|
5
5
|
import { hasValue } from '../validators/index.js';
|
6
6
|
import { FileInputFieldFF } from './FileInputFieldFF.js';
|
7
|
-
const description = `
|
8
|
-
The \`FileInputFieldFF\` is a wrapper around a \`FileInputField\` that enables it to work with Final Form, the preferred library in DHIS 2 apps for form validation and utilities.
|
9
|
-
|
10
|
-
#### Final Form
|
11
|
-
|
12
|
-
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
|
13
|
-
|
14
|
-
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={FileInputFieldFF} />\`. See the code samples below for examples.
|
15
|
-
|
16
|
-
#### Props
|
17
|
-
|
18
|
-
The props shown in the table below are generally provided to the \`FileInputFieldFF\` wrapper by the Final Form \`Field\`.
|
19
|
-
|
20
|
-
Note that any props beyond the API of the \`Field\` component will be spread to the \`FileInputFieldFF\`, which passes any extra props to the underlying \`FileInputField\` using \`{...rest}\`.
|
21
|
-
|
22
|
-
Therefore, to add any props to the \`FileInputFieldFF\` or \`FileInputField\`, add those props to the parent Final Form \`Field\` component.
|
23
|
-
|
24
|
-
Also see \`FileInput\` and \`FileInputField\` for notes about props and implementation.
|
25
|
-
|
26
|
-
\`\`\`js
|
27
|
-
import { FileInputFieldFF } from '@dhis2/ui'
|
28
|
-
\`\`\`
|
29
|
-
|
30
|
-
Press **Submit** to see the form values logged to the console.
|
31
|
-
`;
|
7
|
+
const description = "\nThe `FileInputFieldFF` is a wrapper around a `FileInputField` that enables it to work with Final Form, the preferred library in DHIS 2 apps for form validation and utilities.\n\n#### Final Form\n\nSee how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).\n\nInside a Final Form `<Form>` component, these 'FF' UI components are intended to be used in the `component` prop of the [Final Form `<Field>` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. `<Field component={FileInputFieldFF} />`. See the code samples below for examples.\n\n#### Props\n\nThe props shown in the table below are generally provided to the `FileInputFieldFF` wrapper by the Final Form `Field`.\n\nNote that any props beyond the API of the `Field` component will be spread to the `FileInputFieldFF`, which passes any extra props to the underlying `FileInputField` using `{...rest}`.\n\nTherefore, to add any props to the `FileInputFieldFF` or `FileInputField`, add those props to the parent Final Form `Field` component.\n\nAlso see `FileInput` and `FileInputField` for notes about props and implementation.\n\n```js\nimport { FileInputFieldFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n";
|
32
8
|
const files = [new File([], 'file1.txt'), new File([], 'file2.txt')];
|
33
9
|
export default {
|
34
|
-
title: '
|
10
|
+
title: 'File Input Field (Final Form)',
|
35
11
|
component: FileInputFieldFF,
|
36
12
|
decorators: [formDecorator],
|
37
13
|
parameters: {
|
@@ -5,30 +5,33 @@ import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
6
6
|
import { createChangeHandler, createFocusHandler, createBlurHandler, hasError, isLoading, isValid, getValidationText } from '../shared/helpers.js';
|
7
7
|
import { metaPropType, inputPropType } from '../shared/propTypes.js';
|
8
|
-
export const InputFieldFF =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
8
|
+
export const InputFieldFF = _ref => {
|
9
|
+
let {
|
10
|
+
input,
|
11
|
+
meta,
|
12
|
+
error,
|
13
|
+
showValidStatus,
|
14
|
+
valid,
|
15
|
+
validationText,
|
16
|
+
onBlur,
|
17
|
+
onFocus,
|
18
|
+
loading,
|
19
|
+
showLoadingStatus,
|
20
|
+
...rest
|
21
|
+
} = _ref;
|
22
|
+
return /*#__PURE__*/React.createElement(InputField, _extends({}, rest, {
|
23
|
+
name: input.name,
|
24
|
+
type: input.type,
|
25
|
+
error: hasError(meta, error),
|
26
|
+
valid: isValid(meta, valid, showValidStatus),
|
27
|
+
loading: isLoading(meta, loading, showLoadingStatus),
|
28
|
+
validationText: getValidationText(meta, validationText, error),
|
29
|
+
onFocus: createFocusHandler(input, onFocus),
|
30
|
+
onChange: createChangeHandler(input),
|
31
|
+
onBlur: createBlurHandler(input, onBlur),
|
32
|
+
value: input.value
|
33
|
+
}));
|
34
|
+
};
|
32
35
|
InputFieldFF.propTypes = {
|
33
36
|
/** `input` props received from Final Form `Field` */
|
34
37
|
input: inputPropType.isRequired,
|
@@ -4,33 +4,9 @@ import { formDecorator } from '../formDecorator.js';
|
|
4
4
|
import { inputArgType, metaArgType } from '../shared/propTypes.js';
|
5
5
|
import { hasValue } from '../validators/index.js';
|
6
6
|
import { InputFieldFF } from './InputFieldFF.js';
|
7
|
-
const description = `
|
8
|
-
The \`InputFieldFF\` is a wrapper around a \`InputField\` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.
|
9
|
-
|
10
|
-
#### Final Form
|
11
|
-
|
12
|
-
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
|
13
|
-
|
14
|
-
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={InputFieldFF} />\`. See the code samples below for examples.
|
15
|
-
|
16
|
-
#### Props
|
17
|
-
|
18
|
-
The props shown in the table below are generally provided to the \`InputFieldFF\` wrapper by the Final Form \`Field\`.
|
19
|
-
|
20
|
-
Note that any props beyond the API of the \`Field\` component will be spread to the \`InputFieldFF\`, which passes any extra props to the underlying \`InputField\` using \`{...rest}\`.
|
21
|
-
|
22
|
-
Therefore, to add any props to the \`InputFieldFF\` or \`InputField\`, add those props to the parent Final Form \`Field\` component.
|
23
|
-
|
24
|
-
Also see \`InputField\` for notes about props and implementation.
|
25
|
-
|
26
|
-
\`\`\`js
|
27
|
-
import { InputFieldFF } from '@dhis2/ui'
|
28
|
-
\`\`\`
|
29
|
-
|
30
|
-
Press **Submit** to see the form values logged to the console.
|
31
|
-
`;
|
7
|
+
const description = "\nThe `InputFieldFF` is a wrapper around a `InputField` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.\n\n#### Final Form\n\nSee how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).\n\nInside a Final Form `<Form>` component, these 'FF' UI components are intended to be used in the `component` prop of the [Final Form `<Field>` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. `<Field component={InputFieldFF} />`. See the code samples below for examples.\n\n#### Props\n\nThe props shown in the table below are generally provided to the `InputFieldFF` wrapper by the Final Form `Field`.\n\nNote that any props beyond the API of the `Field` component will be spread to the `InputFieldFF`, which passes any extra props to the underlying `InputField` using `{...rest}`.\n\nTherefore, to add any props to the `InputFieldFF` or `InputField`, add those props to the parent Final Form `Field` component.\n\nAlso see `InputField` for notes about props and implementation.\n\n```js\nimport { InputFieldFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n";
|
32
8
|
export default {
|
33
|
-
title: '
|
9
|
+
title: 'Input Field (Final Form)',
|
34
10
|
component: InputFieldFF,
|
35
11
|
decorators: [formDecorator],
|
36
12
|
parameters: {
|
@@ -5,20 +5,21 @@ import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
6
6
|
import { createSelectChangeHandler, createFocusHandler, createBlurHandler, hasError, isLoading, isValid, getValidationText } from '../shared/helpers.js';
|
7
7
|
import { inputPropType, metaPropType } from '../shared/propTypes.js';
|
8
|
-
export const MultiSelectFieldFF =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
export const MultiSelectFieldFF = _ref => {
|
9
|
+
let {
|
10
|
+
error,
|
11
|
+
input,
|
12
|
+
loading,
|
13
|
+
meta,
|
14
|
+
onBlur,
|
15
|
+
onFocus,
|
16
|
+
options = [],
|
17
|
+
showLoadingStatus,
|
18
|
+
showValidStatus,
|
19
|
+
valid,
|
20
|
+
validationText,
|
21
|
+
...rest
|
22
|
+
} = _ref;
|
22
23
|
return /*#__PURE__*/React.createElement(MultiSelectField, _extends({}, rest, {
|
23
24
|
name: input.name,
|
24
25
|
error: hasError(meta, error),
|
@@ -15,13 +15,16 @@ storiesOf('Testing:MultiSelectFieldFF', module).addDecorator(formDecorator).addP
|
|
15
15
|
options: {
|
16
16
|
showPanel: false
|
17
17
|
}
|
18
|
-
}).add('Required', (_, {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
}).add('Required', (_, _ref) => {
|
19
|
+
let {
|
20
|
+
cypressProps
|
21
|
+
} = _ref;
|
22
|
+
return /*#__PURE__*/React.createElement(Field, {
|
23
|
+
required: true,
|
24
|
+
name: "multiSelect",
|
25
|
+
label: "Multi select",
|
26
|
+
component: MultiSelectFieldFF,
|
27
|
+
validate: hasValue,
|
28
|
+
options: cypressProps.options || defaultOptions
|
29
|
+
});
|
30
|
+
});
|
@@ -3,33 +3,7 @@ import { Field } from 'react-final-form';
|
|
3
3
|
import { formDecorator } from '../formDecorator.js';
|
4
4
|
import { inputArgType, metaArgType } from '../shared/propTypes.js';
|
5
5
|
import { MultiSelectFieldFF } from './MultiSelectFieldFF.js';
|
6
|
-
const description = `
|
7
|
-
The \`MultiSelectFieldFF\` is a wrapper around a \`MultiSelectField\` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.
|
8
|
-
|
9
|
-
#### Final Form
|
10
|
-
|
11
|
-
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
|
12
|
-
|
13
|
-
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={MultiSelectFieldFF} />\`. See the code samples below for examples.
|
14
|
-
|
15
|
-
#### Props
|
16
|
-
|
17
|
-
The props shown in the table below are generally provided to the \`MultiSelectFieldFF\` wrapper by the Final Form \`Field\`.
|
18
|
-
|
19
|
-
Note that any props beyond the API of the \`Field\` component will be spread to the \`MultiSelectFieldFF\`, which passes any extra props to the underlying \`MultiSelectField\` using \`{...rest}\`.
|
20
|
-
|
21
|
-
Therefore, to add any props to the \`MultiSelectFieldFF\` or \`MultiSelectField\`, add those props to the parent Final Form \`Field\` component.
|
22
|
-
|
23
|
-
Also see \`MultiSelect\` and \`MultiSelectField\` for notes about props and implementation.
|
24
|
-
|
25
|
-
\`\`\`js
|
26
|
-
import { MultiSelectFieldFF } from '@dhis2/ui'
|
27
|
-
\`\`\`
|
28
|
-
|
29
|
-
Press **Submit** to see the form values logged to the console.
|
30
|
-
|
31
|
-
_**Note:** Dropdowns may not appear correctly on this page. See the affected demos in the 'Canvas' tab for propper dropdown placement._
|
32
|
-
`;
|
6
|
+
const description = "\nThe `MultiSelectFieldFF` is a wrapper around a `MultiSelectField` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.\n\n#### Final Form\n\nSee how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).\n\nInside a Final Form `<Form>` component, these 'FF' UI components are intended to be used in the `component` prop of the [Final Form `<Field>` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. `<Field component={MultiSelectFieldFF} />`. See the code samples below for examples.\n\n#### Props\n\nThe props shown in the table below are generally provided to the `MultiSelectFieldFF` wrapper by the Final Form `Field`.\n\nNote that any props beyond the API of the `Field` component will be spread to the `MultiSelectFieldFF`, which passes any extra props to the underlying `MultiSelectField` using `{...rest}`.\n\nTherefore, to add any props to the `MultiSelectFieldFF` or `MultiSelectField`, add those props to the parent Final Form `Field` component.\n\nAlso see `MultiSelect` and `MultiSelectField` for notes about props and implementation.\n\n```js\nimport { MultiSelectFieldFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n\n_**Note:** Dropdowns may not appear correctly on this page. See the affected demos in the 'Canvas' tab for propper dropdown placement._\n";
|
33
7
|
const options = [{
|
34
8
|
value: '1',
|
35
9
|
label: 'one'
|
@@ -63,7 +37,7 @@ const options = [{
|
|
63
37
|
}];
|
64
38
|
const initialValue = ['3', '4', '9', '10'];
|
65
39
|
export default {
|
66
|
-
title: '
|
40
|
+
title: 'Multi Select Field (Final Form)',
|
67
41
|
component: MultiSelectFieldFF,
|
68
42
|
decorators: [formDecorator],
|
69
43
|
parameters: {
|
@@ -5,27 +5,30 @@ import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
6
6
|
import { createToggleChangeHandler, createFocusHandler, createBlurHandler, hasError, isValid, getValidationText } from '../shared/helpers.js';
|
7
7
|
import { metaPropType, inputPropType } from '../shared/propTypes.js';
|
8
|
-
export const RadioFieldFF =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
export const RadioFieldFF = _ref => {
|
9
|
+
let {
|
10
|
+
error,
|
11
|
+
input,
|
12
|
+
meta,
|
13
|
+
showValidStatus,
|
14
|
+
valid,
|
15
|
+
validationText,
|
16
|
+
onBlur,
|
17
|
+
onFocus,
|
18
|
+
...rest
|
19
|
+
} = _ref;
|
20
|
+
return /*#__PURE__*/React.createElement(Radio, _extends({}, rest, {
|
21
|
+
name: input.name,
|
22
|
+
checked: input.checked,
|
23
|
+
value: input.value,
|
24
|
+
error: hasError(meta, error),
|
25
|
+
valid: isValid(meta, valid, showValidStatus),
|
26
|
+
validationText: getValidationText(meta, validationText, error),
|
27
|
+
onFocus: createFocusHandler(input, onFocus),
|
28
|
+
onChange: createToggleChangeHandler(input),
|
29
|
+
onBlur: createBlurHandler(input, onBlur)
|
30
|
+
}));
|
31
|
+
};
|
29
32
|
RadioFieldFF.propTypes = {
|
30
33
|
/** `input` props received from Final Form `Field` */
|
31
34
|
input: inputPropType.isRequired,
|
@@ -4,33 +4,9 @@ import { Field } from 'react-final-form';
|
|
4
4
|
import { formDecorator } from '../formDecorator.js';
|
5
5
|
import { inputArgType, metaArgType } from '../shared/propTypes.js';
|
6
6
|
import { RadioFieldFF } from './RadioFieldFF.js';
|
7
|
-
const description = `
|
8
|
-
The \`RadioFieldFF\` is a wrapper around a \`Radio\` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.
|
9
|
-
|
10
|
-
#### Final Form
|
11
|
-
|
12
|
-
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
|
13
|
-
|
14
|
-
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={RadioFieldFF} />\`. See the code samples below for examples.
|
15
|
-
|
16
|
-
#### Props
|
17
|
-
|
18
|
-
The props shown in the table below are generally provided to the \`RadioFieldFF\` wrapper by the Final Form \`Field\`.
|
19
|
-
|
20
|
-
Note that any props beyond the API of the \`Field\` component will be spread to the \`RadioFieldFF\`, which passes any extra props to the underlying \`Radio\` using \`{...rest}\`.
|
21
|
-
|
22
|
-
Therefore, to add any props to the \`RadioFieldFF\` or \`Radio\`, add those props to the parent Final Form \`Field\` component.
|
23
|
-
|
24
|
-
Also see \`Radio\` for notes about props and implementation.
|
25
|
-
|
26
|
-
\`\`\`js
|
27
|
-
import { RadioFieldFF } from '@dhis2/ui'
|
28
|
-
\`\`\`
|
29
|
-
|
30
|
-
Press **Submit** to see the form values logged to the console.
|
31
|
-
`;
|
7
|
+
const description = "\nThe `RadioFieldFF` is a wrapper around a `Radio` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.\n\n#### Final Form\n\nSee how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).\n\nInside a Final Form `<Form>` component, these 'FF' UI components are intended to be used in the `component` prop of the [Final Form `<Field>` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. `<Field component={RadioFieldFF} />`. See the code samples below for examples.\n\n#### Props\n\nThe props shown in the table below are generally provided to the `RadioFieldFF` wrapper by the Final Form `Field`.\n\nNote that any props beyond the API of the `Field` component will be spread to the `RadioFieldFF`, which passes any extra props to the underlying `Radio` using `{...rest}`.\n\nTherefore, to add any props to the `RadioFieldFF` or `Radio`, add those props to the parent Final Form `Field` component.\n\nAlso see `Radio` for notes about props and implementation.\n\n```js\nimport { RadioFieldFF } from '@dhis2/ui'\n```\n\nPress **Submit** to see the form values logged to the console.\n";
|
32
8
|
export default {
|
33
|
-
title: '
|
9
|
+
title: 'Radio Field (Final Form)',
|
34
10
|
component: RadioFieldFF,
|
35
11
|
decorators: [formDecorator],
|
36
12
|
parameters: {
|
@@ -5,20 +5,21 @@ import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
6
6
|
import { createSelectChangeHandler, createFocusHandler, createBlurHandler, hasError, isLoading, isValid, getValidationText } from '../shared/helpers.js';
|
7
7
|
import { inputPropType, metaPropType } from '../shared/propTypes.js';
|
8
|
-
export const SingleSelectFieldFF =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
export const SingleSelectFieldFF = _ref => {
|
9
|
+
let {
|
10
|
+
error,
|
11
|
+
input,
|
12
|
+
loading,
|
13
|
+
meta,
|
14
|
+
onBlur,
|
15
|
+
onFocus,
|
16
|
+
options,
|
17
|
+
showLoadingStatus,
|
18
|
+
showValidStatus,
|
19
|
+
valid,
|
20
|
+
validationText,
|
21
|
+
...rest
|
22
|
+
} = _ref;
|
22
23
|
return /*#__PURE__*/React.createElement(SingleSelectField, _extends({}, rest, {
|
23
24
|
name: input.name,
|
24
25
|
error: hasError(meta, error),
|
@@ -12,13 +12,16 @@ storiesOf('Testing:SingleSelectFieldFF', module).addDecorator(formDecorator).add
|
|
12
12
|
options: {
|
13
13
|
showPanel: false
|
14
14
|
}
|
15
|
-
}).add('Required', (_, {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
}).add('Required', (_, _ref) => {
|
16
|
+
let {
|
17
|
+
cypressProps
|
18
|
+
} = _ref;
|
19
|
+
return /*#__PURE__*/React.createElement(Field, {
|
20
|
+
required: true,
|
21
|
+
name: "singleSelect",
|
22
|
+
label: "Single select",
|
23
|
+
component: SingleSelectFieldFF,
|
24
|
+
validate: hasValue,
|
25
|
+
options: cypressProps.options || defaultOptions
|
26
|
+
});
|
27
|
+
});
|