@dhis2-ui/file-input 9.11.0 → 9.11.1-beta.1

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.
Files changed (82) hide show
  1. package/build/cjs/file-input/__tests__/file-input.test.js +1 -9
  2. package/build/cjs/file-input/features/accepts_multiple_files/index.js +1 -2
  3. package/build/cjs/file-input/features/can_be_blurred/index.js +1 -2
  4. package/build/cjs/file-input/features/can_be_changed/index.js +1 -2
  5. package/build/cjs/file-input/features/can_be_focused/index.js +1 -2
  6. package/build/cjs/file-input/features/common/index.js +0 -1
  7. package/build/cjs/file-input/file-input.e2e.stories.js +49 -0
  8. package/build/cjs/file-input/file-input.js +13 -44
  9. package/build/cjs/file-input/{file-input.stories.js → file-input.prod.stories.js} +29 -36
  10. package/build/cjs/file-input/index.js +0 -1
  11. package/build/cjs/file-input-field/__tests__/file-input-field.test.js +1 -9
  12. package/build/cjs/file-input-field/features/can_be_required/index.js +0 -1
  13. package/build/cjs/file-input-field/features/has_default_button_label/index.js +0 -1
  14. package/build/cjs/file-input-field/features/has_default_placeholder/index.js +0 -1
  15. package/build/cjs/file-input-field/file-input-field.e2e.stories.js +24 -0
  16. package/build/cjs/file-input-field/file-input-field.js +8 -36
  17. package/build/cjs/file-input-field/{file-input-field.stories.js → file-input-field.prod.stories.js} +33 -51
  18. package/build/cjs/file-input-field/index.js +0 -1
  19. package/build/cjs/file-input-field-with-list/__tests__/file-input-field-with-list.test.js +1 -9
  20. package/build/cjs/file-input-field-with-list/features/common/index.js +0 -1
  21. package/build/cjs/file-input-field-with-list/features/deduplicates_the_file_list/index.js +0 -1
  22. package/build/cjs/file-input-field-with-list/features/disables_button_when_full/index.js +0 -1
  23. package/build/cjs/file-input-field-with-list/features/displays_files_in_a_list/index.js +0 -1
  24. package/build/cjs/file-input-field-with-list/features/files_can_be_removed/index.js +0 -1
  25. package/build/cjs/file-input-field-with-list/features/has_default_button_label/index.js +0 -1
  26. package/build/cjs/file-input-field-with-list/features/has_default_placeholder/index.js +0 -1
  27. package/build/cjs/file-input-field-with-list/features/has_default_remove_text/index.js +0 -1
  28. package/build/cjs/file-input-field-with-list/file-input-field-with-list.e2e.stories.js +63 -0
  29. package/build/cjs/file-input-field-with-list/file-input-field-with-list.js +9 -47
  30. 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
  31. package/build/cjs/file-input-field-with-list/file-list-item-with-remove.js +7 -17
  32. package/build/cjs/file-input-field-with-list/index.js +0 -1
  33. package/build/cjs/file-list/features/accepts_cancel_text/index.js +1 -2
  34. package/build/cjs/file-list/features/accepts_label/index.js +0 -1
  35. package/build/cjs/file-list/features/accepts_remove_text/index.js +1 -2
  36. package/build/cjs/file-list/features/can_be_removed/index.js +1 -2
  37. package/build/cjs/file-list/features/file-list-item-accepts_children/index.js +0 -1
  38. package/build/cjs/file-list/features/file-list-placeholder-accepts_children/index.js +0 -1
  39. package/build/cjs/file-list/features/loading_can_be_cancelled/index.js +1 -2
  40. package/build/cjs/file-list/file-list-item.e2e.stories.js +49 -0
  41. package/build/cjs/file-list/file-list-item.js +5 -18
  42. package/build/cjs/file-list/file-list-placeholder.e2e.stories.js +14 -0
  43. package/build/cjs/file-list/file-list-placeholder.js +2 -9
  44. package/build/cjs/file-list/file-list.e2e.stories.js +14 -0
  45. package/build/cjs/file-list/file-list.js +1 -7
  46. package/build/cjs/file-list/index.js +0 -3
  47. package/build/cjs/index.js +0 -4
  48. package/build/cjs/locales/index.js +3 -73
  49. package/build/es/file-input/features/accepts_multiple_files/index.js +1 -1
  50. package/build/es/file-input/features/can_be_blurred/index.js +1 -1
  51. package/build/es/file-input/features/can_be_changed/index.js +1 -1
  52. package/build/es/file-input/features/can_be_focused/index.js +1 -1
  53. package/build/es/file-input/{file-input.stories.e2e.js → file-input.e2e.stories.js} +14 -9
  54. package/build/es/file-input/file-input.js +10 -31
  55. package/build/es/file-input/{file-input.stories.js → file-input.prod.stories.js} +23 -15
  56. package/build/es/file-input-field/file-input-field.e2e.stories.js +15 -0
  57. package/build/es/file-input-field/file-input-field.js +5 -23
  58. package/build/es/file-input-field/{file-input-field.stories.js → file-input-field.prod.stories.js} +21 -15
  59. 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
  60. package/build/es/file-input-field-with-list/file-input-field-with-list.js +8 -35
  61. 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
  62. package/build/es/file-input-field-with-list/file-list-item-with-remove.js +4 -8
  63. package/build/es/file-list/features/accepts_cancel_text/index.js +1 -1
  64. package/build/es/file-list/features/accepts_remove_text/index.js +1 -1
  65. package/build/es/file-list/features/can_be_removed/index.js +1 -1
  66. package/build/es/file-list/features/loading_can_be_cancelled/index.js +1 -1
  67. package/build/es/file-list/{file-list-item.stories.e2e.js → file-list-item.e2e.stories.js} +13 -7
  68. package/build/es/file-list/file-list-item.js +4 -9
  69. package/build/es/file-list/file-list-placeholder.e2e.stories.js +6 -0
  70. package/build/es/file-list/file-list-placeholder.js +1 -3
  71. package/build/es/file-list/file-list.e2e.stories.js +6 -0
  72. package/build/es/file-list/file-list.js +0 -2
  73. package/package.json +11 -11
  74. package/build/cjs/file-input/file-input.stories.e2e.js +0 -40
  75. package/build/cjs/file-input-field/file-input-field.stories.e2e.js +0 -19
  76. package/build/cjs/file-input-field-with-list/file-input-field-with-list.stories.e2e.js +0 -53
  77. package/build/cjs/file-list/file-list-item.stories.e2e.js +0 -38
  78. package/build/cjs/file-list/file-list-placeholder.stories.e2e.js +0 -11
  79. package/build/cjs/file-list/file-list.stories.e2e.js +0 -11
  80. package/build/es/file-input-field/file-input-field.stories.e2e.js +0 -12
  81. package/build/es/file-list/file-list-placeholder.stories.e2e.js +0 -4
  82. package/build/es/file-list/file-list.stories.e2e.js +0 -4
@@ -1,61 +1,52 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
-
3
- 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; }
4
-
5
- import { Button } from '@dhis2-ui/button';
6
- import { StatusIcon } from '@dhis2-ui/status-icon';
2
+ 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; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
+ 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); }
7
5
  import { colors, spacers, sharedPropTypes } from '@dhis2/ui-constants';
8
6
  import { IconUpload24 } from '@dhis2/ui-icons';
7
+ import { Button } from '@dhis2-ui/button';
8
+ import { StatusIcon } from '@dhis2-ui/status-icon';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
11
  import React, { createRef, Component } from 'react';
12
-
13
12
  class FileInput extends Component {
14
13
  constructor() {
15
14
  super(...arguments);
16
-
17
15
  _defineProperty(this, "ref", /*#__PURE__*/createRef());
18
-
19
16
  _defineProperty(this, "handleClick", () => {
20
17
  this.ref.current.click();
21
18
  });
22
-
23
19
  _defineProperty(this, "handleChange", e => {
24
20
  if (this.props.onChange) {
25
21
  this.props.onChange(this.createHandlerPayload(), e);
26
- } // reset the file input so it won't prevent on-change
27
- // if the same file was added in a second attempt
28
-
22
+ }
29
23
 
24
+ // reset the file input so it won't prevent on-change
25
+ // if the same file was added in a second attempt
30
26
  this.ref.current.value = '';
31
27
  });
32
-
33
28
  _defineProperty(this, "handleBlur", e => {
34
29
  if (this.props.onBlur) {
35
30
  this.props.onBlur(this.createHandlerPayload(), e);
36
31
  }
37
32
  });
38
-
39
33
  _defineProperty(this, "handleFocus", e => {
40
34
  if (this.props.onFocus) {
41
35
  this.props.onFocus(this.createHandlerPayload(), e);
42
36
  }
43
37
  });
44
-
45
38
  _defineProperty(this, "handleKeyDown", e => {
46
39
  if (this.props.onKeyDown) {
47
40
  this.props.onKeyDown(this.createHandlerPayload(), e);
48
41
  }
49
42
  });
50
43
  }
51
-
52
44
  createHandlerPayload() {
53
45
  return {
54
46
  files: this.ref.current.files,
55
47
  name: this.props.name
56
48
  };
57
49
  }
58
-
59
50
  render() {
60
51
  const {
61
52
  accept,
@@ -87,7 +78,7 @@ class FileInput extends Component {
87
78
  accept: accept,
88
79
  multiple: multiple,
89
80
  disabled: disabled,
90
- "data-test": "".concat(dataTest, "-input"),
81
+ "data-test": `${dataTest}-input`,
91
82
  className: _JSXStyle.dynamic([["1746996489", [spacers.dp8, spacers.dp4]]])
92
83
  }), /*#__PURE__*/React.createElement(Button, {
93
84
  disabled: disabled,
@@ -110,11 +101,9 @@ class FileInput extends Component {
110
101
  }), /*#__PURE__*/React.createElement(_JSXStyle, {
111
102
  id: "1746996489",
112
103
  dynamic: [spacers.dp8, spacers.dp4]
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:".concat(spacers.dp8, ";padding-bottom:").concat(spacers.dp4, ";}")]));
104
+ }, ["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:${spacers.dp8};padding-bottom:${spacers.dp4};}`]));
114
105
  }
115
-
116
106
  }
117
-
118
107
  FileInput.defaultProps = {
119
108
  accept: '*',
120
109
  dataTest: 'dhis2-uicore-fileinput'
@@ -128,39 +117,29 @@ FileInput.propTypes = {
128
117
  className: PropTypes.string,
129
118
  dataTest: PropTypes.string,
130
119
  disabled: PropTypes.bool,
131
-
132
120
  /** Input status. Mutually exclusive with `warning` and `valid` */
133
121
  error: sharedPropTypes.statusPropType,
134
122
  initialFocus: PropTypes.bool,
135
-
136
123
  /** Button size. Mutually exclusive with `small` */
137
124
  large: sharedPropTypes.sizePropType,
138
-
139
125
  /**
140
126
  * The `multiple` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple)
141
127
  */
142
128
  multiple: PropTypes.bool,
143
129
  name: PropTypes.string,
144
-
145
130
  /** Button size. Mutually exclusive with `large` */
146
131
  small: sharedPropTypes.sizePropType,
147
132
  tabIndex: PropTypes.string,
148
-
149
133
  /** Input status. Mutually exclusive with `warning` and `error` */
150
134
  valid: sharedPropTypes.statusPropType,
151
-
152
135
  /** Input status. Mutually exclusive with `valid` and `error` */
153
136
  warning: sharedPropTypes.statusPropType,
154
-
155
137
  /** Called with signature `(object, event)` */
156
138
  onBlur: PropTypes.func,
157
-
158
139
  /** Called with signature `(object, event)` */
159
140
  onChange: PropTypes.func,
160
-
161
141
  /** Called with signature `(object, event)` */
162
142
  onFocus: PropTypes.func,
163
-
164
143
  /** Called with signature `(object, event)` */
165
144
  onKeyDown: PropTypes.func
166
145
  };
@@ -1,21 +1,26 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
1
+ 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); }
3
2
  import { sharedPropTypes } from '@dhis2/ui-constants';
4
3
  import React from 'react';
5
4
  import { FileInput } from './index.js';
6
- const subtitle = "The file input component allows users to select and upload files from their local machine.";
7
- const description = "\nUse 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.\n\n```js\nimport { FileInput } from '@dhis2/ui'\n```\n";
5
+ const subtitle = `The file input component allows users to select and upload files from their local machine.`;
6
+ const description = `
7
+ 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.
8
8
 
9
+ \`\`\`js
10
+ import { FileInput } from '@dhis2/ui'
11
+ \`\`\`
12
+ `;
9
13
  const onChange = (payload, event) => {
10
14
  console.log('onChange payload', payload);
11
- console.log('onChange event', event); // NOTE: if files is not transformed into an array,
12
- // cypress will get an empty file list!
15
+ console.log('onChange event', event);
13
16
 
14
- window.onChange && window.onChange({ ...payload,
17
+ // NOTE: if files is not transformed into an array,
18
+ // cypress will get an empty file list!
19
+ window.onChange && window.onChange({
20
+ ...payload,
15
21
  files: [...payload.files]
16
22
  }, event);
17
23
  };
18
-
19
24
  const {
20
25
  sizeArgType,
21
26
  statusArgType
@@ -30,15 +35,20 @@ export default {
30
35
  onChange
31
36
  },
32
37
  argTypes: {
33
- valid: { ...statusArgType
38
+ valid: {
39
+ ...statusArgType
34
40
  },
35
- warning: { ...statusArgType
41
+ warning: {
42
+ ...statusArgType
36
43
  },
37
- error: { ...statusArgType
44
+ error: {
45
+ ...statusArgType
38
46
  },
39
- small: { ...sizeArgType
47
+ small: {
48
+ ...sizeArgType
40
49
  },
41
- large: { ...sizeArgType
50
+ large: {
51
+ ...sizeArgType
42
52
  }
43
53
  },
44
54
  parameters: {
@@ -50,9 +60,7 @@ export default {
50
60
  }
51
61
  }
52
62
  };
53
-
54
63
  const Template = args => /*#__PURE__*/React.createElement(FileInput, args);
55
-
56
64
  export const Default = Template.bind({});
57
65
  export const Multiple = Template.bind({});
58
66
  Multiple.args = {
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { FileInputField } from './file-input-field.js';
3
+ export default {
4
+ title: 'FileInputField'
5
+ };
6
+ export const WithLabelAndRequired = () => /*#__PURE__*/React.createElement(FileInputField, {
7
+ name: "upload",
8
+ label: "upload something",
9
+ buttonLabel: "Upload file",
10
+ required: true
11
+ });
12
+ export const Default = () => /*#__PURE__*/React.createElement(FileInputField, {
13
+ name: "upload",
14
+ label: "upload something"
15
+ });
@@ -1,19 +1,19 @@
1
+ import { sharedPropTypes } from '@dhis2/ui-constants';
1
2
  import { Field } from '@dhis2-ui/field';
2
3
  import { Label } from '@dhis2-ui/label';
3
- import { sharedPropTypes } from '@dhis2/ui-constants';
4
4
  import PropTypes from 'prop-types';
5
5
  import React from 'react';
6
- import { FileInput, FileList, FileListPlaceholder } from '../index.js';
7
- import i18n from '../locales/index.js'; // TODO: i18n
6
+ import { FileInput } from '../file-input/index.js';
7
+ import { FileList, FileListPlaceholder } from '../file-list/index.js';
8
+ import i18n from '../locales/index.js';
8
9
 
10
+ // TODO: i18n
9
11
  const translate = (prop, interpolationObject) => {
10
12
  if (typeof prop === 'function') {
11
13
  return prop(interpolationObject);
12
14
  }
13
-
14
15
  return prop;
15
16
  };
16
-
17
17
  const FileInputField = _ref => {
18
18
  let {
19
19
  accept,
@@ -73,7 +73,6 @@ const FileInputField = _ref => {
73
73
  warning: warning
74
74
  }), /*#__PURE__*/React.createElement(FileList, null, children ? children : /*#__PURE__*/React.createElement(FileListPlaceholder, null, translate(placeholder))));
75
75
  };
76
-
77
76
  FileInputField.defaultProps = {
78
77
  accept: '*',
79
78
  dataTest: 'dhis2-uiwidgets-fileinputfield',
@@ -83,61 +82,44 @@ FileInputField.defaultProps = {
83
82
  FileInputField.propTypes = {
84
83
  /** The `accept` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) */
85
84
  accept: PropTypes.string,
86
-
87
85
  /** Text on the button */
88
86
  buttonLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
89
87
  children: PropTypes.node,
90
88
  className: PropTypes.string,
91
89
  dataTest: PropTypes.string,
92
-
93
90
  /** Disables the button */
94
91
  disabled: PropTypes.bool,
95
-
96
92
  /** Applies 'error' styling to the validation text. Mutually exclusive with `warning` and `valid` props */
97
93
  error: sharedPropTypes.statusPropType,
98
-
99
94
  /** Useful guiding text for the user */
100
95
  helpText: PropTypes.string,
101
96
  initialFocus: PropTypes.bool,
102
-
103
97
  /** A descriptive label above the button */
104
98
  label: PropTypes.string,
105
-
106
99
  /** Size of the button. Mutually exclusive with the `small` prop */
107
100
  large: sharedPropTypes.sizePropType,
108
-
109
101
  /** The `multiple` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple) */
110
102
  multiple: PropTypes.bool,
111
-
112
103
  /** Name associated with input. Passed to event handler callbacks */
113
104
  name: PropTypes.string,
114
-
115
105
  /** Placeholder below the button */
116
106
  placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
117
-
118
107
  /** Adds an asterisk to indicate this field is required */
119
108
  required: PropTypes.bool,
120
-
121
109
  /** Size of the button. Mutually exclusive with the `large` prop */
122
110
  small: sharedPropTypes.sizePropType,
123
111
  tabIndex: PropTypes.string,
124
-
125
112
  /** Applies 'valid' styling to the validation text. Mutually exclusive with `warning` and `error` props */
126
113
  valid: sharedPropTypes.statusPropType,
127
-
128
114
  /** Text below the button that provides validation feedback */
129
115
  validationText: PropTypes.string,
130
-
131
116
  /** Applies 'warning' styling to the validation text. Mutually exclusive with `valid` and `error` props */
132
117
  warning: sharedPropTypes.statusPropType,
133
118
  onBlur: PropTypes.func,
134
-
135
119
  /** Called with signature `({ name: string, files: [] }, event)` */
136
120
  onChange: PropTypes.func,
137
-
138
121
  /** Called with signature `({ name: string, files: [] }, event)` */
139
122
  onFocus: PropTypes.func,
140
-
141
123
  /** Called with signature `({ name: string, files: [] }, event)` */
142
124
  onKeyDown: PropTypes.func
143
125
  };
@@ -1,17 +1,18 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
1
+ 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); }
3
2
  import { sharedPropTypes } from '@dhis2/ui-constants';
4
3
  import React from 'react';
5
4
  import { FileListItem } from '../index.js';
6
5
  import { FileInputField } from './file-input-field.js';
7
- const description = "\nThe `FileInputField` component wraps the `FileInput` component in a `Field` wrapper to add labels, help text, and validation text.\n\n```js\nimport { FileInputField, FileListItem } from '@dhis2/ui'\n```\n";
6
+ const description = `
7
+ The \`FileInputField\` component wraps the \`FileInput\` component in a \`Field\` wrapper to add labels, help text, and validation text.
8
8
 
9
+ \`\`\`js
10
+ import { FileInputField, FileListItem } from '@dhis2/ui'
11
+ \`\`\`
12
+ `;
9
13
  const onChange = obj => console.log('onChange', obj);
10
-
11
14
  const onRemove = () => console.log('onRemove');
12
-
13
15
  const onCancel = () => console.log('onCancel');
14
-
15
16
  export default {
16
17
  title: 'File Input Field',
17
18
  component: FileInputField,
@@ -23,28 +24,32 @@ export default {
23
24
  }
24
25
  },
25
26
  // Default args:
26
- args: { // Handle default values (see comment in Transfer.js)
27
+ args: {
28
+ // Handle default values (see comment in Transfer.js)
27
29
  ...FileInputField.defaultProps,
28
30
  onChange: onChange,
29
31
  name: 'uploadName',
30
32
  label: 'Upload something'
31
33
  },
32
34
  argTypes: {
33
- small: { ...sharedPropTypes.sizeArgType
35
+ small: {
36
+ ...sharedPropTypes.sizeArgType
34
37
  },
35
- large: { ...sharedPropTypes.sizeArgType
38
+ large: {
39
+ ...sharedPropTypes.sizeArgType
36
40
  },
37
- valid: { ...sharedPropTypes.statusArgType
41
+ valid: {
42
+ ...sharedPropTypes.statusArgType
38
43
  },
39
- warning: { ...sharedPropTypes.statusArgType
44
+ warning: {
45
+ ...sharedPropTypes.statusArgType
40
46
  },
41
- error: { ...sharedPropTypes.statusArgType
47
+ error: {
48
+ ...sharedPropTypes.statusArgType
42
49
  }
43
50
  }
44
51
  };
45
-
46
52
  const Template = args => /*#__PURE__*/React.createElement(FileInputField, args);
47
-
48
53
  export const Default = Template.bind({});
49
54
  Default.args = {
50
55
  label: null
@@ -148,7 +153,8 @@ DesignSystemStackingOrder.args = {
148
153
  helpText: 'Please upload something'
149
154
  };
150
155
  export const DesignSystemStackingOrderEmptyFileList = Template.bind({});
151
- DesignSystemStackingOrderEmptyFileList.args = { ...DesignSystemStackingOrder.args
156
+ DesignSystemStackingOrderEmptyFileList.args = {
157
+ ...DesignSystemStackingOrder.args
152
158
  };
153
159
  DesignSystemStackingOrderEmptyFileList.storyName = 'Design system stacking order - empty file list';
154
160
  export const DefaultButtonLabelAndPlaceholder = Template.bind({});
@@ -1,4 +1,3 @@
1
- import { storiesOf } from '@storybook/react';
2
1
  import React from 'react';
3
2
  import { FileInputFieldWithList } from './index.js';
4
3
  window.onChange = window.Cypress && window.Cypress.cy.stub();
@@ -8,39 +7,45 @@ window.duplicateFileConstructorArgs = [[], 'duplicate.md', {
8
7
  type: 'text/markdown'
9
8
  }];
10
9
  const multipleFileArray = [new File([], 'test1.md'), new File(...window.duplicateFileConstructorArgs), new File([], 'test2.md')];
11
-
12
10
  const onChange = (payload, event) => {
13
11
  // NOTE: if files is not transformed into an array,
14
12
  // cypress will get an empty file list!
15
- window.onChange({ ...payload,
13
+ window.onChange({
14
+ ...payload,
16
15
  files: [...payload.files]
17
16
  }, event);
18
17
  };
19
-
20
- storiesOf('FileInputFieldWithList', module).add('Single file - with file', () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
18
+ export default {
19
+ title: 'FileInputFieldWithList'
20
+ };
21
+ export const SingleFileWithFile = () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
21
22
  buttonLabel: "Upload file",
22
23
  name: "upload",
23
24
  files: singleFileArray,
24
25
  removeText: "remove",
25
26
  onChange: onChange
26
- })).add('Multiple files - empty', () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
27
+ });
28
+ export const MultipleFilesEmpty = () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
27
29
  buttonLabel: "Upload file",
28
30
  multiple: true,
29
31
  name: "upload",
30
32
  removeText: "remove",
31
33
  onChange: onChange
32
- })).add('Multiple files - with files', () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
34
+ });
35
+ export const MultipleFilesWithFiles = () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
33
36
  buttonLabel: "Upload file",
34
37
  multiple: true,
35
38
  name: "upload",
36
39
  files: multipleFileArray,
37
40
  removeText: "remove",
38
41
  onChange: onChange
39
- })).add('With file and default texts', () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
42
+ });
43
+ export const WithFileAndDefaultTexts = () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
40
44
  name: "upload",
41
45
  files: singleFileArray,
42
46
  onChange: onChange
43
- })).add('With default texts', () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
47
+ });
48
+ export const WithDefaultTexts = () => /*#__PURE__*/React.createElement(FileInputFieldWithList, {
44
49
  name: "upload",
45
50
  onChange: onChange
46
- }));
51
+ });
@@ -1,24 +1,23 @@
1
- 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; }
2
-
1
+ 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; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ 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); }
3
4
  import { sharedPropTypes } from '@dhis2/ui-constants';
4
5
  import PropTypes from 'prop-types';
5
6
  import React, { Component } from 'react';
6
- import { FileInputField } from '../index.js';
7
+ import { FileInputField } from '../file-input-field/index.js';
7
8
  import i18n from '../locales/index.js';
8
- import { FileListItemWithRemove } from './file-list-item-with-remove.js'; // TODO: i18n
9
+ import { FileListItemWithRemove } from './file-list-item-with-remove.js';
9
10
 
11
+ // TODO: i18n
10
12
  const translate = (prop, interpolationObject) => {
11
13
  if (typeof prop === 'function') {
12
14
  return prop(interpolationObject);
13
15
  }
14
-
15
16
  return prop;
16
17
  };
17
-
18
18
  class FileInputFieldWithList extends Component {
19
19
  constructor() {
20
20
  super(...arguments);
21
-
22
21
  _defineProperty(this, "handleChange", (_ref, event) => {
23
22
  let {
24
23
  files: fileList
@@ -32,7 +31,6 @@ class FileInputFieldWithList extends Component {
32
31
  name: name
33
32
  }, event);
34
33
  });
35
-
36
34
  _defineProperty(this, "handleRemove", (_ref2, event) => {
37
35
  let {
38
36
  file: fileToRemove
@@ -48,7 +46,6 @@ class FileInputFieldWithList extends Component {
48
46
  }, event);
49
47
  });
50
48
  }
51
-
52
49
  /**
53
50
  * @param {FileList} fileList
54
51
  * @returns {File[]}
@@ -57,17 +54,14 @@ class FileInputFieldWithList extends Component {
57
54
  const {
58
55
  multiple,
59
56
  files
60
- } = this.props; // Spread immutable FileList instance onto array
61
-
57
+ } = this.props;
58
+ // Spread immutable FileList instance onto array
62
59
  const newFiles = [...fileList];
63
-
64
60
  if (!multiple) {
65
61
  return newFiles;
66
62
  }
67
-
68
63
  return files.filter(file => !newFiles.some(x => x.name === file.name && x.lastModified === file.lastModified && x.size === file.size && x.type === file.type)).concat(newFiles);
69
64
  }
70
-
71
65
  render() {
72
66
  const {
73
67
  accept,
@@ -127,9 +121,7 @@ class FileInputFieldWithList extends Component {
127
121
  file: file
128
122
  })));
129
123
  }
130
-
131
124
  }
132
-
133
125
  FileInputFieldWithList.defaultProps = {
134
126
  dataTest: 'dhis2-uiwidgets-fileinputfieldwithlist',
135
127
  files: [],
@@ -140,66 +132,47 @@ FileInputFieldWithList.defaultProps = {
140
132
  FileInputFieldWithList.propTypes = {
141
133
  /** Called with signature `({ name: string, files: [File] }, event)` */
142
134
  onChange: PropTypes.func.isRequired,
143
-
144
135
  /** The `accept` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) */
145
136
  accept: PropTypes.string,
146
-
147
137
  /** Text on the button */
148
138
  buttonLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
149
139
  className: PropTypes.string,
150
140
  dataTest: PropTypes.string,
151
-
152
141
  /** Disables the button */
153
142
  disabled: PropTypes.bool,
154
-
155
143
  /** Applies 'error' styling to the button and validation text. Mutually exclusive with `warning` and `valid` props */
156
144
  error: sharedPropTypes.statusPropType,
157
145
  files: PropTypes.arrayOf(PropTypes.instanceOf(File)),
158
-
159
146
  /** Useful guiding text for the user */
160
147
  helpText: PropTypes.string,
161
148
  initialFocus: PropTypes.bool,
162
-
163
149
  /** A descriptive label above the button */
164
150
  label: PropTypes.string,
165
-
166
151
  /** Size of the button. Mutually exclusive with the `small` prop */
167
152
  large: sharedPropTypes.sizePropType,
168
-
169
153
  /** The `multiple` attribute of the [native file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple) */
170
154
  multiple: PropTypes.bool,
171
-
172
155
  /** Name associated with input. Passed to event handler callbacks */
173
156
  name: PropTypes.string,
174
-
175
157
  /** Placeholder below the button */
176
158
  placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
177
-
178
159
  /** Text used for the button that removes a file from the list */
179
160
  removeText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
180
-
181
161
  /** Adds an asterisk to indicate this field is required */
182
162
  required: PropTypes.bool,
183
-
184
163
  /** Size of the button. Mutually exclusive with the `large` prop */
185
164
  small: sharedPropTypes.sizePropType,
186
165
  tabIndex: PropTypes.string,
187
-
188
166
  /** Applies 'valid' styling to the button and validation text. Mutually exclusive with `warning` and `error` props */
189
167
  valid: sharedPropTypes.statusPropType,
190
-
191
168
  /** Text below the button that provides validation feedback */
192
169
  validationText: PropTypes.string,
193
-
194
170
  /** Applies 'warning' styling to the button and validation text. Mutually exclusive with `valid` and `error` props */
195
171
  warning: sharedPropTypes.statusPropType,
196
-
197
172
  /** Called with signature `({ name: string, files: [] }, event)` */
198
173
  onBlur: PropTypes.func,
199
-
200
174
  /** Called with signature `({ name: string, files: [] }, event)` */
201
175
  onFocus: PropTypes.func,
202
-
203
176
  /** Called with signature `({ name: string, files: [] }, event)` */
204
177
  onKeyDown: PropTypes.func
205
178
  };
@@ -1,16 +1,20 @@
1
1
  import { sharedPropTypes } from '@dhis2/ui-constants';
2
2
  import React from 'react';
3
3
  import { FileInputFieldWithList } from './file-input-field-with-list.js';
4
- const description = "\nA FileInputField with logic for creating a dynamic list of removable files from an array of `File` objects.\n\n```js\nimport { FileInputFieldWithList } from '@dhis2/ui'\n```\n";
5
- const files = new Array(10).fill('dummy-file-name').map((name, i) => new File([], "".concat(name, "-").concat(i + 1, ".txt")));
4
+ const description = `
5
+ A FileInputField with logic for creating a dynamic list of removable files from an array of \`File\` objects.
6
6
 
7
+ \`\`\`js
8
+ import { FileInputFieldWithList } from '@dhis2/ui'
9
+ \`\`\`
10
+ `;
11
+ const files = new Array(10).fill('dummy-file-name').map((name, i) => new File([], `${name}-${i + 1}.txt`));
7
12
  const onChange = _ref => {
8
13
  let {
9
14
  files
10
15
  } = _ref;
11
16
  console.log('files: ', files);
12
17
  };
13
-
14
18
  export default {
15
19
  title: 'File Input Field With List',
16
20
  component: FileInputFieldWithList,
@@ -21,28 +25,32 @@ export default {
21
25
  }
22
26
  }
23
27
  },
24
- args: { // Handle default props bug (see Transfer stories)
28
+ args: {
29
+ // Handle default props bug (see Transfer stories)
25
30
  ...FileInputFieldWithList.defaultProps,
26
31
  multiple: true,
27
32
  onChange: onChange,
28
33
  name: 'uploadName'
29
34
  },
30
35
  argTypes: {
31
- small: { ...sharedPropTypes.sizeArgType
36
+ small: {
37
+ ...sharedPropTypes.sizeArgType
32
38
  },
33
- large: { ...sharedPropTypes.sizeArgType
39
+ large: {
40
+ ...sharedPropTypes.sizeArgType
34
41
  },
35
- valid: { ...sharedPropTypes.statusArgType
42
+ valid: {
43
+ ...sharedPropTypes.statusArgType
36
44
  },
37
- warning: { ...sharedPropTypes.statusArgType
45
+ warning: {
46
+ ...sharedPropTypes.statusArgType
38
47
  },
39
- error: { ...sharedPropTypes.statusArgType
48
+ error: {
49
+ ...sharedPropTypes.statusArgType
40
50
  }
41
51
  }
42
52
  };
43
-
44
53
  const Template = args => /*#__PURE__*/React.createElement(FileInputFieldWithList, args);
45
-
46
54
  export const Default = Template.bind({});
47
55
  Default.args = {
48
56
  buttonLabel: 'Upload file (custom label)',