@dhis2-ui/file-input 9.11.0 → 9.11.1-beta.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/build/cjs/file-input/__tests__/file-input.test.js +1 -9
- package/build/cjs/file-input/features/accepts_multiple_files/index.js +1 -2
- package/build/cjs/file-input/features/can_be_blurred/index.js +1 -2
- package/build/cjs/file-input/features/can_be_changed/index.js +1 -2
- package/build/cjs/file-input/features/can_be_focused/index.js +1 -2
- package/build/cjs/file-input/features/common/index.js +0 -1
- package/build/cjs/file-input/file-input.e2e.stories.js +49 -0
- package/build/cjs/file-input/file-input.js +13 -44
- package/build/cjs/file-input/{file-input.stories.js → file-input.prod.stories.js} +29 -36
- package/build/cjs/file-input/index.js +0 -1
- package/build/cjs/file-input-field/__tests__/file-input-field.test.js +1 -9
- package/build/cjs/file-input-field/features/can_be_required/index.js +0 -1
- package/build/cjs/file-input-field/features/has_default_button_label/index.js +0 -1
- package/build/cjs/file-input-field/features/has_default_placeholder/index.js +0 -1
- package/build/cjs/file-input-field/file-input-field.e2e.stories.js +24 -0
- package/build/cjs/file-input-field/file-input-field.js +8 -36
- package/build/cjs/file-input-field/{file-input-field.stories.js → file-input-field.prod.stories.js} +33 -51
- package/build/cjs/file-input-field/index.js +0 -1
- package/build/cjs/file-input-field-with-list/__tests__/file-input-field-with-list.test.js +1 -9
- package/build/cjs/file-input-field-with-list/features/common/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/deduplicates_the_file_list/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/disables_button_when_full/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/displays_files_in_a_list/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/files_can_be_removed/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/has_default_button_label/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/has_default_placeholder/index.js +0 -1
- package/build/cjs/file-input-field-with-list/features/has_default_remove_text/index.js +0 -1
- package/build/cjs/file-input-field-with-list/file-input-field-with-list.e2e.stories.js +63 -0
- package/build/cjs/file-input-field-with-list/file-input-field-with-list.js +9 -47
- package/build/cjs/file-input-field-with-list/{file-input-field-with-list.stories.js → file-input-field-with-list.prod.stories.js} +24 -27
- package/build/cjs/file-input-field-with-list/file-list-item-with-remove.js +7 -17
- package/build/cjs/file-input-field-with-list/index.js +0 -1
- package/build/cjs/file-list/features/accepts_cancel_text/index.js +1 -2
- package/build/cjs/file-list/features/accepts_label/index.js +0 -1
- package/build/cjs/file-list/features/accepts_remove_text/index.js +1 -2
- package/build/cjs/file-list/features/can_be_removed/index.js +1 -2
- package/build/cjs/file-list/features/file-list-item-accepts_children/index.js +0 -1
- package/build/cjs/file-list/features/file-list-placeholder-accepts_children/index.js +0 -1
- package/build/cjs/file-list/features/loading_can_be_cancelled/index.js +1 -2
- package/build/cjs/file-list/file-list-item.e2e.stories.js +49 -0
- package/build/cjs/file-list/file-list-item.js +5 -18
- package/build/cjs/file-list/file-list-placeholder.e2e.stories.js +14 -0
- package/build/cjs/file-list/file-list-placeholder.js +2 -9
- package/build/cjs/file-list/file-list.e2e.stories.js +14 -0
- package/build/cjs/file-list/file-list.js +1 -7
- package/build/cjs/file-list/index.js +0 -3
- package/build/cjs/index.js +0 -4
- package/build/cjs/locales/index.js +3 -73
- package/build/es/file-input/features/accepts_multiple_files/index.js +1 -1
- package/build/es/file-input/features/can_be_blurred/index.js +1 -1
- package/build/es/file-input/features/can_be_changed/index.js +1 -1
- package/build/es/file-input/features/can_be_focused/index.js +1 -1
- package/build/es/file-input/{file-input.stories.e2e.js → file-input.e2e.stories.js} +14 -9
- package/build/es/file-input/file-input.js +10 -31
- package/build/es/file-input/{file-input.stories.js → file-input.prod.stories.js} +23 -15
- package/build/es/file-input-field/file-input-field.e2e.stories.js +15 -0
- package/build/es/file-input-field/file-input-field.js +5 -23
- package/build/es/file-input-field/{file-input-field.stories.js → file-input-field.prod.stories.js} +21 -15
- package/build/es/file-input-field-with-list/{file-input-field-with-list.stories.e2e.js → file-input-field-with-list.e2e.stories.js} +15 -10
- package/build/es/file-input-field-with-list/file-input-field-with-list.js +8 -35
- package/build/es/file-input-field-with-list/{file-input-field-with-list.stories.js → file-input-field-with-list.prod.stories.js} +19 -11
- package/build/es/file-input-field-with-list/file-list-item-with-remove.js +4 -8
- package/build/es/file-list/features/accepts_cancel_text/index.js +1 -1
- package/build/es/file-list/features/accepts_remove_text/index.js +1 -1
- package/build/es/file-list/features/can_be_removed/index.js +1 -1
- package/build/es/file-list/features/loading_can_be_cancelled/index.js +1 -1
- package/build/es/file-list/{file-list-item.stories.e2e.js → file-list-item.e2e.stories.js} +13 -7
- package/build/es/file-list/file-list-item.js +4 -9
- package/build/es/file-list/file-list-placeholder.e2e.stories.js +6 -0
- package/build/es/file-list/file-list-placeholder.js +1 -3
- package/build/es/file-list/file-list.e2e.stories.js +6 -0
- package/build/es/file-list/file-list.js +0 -2
- package/package.json +11 -11
- package/build/cjs/file-input/file-input.stories.e2e.js +0 -40
- package/build/cjs/file-input-field/file-input-field.stories.e2e.js +0 -19
- package/build/cjs/file-input-field-with-list/file-input-field-with-list.stories.e2e.js +0 -53
- package/build/cjs/file-list/file-list-item.stories.e2e.js +0 -38
- package/build/cjs/file-list/file-list-placeholder.stories.e2e.js +0 -11
- package/build/cjs/file-list/file-list.stories.e2e.js +0 -11
- package/build/es/file-input-field/file-input-field.stories.e2e.js +0 -12
- package/build/es/file-list/file-list-placeholder.stories.e2e.js +0 -4
- package/build/es/file-list/file-list.stories.e2e.js +0 -4
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
5
|
var _fileInput = require("../file-input.js");
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
7
|
describe('<FileInput />', () => {
|
|
12
8
|
it('should call the onKeyDown callback when provided', () => {
|
|
13
9
|
const onKeyDown = jest.fn();
|
|
@@ -17,13 +13,9 @@ describe('<FileInput />', () => {
|
|
|
17
13
|
checked: false,
|
|
18
14
|
onKeyDown: onKeyDown
|
|
19
15
|
}));
|
|
20
|
-
|
|
21
16
|
_react.fireEvent.keyDown(_react.screen.getByRole('button'), {});
|
|
22
|
-
|
|
23
17
|
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
24
|
-
|
|
25
18
|
const input = _react.screen.getByTestId('dhis2-uicore-fileinput-input');
|
|
26
|
-
|
|
27
19
|
expect(onKeyDown).toHaveBeenCalledWith({
|
|
28
20
|
name: 'foo',
|
|
29
21
|
files: input.files
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('a FileInput with multiple and onChange handler is rendered', () => {
|
|
6
|
-
cy.visitStory('FileInput', 'With
|
|
5
|
+
cy.visitStory('FileInput', 'With on change and multiple');
|
|
7
6
|
});
|
|
8
7
|
(0, _cypressCucumberPreprocessor.When)('the user selected multiple files', () => {
|
|
9
8
|
cy.get('[data-test="dhis2-uicore-fileinput"] input').uploadMultipleFiles([{
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('an FileInput with initialFocus and onBlur handler is rendered', () => {
|
|
6
|
-
cy.visitStory('FileInput', 'With
|
|
5
|
+
cy.visitStory('FileInput', 'With initial focus and on blur');
|
|
7
6
|
});
|
|
8
7
|
(0, _cypressCucumberPreprocessor.When)('the FileInput is blurred', () => {
|
|
9
8
|
cy.focused();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('a FileInput with onChange handler is rendered', () => {
|
|
6
|
-
cy.visitStory('FileInput', 'With
|
|
5
|
+
cy.visitStory('FileInput', 'With on change');
|
|
7
6
|
});
|
|
8
7
|
(0, _cypressCucumberPreprocessor.When)('a file is selected', () => {
|
|
9
8
|
cy.get('[data-test="dhis2-uicore-fileinput"] input').uploadSingleFile('.md', 'FileInput/file.md');
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('a FileInput with onFocus handler is rendered', () => {
|
|
6
|
-
cy.visitStory('FileInput', 'With
|
|
5
|
+
cy.visitStory('FileInput', 'With on focus');
|
|
7
6
|
});
|
|
8
7
|
(0, _cypressCucumberPreprocessor.When)('the FileInput is focused', () => {
|
|
9
8
|
cy.get('[data-test="dhis2-uicore-fileinput"] button').focus();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('the FileInput does not have any files', () => {
|
|
6
5
|
cy.get('[data-test="dhis2-uicore-fileinput"] input').then($input => {
|
|
7
6
|
const files = $input[0].files;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.WithOnFocus = exports.WithOnChangeAndMultiple = exports.WithOnChange = exports.WithInitialFocusAndOnBlur = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _index = require("./index.js");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
window.onBlur = window.Cypress && window.Cypress.cy.stub();
|
|
11
|
+
window.onFocus = window.Cypress && window.Cypress.cy.stub();
|
|
12
|
+
window.onChange = window.Cypress && window.Cypress.cy.stub();
|
|
13
|
+
const onChange = (payload, event) => {
|
|
14
|
+
// NOTE: if files is not transformed into an array,
|
|
15
|
+
// cypress will get an empty file list!
|
|
16
|
+
window.onChange({
|
|
17
|
+
...payload,
|
|
18
|
+
files: [...payload.files]
|
|
19
|
+
}, event);
|
|
20
|
+
};
|
|
21
|
+
var _default = exports.default = {
|
|
22
|
+
title: 'FileInput'
|
|
23
|
+
};
|
|
24
|
+
const WithOnChange = () => /*#__PURE__*/_react.default.createElement(_index.FileInput, {
|
|
25
|
+
onChange: onChange,
|
|
26
|
+
buttonLabel: "Upload file",
|
|
27
|
+
name: "upload"
|
|
28
|
+
});
|
|
29
|
+
exports.WithOnChange = WithOnChange;
|
|
30
|
+
const WithOnChangeAndMultiple = () => /*#__PURE__*/_react.default.createElement(_index.FileInput, {
|
|
31
|
+
name: "upload",
|
|
32
|
+
onChange: onChange,
|
|
33
|
+
buttonLabel: "Upload files",
|
|
34
|
+
multiple: true
|
|
35
|
+
});
|
|
36
|
+
exports.WithOnChangeAndMultiple = WithOnChangeAndMultiple;
|
|
37
|
+
const WithInitialFocusAndOnBlur = () => /*#__PURE__*/_react.default.createElement(_index.FileInput, {
|
|
38
|
+
buttonLabel: "Upload file",
|
|
39
|
+
name: "upload",
|
|
40
|
+
initialFocus: true,
|
|
41
|
+
onBlur: window.onBlur
|
|
42
|
+
});
|
|
43
|
+
exports.WithInitialFocusAndOnBlur = WithInitialFocusAndOnBlur;
|
|
44
|
+
const WithOnFocus = () => /*#__PURE__*/_react.default.createElement(_index.FileInput, {
|
|
45
|
+
buttonLabel: "Upload file",
|
|
46
|
+
name: "upload",
|
|
47
|
+
onFocus: window.onFocus
|
|
48
|
+
});
|
|
49
|
+
exports.WithOnFocus = WithOnFocus;
|
|
@@ -4,77 +4,58 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FileInput = void 0;
|
|
7
|
-
|
|
8
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
9
|
-
|
|
10
|
-
var _button = require("@dhis2-ui/button");
|
|
11
|
-
|
|
12
|
-
var _statusIcon = require("@dhis2-ui/status-icon");
|
|
13
|
-
|
|
14
8
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
15
|
-
|
|
16
9
|
var _uiIcons = require("@dhis2/ui-icons");
|
|
17
|
-
|
|
10
|
+
var _button = require("@dhis2-ui/button");
|
|
11
|
+
var _statusIcon = require("@dhis2-ui/status-icon");
|
|
18
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
19
|
-
|
|
20
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
21
|
-
|
|
22
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
31
|
-
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
32
21
|
class FileInput extends _react.Component {
|
|
33
22
|
constructor() {
|
|
34
23
|
super(...arguments);
|
|
35
|
-
|
|
36
24
|
_defineProperty(this, "ref", /*#__PURE__*/(0, _react.createRef)());
|
|
37
|
-
|
|
38
25
|
_defineProperty(this, "handleClick", () => {
|
|
39
26
|
this.ref.current.click();
|
|
40
27
|
});
|
|
41
|
-
|
|
42
28
|
_defineProperty(this, "handleChange", e => {
|
|
43
29
|
if (this.props.onChange) {
|
|
44
30
|
this.props.onChange(this.createHandlerPayload(), e);
|
|
45
|
-
}
|
|
46
|
-
// if the same file was added in a second attempt
|
|
47
|
-
|
|
31
|
+
}
|
|
48
32
|
|
|
33
|
+
// reset the file input so it won't prevent on-change
|
|
34
|
+
// if the same file was added in a second attempt
|
|
49
35
|
this.ref.current.value = '';
|
|
50
36
|
});
|
|
51
|
-
|
|
52
37
|
_defineProperty(this, "handleBlur", e => {
|
|
53
38
|
if (this.props.onBlur) {
|
|
54
39
|
this.props.onBlur(this.createHandlerPayload(), e);
|
|
55
40
|
}
|
|
56
41
|
});
|
|
57
|
-
|
|
58
42
|
_defineProperty(this, "handleFocus", e => {
|
|
59
43
|
if (this.props.onFocus) {
|
|
60
44
|
this.props.onFocus(this.createHandlerPayload(), e);
|
|
61
45
|
}
|
|
62
46
|
});
|
|
63
|
-
|
|
64
47
|
_defineProperty(this, "handleKeyDown", e => {
|
|
65
48
|
if (this.props.onKeyDown) {
|
|
66
49
|
this.props.onKeyDown(this.createHandlerPayload(), e);
|
|
67
50
|
}
|
|
68
51
|
});
|
|
69
52
|
}
|
|
70
|
-
|
|
71
53
|
createHandlerPayload() {
|
|
72
54
|
return {
|
|
73
55
|
files: this.ref.current.files,
|
|
74
56
|
name: this.props.name
|
|
75
57
|
};
|
|
76
58
|
}
|
|
77
|
-
|
|
78
59
|
render() {
|
|
79
60
|
const {
|
|
80
61
|
accept,
|
|
@@ -106,7 +87,7 @@ class FileInput extends _react.Component {
|
|
|
106
87
|
accept: accept,
|
|
107
88
|
multiple: multiple,
|
|
108
89
|
disabled: disabled,
|
|
109
|
-
"data-test":
|
|
90
|
+
"data-test": `${dataTest}-input`,
|
|
110
91
|
className: _style.default.dynamic([["1746996489", [_uiConstants.spacers.dp8, _uiConstants.spacers.dp4]]])
|
|
111
92
|
}), /*#__PURE__*/_react.default.createElement(_button.Button, {
|
|
112
93
|
disabled: disabled,
|
|
@@ -129,11 +110,9 @@ class FileInput extends _react.Component {
|
|
|
129
110
|
}), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
130
111
|
id: "1746996489",
|
|
131
112
|
dynamic: [_uiConstants.spacers.dp8, _uiConstants.spacers.dp4]
|
|
132
|
-
}, ["input.__jsx-style-dynamic-selector{display:none;}",
|
|
113
|
+
}, ["input.__jsx-style-dynamic-selector{display:none;}", `.file-input.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:${_uiConstants.spacers.dp8};padding-bottom:${_uiConstants.spacers.dp4};}`]));
|
|
133
114
|
}
|
|
134
|
-
|
|
135
115
|
}
|
|
136
|
-
|
|
137
116
|
exports.FileInput = FileInput;
|
|
138
117
|
FileInput.defaultProps = {
|
|
139
118
|
accept: '*',
|
|
@@ -148,39 +127,29 @@ FileInput.propTypes = {
|
|
|
148
127
|
className: _propTypes.default.string,
|
|
149
128
|
dataTest: _propTypes.default.string,
|
|
150
129
|
disabled: _propTypes.default.bool,
|
|
151
|
-
|
|
152
130
|
/** Input status. Mutually exclusive with `warning` and `valid` */
|
|
153
131
|
error: _uiConstants.sharedPropTypes.statusPropType,
|
|
154
132
|
initialFocus: _propTypes.default.bool,
|
|
155
|
-
|
|
156
133
|
/** Button size. Mutually exclusive with `small` */
|
|
157
134
|
large: _uiConstants.sharedPropTypes.sizePropType,
|
|
158
|
-
|
|
159
135
|
/**
|
|
160
136
|
* The `multiple` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple)
|
|
161
137
|
*/
|
|
162
138
|
multiple: _propTypes.default.bool,
|
|
163
139
|
name: _propTypes.default.string,
|
|
164
|
-
|
|
165
140
|
/** Button size. Mutually exclusive with `large` */
|
|
166
141
|
small: _uiConstants.sharedPropTypes.sizePropType,
|
|
167
142
|
tabIndex: _propTypes.default.string,
|
|
168
|
-
|
|
169
143
|
/** Input status. Mutually exclusive with `warning` and `error` */
|
|
170
144
|
valid: _uiConstants.sharedPropTypes.statusPropType,
|
|
171
|
-
|
|
172
145
|
/** Input status. Mutually exclusive with `valid` and `error` */
|
|
173
146
|
warning: _uiConstants.sharedPropTypes.statusPropType,
|
|
174
|
-
|
|
175
147
|
/** Called with signature `(object, event)` */
|
|
176
148
|
onBlur: _propTypes.default.func,
|
|
177
|
-
|
|
178
149
|
/** Called with signature `(object, event)` */
|
|
179
150
|
onChange: _propTypes.default.func,
|
|
180
|
-
|
|
181
151
|
/** Called with signature `(object, event)` */
|
|
182
152
|
onFocus: _propTypes.default.func,
|
|
183
|
-
|
|
184
153
|
/** Called with signature `(object, event)` */
|
|
185
154
|
onKeyDown: _propTypes.default.func
|
|
186
155
|
};
|
|
@@ -4,35 +4,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Statuses = exports.Sizes = exports.RTL = exports.Multiple = exports.Disabled = exports.Default = void 0;
|
|
7
|
-
|
|
8
7
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _index = require("./index.js");
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
12
|
+
const subtitle = `The file input component allows users to select and upload files from their local machine.`;
|
|
13
|
+
const description = `
|
|
14
|
+
Use a file input component in forms and interfaces wherever a user needs to be able to select and upload a file from their local machine.
|
|
15
|
+
|
|
16
|
+
\`\`\`js
|
|
17
|
+
import { FileInput } from '@dhis2/ui'
|
|
18
|
+
\`\`\`
|
|
19
|
+
`;
|
|
21
20
|
const onChange = (payload, event) => {
|
|
22
21
|
console.log('onChange payload', payload);
|
|
23
|
-
console.log('onChange event', event);
|
|
24
|
-
// cypress will get an empty file list!
|
|
22
|
+
console.log('onChange event', event);
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
// NOTE: if files is not transformed into an array,
|
|
25
|
+
// cypress will get an empty file list!
|
|
26
|
+
window.onChange && window.onChange({
|
|
27
|
+
...payload,
|
|
27
28
|
files: [...payload.files]
|
|
28
29
|
}, event);
|
|
29
30
|
};
|
|
30
|
-
|
|
31
31
|
const {
|
|
32
32
|
sizeArgType,
|
|
33
33
|
statusArgType
|
|
34
34
|
} = _uiConstants.sharedPropTypes;
|
|
35
|
-
var _default = {
|
|
35
|
+
var _default = exports.default = {
|
|
36
36
|
title: 'File Input',
|
|
37
37
|
component: _index.FileInput,
|
|
38
38
|
// Default args for each story unless overridden
|
|
@@ -42,15 +42,20 @@ var _default = {
|
|
|
42
42
|
onChange
|
|
43
43
|
},
|
|
44
44
|
argTypes: {
|
|
45
|
-
valid: {
|
|
45
|
+
valid: {
|
|
46
|
+
...statusArgType
|
|
46
47
|
},
|
|
47
|
-
warning: {
|
|
48
|
+
warning: {
|
|
49
|
+
...statusArgType
|
|
48
50
|
},
|
|
49
|
-
error: {
|
|
51
|
+
error: {
|
|
52
|
+
...statusArgType
|
|
50
53
|
},
|
|
51
|
-
small: {
|
|
54
|
+
small: {
|
|
55
|
+
...sizeArgType
|
|
52
56
|
},
|
|
53
|
-
large: {
|
|
57
|
+
large: {
|
|
58
|
+
...sizeArgType
|
|
54
59
|
}
|
|
55
60
|
},
|
|
56
61
|
parameters: {
|
|
@@ -62,24 +67,17 @@ var _default = {
|
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
};
|
|
65
|
-
exports.default = _default;
|
|
66
|
-
|
|
67
70
|
const Template = args => /*#__PURE__*/_react.default.createElement(_index.FileInput, args);
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
exports.Default = Default;
|
|
71
|
-
const Multiple = Template.bind({});
|
|
72
|
-
exports.Multiple = Multiple;
|
|
71
|
+
const Default = exports.Default = Template.bind({});
|
|
72
|
+
const Multiple = exports.Multiple = Template.bind({});
|
|
73
73
|
Multiple.args = {
|
|
74
74
|
multiple: true,
|
|
75
75
|
buttonLabel: 'Upload files'
|
|
76
76
|
};
|
|
77
|
-
const Disabled = Template.bind({});
|
|
78
|
-
exports.Disabled = Disabled;
|
|
77
|
+
const Disabled = exports.Disabled = Template.bind({});
|
|
79
78
|
Disabled.args = {
|
|
80
79
|
disabled: true
|
|
81
80
|
};
|
|
82
|
-
|
|
83
81
|
const Sizes = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.FileInput, _extends({}, args, {
|
|
84
82
|
buttonLabel: "Default size",
|
|
85
83
|
name: "default"
|
|
@@ -92,9 +90,7 @@ const Sizes = args => /*#__PURE__*/_react.default.createElement(_react.default.F
|
|
|
92
90
|
buttonLabel: "Large",
|
|
93
91
|
name: "large"
|
|
94
92
|
})));
|
|
95
|
-
|
|
96
93
|
exports.Sizes = Sizes;
|
|
97
|
-
|
|
98
94
|
const Statuses = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.FileInput, _extends({}, args, {
|
|
99
95
|
buttonLabel: "Default",
|
|
100
96
|
name: "default"
|
|
@@ -111,14 +107,11 @@ const Statuses = args => /*#__PURE__*/_react.default.createElement(_react.defaul
|
|
|
111
107
|
name: "error",
|
|
112
108
|
error: true
|
|
113
109
|
})));
|
|
114
|
-
|
|
115
110
|
exports.Statuses = Statuses;
|
|
116
|
-
|
|
117
111
|
const RTL = args => /*#__PURE__*/_react.default.createElement("div", {
|
|
118
112
|
dir: "rtl"
|
|
119
113
|
}, /*#__PURE__*/_react.default.createElement(_index.FileInput, _extends({}, args, {
|
|
120
114
|
buttonLabel: "Default",
|
|
121
115
|
name: "default"
|
|
122
116
|
})));
|
|
123
|
-
|
|
124
117
|
exports.RTL = RTL;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
5
|
var _fileInputField = require("../file-input-field.js");
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
7
|
describe('<FileInputField />', () => {
|
|
12
8
|
it('should call the onKeyDown callback when provided', () => {
|
|
13
9
|
const onKeyDown = jest.fn();
|
|
@@ -18,13 +14,9 @@ describe('<FileInputField />', () => {
|
|
|
18
14
|
checked: false,
|
|
19
15
|
onKeyDown: onKeyDown
|
|
20
16
|
}));
|
|
21
|
-
|
|
22
17
|
_react.fireEvent.keyDown(_react.screen.getByRole('button'), {});
|
|
23
|
-
|
|
24
18
|
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
25
|
-
|
|
26
19
|
const input = _react.screen.getByTestId('dhis2-uicore-fileinput-input');
|
|
27
|
-
|
|
28
20
|
expect(onKeyDown).toHaveBeenCalledWith({
|
|
29
21
|
name: 'foo',
|
|
30
22
|
files: input.files
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
|
4
|
-
|
|
5
4
|
(0, _cypressCucumberPreprocessor.Given)('a FileInputField with label and a required flag is rendered', () => {
|
|
6
5
|
cy.visitStory('FileInputField', 'With label and required');
|
|
7
6
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.WithLabelAndRequired = exports.Default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _fileInputField = require("./file-input-field.js");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var _default = exports.default = {
|
|
11
|
+
title: 'FileInputField'
|
|
12
|
+
};
|
|
13
|
+
const WithLabelAndRequired = () => /*#__PURE__*/_react.default.createElement(_fileInputField.FileInputField, {
|
|
14
|
+
name: "upload",
|
|
15
|
+
label: "upload something",
|
|
16
|
+
buttonLabel: "Upload file",
|
|
17
|
+
required: true
|
|
18
|
+
});
|
|
19
|
+
exports.WithLabelAndRequired = WithLabelAndRequired;
|
|
20
|
+
const Default = () => /*#__PURE__*/_react.default.createElement(_fileInputField.FileInputField, {
|
|
21
|
+
name: "upload",
|
|
22
|
+
label: "upload something"
|
|
23
|
+
});
|
|
24
|
+
exports.Default = Default;
|
|
@@ -4,32 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FileInputField = void 0;
|
|
7
|
-
|
|
7
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
8
8
|
var _field = require("@dhis2-ui/field");
|
|
9
|
-
|
|
10
9
|
var _label = require("@dhis2-ui/label");
|
|
11
|
-
|
|
12
|
-
var _uiConstants = require("@dhis2/ui-constants");
|
|
13
|
-
|
|
14
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
-
|
|
16
11
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
12
|
+
var _index = require("../file-input/index.js");
|
|
13
|
+
var _index2 = require("../file-list/index.js");
|
|
14
|
+
var _index3 = _interopRequireDefault(require("../locales/index.js"));
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
16
|
// TODO: i18n
|
|
25
17
|
const translate = (prop, interpolationObject) => {
|
|
26
18
|
if (typeof prop === 'function') {
|
|
27
19
|
return prop(interpolationObject);
|
|
28
20
|
}
|
|
29
|
-
|
|
30
21
|
return prop;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
const FileInputField = _ref => {
|
|
34
24
|
let {
|
|
35
25
|
accept,
|
|
@@ -87,74 +77,56 @@ const FileInputField = _ref => {
|
|
|
87
77
|
tabIndex: tabIndex,
|
|
88
78
|
valid: valid,
|
|
89
79
|
warning: warning
|
|
90
|
-
}), /*#__PURE__*/_react.default.createElement(
|
|
80
|
+
}), /*#__PURE__*/_react.default.createElement(_index2.FileList, null, children ? children : /*#__PURE__*/_react.default.createElement(_index2.FileListPlaceholder, null, translate(placeholder))));
|
|
91
81
|
};
|
|
92
|
-
|
|
93
82
|
exports.FileInputField = FileInputField;
|
|
94
83
|
FileInputField.defaultProps = {
|
|
95
84
|
accept: '*',
|
|
96
85
|
dataTest: 'dhis2-uiwidgets-fileinputfield',
|
|
97
|
-
buttonLabel: () =>
|
|
98
|
-
placeholder: () =>
|
|
86
|
+
buttonLabel: () => _index3.default.t('Upload a file'),
|
|
87
|
+
placeholder: () => _index3.default.t('No file uploaded yet')
|
|
99
88
|
};
|
|
100
89
|
FileInputField.propTypes = {
|
|
101
90
|
/** The `accept` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) */
|
|
102
91
|
accept: _propTypes.default.string,
|
|
103
|
-
|
|
104
92
|
/** Text on the button */
|
|
105
93
|
buttonLabel: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
|
|
106
94
|
children: _propTypes.default.node,
|
|
107
95
|
className: _propTypes.default.string,
|
|
108
96
|
dataTest: _propTypes.default.string,
|
|
109
|
-
|
|
110
97
|
/** Disables the button */
|
|
111
98
|
disabled: _propTypes.default.bool,
|
|
112
|
-
|
|
113
99
|
/** Applies 'error' styling to the validation text. Mutually exclusive with `warning` and `valid` props */
|
|
114
100
|
error: _uiConstants.sharedPropTypes.statusPropType,
|
|
115
|
-
|
|
116
101
|
/** Useful guiding text for the user */
|
|
117
102
|
helpText: _propTypes.default.string,
|
|
118
103
|
initialFocus: _propTypes.default.bool,
|
|
119
|
-
|
|
120
104
|
/** A descriptive label above the button */
|
|
121
105
|
label: _propTypes.default.string,
|
|
122
|
-
|
|
123
106
|
/** Size of the button. Mutually exclusive with the `small` prop */
|
|
124
107
|
large: _uiConstants.sharedPropTypes.sizePropType,
|
|
125
|
-
|
|
126
108
|
/** The `multiple` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple) */
|
|
127
109
|
multiple: _propTypes.default.bool,
|
|
128
|
-
|
|
129
110
|
/** Name associated with input. Passed to event handler callbacks */
|
|
130
111
|
name: _propTypes.default.string,
|
|
131
|
-
|
|
132
112
|
/** Placeholder below the button */
|
|
133
113
|
placeholder: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
|
|
134
|
-
|
|
135
114
|
/** Adds an asterisk to indicate this field is required */
|
|
136
115
|
required: _propTypes.default.bool,
|
|
137
|
-
|
|
138
116
|
/** Size of the button. Mutually exclusive with the `large` prop */
|
|
139
117
|
small: _uiConstants.sharedPropTypes.sizePropType,
|
|
140
118
|
tabIndex: _propTypes.default.string,
|
|
141
|
-
|
|
142
119
|
/** Applies 'valid' styling to the validation text. Mutually exclusive with `warning` and `error` props */
|
|
143
120
|
valid: _uiConstants.sharedPropTypes.statusPropType,
|
|
144
|
-
|
|
145
121
|
/** Text below the button that provides validation feedback */
|
|
146
122
|
validationText: _propTypes.default.string,
|
|
147
|
-
|
|
148
123
|
/** Applies 'warning' styling to the validation text. Mutually exclusive with `valid` and `error` props */
|
|
149
124
|
warning: _uiConstants.sharedPropTypes.statusPropType,
|
|
150
125
|
onBlur: _propTypes.default.func,
|
|
151
|
-
|
|
152
126
|
/** Called with signature `({ name: string, files: [] }, event)` */
|
|
153
127
|
onChange: _propTypes.default.func,
|
|
154
|
-
|
|
155
128
|
/** Called with signature `({ name: string, files: [] }, event)` */
|
|
156
129
|
onFocus: _propTypes.default.func,
|
|
157
|
-
|
|
158
130
|
/** Called with signature `({ name: string, files: [] }, event)` */
|
|
159
131
|
onKeyDown: _propTypes.default.func
|
|
160
132
|
};
|