@pingux/astro 0.42.0 → 1.0.0-alpha.11
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/CHANGELOG.md +132 -0
- package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.js +1 -1
- package/lib/cjs/components/AccordionItem/AccordionItem.js +3 -1
- package/lib/cjs/components/CopyText/CopyText.js +3 -73
- package/lib/cjs/components/FileInputField/FileInputField.js +324 -0
- package/lib/cjs/components/FileInputField/FileInputField.stories.js +250 -0
- package/lib/cjs/components/FileInputField/FileInputField.test.js +227 -0
- package/lib/cjs/components/FileInputField/FileItem.js +125 -0
- package/lib/cjs/components/FileInputField/FileSelect.js +48 -0
- package/lib/cjs/components/FileInputField/index.js +18 -0
- package/lib/cjs/components/ListView/ListView.js +4 -3
- package/lib/cjs/components/ListViewItem/ListViewItem.js +3 -6
- package/lib/cjs/components/NumberField/NumberField.js +4 -2
- package/lib/cjs/components/NumberField/NumberField.test.js +15 -0
- package/lib/cjs/components/Tab/Tab.js +11 -4
- package/lib/cjs/components/Tabs/Tabs.js +7 -1
- package/lib/cjs/components/Tabs/Tabs.stories.js +60 -6
- package/lib/cjs/components/Tabs/Tabs.test.js +78 -15
- package/lib/cjs/hooks/useCopyToClipboard/index.js +18 -0
- package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +83 -0
- package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.test.js +79 -0
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/recipes/CopyToClipboard.stories.js +45 -0
- package/lib/cjs/recipes/RadioButtonsWithLinks.stories.js +146 -0
- package/lib/cjs/recipes/RowLineChart.stories.js +6 -1
- package/lib/cjs/styles/forms/input.js +11 -0
- package/lib/cjs/styles/variants/accordion.js +2 -2
- package/lib/cjs/styles/variants/boxes.js +27 -0
- package/lib/cjs/styles/variants/buttons.js +20 -0
- package/lib/cjs/styles/variants/tabs.js +1 -0
- package/lib/components/AccordionGridGroup/AccordionGridGroup.js +1 -1
- package/lib/components/AccordionItem/AccordionItem.js +3 -1
- package/lib/components/CopyText/CopyText.js +2 -71
- package/lib/components/FileInputField/FileInputField.js +280 -0
- package/lib/components/FileInputField/FileInputField.stories.js +206 -0
- package/lib/components/FileInputField/FileInputField.test.js +187 -0
- package/lib/components/FileInputField/FileItem.js +100 -0
- package/lib/components/FileInputField/FileSelect.js +31 -0
- package/lib/components/FileInputField/index.js +1 -0
- package/lib/components/ListView/ListView.js +4 -3
- package/lib/components/ListViewItem/ListViewItem.js +3 -5
- package/lib/components/NumberField/NumberField.js +4 -2
- package/lib/components/NumberField/NumberField.test.js +9 -0
- package/lib/components/Tab/Tab.js +11 -4
- package/lib/components/Tabs/Tabs.js +7 -1
- package/lib/components/Tabs/Tabs.stories.js +56 -4
- package/lib/components/Tabs/Tabs.test.js +78 -15
- package/lib/hooks/useCopyToClipboard/index.js +1 -0
- package/lib/hooks/useCopyToClipboard/useCopyToClipboard.js +69 -0
- package/lib/hooks/useCopyToClipboard/useCopyToClipboard.test.js +64 -0
- package/lib/index.js +1 -0
- package/lib/recipes/CopyToClipboard.stories.js +25 -0
- package/lib/recipes/RadioButtonsWithLinks.stories.js +120 -0
- package/lib/recipes/RowLineChart.stories.js +6 -1
- package/lib/styles/forms/input.js +11 -0
- package/lib/styles/variants/accordion.js +2 -2
- package/lib/styles/variants/boxes.js +27 -0
- package/lib/styles/variants/buttons.js +20 -0
- package/lib/styles/variants/tabs.js +1 -0
- package/package.json +3 -2
@@ -0,0 +1,250 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard");
|
4
|
+
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
6
|
+
|
7
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
8
|
+
|
9
|
+
_Object$defineProperty(exports, "__esModule", {
|
10
|
+
value: true
|
11
|
+
});
|
12
|
+
|
13
|
+
exports.WithCustomWidth = exports.ErrorWithMultipleFiles = exports.ErrorStatusSingleFile = exports.DefaultFileListUncontrolled = exports.ControlledState = exports.CustomButtonText = exports.Default = exports["default"] = void 0;
|
14
|
+
|
15
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
16
|
+
|
17
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
18
|
+
|
19
|
+
var _react = _interopRequireWildcard(require("react"));
|
20
|
+
|
21
|
+
var _uuid = require("uuid");
|
22
|
+
|
23
|
+
var _ = _interopRequireDefault(require("./"));
|
24
|
+
|
25
|
+
var _index = require("../../index");
|
26
|
+
|
27
|
+
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
28
|
+
|
29
|
+
var _react2 = require("@emotion/react");
|
30
|
+
|
31
|
+
var _default = {
|
32
|
+
title: 'Form/FileInputField',
|
33
|
+
component: _["default"],
|
34
|
+
parameters: {
|
35
|
+
docs: {
|
36
|
+
source: {
|
37
|
+
type: 'code'
|
38
|
+
}
|
39
|
+
}
|
40
|
+
},
|
41
|
+
argTypes: {
|
42
|
+
label: {
|
43
|
+
control: {
|
44
|
+
type: 'text'
|
45
|
+
},
|
46
|
+
defaultValue: 'Field Label'
|
47
|
+
},
|
48
|
+
helperText: {
|
49
|
+
control: {
|
50
|
+
type: 'text'
|
51
|
+
}
|
52
|
+
},
|
53
|
+
status: {
|
54
|
+
control: {
|
55
|
+
type: 'select',
|
56
|
+
options: _statuses["default"]
|
57
|
+
},
|
58
|
+
defaultValue: _statuses["default"].DEFAULT
|
59
|
+
},
|
60
|
+
defaultButtonText: {
|
61
|
+
control: {
|
62
|
+
type: 'text'
|
63
|
+
}
|
64
|
+
},
|
65
|
+
isMultiple: {
|
66
|
+
control: {
|
67
|
+
type: 'boolean'
|
68
|
+
}
|
69
|
+
},
|
70
|
+
isLoading: {
|
71
|
+
control: {
|
72
|
+
type: 'boolean'
|
73
|
+
}
|
74
|
+
},
|
75
|
+
isDisabled: {
|
76
|
+
control: {
|
77
|
+
type: 'boolean'
|
78
|
+
}
|
79
|
+
},
|
80
|
+
fileList: {
|
81
|
+
control: {
|
82
|
+
type: 'none'
|
83
|
+
}
|
84
|
+
},
|
85
|
+
defaultFileList: {
|
86
|
+
control: {
|
87
|
+
type: 'none'
|
88
|
+
}
|
89
|
+
},
|
90
|
+
textProps: {
|
91
|
+
control: {
|
92
|
+
type: 'none'
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
};
|
97
|
+
exports["default"] = _default;
|
98
|
+
var fitContentWidthSx = {
|
99
|
+
width: 'fit-content'
|
100
|
+
};
|
101
|
+
|
102
|
+
var Default = function Default(args) {
|
103
|
+
return (0, _react2.jsx)(_["default"], (0, _extends2["default"])({
|
104
|
+
sx: fitContentWidthSx
|
105
|
+
}, args));
|
106
|
+
};
|
107
|
+
|
108
|
+
exports.Default = Default;
|
109
|
+
|
110
|
+
var CustomButtonText = function CustomButtonText() {
|
111
|
+
return (0, _react2.jsx)(_["default"], {
|
112
|
+
defaultButtonText: "Original Button Name",
|
113
|
+
label: "Custom Button Text",
|
114
|
+
sx: fitContentWidthSx
|
115
|
+
});
|
116
|
+
};
|
117
|
+
|
118
|
+
exports.CustomButtonText = CustomButtonText;
|
119
|
+
|
120
|
+
var ControlledState = function ControlledState() {
|
121
|
+
var _useState = (0, _react.useState)([]),
|
122
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
123
|
+
userFiles = _useState2[0],
|
124
|
+
setUserFiles = _useState2[1];
|
125
|
+
|
126
|
+
var _useState3 = (0, _react.useState)(),
|
127
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
128
|
+
error = _useState4[0],
|
129
|
+
setError = _useState4[1];
|
130
|
+
|
131
|
+
var handleFileSelect = function handleFileSelect(event, files) {
|
132
|
+
// this is approximate conversion just for an example
|
133
|
+
var uploadedFileSizeMb = files[0].size / 1e6;
|
134
|
+
|
135
|
+
if (uploadedFileSizeMb > 2) {
|
136
|
+
setError('Only files under 2 MB can be uploaded.');
|
137
|
+
} else {
|
138
|
+
setUserFiles([{
|
139
|
+
id: (0, _uuid.v4)(),
|
140
|
+
name: files[0].name,
|
141
|
+
downloadLink: 'link for testing purposes'
|
142
|
+
}]);
|
143
|
+
setError(null);
|
144
|
+
}
|
145
|
+
}; // you would want to handle this differently in case you have multiple files
|
146
|
+
|
147
|
+
|
148
|
+
var handleFileRemove = function handleFileRemove() {
|
149
|
+
setUserFiles([]);
|
150
|
+
setError(null);
|
151
|
+
};
|
152
|
+
|
153
|
+
return (0, _react2.jsx)(_["default"], {
|
154
|
+
label: "Controlled State With limit on file size upload below 2 mb",
|
155
|
+
onFileSelect: handleFileSelect,
|
156
|
+
onRemove: handleFileRemove,
|
157
|
+
fileList: userFiles,
|
158
|
+
sx: fitContentWidthSx,
|
159
|
+
status: error && _statuses["default"].ERROR,
|
160
|
+
helperText: error
|
161
|
+
});
|
162
|
+
};
|
163
|
+
|
164
|
+
exports.ControlledState = ControlledState;
|
165
|
+
|
166
|
+
var DefaultFileListUncontrolled = function DefaultFileListUncontrolled() {
|
167
|
+
return (0, _react2.jsx)(_["default"], {
|
168
|
+
defaultFileList: [{
|
169
|
+
id: 'test-id1',
|
170
|
+
name: 'PingId Mobile (Android)',
|
171
|
+
downloadLink: 'https://download.pingidentity.com/public/PingID/android/PingID.apk'
|
172
|
+
}, {
|
173
|
+
id: 'test-id2',
|
174
|
+
name: 'PingId Desktop (macOS)',
|
175
|
+
downloadLink: 'https://downloads.pingidentity.com/pingid/mac-client/PingID.pkg'
|
176
|
+
}, {
|
177
|
+
id: 'test-id3',
|
178
|
+
name: 'PingId Desktop (Windows)',
|
179
|
+
downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip'
|
180
|
+
}],
|
181
|
+
isMultiple: true,
|
182
|
+
label: "Uncontrolled File List with default files",
|
183
|
+
sx: fitContentWidthSx
|
184
|
+
});
|
185
|
+
};
|
186
|
+
|
187
|
+
exports.DefaultFileListUncontrolled = DefaultFileListUncontrolled;
|
188
|
+
|
189
|
+
var ErrorStatusSingleFile = function ErrorStatusSingleFile() {
|
190
|
+
return (0, _react2.jsx)(_["default"], {
|
191
|
+
defaultFileList: [{
|
192
|
+
id: 'test-id3',
|
193
|
+
name: 'PingId Desktop (Windows)',
|
194
|
+
downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip',
|
195
|
+
status: _statuses["default"].ERROR
|
196
|
+
}],
|
197
|
+
label: "Error Status Single File",
|
198
|
+
sx: fitContentWidthSx,
|
199
|
+
helperText: "There is an error",
|
200
|
+
status: _statuses["default"].ERROR
|
201
|
+
});
|
202
|
+
};
|
203
|
+
|
204
|
+
exports.ErrorStatusSingleFile = ErrorStatusSingleFile;
|
205
|
+
|
206
|
+
var ErrorWithMultipleFiles = function ErrorWithMultipleFiles() {
|
207
|
+
return (0, _react2.jsx)(_["default"], {
|
208
|
+
defaultFileList: [{
|
209
|
+
id: 'test-id3',
|
210
|
+
name: 'PingId Desktop (Windows)',
|
211
|
+
downloadLink: 'https://download.pingidentity.com/public/PingID/PingID_1.7.2.zip',
|
212
|
+
status: _statuses["default"].ERROR
|
213
|
+
}, {
|
214
|
+
id: 'test-id2',
|
215
|
+
name: 'PingId Desktop (macOS)',
|
216
|
+
downloadLink: 'https://downloads.pingidentity.com/pingid/mac-client/PingID.pkg'
|
217
|
+
}],
|
218
|
+
label: "Error Status With Multiple Files but without a red border",
|
219
|
+
sx: fitContentWidthSx,
|
220
|
+
helperText: "There is an error but helperText text will be default since no status passed",
|
221
|
+
isMultiple: true
|
222
|
+
});
|
223
|
+
};
|
224
|
+
|
225
|
+
exports.ErrorWithMultipleFiles = ErrorWithMultipleFiles;
|
226
|
+
|
227
|
+
var WithCustomWidth = function WithCustomWidth() {
|
228
|
+
var textSx = {
|
229
|
+
textOverflow: 'ellipsis',
|
230
|
+
overflow: 'hidden',
|
231
|
+
whiteSpace: 'nowrap'
|
232
|
+
};
|
233
|
+
return (0, _react2.jsx)(_index.Box, {
|
234
|
+
width: 200
|
235
|
+
}, (0, _react2.jsx)(_["default"], {
|
236
|
+
defaultButtonText: "Long Long Button Text With A Lot of Words In It",
|
237
|
+
defaultFileList: [{
|
238
|
+
id: 'test-id1',
|
239
|
+
name: 'Really Long File Name That Cant Fit',
|
240
|
+
downloadLink: 'https://download.pingidentity.com/public/PingID/android/PingID.apk'
|
241
|
+
}],
|
242
|
+
label: "Custom Width",
|
243
|
+
textProps: {
|
244
|
+
sx: textSx
|
245
|
+
},
|
246
|
+
isMultiple: true
|
247
|
+
}));
|
248
|
+
};
|
249
|
+
|
250
|
+
exports.WithCustomWidth = WithCustomWidth;
|
@@ -0,0 +1,227 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
6
|
+
|
7
|
+
var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-properties"));
|
8
|
+
|
9
|
+
var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"));
|
10
|
+
|
11
|
+
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
12
|
+
|
13
|
+
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"));
|
14
|
+
|
15
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
16
|
+
|
17
|
+
var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
|
18
|
+
|
19
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
20
|
+
|
21
|
+
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
22
|
+
|
23
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
24
|
+
|
25
|
+
var _react = _interopRequireDefault(require("react"));
|
26
|
+
|
27
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
28
|
+
|
29
|
+
var _react2 = require("@testing-library/react");
|
30
|
+
|
31
|
+
var _testAxe = _interopRequireDefault(require("../../utils/testUtils/testAxe"));
|
32
|
+
|
33
|
+
var _FileInputField = _interopRequireDefault(require("./FileInputField"));
|
34
|
+
|
35
|
+
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
36
|
+
|
37
|
+
var _react3 = require("@emotion/react");
|
38
|
+
|
39
|
+
function ownKeys(object, enumerableOnly) { var keys = (0, _keys["default"])(object); if (_getOwnPropertySymbols["default"]) { var symbols = (0, _getOwnPropertySymbols["default"])(object); if (enumerableOnly) symbols = (0, _filter["default"])(symbols).call(symbols, function (sym) { return (0, _getOwnPropertyDescriptor["default"])(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
40
|
+
|
41
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context; (0, _forEach["default"])(_context = ownKeys(Object(source), true)).call(_context, function (key) { (0, _defineProperty3["default"])(target, key, source[key]); }); } else if (_getOwnPropertyDescriptors["default"]) { (0, _defineProperties["default"])(target, (0, _getOwnPropertyDescriptors["default"])(source)); } else { var _context2; (0, _forEach["default"])(_context2 = ownKeys(Object(source))).call(_context2, function (key) { (0, _defineProperty2["default"])(target, key, (0, _getOwnPropertyDescriptor["default"])(source, key)); }); } } return target; }
|
42
|
+
|
43
|
+
var fileInputFieldTestId = 'file-input-test-id';
|
44
|
+
var testLabel = 'file-input-test-label';
|
45
|
+
var fileSelectTestIdButton = 'file-input-field__file-select';
|
46
|
+
var fileUploadedDeleteIconTestId = 'file-uploaded__delete-file-button';
|
47
|
+
var fileUploadedFileIconErrorTestId = 'file-uploaded__file-icon--is-error';
|
48
|
+
var fileUploadedDownloadTestId = 'file-uploaded__download-file-button';
|
49
|
+
var fileUploadedDownloadLinkTestId = 'file-uploaded__download-link';
|
50
|
+
var loaderTestId = 'file-input-field__loader';
|
51
|
+
var testFileURL = 'test-file-url';
|
52
|
+
var testFileId = 'test-file-id-1';
|
53
|
+
var testFileName = 'chucknorris.png';
|
54
|
+
var testFileName2 = 'chucknorris222.png';
|
55
|
+
var testFile = new File(['(⌐□_□)'], testFileName, {
|
56
|
+
type: 'image/png'
|
57
|
+
});
|
58
|
+
var testFile2 = new File(['(⌐□_□)'], testFileName2, {
|
59
|
+
type: 'image/png'
|
60
|
+
});
|
61
|
+
var testFileObject = {
|
62
|
+
id: testFileId,
|
63
|
+
name: testFileName,
|
64
|
+
downloadLink: testFileURL
|
65
|
+
};
|
66
|
+
var originalValue = global.URL.createObjectURL;
|
67
|
+
var defaultProps = {
|
68
|
+
'data-testid': fileInputFieldTestId,
|
69
|
+
label: testLabel
|
70
|
+
};
|
71
|
+
beforeAll(function () {
|
72
|
+
global.URL.createObjectURL = jest.fn(function () {
|
73
|
+
return testFileURL;
|
74
|
+
});
|
75
|
+
});
|
76
|
+
afterAll(function () {
|
77
|
+
global.URL.createObjectURL = originalValue;
|
78
|
+
});
|
79
|
+
|
80
|
+
var getComponent = function getComponent(props) {
|
81
|
+
return (0, _react2.render)((0, _react3.jsx)(_FileInputField["default"], (0, _extends2["default"])({}, defaultProps, props)));
|
82
|
+
};
|
83
|
+
|
84
|
+
(0, _testAxe["default"])(getComponent);
|
85
|
+
test('should render file input field component by default', function () {
|
86
|
+
getComponent();
|
87
|
+
|
88
|
+
var fileUploadField = _react2.screen.getByTestId(fileInputFieldTestId);
|
89
|
+
|
90
|
+
expect(fileUploadField).toBeInstanceOf(HTMLDivElement);
|
91
|
+
expect(fileUploadField).toBeInTheDocument();
|
92
|
+
});
|
93
|
+
test('should render files if they are passed as default', function () {
|
94
|
+
getComponent({
|
95
|
+
defaultFileList: [testFileObject]
|
96
|
+
});
|
97
|
+
expect(_react2.screen.getByText(testFileName)).toBeInTheDocument();
|
98
|
+
});
|
99
|
+
test('should render files if they are passed as controlled prop', function () {
|
100
|
+
getComponent({
|
101
|
+
fileList: [testFileObject]
|
102
|
+
});
|
103
|
+
expect(_react2.screen.getByText(testFileName)).toBeInTheDocument();
|
104
|
+
});
|
105
|
+
test('should be able to display uploaded file', function () {
|
106
|
+
getComponent();
|
107
|
+
|
108
|
+
var fileUploadFieldInput = _react2.screen.getByLabelText(testLabel);
|
109
|
+
|
110
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileSelectTestIdButton));
|
111
|
+
|
112
|
+
_react2.fireEvent.change(fileUploadFieldInput, {
|
113
|
+
target: {
|
114
|
+
files: [testFile]
|
115
|
+
}
|
116
|
+
});
|
117
|
+
|
118
|
+
expect(_react2.screen.getByText(testFileName)).toBeInTheDocument();
|
119
|
+
});
|
120
|
+
test('should be able to add uploaded file if isMultiple true and file select always present', function () {
|
121
|
+
var testCustomButtonName = 'test Custom Button Name';
|
122
|
+
getComponent({
|
123
|
+
defaultFileList: [testFileObject],
|
124
|
+
defaultButtonText: testCustomButtonName,
|
125
|
+
isMultiple: true
|
126
|
+
});
|
127
|
+
|
128
|
+
var fileUploadFieldInput = _react2.screen.getByLabelText(testLabel);
|
129
|
+
|
130
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileSelectTestIdButton));
|
131
|
+
|
132
|
+
_react2.fireEvent.change(fileUploadFieldInput, {
|
133
|
+
target: {
|
134
|
+
files: [testFile2]
|
135
|
+
}
|
136
|
+
});
|
137
|
+
|
138
|
+
expect(_react2.screen.getByText(testFileName)).toBeInTheDocument();
|
139
|
+
expect(_react2.screen.getByText(testFileName2)).toBeInTheDocument();
|
140
|
+
expect(_react2.screen.getByText(testCustomButtonName)).toBeInTheDocument();
|
141
|
+
});
|
142
|
+
test('should call onFileSelect if file uploaded', function () {
|
143
|
+
var mockOnFileSelect = jest.fn();
|
144
|
+
getComponent({
|
145
|
+
onFileSelect: mockOnFileSelect
|
146
|
+
});
|
147
|
+
|
148
|
+
var fileUploadFieldInput = _react2.screen.getByLabelText(testLabel);
|
149
|
+
|
150
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileSelectTestIdButton));
|
151
|
+
|
152
|
+
_react2.fireEvent.change(fileUploadFieldInput, {
|
153
|
+
target: {
|
154
|
+
files: [testFile]
|
155
|
+
}
|
156
|
+
});
|
157
|
+
|
158
|
+
expect(mockOnFileSelect).toHaveBeenCalledTimes(1);
|
159
|
+
});
|
160
|
+
test('file should have download link as attribute', function () {
|
161
|
+
getComponent({
|
162
|
+
defaultFileList: [testFileObject]
|
163
|
+
});
|
164
|
+
|
165
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileUploadedDownloadTestId));
|
166
|
+
|
167
|
+
expect(_react2.screen.getByTestId(fileUploadedDownloadLinkTestId)).toHaveAttribute('href', testFileURL);
|
168
|
+
});
|
169
|
+
test('should remove file if trash icon clicked', function () {
|
170
|
+
getComponent({
|
171
|
+
defaultFileList: [testFileObject]
|
172
|
+
});
|
173
|
+
expect(_react2.screen.getByText(testFileName)).toBeInTheDocument();
|
174
|
+
|
175
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileUploadedDeleteIconTestId));
|
176
|
+
|
177
|
+
expect(_react2.screen.queryByText(testFileName)).not.toBeInTheDocument();
|
178
|
+
});
|
179
|
+
test('should call onRemove if trash icon clicked', function () {
|
180
|
+
var mockOnRemove = jest.fn();
|
181
|
+
getComponent({
|
182
|
+
defaultFileList: [{
|
183
|
+
id: testFileId,
|
184
|
+
name: 'test'
|
185
|
+
}],
|
186
|
+
onRemove: mockOnRemove
|
187
|
+
});
|
188
|
+
|
189
|
+
_userEvent["default"].click(_react2.screen.getByTestId(fileUploadedDeleteIconTestId));
|
190
|
+
|
191
|
+
expect(mockOnRemove).toHaveBeenCalledTimes(1);
|
192
|
+
expect(mockOnRemove).toHaveBeenCalledWith(expect.anything(), testFileId);
|
193
|
+
});
|
194
|
+
test('file select will have custom text if from props if provided', function () {
|
195
|
+
var mockTitle = 'test-title';
|
196
|
+
getComponent({
|
197
|
+
defaultButtonText: mockTitle
|
198
|
+
});
|
199
|
+
expect(_react2.screen.getByText(mockTitle)).toBeInTheDocument();
|
200
|
+
});
|
201
|
+
test('should render error border if appropriate state passed', function () {
|
202
|
+
getComponent({
|
203
|
+
status: _statuses["default"].ERROR
|
204
|
+
});
|
205
|
+
expect(_react2.screen.getByTestId(fileInputFieldTestId)).toHaveClass('is-error');
|
206
|
+
});
|
207
|
+
test('file uploaded should render red error icon', function () {
|
208
|
+
getComponent({
|
209
|
+
defaultFileList: [_objectSpread(_objectSpread({}, testFileObject), {}, {
|
210
|
+
status: _statuses["default"].ERROR
|
211
|
+
})]
|
212
|
+
});
|
213
|
+
expect(_react2.screen.getByTestId(fileUploadedFileIconErrorTestId)).toBeInTheDocument();
|
214
|
+
});
|
215
|
+
test('should display loader if appropriate prop is passed', function () {
|
216
|
+
getComponent({
|
217
|
+
isLoading: true
|
218
|
+
});
|
219
|
+
expect(_react2.screen.getByTestId(loaderTestId)).toBeInTheDocument();
|
220
|
+
});
|
221
|
+
test('should display helper text if passed', function () {
|
222
|
+
var testHelperText = 'testHelperText';
|
223
|
+
getComponent({
|
224
|
+
helperText: testHelperText
|
225
|
+
});
|
226
|
+
expect(_react2.screen.getByText(testHelperText)).toBeInTheDocument();
|
227
|
+
});
|
@@ -0,0 +1,125 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard");
|
4
|
+
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
6
|
+
|
7
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
8
|
+
|
9
|
+
_Object$defineProperty(exports, "__esModule", {
|
10
|
+
value: true
|
11
|
+
});
|
12
|
+
|
13
|
+
exports["default"] = void 0;
|
14
|
+
|
15
|
+
var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
|
16
|
+
|
17
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
18
|
+
|
19
|
+
var _react = _interopRequireWildcard(require("react"));
|
20
|
+
|
21
|
+
var _InsertDriveFileIcon = _interopRequireDefault(require("mdi-react/InsertDriveFileIcon"));
|
22
|
+
|
23
|
+
var _ErrorIcon = _interopRequireDefault(require("mdi-react/ErrorIcon"));
|
24
|
+
|
25
|
+
var _DeleteIcon = _interopRequireDefault(require("mdi-react/DeleteIcon"));
|
26
|
+
|
27
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
28
|
+
|
29
|
+
var _visuallyHidden = require("@react-aria/visually-hidden");
|
30
|
+
|
31
|
+
var _index = require("../../index");
|
32
|
+
|
33
|
+
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
34
|
+
|
35
|
+
var _react2 = require("@emotion/react");
|
36
|
+
|
37
|
+
var FileItem = function FileItem(props) {
|
38
|
+
var downloadLink = props.downloadLink,
|
39
|
+
handleFileDelete = props.handleFileDelete,
|
40
|
+
id = props.id,
|
41
|
+
isDisabled = props.isDisabled,
|
42
|
+
name = props.name,
|
43
|
+
status = props.status,
|
44
|
+
textProps = props.textProps;
|
45
|
+
var handleDeleteButtonPress = (0, _react.useCallback)(function (e) {
|
46
|
+
return handleFileDelete(e, id);
|
47
|
+
}, [id, handleFileDelete]);
|
48
|
+
|
49
|
+
var _useVisuallyHidden = (0, _visuallyHidden.useVisuallyHidden)(),
|
50
|
+
visuallyHiddenProps = _useVisuallyHidden.visuallyHiddenProps;
|
51
|
+
|
52
|
+
var downloadRef = (0, _react.useRef)();
|
53
|
+
var getFileIconProps = (0, _react.useCallback)(function () {
|
54
|
+
switch (status) {
|
55
|
+
case _statuses["default"].ERROR:
|
56
|
+
return {
|
57
|
+
icon: _ErrorIcon["default"],
|
58
|
+
color: 'critical.dark',
|
59
|
+
'data-testid': 'file-uploaded__file-icon--is-error'
|
60
|
+
};
|
61
|
+
|
62
|
+
default:
|
63
|
+
return {
|
64
|
+
icon: _InsertDriveFileIcon["default"]
|
65
|
+
};
|
66
|
+
}
|
67
|
+
}, [status]);
|
68
|
+
|
69
|
+
var handleDownloadPress = function handleDownloadPress() {
|
70
|
+
downloadRef.current.click();
|
71
|
+
};
|
72
|
+
|
73
|
+
return (0, _react2.jsx)(_index.Box, {
|
74
|
+
isRow: true,
|
75
|
+
alignItems: "center",
|
76
|
+
mx: 15,
|
77
|
+
my: 5
|
78
|
+
}, (0, _react2.jsx)(_index.Icon, (0, _extends2["default"])({
|
79
|
+
size: 15,
|
80
|
+
"data-testid": "file-uploaded__file-icon"
|
81
|
+
}, getFileIconProps(), {
|
82
|
+
isDisabled: isDisabled
|
83
|
+
})), (0, _react2.jsx)(_index.Button, {
|
84
|
+
variant: "fileInputField",
|
85
|
+
mx: 5,
|
86
|
+
isDisabled: isDisabled,
|
87
|
+
"aria-label": name,
|
88
|
+
"data-testid": "file-uploaded__download-file-button",
|
89
|
+
onPress: handleDownloadPress
|
90
|
+
}, (0, _react2.jsx)(_index.Text, (0, _extends2["default"])({
|
91
|
+
color: "active"
|
92
|
+
}, textProps), name)), (0, _react2.jsx)(_index.IconButton, {
|
93
|
+
"aria-label": "Delete ".concat(name, " file icon"),
|
94
|
+
"data-testid": "file-uploaded__delete-file-button",
|
95
|
+
isDisabled: isDisabled,
|
96
|
+
onPress: handleDeleteButtonPress,
|
97
|
+
sx: {
|
98
|
+
alignSelf: 'auto'
|
99
|
+
}
|
100
|
+
}, (0, _react2.jsx)(_index.Icon, {
|
101
|
+
icon: _DeleteIcon["default"],
|
102
|
+
size: 15,
|
103
|
+
isDisabled: isDisabled
|
104
|
+
})), (0, _react2.jsx)("a", (0, _extends2["default"])({
|
105
|
+
href: downloadLink
|
106
|
+
}, visuallyHiddenProps, {
|
107
|
+
download: true,
|
108
|
+
ref: downloadRef,
|
109
|
+
"aria-label": "download",
|
110
|
+
"data-testid": "file-uploaded__download-link",
|
111
|
+
tabIndex: -1
|
112
|
+
})));
|
113
|
+
};
|
114
|
+
|
115
|
+
var _default = FileItem;
|
116
|
+
exports["default"] = _default;
|
117
|
+
FileItem.propTypes = {
|
118
|
+
downloadLink: _propTypes["default"].string,
|
119
|
+
handleFileDelete: _propTypes["default"].func,
|
120
|
+
id: _propTypes["default"].string,
|
121
|
+
isDisabled: _propTypes["default"].bool,
|
122
|
+
name: _propTypes["default"].string,
|
123
|
+
status: _propTypes["default"].oneOf((0, _values["default"])(_statuses["default"])),
|
124
|
+
textProps: _propTypes["default"].shape({})
|
125
|
+
};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
|
11
|
+
exports["default"] = void 0;
|
12
|
+
|
13
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
14
|
+
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
16
|
+
|
17
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
18
|
+
|
19
|
+
var _index = require("../../index");
|
20
|
+
|
21
|
+
var _react2 = require("@emotion/react");
|
22
|
+
|
23
|
+
var FileSelect = function FileSelect(props) {
|
24
|
+
var buttonText = props.buttonText,
|
25
|
+
handleFileSelect = props.handleFileSelect,
|
26
|
+
isDisabled = props.isDisabled,
|
27
|
+
textProps = props.textProps;
|
28
|
+
return (0, _react2.jsx)(_index.Button, {
|
29
|
+
"aria-label": buttonText,
|
30
|
+
"data-testid": "file-input-field__file-select",
|
31
|
+
isDisabled: isDisabled,
|
32
|
+
mx: 15,
|
33
|
+
my: 5,
|
34
|
+
onPress: handleFileSelect,
|
35
|
+
variant: "fileInputField"
|
36
|
+
}, (0, _react2.jsx)(_index.Text, (0, _extends2["default"])({
|
37
|
+
color: "active"
|
38
|
+
}, textProps), buttonText));
|
39
|
+
};
|
40
|
+
|
41
|
+
var _default = FileSelect;
|
42
|
+
exports["default"] = _default;
|
43
|
+
FileSelect.propTypes = {
|
44
|
+
buttonText: _propTypes["default"].string,
|
45
|
+
handleFileSelect: _propTypes["default"].func,
|
46
|
+
isDisabled: _propTypes["default"].bool,
|
47
|
+
textProps: _propTypes["default"].shape({})
|
48
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
|
11
|
+
_Object$defineProperty(exports, "default", {
|
12
|
+
enumerable: true,
|
13
|
+
get: function get() {
|
14
|
+
return _FileInputField["default"];
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
var _FileInputField = _interopRequireDefault(require("./FileInputField"));
|
@@ -81,18 +81,19 @@ var collectionTypes = {
|
|
81
81
|
exports.collectionTypes = collectionTypes;
|
82
82
|
|
83
83
|
function useListLayout(state) {
|
84
|
+
var ROW_HEIGHT = 81;
|
84
85
|
var collator = (0, _i18n.useCollator)({
|
85
86
|
usage: 'search',
|
86
87
|
sensitivity: 'base'
|
87
88
|
});
|
88
89
|
var layout = (0, _react.useMemo)(function () {
|
89
90
|
return new _layout.ListLayout({
|
90
|
-
estimatedRowHeight:
|
91
|
+
estimatedRowHeight: ROW_HEIGHT,
|
91
92
|
estimatedHeadingHeight: 26,
|
92
93
|
paddingRight: 4,
|
93
94
|
paddingLeft: 4,
|
94
|
-
loaderHeight:
|
95
|
-
placeholderHeight:
|
95
|
+
loaderHeight: ROW_HEIGHT,
|
96
|
+
placeholderHeight: ROW_HEIGHT,
|
96
97
|
collator: collator
|
97
98
|
});
|
98
99
|
}, [collator]);
|