@pingux/astro 1.0.0-alpha.3 → 1.0.0-alpha.7
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 +47 -0
- 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/Tab/Tab.js +10 -3
- package/lib/cjs/components/Tabs/Tabs.js +4 -1
- package/lib/cjs/components/Tabs/Tabs.stories.js +57 -2
- package/lib/cjs/components/Tabs/Tabs.test.js +34 -0
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/recipes/RadioButtonsWithLinks.stories.js +146 -0
- package/lib/cjs/styles/forms/input.js +11 -0
- package/lib/cjs/styles/variants/boxes.js +23 -0
- package/lib/cjs/styles/variants/buttons.js +20 -0
- package/lib/cjs/styles/variants/tabs.js +1 -0
- 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/Tab/Tab.js +10 -3
- package/lib/components/Tabs/Tabs.js +4 -1
- package/lib/components/Tabs/Tabs.stories.js +53 -0
- package/lib/components/Tabs/Tabs.test.js +38 -0
- package/lib/index.js +1 -0
- package/lib/recipes/RadioButtonsWithLinks.stories.js +120 -0
- package/lib/styles/forms/input.js +11 -0
- package/lib/styles/variants/boxes.js +23 -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,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
|
+
};
|
@@ -0,0 +1,187 @@
|
|
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 _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
|
12
|
+
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; }
|
13
|
+
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context; _forEachInstanceProperty(_context = ownKeys(Object(source), true)).call(_context, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
15
|
+
|
16
|
+
import React from 'react';
|
17
|
+
import userEvent from '@testing-library/user-event';
|
18
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
19
|
+
import axeTest from '../../utils/testUtils/testAxe';
|
20
|
+
import FileInputField from './FileInputField';
|
21
|
+
import statuses from '../../utils/devUtils/constants/statuses';
|
22
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
23
|
+
var fileInputFieldTestId = 'file-input-test-id';
|
24
|
+
var testLabel = 'file-input-test-label';
|
25
|
+
var fileSelectTestIdButton = 'file-input-field__file-select';
|
26
|
+
var fileUploadedDeleteIconTestId = 'file-uploaded__delete-file-button';
|
27
|
+
var fileUploadedFileIconErrorTestId = 'file-uploaded__file-icon--is-error';
|
28
|
+
var fileUploadedDownloadTestId = 'file-uploaded__download-file-button';
|
29
|
+
var fileUploadedDownloadLinkTestId = 'file-uploaded__download-link';
|
30
|
+
var loaderTestId = 'file-input-field__loader';
|
31
|
+
var testFileURL = 'test-file-url';
|
32
|
+
var testFileId = 'test-file-id-1';
|
33
|
+
var testFileName = 'chucknorris.png';
|
34
|
+
var testFileName2 = 'chucknorris222.png';
|
35
|
+
var testFile = new File(['(⌐□_□)'], testFileName, {
|
36
|
+
type: 'image/png'
|
37
|
+
});
|
38
|
+
var testFile2 = new File(['(⌐□_□)'], testFileName2, {
|
39
|
+
type: 'image/png'
|
40
|
+
});
|
41
|
+
var testFileObject = {
|
42
|
+
id: testFileId,
|
43
|
+
name: testFileName,
|
44
|
+
downloadLink: testFileURL
|
45
|
+
};
|
46
|
+
var originalValue = global.URL.createObjectURL;
|
47
|
+
var defaultProps = {
|
48
|
+
'data-testid': fileInputFieldTestId,
|
49
|
+
label: testLabel
|
50
|
+
};
|
51
|
+
beforeAll(function () {
|
52
|
+
global.URL.createObjectURL = jest.fn(function () {
|
53
|
+
return testFileURL;
|
54
|
+
});
|
55
|
+
});
|
56
|
+
afterAll(function () {
|
57
|
+
global.URL.createObjectURL = originalValue;
|
58
|
+
});
|
59
|
+
|
60
|
+
var getComponent = function getComponent(props) {
|
61
|
+
return render(___EmotionJSX(FileInputField, _extends({}, defaultProps, props)));
|
62
|
+
};
|
63
|
+
|
64
|
+
axeTest(getComponent);
|
65
|
+
test('should render file input field component by default', function () {
|
66
|
+
getComponent();
|
67
|
+
var fileUploadField = screen.getByTestId(fileInputFieldTestId);
|
68
|
+
expect(fileUploadField).toBeInstanceOf(HTMLDivElement);
|
69
|
+
expect(fileUploadField).toBeInTheDocument();
|
70
|
+
});
|
71
|
+
test('should render files if they are passed as default', function () {
|
72
|
+
getComponent({
|
73
|
+
defaultFileList: [testFileObject]
|
74
|
+
});
|
75
|
+
expect(screen.getByText(testFileName)).toBeInTheDocument();
|
76
|
+
});
|
77
|
+
test('should render files if they are passed as controlled prop', function () {
|
78
|
+
getComponent({
|
79
|
+
fileList: [testFileObject]
|
80
|
+
});
|
81
|
+
expect(screen.getByText(testFileName)).toBeInTheDocument();
|
82
|
+
});
|
83
|
+
test('should be able to display uploaded file', function () {
|
84
|
+
getComponent();
|
85
|
+
var fileUploadFieldInput = screen.getByLabelText(testLabel);
|
86
|
+
userEvent.click(screen.getByTestId(fileSelectTestIdButton));
|
87
|
+
fireEvent.change(fileUploadFieldInput, {
|
88
|
+
target: {
|
89
|
+
files: [testFile]
|
90
|
+
}
|
91
|
+
});
|
92
|
+
expect(screen.getByText(testFileName)).toBeInTheDocument();
|
93
|
+
});
|
94
|
+
test('should be able to add uploaded file if isMultiple true and file select always present', function () {
|
95
|
+
var testCustomButtonName = 'test Custom Button Name';
|
96
|
+
getComponent({
|
97
|
+
defaultFileList: [testFileObject],
|
98
|
+
defaultButtonText: testCustomButtonName,
|
99
|
+
isMultiple: true
|
100
|
+
});
|
101
|
+
var fileUploadFieldInput = screen.getByLabelText(testLabel);
|
102
|
+
userEvent.click(screen.getByTestId(fileSelectTestIdButton));
|
103
|
+
fireEvent.change(fileUploadFieldInput, {
|
104
|
+
target: {
|
105
|
+
files: [testFile2]
|
106
|
+
}
|
107
|
+
});
|
108
|
+
expect(screen.getByText(testFileName)).toBeInTheDocument();
|
109
|
+
expect(screen.getByText(testFileName2)).toBeInTheDocument();
|
110
|
+
expect(screen.getByText(testCustomButtonName)).toBeInTheDocument();
|
111
|
+
});
|
112
|
+
test('should call onFileSelect if file uploaded', function () {
|
113
|
+
var mockOnFileSelect = jest.fn();
|
114
|
+
getComponent({
|
115
|
+
onFileSelect: mockOnFileSelect
|
116
|
+
});
|
117
|
+
var fileUploadFieldInput = screen.getByLabelText(testLabel);
|
118
|
+
userEvent.click(screen.getByTestId(fileSelectTestIdButton));
|
119
|
+
fireEvent.change(fileUploadFieldInput, {
|
120
|
+
target: {
|
121
|
+
files: [testFile]
|
122
|
+
}
|
123
|
+
});
|
124
|
+
expect(mockOnFileSelect).toHaveBeenCalledTimes(1);
|
125
|
+
});
|
126
|
+
test('file should have download link as attribute', function () {
|
127
|
+
getComponent({
|
128
|
+
defaultFileList: [testFileObject]
|
129
|
+
});
|
130
|
+
userEvent.click(screen.getByTestId(fileUploadedDownloadTestId));
|
131
|
+
expect(screen.getByTestId(fileUploadedDownloadLinkTestId)).toHaveAttribute('href', testFileURL);
|
132
|
+
});
|
133
|
+
test('should remove file if trash icon clicked', function () {
|
134
|
+
getComponent({
|
135
|
+
defaultFileList: [testFileObject]
|
136
|
+
});
|
137
|
+
expect(screen.getByText(testFileName)).toBeInTheDocument();
|
138
|
+
userEvent.click(screen.getByTestId(fileUploadedDeleteIconTestId));
|
139
|
+
expect(screen.queryByText(testFileName)).not.toBeInTheDocument();
|
140
|
+
});
|
141
|
+
test('should call onRemove if trash icon clicked', function () {
|
142
|
+
var mockOnRemove = jest.fn();
|
143
|
+
getComponent({
|
144
|
+
defaultFileList: [{
|
145
|
+
id: testFileId,
|
146
|
+
name: 'test'
|
147
|
+
}],
|
148
|
+
onRemove: mockOnRemove
|
149
|
+
});
|
150
|
+
userEvent.click(screen.getByTestId(fileUploadedDeleteIconTestId));
|
151
|
+
expect(mockOnRemove).toHaveBeenCalledTimes(1);
|
152
|
+
expect(mockOnRemove).toHaveBeenCalledWith(expect.anything(), testFileId);
|
153
|
+
});
|
154
|
+
test('file select will have custom text if from props if provided', function () {
|
155
|
+
var mockTitle = 'test-title';
|
156
|
+
getComponent({
|
157
|
+
defaultButtonText: mockTitle
|
158
|
+
});
|
159
|
+
expect(screen.getByText(mockTitle)).toBeInTheDocument();
|
160
|
+
});
|
161
|
+
test('should render error border if appropriate state passed', function () {
|
162
|
+
getComponent({
|
163
|
+
status: statuses.ERROR
|
164
|
+
});
|
165
|
+
expect(screen.getByTestId(fileInputFieldTestId)).toHaveClass('is-error');
|
166
|
+
});
|
167
|
+
test('file uploaded should render red error icon', function () {
|
168
|
+
getComponent({
|
169
|
+
defaultFileList: [_objectSpread(_objectSpread({}, testFileObject), {}, {
|
170
|
+
status: statuses.ERROR
|
171
|
+
})]
|
172
|
+
});
|
173
|
+
expect(screen.getByTestId(fileUploadedFileIconErrorTestId)).toBeInTheDocument();
|
174
|
+
});
|
175
|
+
test('should display loader if appropriate prop is passed', function () {
|
176
|
+
getComponent({
|
177
|
+
isLoading: true
|
178
|
+
});
|
179
|
+
expect(screen.getByTestId(loaderTestId)).toBeInTheDocument();
|
180
|
+
});
|
181
|
+
test('should display helper text if passed', function () {
|
182
|
+
var testHelperText = 'testHelperText';
|
183
|
+
getComponent({
|
184
|
+
helperText: testHelperText
|
185
|
+
});
|
186
|
+
expect(screen.getByText(testHelperText)).toBeInTheDocument();
|
187
|
+
});
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
2
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
3
|
+
import React, { useCallback, useRef } from 'react';
|
4
|
+
import InsertDriveFileIcon from 'mdi-react/InsertDriveFileIcon';
|
5
|
+
import ErrorIcon from 'mdi-react/ErrorIcon';
|
6
|
+
import DeleteIcon from 'mdi-react/DeleteIcon';
|
7
|
+
import PropTypes from 'prop-types';
|
8
|
+
import { useVisuallyHidden } from '@react-aria/visually-hidden';
|
9
|
+
import { Box, Button, IconButton, Icon, Text } from '../../index';
|
10
|
+
import statuses from '../../utils/devUtils/constants/statuses';
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
|
+
|
13
|
+
var FileItem = function FileItem(props) {
|
14
|
+
var downloadLink = props.downloadLink,
|
15
|
+
handleFileDelete = props.handleFileDelete,
|
16
|
+
id = props.id,
|
17
|
+
isDisabled = props.isDisabled,
|
18
|
+
name = props.name,
|
19
|
+
status = props.status,
|
20
|
+
textProps = props.textProps;
|
21
|
+
var handleDeleteButtonPress = useCallback(function (e) {
|
22
|
+
return handleFileDelete(e, id);
|
23
|
+
}, [id, handleFileDelete]);
|
24
|
+
|
25
|
+
var _useVisuallyHidden = useVisuallyHidden(),
|
26
|
+
visuallyHiddenProps = _useVisuallyHidden.visuallyHiddenProps;
|
27
|
+
|
28
|
+
var downloadRef = useRef();
|
29
|
+
var getFileIconProps = useCallback(function () {
|
30
|
+
switch (status) {
|
31
|
+
case statuses.ERROR:
|
32
|
+
return {
|
33
|
+
icon: ErrorIcon,
|
34
|
+
color: 'critical.dark',
|
35
|
+
'data-testid': 'file-uploaded__file-icon--is-error'
|
36
|
+
};
|
37
|
+
|
38
|
+
default:
|
39
|
+
return {
|
40
|
+
icon: InsertDriveFileIcon
|
41
|
+
};
|
42
|
+
}
|
43
|
+
}, [status]);
|
44
|
+
|
45
|
+
var handleDownloadPress = function handleDownloadPress() {
|
46
|
+
downloadRef.current.click();
|
47
|
+
};
|
48
|
+
|
49
|
+
return ___EmotionJSX(Box, {
|
50
|
+
isRow: true,
|
51
|
+
alignItems: "center",
|
52
|
+
mx: 15,
|
53
|
+
my: 5
|
54
|
+
}, ___EmotionJSX(Icon, _extends({
|
55
|
+
size: 15,
|
56
|
+
"data-testid": "file-uploaded__file-icon"
|
57
|
+
}, getFileIconProps(), {
|
58
|
+
isDisabled: isDisabled
|
59
|
+
})), ___EmotionJSX(Button, {
|
60
|
+
variant: "fileInputField",
|
61
|
+
mx: 5,
|
62
|
+
isDisabled: isDisabled,
|
63
|
+
"aria-label": name,
|
64
|
+
"data-testid": "file-uploaded__download-file-button",
|
65
|
+
onPress: handleDownloadPress
|
66
|
+
}, ___EmotionJSX(Text, _extends({
|
67
|
+
color: "active"
|
68
|
+
}, textProps), name)), ___EmotionJSX(IconButton, {
|
69
|
+
"aria-label": "Delete ".concat(name, " file icon"),
|
70
|
+
"data-testid": "file-uploaded__delete-file-button",
|
71
|
+
isDisabled: isDisabled,
|
72
|
+
onPress: handleDeleteButtonPress,
|
73
|
+
sx: {
|
74
|
+
alignSelf: 'auto'
|
75
|
+
}
|
76
|
+
}, ___EmotionJSX(Icon, {
|
77
|
+
icon: DeleteIcon,
|
78
|
+
size: 15,
|
79
|
+
isDisabled: isDisabled
|
80
|
+
})), ___EmotionJSX("a", _extends({
|
81
|
+
href: downloadLink
|
82
|
+
}, visuallyHiddenProps, {
|
83
|
+
download: true,
|
84
|
+
ref: downloadRef,
|
85
|
+
"aria-label": "download",
|
86
|
+
"data-testid": "file-uploaded__download-link",
|
87
|
+
tabIndex: -1
|
88
|
+
})));
|
89
|
+
};
|
90
|
+
|
91
|
+
export default FileItem;
|
92
|
+
FileItem.propTypes = {
|
93
|
+
downloadLink: PropTypes.string,
|
94
|
+
handleFileDelete: PropTypes.func,
|
95
|
+
id: PropTypes.string,
|
96
|
+
isDisabled: PropTypes.bool,
|
97
|
+
name: PropTypes.string,
|
98
|
+
status: PropTypes.oneOf(_Object$values(statuses)),
|
99
|
+
textProps: PropTypes.shape({})
|
100
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React from 'react';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
import { Button, Text } from '../../index';
|
5
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
6
|
+
|
7
|
+
var FileSelect = function FileSelect(props) {
|
8
|
+
var buttonText = props.buttonText,
|
9
|
+
handleFileSelect = props.handleFileSelect,
|
10
|
+
isDisabled = props.isDisabled,
|
11
|
+
textProps = props.textProps;
|
12
|
+
return ___EmotionJSX(Button, {
|
13
|
+
"aria-label": buttonText,
|
14
|
+
"data-testid": "file-input-field__file-select",
|
15
|
+
isDisabled: isDisabled,
|
16
|
+
mx: 15,
|
17
|
+
my: 5,
|
18
|
+
onPress: handleFileSelect,
|
19
|
+
variant: "fileInputField"
|
20
|
+
}, ___EmotionJSX(Text, _extends({
|
21
|
+
color: "active"
|
22
|
+
}, textProps), buttonText));
|
23
|
+
};
|
24
|
+
|
25
|
+
export default FileSelect;
|
26
|
+
FileSelect.propTypes = {
|
27
|
+
buttonText: PropTypes.string,
|
28
|
+
handleFileSelect: PropTypes.func,
|
29
|
+
isDisabled: PropTypes.bool,
|
30
|
+
textProps: PropTypes.shape({})
|
31
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './FileInputField';
|
@@ -21,6 +21,7 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
21
21
|
tabsDisabled = props.isDisabled,
|
22
22
|
orientation = props.orientation,
|
23
23
|
mode = props.mode,
|
24
|
+
slots = props.slots,
|
24
25
|
tooltipTriggerProps = props.tooltipTriggerProps;
|
25
26
|
var key = item.key,
|
26
27
|
rendered = item.rendered,
|
@@ -70,14 +71,16 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
70
71
|
}, state, tabRef),
|
71
72
|
tabProps = _useTab.tabProps;
|
72
73
|
|
73
|
-
var tab = ___EmotionJSX(Box,
|
74
|
+
var tab = ___EmotionJSX(Box, {
|
75
|
+
isRow: true
|
76
|
+
}, slots === null || slots === void 0 ? void 0 : slots.beforeTab, ___EmotionJSX(Box, _extends({
|
74
77
|
className: classNames,
|
75
78
|
variant: "tab"
|
76
79
|
}, mergeProps(focusProps, hoverProps, tabProps), otherItemProps, {
|
77
80
|
ref: tabRef
|
78
81
|
}), icon, ___EmotionJSX(Text, _extends({
|
79
82
|
variant: "tabLabel"
|
80
|
-
}, tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, tabLineProps));
|
83
|
+
}, tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, tabLineProps)), slots === null || slots === void 0 ? void 0 : slots.afterTab);
|
81
84
|
|
82
85
|
if (mode === 'tooltip') {
|
83
86
|
return ___EmotionJSX(React.Fragment, null, separator, ___EmotionJSX(TooltipTrigger, _extends({}, tooltipTriggerProps, {
|
@@ -100,7 +103,11 @@ CollectionTab.propTypes = {
|
|
100
103
|
}),
|
101
104
|
mode: PropTypes.oneOf(['default', 'tooltip']),
|
102
105
|
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
103
|
-
tooltipTriggerProps: PropTypes.shape({})
|
106
|
+
tooltipTriggerProps: PropTypes.shape({}),
|
107
|
+
slots: PropTypes.shape({
|
108
|
+
beforeTab: PropTypes.node,
|
109
|
+
afterTab: PropTypes.node
|
110
|
+
})
|
104
111
|
};
|
105
112
|
|
106
113
|
var TabLine = function TabLine(props) {
|
@@ -71,12 +71,15 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
71
71
|
}, tabListProps, raTabListProps, {
|
72
72
|
ref: tabListRef
|
73
73
|
}), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
|
74
|
+
var _item$props;
|
75
|
+
|
74
76
|
return ___EmotionJSX(CollectionTab, {
|
75
77
|
key: item.key,
|
76
78
|
item: item,
|
77
79
|
isDisabled: isDisabled,
|
78
80
|
orientation: orientation,
|
79
|
-
mode: mode
|
81
|
+
mode: mode,
|
82
|
+
slots: item === null || item === void 0 ? void 0 : (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.slots
|
80
83
|
});
|
81
84
|
})), ___EmotionJSX(Box, _extends({
|
82
85
|
variant: "tabPanel",
|
@@ -2,10 +2,12 @@ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
2
2
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
3
3
|
import React, { useState } from 'react';
|
4
4
|
import Earth from 'mdi-react/GlobeModelIcon';
|
5
|
+
import LockIcon from 'mdi-react/LockIcon';
|
5
6
|
import Tabs from './Tabs';
|
6
7
|
import Tab from '../Tab';
|
7
8
|
import Icon from '../Icon';
|
8
9
|
import Text from '../Text';
|
10
|
+
import { Chip } from '../../index';
|
9
11
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
10
12
|
export default {
|
11
13
|
title: 'Tabs',
|
@@ -184,4 +186,55 @@ export var TabPanelProps = function TabPanelProps() {
|
|
184
186
|
title: item.name
|
185
187
|
}, item.children);
|
186
188
|
});
|
189
|
+
};
|
190
|
+
export var ContentSlots = function ContentSlots() {
|
191
|
+
var beforeTabNode = ___EmotionJSX(Icon, {
|
192
|
+
icon: LockIcon,
|
193
|
+
sx: {
|
194
|
+
marginTop: 10,
|
195
|
+
marginRight: 5
|
196
|
+
}
|
197
|
+
});
|
198
|
+
|
199
|
+
var nodeSx = {
|
200
|
+
alignItems: 'center',
|
201
|
+
backgroundColor: 'neutral.95',
|
202
|
+
borderRadius: '50%',
|
203
|
+
color: 'neutral.30',
|
204
|
+
fontSize: 'sm',
|
205
|
+
height: 20,
|
206
|
+
justifyContent: 'center',
|
207
|
+
marginLeft: 6,
|
208
|
+
marginTop: 10,
|
209
|
+
minWidth: 20
|
210
|
+
};
|
211
|
+
|
212
|
+
var afterTabNode = ___EmotionJSX(Chip, {
|
213
|
+
sx: nodeSx
|
214
|
+
}, "14");
|
215
|
+
|
216
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Tabs, {
|
217
|
+
items: tabs,
|
218
|
+
mb: 50
|
219
|
+
}, ___EmotionJSX(Tab, {
|
220
|
+
key: "tab1",
|
221
|
+
title: "Tab 1",
|
222
|
+
slots: {
|
223
|
+
beforeTab: beforeTabNode
|
224
|
+
}
|
225
|
+
}, ___EmotionJSX(Text, null, "This is content for Tab 1")), ___EmotionJSX(Tab, {
|
226
|
+
key: "tab2",
|
227
|
+
title: "Tab 2"
|
228
|
+
}, ___EmotionJSX(Text, null, "This is content for Tab 2"))), ___EmotionJSX(Tabs, {
|
229
|
+
items: tabs
|
230
|
+
}, ___EmotionJSX(Tab, {
|
231
|
+
key: "tab1",
|
232
|
+
title: "Tab 1"
|
233
|
+
}, ___EmotionJSX(Text, null, "Compose Filter")), ___EmotionJSX(Tab, {
|
234
|
+
key: "tab2",
|
235
|
+
title: "Tab 2",
|
236
|
+
slots: {
|
237
|
+
afterTab: afterTabNode
|
238
|
+
}
|
239
|
+
}, ___EmotionJSX(Text, null, "Users Matched"))));
|
187
240
|
};
|
@@ -351,4 +351,42 @@ test('hover tab style', function () {
|
|
351
351
|
expect(tab0).not.toHaveClass('is-hovered');
|
352
352
|
userEvent.hover(tab0);
|
353
353
|
expect(tab0).toHaveClass('is-hovered');
|
354
|
+
});
|
355
|
+
test('will render slots.beforeTab if provided', function () {
|
356
|
+
var testText = 'test-text';
|
357
|
+
|
358
|
+
var testComponent = ___EmotionJSX("div", null, testText);
|
359
|
+
|
360
|
+
var tabs = [{
|
361
|
+
name: 'Tab 1',
|
362
|
+
children: 'Tab 1 body',
|
363
|
+
props: {
|
364
|
+
slots: {
|
365
|
+
beforeTab: testComponent
|
366
|
+
}
|
367
|
+
}
|
368
|
+
}];
|
369
|
+
getComponent({}, {
|
370
|
+
tabs: tabs
|
371
|
+
});
|
372
|
+
expect(screen.getByText(testText)).toBeInTheDocument();
|
373
|
+
});
|
374
|
+
test('will render slots.afterTab if provided', function () {
|
375
|
+
var testText = 'test-text';
|
376
|
+
|
377
|
+
var testComponent = ___EmotionJSX("div", null, testText);
|
378
|
+
|
379
|
+
var tabs = [{
|
380
|
+
name: 'Tab 1',
|
381
|
+
children: 'Tab 1 body',
|
382
|
+
props: {
|
383
|
+
slots: {
|
384
|
+
afterTab: testComponent
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}];
|
388
|
+
getComponent({}, {
|
389
|
+
tabs: tabs
|
390
|
+
});
|
391
|
+
expect(screen.getByText(testText)).toBeInTheDocument();
|
354
392
|
});
|