@pingux/astro 0.41.0 → 1.0.0-alpha.10

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 (64) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.js +1 -1
  3. package/lib/cjs/components/AccordionItem/AccordionItem.js +3 -1
  4. package/lib/cjs/components/CopyText/CopyText.js +3 -73
  5. package/lib/cjs/components/FileInputField/FileInputField.js +324 -0
  6. package/lib/cjs/components/FileInputField/FileInputField.stories.js +250 -0
  7. package/lib/cjs/components/FileInputField/FileInputField.test.js +227 -0
  8. package/lib/cjs/components/FileInputField/FileItem.js +125 -0
  9. package/lib/cjs/components/FileInputField/FileSelect.js +48 -0
  10. package/lib/cjs/components/FileInputField/index.js +18 -0
  11. package/lib/cjs/components/ListView/ListView.js +2 -1
  12. package/lib/cjs/components/ListViewItem/ListViewItem.js +14 -6
  13. package/lib/cjs/components/NumberField/NumberField.js +4 -2
  14. package/lib/cjs/components/NumberField/NumberField.test.js +15 -0
  15. package/lib/cjs/components/Tab/Tab.js +11 -4
  16. package/lib/cjs/components/Tabs/Tabs.js +7 -1
  17. package/lib/cjs/components/Tabs/Tabs.stories.js +60 -6
  18. package/lib/cjs/components/Tabs/Tabs.test.js +78 -15
  19. package/lib/cjs/hooks/useCopyToClipboard/index.js +18 -0
  20. package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +83 -0
  21. package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.test.js +79 -0
  22. package/lib/cjs/index.js +10 -0
  23. package/lib/cjs/recipes/ApplicationSearchDropdown.stories.js +310 -0
  24. package/lib/cjs/recipes/CopyToClipboard.stories.js +45 -0
  25. package/lib/cjs/recipes/RadioButtonsWithLinks.stories.js +146 -0
  26. package/lib/cjs/recipes/RowLineChart.stories.js +6 -1
  27. package/lib/cjs/recipes/ScrollableListView.stories.js +1 -1
  28. package/lib/cjs/styles/forms/input.js +11 -0
  29. package/lib/cjs/styles/variants/accordion.js +2 -2
  30. package/lib/cjs/styles/variants/boxes.js +23 -0
  31. package/lib/cjs/styles/variants/buttons.js +56 -1
  32. package/lib/cjs/styles/variants/tabs.js +1 -0
  33. package/lib/components/AccordionGridGroup/AccordionGridGroup.js +1 -1
  34. package/lib/components/AccordionItem/AccordionItem.js +3 -1
  35. package/lib/components/CopyText/CopyText.js +2 -71
  36. package/lib/components/FileInputField/FileInputField.js +280 -0
  37. package/lib/components/FileInputField/FileInputField.stories.js +206 -0
  38. package/lib/components/FileInputField/FileInputField.test.js +187 -0
  39. package/lib/components/FileInputField/FileItem.js +100 -0
  40. package/lib/components/FileInputField/FileSelect.js +31 -0
  41. package/lib/components/FileInputField/index.js +1 -0
  42. package/lib/components/ListView/ListView.js +2 -1
  43. package/lib/components/ListViewItem/ListViewItem.js +14 -6
  44. package/lib/components/NumberField/NumberField.js +4 -2
  45. package/lib/components/NumberField/NumberField.test.js +9 -0
  46. package/lib/components/Tab/Tab.js +11 -4
  47. package/lib/components/Tabs/Tabs.js +7 -1
  48. package/lib/components/Tabs/Tabs.stories.js +56 -4
  49. package/lib/components/Tabs/Tabs.test.js +78 -15
  50. package/lib/hooks/useCopyToClipboard/index.js +1 -0
  51. package/lib/hooks/useCopyToClipboard/useCopyToClipboard.js +69 -0
  52. package/lib/hooks/useCopyToClipboard/useCopyToClipboard.test.js +64 -0
  53. package/lib/index.js +1 -0
  54. package/lib/recipes/ApplicationSearchDropdown.stories.js +272 -0
  55. package/lib/recipes/CopyToClipboard.stories.js +25 -0
  56. package/lib/recipes/RadioButtonsWithLinks.stories.js +120 -0
  57. package/lib/recipes/RowLineChart.stories.js +6 -1
  58. package/lib/recipes/ScrollableListView.stories.js +1 -1
  59. package/lib/styles/forms/input.js +11 -0
  60. package/lib/styles/variants/accordion.js +2 -2
  61. package/lib/styles/variants/boxes.js +23 -0
  62. package/lib/styles/variants/buttons.js +56 -1
  63. package/lib/styles/variants/tabs.js +1 -0
  64. package/package.json +3 -2
@@ -40,7 +40,7 @@ export var collectionTypes = {
40
40
  * which will be control expansion of the body, and 2) a Body which renders non-interactive content.
41
41
  * The purpose of this component is to allow keyboard interaction
42
42
  * with children passed into the Body and Header
43
- * If a more simple implementation is desired, please consider the AccordionGroup
43
+ * If a more simple implementation is desired, please consider the AccordionGroup.
44
44
  */
45
45
 
46
46
  var AccordionGridGroup = /*#__PURE__*/forwardRef(function (props, ref) {
@@ -80,7 +80,9 @@ var AccordionItem = /*#__PURE__*/forwardRef(function (props, ref) {
80
80
  "aria-label": ariaLabel || 'Accordion',
81
81
  ref: buttonRef,
82
82
  sx: {
83
- display: 'flex'
83
+ display: 'flex',
84
+ px: '0',
85
+ height: 'unset'
84
86
  },
85
87
  variant: "accordionHeader",
86
88
  className: buttonClasses
@@ -1,6 +1,4 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
3
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
4
2
  import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
5
3
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
6
4
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
@@ -11,6 +9,7 @@ import { Pressable, useHover } from '@react-aria/interactions';
11
9
  import { mergeProps } from '@react-aria/utils';
12
10
  import { Box, Button, Tooltip, TooltipTrigger } from '../../index';
13
11
  import CopyButton from './CopyButton';
12
+ import useCopyToClipboard from '../../hooks/useCopyToClipboard';
14
13
  import { jsx as ___EmotionJSX } from "@emotion/react";
15
14
 
16
15
  var TooltipWrapper = function TooltipWrapper(_ref) {
@@ -75,75 +74,7 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
75
74
 
76
75
  return undefined;
77
76
  }, [isCopied]);
78
-
79
- var copyToClipboard = /*#__PURE__*/function () {
80
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
81
- var textArea, isSuccessful;
82
- return _regeneratorRuntime.wrap(function _callee$(_context) {
83
- while (1) {
84
- switch (_context.prev = _context.next) {
85
- case 0:
86
- _context.prev = 0;
87
-
88
- if (!navigator.clipboard) {
89
- _context.next = 7;
90
- break;
91
- }
92
-
93
- _context.next = 4;
94
- return navigator.clipboard.writeText(value);
95
-
96
- case 4:
97
- setIsCopied(true);
98
- _context.next = 20;
99
- break;
100
-
101
- case 7:
102
- // Workaround for copying in insecure origin
103
- textArea = document.createElement('textarea');
104
- textArea.value = value;
105
- textArea.style.position = 'fixed';
106
- document.body.appendChild(textArea);
107
- textArea.focus();
108
- textArea.select();
109
- isSuccessful = document.execCommand('copy');
110
- textArea.remove();
111
-
112
- if (!isSuccessful) {
113
- _context.next = 19;
114
- break;
115
- }
116
-
117
- setIsCopied(isSuccessful);
118
- _context.next = 20;
119
- break;
120
-
121
- case 19:
122
- throw new Error('Unable to copy message');
123
-
124
- case 20:
125
- _context.next = 25;
126
- break;
127
-
128
- case 22:
129
- _context.prev = 22;
130
- _context.t0 = _context["catch"](0);
131
- // eslint-disable-next-line no-console
132
- console.error('Failed to copy: ', _context.t0);
133
-
134
- case 25:
135
- case "end":
136
- return _context.stop();
137
- }
138
- }
139
- }, _callee, null, [[0, 22]]);
140
- }));
141
-
142
- return function copyToClipboard() {
143
- return _ref2.apply(this, arguments);
144
- };
145
- }();
146
-
77
+ var copyToClipboard = useCopyToClipboard(value, setIsCopied);
147
78
  var content = mode === 'link' ? children : ___EmotionJSX(Button, _extends({
148
79
  variant: "quiet",
149
80
  onPress: copyToClipboard,
@@ -0,0 +1,280 @@
1
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
2
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
3
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
4
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
5
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
6
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
7
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
8
+ import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
9
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
10
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
11
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
12
+ import _URL from "@babel/runtime-corejs3/core-js-stable/url";
13
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
14
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
15
+ import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
16
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
17
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
18
+ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source), true)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
+
24
+ import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState } from 'react';
25
+ import { useVisuallyHidden } from '@react-aria/visually-hidden';
26
+ import { useDropzone } from 'react-dropzone';
27
+ import PropTypes from 'prop-types';
28
+ import { mergeProps } from '@react-aria/utils';
29
+ import { v4 as uuidv4 } from 'uuid';
30
+ import { Box, Input, FieldHelperText, Label, Loader } from '../../index';
31
+ import FileItem from './FileItem';
32
+ import FileSelect from './FileSelect';
33
+ import useStatusClasses from '../../hooks/useStatusClasses';
34
+ import useField from '../../hooks/useField';
35
+ import statuses from '../../utils/devUtils/constants/statuses';
36
+ /**
37
+ * The FileInputField component allows users to upload one or more files by
38
+ * clicking the button or via drag and drop.
39
+ *
40
+ * We utilize [react-dropzone](https://react-dropzone.js.org/) for the drag and drop functionality.
41
+ * */
42
+
43
+ import { jsx as ___EmotionJSX } from "@emotion/react";
44
+ var FileInputField = /*#__PURE__*/forwardRef(function (props, ref) {
45
+ var defaultButtonText = props.defaultButtonText,
46
+ defaultFileList = props.defaultFileList,
47
+ uploadedFilesImperative = props.fileList,
48
+ helperText = props.helperText,
49
+ isDisabled = props.isDisabled,
50
+ isLoading = props.isLoading,
51
+ isMultiple = props.isMultiple,
52
+ onFileSelect = props.onFileSelect,
53
+ onRemove = props.onRemove,
54
+ status = props.status,
55
+ textProps = props.textProps,
56
+ others = _objectWithoutProperties(props, ["defaultButtonText", "defaultFileList", "fileList", "helperText", "isDisabled", "isLoading", "isMultiple", "onFileSelect", "onRemove", "status", "textProps"]);
57
+
58
+ var _useState = useState(defaultFileList || []),
59
+ _useState2 = _slicedToArray(_useState, 2),
60
+ uploadedFiles = _useState2[0],
61
+ setUploadedFiles = _useState2[1];
62
+
63
+ var inputRef = useRef();
64
+ /* istanbul ignore next */
65
+
66
+ useImperativeHandle(ref, function () {
67
+ return inputRef.current;
68
+ });
69
+
70
+ var _useField = useField(_objectSpread({
71
+ status: status,
72
+ isDisabled: isDisabled
73
+ }, others)),
74
+ fieldContainerProps = _useField.fieldContainerProps,
75
+ fieldControlProps = _useField.fieldControlProps,
76
+ fieldLabelProps = _useField.fieldLabelProps;
77
+
78
+ var _useVisuallyHidden = useVisuallyHidden(),
79
+ visuallyHiddenProps = _useVisuallyHidden.visuallyHiddenProps;
80
+
81
+ var handleFileSelect = useCallback(function () {
82
+ inputRef.current.value = null;
83
+ inputRef.current.click();
84
+ }, [inputRef]);
85
+ var handleFileUpload = useCallback(function (event, newFiles) {
86
+ if (onFileSelect) {
87
+ onFileSelect(event, newFiles);
88
+ }
89
+
90
+ var arrayWithNewFiles = _Array$from(newFiles);
91
+
92
+ if (!isMultiple) {
93
+ arrayWithNewFiles = _sliceInstanceProperty(arrayWithNewFiles).call(arrayWithNewFiles, 0, 1);
94
+ }
95
+
96
+ var newFilesWithIdAndLink = _mapInstanceProperty(arrayWithNewFiles).call(arrayWithNewFiles, function (newFile) {
97
+ return {
98
+ fileObj: newFile,
99
+ name: newFile.name,
100
+ id: uuidv4(),
101
+ downloadLink: _URL.createObjectURL(newFile),
102
+ status: statuses.DEFAULT
103
+ };
104
+ });
105
+
106
+ if (isMultiple) {
107
+ setUploadedFiles(function (prevFiles) {
108
+ var _context;
109
+
110
+ return _concatInstanceProperty(_context = []).call(_context, prevFiles, newFilesWithIdAndLink);
111
+ });
112
+ } else {
113
+ setUploadedFiles(newFilesWithIdAndLink);
114
+ }
115
+ }, [isMultiple, onFileSelect]);
116
+ var onDrop = useCallback(function (acceptedFiles, fileRejections, event) {
117
+ handleFileUpload(event, acceptedFiles);
118
+ }, [handleFileUpload]);
119
+
120
+ var _useDropzone = useDropzone({
121
+ onDrop: onDrop,
122
+ noKeyboard: true,
123
+ disabled: isDisabled || isLoading
124
+ }),
125
+ getRootProps = _useDropzone.getRootProps,
126
+ getInputProps = _useDropzone.getInputProps,
127
+ isDragActive = _useDropzone.isDragActive;
128
+
129
+ var handleOnChange = useCallback(function (event) {
130
+ handleFileUpload(event, event.target.files);
131
+ }, [handleFileUpload]);
132
+ var handleFileDelete = useCallback(function (e, fileId) {
133
+ if (onRemove) {
134
+ onRemove(e, fileId);
135
+ }
136
+
137
+ setUploadedFiles(function (prevFiles) {
138
+ return _filterInstanceProperty(prevFiles).call(prevFiles, function (_ref) {
139
+ var id = _ref.id;
140
+ return id !== fileId;
141
+ });
142
+ });
143
+ }, [onRemove]);
144
+ var filesListNode = useMemo(function () {
145
+ var filesToRender = uploadedFilesImperative || uploadedFiles;
146
+
147
+ if (!(filesToRender === null || filesToRender === void 0 ? void 0 : filesToRender.length)) {
148
+ return null;
149
+ }
150
+
151
+ return _mapInstanceProperty(filesToRender).call(filesToRender, function (fileProps) {
152
+ return ___EmotionJSX(FileItem, _extends({
153
+ handleFileDelete: handleFileDelete,
154
+ isDisabled: isDisabled || isLoading,
155
+ key: fileProps.id,
156
+ textProps: textProps
157
+ }, fileProps));
158
+ });
159
+ }, [uploadedFilesImperative, uploadedFiles, handleFileDelete, isDisabled, isLoading, textProps]);
160
+
161
+ var _useStatusClasses = useStatusClasses('fileInputFieldWrapper', _defineProperty({
162
+ isDragActive: isDragActive,
163
+ isLoading: isLoading
164
+ }, "is-".concat(status), true)),
165
+ classNames = _useStatusClasses.classNames;
166
+
167
+ var shouldFileSelectRender = useCallback(function () {
168
+ var isFileUploaded;
169
+
170
+ if (uploadedFilesImperative) {
171
+ isFileUploaded = Boolean(uploadedFilesImperative === null || uploadedFilesImperative === void 0 ? void 0 : uploadedFilesImperative.length);
172
+ } else {
173
+ isFileUploaded = Boolean(uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.length);
174
+ }
175
+
176
+ return isMultiple || !isFileUploaded;
177
+ }, [uploadedFiles, uploadedFilesImperative, isMultiple]);
178
+ return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Label, fieldLabelProps), ___EmotionJSX(Box, _extends({
179
+ variant: "boxes.fileInputFieldWrapper"
180
+ }, mergeProps(fieldContainerProps, others), {
181
+ className: classNames
182
+ }, getRootProps()), ___EmotionJSX(Input, _extends({}, mergeProps(visuallyHiddenProps, fieldControlProps, getInputProps()), {
183
+ "aria-label": "File Input",
184
+ multiple: isMultiple,
185
+ onChange: handleOnChange,
186
+ ref: inputRef,
187
+ type: "file"
188
+ })), filesListNode, shouldFileSelectRender() && ___EmotionJSX(FileSelect, {
189
+ buttonText: defaultButtonText,
190
+ handleFileSelect: handleFileSelect,
191
+ isDisabled: isDisabled || isLoading,
192
+ textProps: textProps
193
+ }), isLoading && ___EmotionJSX(Loader, {
194
+ color: "active",
195
+ sx: {
196
+ position: 'absolute'
197
+ },
198
+ "data-testid": "file-input-field__loader"
199
+ })), helperText && ___EmotionJSX(FieldHelperText, {
200
+ status: status
201
+ }, helperText));
202
+ });
203
+ FileInputField.displayName = 'FileInputField';
204
+ FileInputField.propTypes = {
205
+ /** The rendered label for the field. */
206
+ label: PropTypes.node,
207
+
208
+ /** Text rendered below the input. */
209
+ helperText: PropTypes.node,
210
+
211
+ /** Determines the component border status color indicator and helper text styling. */
212
+ status: PropTypes.oneOf(_Object$values(statuses)),
213
+
214
+ /** Default button text that will be changed on the file name once file is uploaded */
215
+ defaultButtonText: PropTypes.string,
216
+
217
+ /** Defines whether input can accept multiple files or not */
218
+ isMultiple: PropTypes.bool,
219
+
220
+ /** Determines whether the loading indicator is shown. */
221
+ isLoading: PropTypes.bool,
222
+
223
+ /** Whether the field is disabled. */
224
+ isDisabled: PropTypes.bool,
225
+
226
+ /** Array of objects for uploaded files.
227
+ * Objects should have the following structure:
228
+ *
229
+ * {
230
+ *
231
+ * fileObj: File object (optional),
232
+ *
233
+ * id: file id (required - will be returned on delete),
234
+ *
235
+ * name: file name that will be displayed (required - will be displayed),
236
+ *
237
+ * downloadLink: link for the file download (optional),
238
+ *
239
+ * status: file status (if error - icon of the
240
+ * component will be red icon and warning sign)(optional),
241
+ *
242
+ * }
243
+ * */
244
+ fileList: PropTypes.arrayOf(PropTypes.shape({
245
+ fileObj: PropTypes.shape({}),
246
+ id: PropTypes.string.required,
247
+ name: PropTypes.string.required,
248
+ downloadLink: PropTypes.string,
249
+ status: PropTypes.oneOf(_Object$values(statuses))
250
+ })),
251
+
252
+ /** Default array of objects for uploaded files. */
253
+ defaultFileList: PropTypes.arrayOf(PropTypes.shape({
254
+ fileObj: PropTypes.shape({}),
255
+ id: PropTypes.string.required,
256
+ name: PropTypes.string.required,
257
+ downloadLink: PropTypes.string,
258
+ status: PropTypes.oneOf(_Object$values(statuses))
259
+ })),
260
+
261
+ /** The handler that is called when the input files is uploaded.
262
+ *
263
+ * `(event, files) => void`
264
+ * */
265
+ onFileSelect: PropTypes.func,
266
+
267
+ /** The handler that is called when an uploaded file got removed.
268
+ *
269
+ * `(fileId) => void`
270
+ * */
271
+ onRemove: PropTypes.func,
272
+
273
+ /** These props will be spread to the field text component. */
274
+ textProps: PropTypes.shape({})
275
+ };
276
+ FileInputField.defaultProps = {
277
+ defaultButtonText: 'Select a file',
278
+ status: statuses.DEFAULT
279
+ };
280
+ export default FileInputField;
@@ -0,0 +1,206 @@
1
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
3
+ import React, { useState } from 'react';
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ import FileInputField from './';
6
+ import { Box } from '../../index';
7
+ import statuses from '../../utils/devUtils/constants/statuses';
8
+ import { jsx as ___EmotionJSX } from "@emotion/react";
9
+ export default {
10
+ title: 'Form/FileInputField',
11
+ component: FileInputField,
12
+ parameters: {
13
+ docs: {
14
+ source: {
15
+ type: 'code'
16
+ }
17
+ }
18
+ },
19
+ argTypes: {
20
+ label: {
21
+ control: {
22
+ type: 'text'
23
+ },
24
+ defaultValue: 'Field Label'
25
+ },
26
+ helperText: {
27
+ control: {
28
+ type: 'text'
29
+ }
30
+ },
31
+ status: {
32
+ control: {
33
+ type: 'select',
34
+ options: statuses
35
+ },
36
+ defaultValue: statuses.DEFAULT
37
+ },
38
+ defaultButtonText: {
39
+ control: {
40
+ type: 'text'
41
+ }
42
+ },
43
+ isMultiple: {
44
+ control: {
45
+ type: 'boolean'
46
+ }
47
+ },
48
+ isLoading: {
49
+ control: {
50
+ type: 'boolean'
51
+ }
52
+ },
53
+ isDisabled: {
54
+ control: {
55
+ type: 'boolean'
56
+ }
57
+ },
58
+ fileList: {
59
+ control: {
60
+ type: 'none'
61
+ }
62
+ },
63
+ defaultFileList: {
64
+ control: {
65
+ type: 'none'
66
+ }
67
+ },
68
+ textProps: {
69
+ control: {
70
+ type: 'none'
71
+ }
72
+ }
73
+ }
74
+ };
75
+ var fitContentWidthSx = {
76
+ width: 'fit-content'
77
+ };
78
+ export var Default = function Default(args) {
79
+ return ___EmotionJSX(FileInputField, _extends({
80
+ sx: fitContentWidthSx
81
+ }, args));
82
+ };
83
+ export var CustomButtonText = function CustomButtonText() {
84
+ return ___EmotionJSX(FileInputField, {
85
+ defaultButtonText: "Original Button Name",
86
+ label: "Custom Button Text",
87
+ sx: fitContentWidthSx
88
+ });
89
+ };
90
+ export var ControlledState = function ControlledState() {
91
+ var _useState = useState([]),
92
+ _useState2 = _slicedToArray(_useState, 2),
93
+ userFiles = _useState2[0],
94
+ setUserFiles = _useState2[1];
95
+
96
+ var _useState3 = useState(),
97
+ _useState4 = _slicedToArray(_useState3, 2),
98
+ error = _useState4[0],
99
+ setError = _useState4[1];
100
+
101
+ var handleFileSelect = function handleFileSelect(event, files) {
102
+ // this is approximate conversion just for an example
103
+ var uploadedFileSizeMb = files[0].size / 1e6;
104
+
105
+ if (uploadedFileSizeMb > 2) {
106
+ setError('Only files under 2 MB can be uploaded.');
107
+ } else {
108
+ setUserFiles([{
109
+ id: uuidv4(),
110
+ name: files[0].name,
111
+ downloadLink: 'link for testing purposes'
112
+ }]);
113
+ setError(null);
114
+ }
115
+ }; // you would want to handle this differently in case you have multiple files
116
+
117
+
118
+ var handleFileRemove = function handleFileRemove() {
119
+ setUserFiles([]);
120
+ setError(null);
121
+ };
122
+
123
+ return ___EmotionJSX(FileInputField, {
124
+ label: "Controlled State With limit on file size upload below 2 mb",
125
+ onFileSelect: handleFileSelect,
126
+ onRemove: handleFileRemove,
127
+ fileList: userFiles,
128
+ sx: fitContentWidthSx,
129
+ status: error && statuses.ERROR,
130
+ helperText: error
131
+ });
132
+ };
133
+ export var DefaultFileListUncontrolled = function DefaultFileListUncontrolled() {
134
+ return ___EmotionJSX(FileInputField, {
135
+ defaultFileList: [{
136
+ id: 'test-id1',
137
+ name: 'PingId Mobile (Android)',
138
+ downloadLink: 'https://download.pingidentity.com/public/PingID/android/PingID.apk'
139
+ }, {
140
+ id: 'test-id2',
141
+ name: 'PingId Desktop (macOS)',
142
+ downloadLink: 'https://downloads.pingidentity.com/pingid/mac-client/PingID.pkg'
143
+ }, {
144
+ id: 'test-id3',
145
+ name: 'PingId Desktop (Windows)',
146
+ downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip'
147
+ }],
148
+ isMultiple: true,
149
+ label: "Uncontrolled File List with default files",
150
+ sx: fitContentWidthSx
151
+ });
152
+ };
153
+ export var ErrorStatusSingleFile = function ErrorStatusSingleFile() {
154
+ return ___EmotionJSX(FileInputField, {
155
+ defaultFileList: [{
156
+ id: 'test-id3',
157
+ name: 'PingId Desktop (Windows)',
158
+ downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip',
159
+ status: statuses.ERROR
160
+ }],
161
+ label: "Error Status Single File",
162
+ sx: fitContentWidthSx,
163
+ helperText: "There is an error",
164
+ status: statuses.ERROR
165
+ });
166
+ };
167
+ export var ErrorWithMultipleFiles = function ErrorWithMultipleFiles() {
168
+ return ___EmotionJSX(FileInputField, {
169
+ defaultFileList: [{
170
+ id: 'test-id3',
171
+ name: 'PingId Desktop (Windows)',
172
+ downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip',
173
+ status: statuses.ERROR
174
+ }, {
175
+ id: 'test-id2',
176
+ name: 'PingId Desktop (macOS)',
177
+ downloadLink: 'https://downloads.pingidentity.com/pingid/mac-client/PingID.pkg'
178
+ }],
179
+ label: "Error Status With Multiple Files but without a red border",
180
+ sx: fitContentWidthSx,
181
+ helperText: "There is an error but helperText text will be default since no status passed",
182
+ isMultiple: true
183
+ });
184
+ };
185
+ export var WithCustomWidth = function WithCustomWidth() {
186
+ var textSx = {
187
+ textOverflow: 'ellipsis',
188
+ overflow: 'hidden',
189
+ whiteSpace: 'nowrap'
190
+ };
191
+ return ___EmotionJSX(Box, {
192
+ width: 200
193
+ }, ___EmotionJSX(FileInputField, {
194
+ defaultButtonText: "Long Long Button Text With A Lot of Words In It",
195
+ defaultFileList: [{
196
+ id: 'test-id1',
197
+ name: 'Really Long File Name That Cant Fit',
198
+ downloadLink: 'https://download.pingidentity.com/public/PingID/android/PingID.apk'
199
+ }],
200
+ label: "Custom Width",
201
+ textProps: {
202
+ sx: textSx
203
+ },
204
+ isMultiple: true
205
+ }));
206
+ };