@dhis2/ui-forms 8.1.11 → 8.2.2
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/ar/translations.json +0 -1
- package/build/cjs/locales/ar_IQ/translations.json +0 -1
- package/build/cjs/locales/ckb/translations.json +0 -1
- package/build/cjs/locales/cs/translations.json +0 -1
- package/build/cjs/locales/da/translations.json +0 -1
- package/build/cjs/locales/en/translations.json +0 -1
- package/build/cjs/locales/es/translations.json +0 -1
- package/build/cjs/locales/fr/translations.json +0 -1
- package/build/cjs/locales/id/translations.json +0 -1
- package/build/cjs/locales/km/translations.json +0 -1
- package/build/cjs/locales/lo/translations.json +0 -1
- package/build/cjs/locales/my/translations.json +0 -1
- package/build/cjs/locales/nb/translations.json +0 -1
- package/build/cjs/locales/prs/translations.json +0 -1
- package/build/cjs/locales/ps/translations.json +0 -1
- package/build/cjs/locales/pt/translations.json +0 -1
- package/build/cjs/locales/pt_BR/translations.json +0 -1
- package/build/cjs/locales/ru/translations.json +0 -1
- package/build/cjs/locales/sv/translations.json +0 -1
- package/build/cjs/locales/tet/translations.json +0 -1
- package/build/cjs/locales/tg/translations.json +0 -1
- package/build/cjs/locales/uk/translations.json +0 -1
- package/build/cjs/locales/ur/translations.json +0 -1
- package/build/cjs/locales/uz/translations.json +0 -1
- package/build/cjs/locales/uz_Latn/translations.json +0 -1
- package/build/cjs/locales/vi/translations.json +0 -1
- package/build/cjs/locales/zh/translations.json +0 -1
- package/build/cjs/locales/zh_CN/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/ar/translations.json +0 -1
- package/build/es/locales/ar_IQ/translations.json +0 -1
- package/build/es/locales/ckb/translations.json +0 -1
- package/build/es/locales/cs/translations.json +0 -1
- package/build/es/locales/da/translations.json +0 -1
- package/build/es/locales/en/translations.json +0 -1
- package/build/es/locales/es/translations.json +0 -1
- package/build/es/locales/fr/translations.json +0 -1
- package/build/es/locales/id/translations.json +0 -1
- package/build/es/locales/km/translations.json +0 -1
- package/build/es/locales/lo/translations.json +0 -1
- package/build/es/locales/my/translations.json +0 -1
- package/build/es/locales/nb/translations.json +0 -1
- package/build/es/locales/prs/translations.json +0 -1
- package/build/es/locales/ps/translations.json +0 -1
- package/build/es/locales/pt/translations.json +0 -1
- package/build/es/locales/pt_BR/translations.json +0 -1
- package/build/es/locales/ru/translations.json +0 -1
- package/build/es/locales/sv/translations.json +0 -1
- package/build/es/locales/tet/translations.json +0 -1
- package/build/es/locales/tg/translations.json +0 -1
- package/build/es/locales/uk/translations.json +0 -1
- package/build/es/locales/ur/translations.json +0 -1
- package/build/es/locales/uz/translations.json +0 -1
- package/build/es/locales/uz_Latn/translations.json +0 -1
- package/build/es/locales/vi/translations.json +0 -1
- package/build/es/locales/zh/translations.json +0 -1
- package/build/es/locales/zh_CN/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
@@ -2,7 +2,6 @@
|
|
2
2
|
"Upload file": "Faylni yuklash",
|
3
3
|
"Upload files": "",
|
4
4
|
"Remove": "Олиб ташлаш",
|
5
|
-
"No file(s) selected yet": "",
|
6
5
|
"Please provide an alpha-numeric value": "",
|
7
6
|
"Please provide a boolean value": "",
|
8
7
|
"Please enter between {{lowerBound}} and {{upperBound}} characters": "",
|
@@ -2,7 +2,6 @@
|
|
2
2
|
"Upload file": "Tải một tập tin",
|
3
3
|
"Upload files": "",
|
4
4
|
"Remove": "Tháo ra",
|
5
|
-
"No file(s) selected yet": "",
|
6
5
|
"Please provide an alpha-numeric value": "",
|
7
6
|
"Please provide a boolean value": "",
|
8
7
|
"Please enter between {{lowerBound}} and {{upperBound}} characters": "",
|
@@ -2,7 +2,6 @@
|
|
2
2
|
"Upload file": "上传文件",
|
3
3
|
"Upload files": "上传文件",
|
4
4
|
"Remove": "移除",
|
5
|
-
"No file(s) selected yet": "尚未选择任何文件",
|
6
5
|
"Please provide an alpha-numeric value": "请提供字母数字值",
|
7
6
|
"Please provide a boolean value": "请提供一个布尔值",
|
8
7
|
"Please enter between {{lowerBound}} and {{upperBound}} characters": "请在 {{lowerBound}} 和 {{upperBound}} 个字符之间输入",
|
@@ -6,22 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.createChangeHandler = void 0;
|
7
7
|
const PRIMITIVE_TYPES = new Set(['string', 'number', 'boolean']);
|
8
8
|
|
9
|
-
const createChangeHandler =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
9
|
+
const createChangeHandler = _ref => {
|
10
|
+
let {
|
11
|
+
onChange
|
12
|
+
} = _ref;
|
13
|
+
return payload => {
|
14
|
+
if (payload && 'value' in payload) {
|
15
|
+
// ui event signature
|
16
|
+
onChange(payload.value);
|
17
|
+
} else if (payload && payload.target && 'value' in payload.target) {
|
18
|
+
// synthetic event
|
19
|
+
onChange(payload.target.value);
|
20
|
+
} else if (PRIMITIVE_TYPES.has(typeof payload)) {
|
21
|
+
// directly usable value
|
22
|
+
onChange(payload);
|
23
|
+
} else {
|
24
|
+
// ¯\_(ツ)_/¯
|
25
|
+
throw new Error('Could not process event payload');
|
26
|
+
}
|
27
|
+
};
|
25
28
|
};
|
26
29
|
|
27
30
|
exports.createChangeHandler = createChangeHandler;
|
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.createSelectChangeHandler = void 0;
|
7
7
|
|
8
|
-
const createSelectChangeHandler =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
const createSelectChangeHandler = _ref => {
|
9
|
+
let {
|
10
|
+
onChange
|
11
|
+
} = _ref;
|
12
|
+
return _ref2 => {
|
13
|
+
let {
|
14
|
+
selected
|
15
|
+
} = _ref2;
|
16
|
+
onChange(selected);
|
17
|
+
};
|
14
18
|
};
|
15
19
|
|
16
20
|
exports.createSelectChangeHandler = createSelectChangeHandler;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.toggleGroupOptionsProp = exports.metaPropType = exports.metaArgType = exports.inputPropType = exports.inputArgType = void 0;
|
7
7
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
9
|
|
@@ -5,9 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.arrayWithIdObjects = void 0;
|
7
7
|
|
8
|
-
const format = value => !value ? [] : value.map(
|
9
|
-
|
10
|
-
|
8
|
+
const format = value => !value ? [] : value.map(_ref => {
|
9
|
+
let {
|
10
|
+
id
|
11
|
+
} = _ref;
|
12
|
+
return id;
|
13
|
+
});
|
11
14
|
|
12
15
|
const parse = value => !value || Array.isArray(value) && value.length === 0 ? undefined : value.map(id => ({
|
13
16
|
id
|
@@ -24,7 +24,7 @@ describe('validator: createPattern', () => {
|
|
24
24
|
});
|
25
25
|
it('should return an error string when input does not match the pattern', () => {
|
26
26
|
const escapedRegexString = '/^test$/';
|
27
|
-
const invalidMsg =
|
27
|
+
const invalidMsg = "Please make sure the value of this input matches the pattern ".concat(escapedRegexString, ".");
|
28
28
|
expect(equalToTestPattern('bad input')).toEqual(invalidMsg);
|
29
29
|
});
|
30
30
|
it('should return an custon error string when one was provided and input does not match the pattern', () => {
|
@@ -5,8 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.composeValidators = void 0;
|
7
7
|
|
8
|
-
const composeValidators = (
|
9
|
-
|
8
|
+
const composeValidators = function () {
|
9
|
+
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {
|
10
|
+
validators[_key] = arguments[_key];
|
11
|
+
}
|
12
|
+
|
13
|
+
return function () {
|
14
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
15
|
+
args[_key2] = arguments[_key2];
|
16
|
+
}
|
17
|
+
|
10
18
|
return validators.reduce((error, validator) => error || validator(...args), undefined);
|
11
19
|
};
|
12
20
|
};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.toNumber = exports.requiredArgumentErrorMessage = exports.requireArgument = exports.isString = exports.isNumeric = exports.isNumber = exports.isInteger = exports.isInRange = exports.isEmpty = void 0;
|
7
7
|
|
8
8
|
const isEmpty = value => typeof value === 'undefined' || value === null || value === '';
|
9
9
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.testValidatorValues = exports.allowsEmptyValues = void 0;
|
7
7
|
|
8
8
|
const testValidatorValues = (validator, returnValue, values) => {
|
9
9
|
const returnValueStr = returnValue === undefined ? 'undefined' : 'an error string';
|
@@ -11,7 +11,7 @@ const testValidatorValues = (validator, returnValue, values) => {
|
|
11
11
|
for (const value of values) {
|
12
12
|
const type = typeof value;
|
13
13
|
const valueStr = type === 'object' ? JSON.stringify(value) : value;
|
14
|
-
it(
|
14
|
+
it("should return ".concat(returnValueStr, " for value `").concat(valueStr, "` of type ").concat(type), () => {
|
15
15
|
expect(validator(value)).toBe(returnValue);
|
16
16
|
});
|
17
17
|
}
|
@@ -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),
|