@pareto-engineering/design-system 4.2.1 → 4.3.0
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/dist/cjs/f/FormInput/FormInput.js +6 -0
- package/dist/cjs/f/common/utils/index.js +8 -1
- package/dist/cjs/f/common/utils/validators.js +17 -0
- package/dist/cjs/f/fields/ChoicesInput/common/Choice/Choice.js +3 -2
- package/dist/cjs/f/fields/FileUpload/FileUpload.js +234 -0
- package/dist/cjs/f/fields/FileUpload/common/FilePreview/FilePreview.js +118 -0
- package/dist/cjs/f/fields/FileUpload/common/FilePreview/index.js +13 -0
- package/dist/cjs/f/fields/FileUpload/common/FilePreview/styles.scss +93 -0
- package/dist/cjs/f/fields/FileUpload/common/index.js +12 -0
- package/dist/cjs/f/fields/FileUpload/index.js +32 -0
- package/dist/cjs/f/fields/FileUpload/styles.scss +73 -0
- package/dist/cjs/f/fields/FileUpload/utils.js +45 -0
- package/dist/cjs/f/fields/index.js +26 -1
- package/dist/cjs/g/FormBuilder/FormBuilder.js +11 -3
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +34 -7
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +14 -4
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -4
- package/dist/es/f/FormInput/FormInput.js +7 -1
- package/dist/es/f/common/utils/index.js +2 -1
- package/dist/es/f/common/utils/validators.js +10 -0
- package/dist/es/f/fields/ChoicesInput/common/Choice/Choice.js +3 -2
- package/dist/es/f/fields/FileUpload/FileUpload.js +223 -0
- package/dist/es/f/fields/FileUpload/common/FilePreview/FilePreview.js +108 -0
- package/dist/es/f/fields/FileUpload/common/FilePreview/index.js +2 -0
- package/dist/es/f/fields/FileUpload/common/FilePreview/styles.scss +93 -0
- package/dist/es/f/fields/FileUpload/common/index.js +2 -0
- package/dist/es/f/fields/FileUpload/index.js +3 -0
- package/dist/es/f/fields/FileUpload/styles.scss +73 -0
- package/dist/es/f/fields/FileUpload/utils.js +37 -0
- package/dist/es/f/fields/index.js +2 -1
- package/dist/es/g/FormBuilder/FormBuilder.js +11 -3
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +35 -8
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +14 -4
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
- package/package.json +3 -3
- package/src/stories/f/FileUpload.stories.jsx +55 -0
- package/src/stories/g/FormBuilder.stories.jsx +19 -97
- package/src/ui/f/FormInput/FormInput.jsx +11 -0
- package/src/ui/f/common/utils/index.js +1 -0
- package/src/ui/f/common/utils/validators.js +10 -0
- package/src/ui/f/fields/ChoicesInput/common/Choice/Choice.jsx +2 -0
- package/src/ui/f/fields/FileUpload/FileUpload.jsx +279 -0
- package/src/ui/f/fields/FileUpload/common/FilePreview/FilePreview.jsx +160 -0
- package/src/ui/f/fields/FileUpload/common/FilePreview/index.js +2 -0
- package/src/ui/f/fields/FileUpload/common/FilePreview/styles.scss +93 -0
- package/src/ui/f/fields/FileUpload/common/index.js +2 -0
- package/src/ui/f/fields/FileUpload/index.js +3 -0
- package/src/ui/f/fields/FileUpload/styles.scss +73 -0
- package/src/ui/f/fields/FileUpload/utils.js +49 -0
- package/src/ui/f/fields/index.js +6 -0
- package/src/ui/g/FormBuilder/FormBuilder.jsx +9 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +53 -11
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +17 -3
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +11 -2
- package/tests/__snapshots__/Storyshots.test.js.snap +180 -154
|
@@ -97,6 +97,12 @@ const FormInput = _ref => {
|
|
|
97
97
|
disabled: disabled
|
|
98
98
|
}, otherProps));
|
|
99
99
|
}
|
|
100
|
+
if (type === 'file') {
|
|
101
|
+
return /*#__PURE__*/React.createElement(_fields.FileUpload, _extends({
|
|
102
|
+
className: newClassName,
|
|
103
|
+
disabled: disabled
|
|
104
|
+
}, otherProps));
|
|
105
|
+
}
|
|
100
106
|
if (extraTypes?.[type]) {
|
|
101
107
|
const Component = extraTypes[type];
|
|
102
108
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "integerAndGreaterThanZero", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _validators.integerAndGreaterThanZero;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "lookUpInputValueFromFetchedOptions", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
9
15
|
return _lookUpInputValueFromFetchedOptions.lookUpInputValueFromFetchedOptions;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
12
|
-
var _lookUpInputValueFromFetchedOptions = require("./lookUpInputValueFromFetchedOptions");
|
|
18
|
+
var _lookUpInputValueFromFetchedOptions = require("./lookUpInputValueFromFetchedOptions");
|
|
19
|
+
var _validators = require("./validators");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.integerAndGreaterThanZero = void 0;
|
|
7
|
+
const integerAndGreaterThanZero = value => {
|
|
8
|
+
let error = '';
|
|
9
|
+
if (value && value <= 0 || value === 0) {
|
|
10
|
+
error = 'Value must be greator than zero.';
|
|
11
|
+
}
|
|
12
|
+
if (value && value % 1 !== 0) {
|
|
13
|
+
error = 'You must enter a whole number.';
|
|
14
|
+
}
|
|
15
|
+
return error;
|
|
16
|
+
};
|
|
17
|
+
exports.integerAndGreaterThanZero = integerAndGreaterThanZero;
|
|
@@ -30,7 +30,8 @@ const Choice = _ref => {
|
|
|
30
30
|
value,
|
|
31
31
|
multiple,
|
|
32
32
|
validate,
|
|
33
|
-
disabled
|
|
33
|
+
disabled,
|
|
34
|
+
...otherProps
|
|
34
35
|
} = _ref;
|
|
35
36
|
const type = multiple ? 'checkbox' : 'radio';
|
|
36
37
|
const [field] = (0, _formik.useField)({
|
|
@@ -46,7 +47,7 @@ const Choice = _ref => {
|
|
|
46
47
|
type: type,
|
|
47
48
|
id: id,
|
|
48
49
|
name: name
|
|
49
|
-
}, field, {
|
|
50
|
+
}, field, otherProps, {
|
|
50
51
|
value: value,
|
|
51
52
|
disabled: disabled
|
|
52
53
|
})), /*#__PURE__*/React.createElement("label", {
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _formik = require("formik");
|
|
10
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
11
|
+
require("./styles.scss");
|
|
12
|
+
var _common = require("./common");
|
|
13
|
+
var _common2 = require("../../common");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
18
|
+
|
|
19
|
+
// Local Definitions
|
|
20
|
+
|
|
21
|
+
const baseClassName = _exports.default.base;
|
|
22
|
+
const componentClassName = 'file-upload';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This is the component description.
|
|
26
|
+
*/
|
|
27
|
+
const FileUpload = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
id,
|
|
30
|
+
className: userClassName,
|
|
31
|
+
style,
|
|
32
|
+
label,
|
|
33
|
+
description,
|
|
34
|
+
accept,
|
|
35
|
+
multiple,
|
|
36
|
+
name,
|
|
37
|
+
disabled,
|
|
38
|
+
maxCount,
|
|
39
|
+
maxCountError,
|
|
40
|
+
maxSize,
|
|
41
|
+
maxSizeError,
|
|
42
|
+
onChange,
|
|
43
|
+
uploadStatus,
|
|
44
|
+
filePreviewAlignment,
|
|
45
|
+
optional,
|
|
46
|
+
labelColor,
|
|
47
|
+
color,
|
|
48
|
+
viewOnly,
|
|
49
|
+
handleFileDelete
|
|
50
|
+
// ...otherProps
|
|
51
|
+
} = _ref;
|
|
52
|
+
const [field,, helpers] = (0, _formik.useField)({
|
|
53
|
+
name
|
|
54
|
+
});
|
|
55
|
+
const {
|
|
56
|
+
value
|
|
57
|
+
} = field;
|
|
58
|
+
const {
|
|
59
|
+
setError,
|
|
60
|
+
setValue,
|
|
61
|
+
setTouched
|
|
62
|
+
} = helpers;
|
|
63
|
+
const handleChange = event => {
|
|
64
|
+
setTouched(true, false);
|
|
65
|
+
const newFiles = Array.from(event.currentTarget.files);
|
|
66
|
+
const currentFiles = value || [];
|
|
67
|
+
const currentCount = currentFiles.length + newFiles.length;
|
|
68
|
+
if (maxCount && currentCount > maxCount) {
|
|
69
|
+
setError(maxCountError || `Maximum of ${maxCount} files allowed`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const duplicateFiles = newFiles.filter(newFile => currentFiles.some(currentFile => currentFile.name === newFile.name));
|
|
73
|
+
if (duplicateFiles.length > 0) {
|
|
74
|
+
setError('You cannot upload the same file twice.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (maxSize) {
|
|
78
|
+
const oversizedFiles = newFiles.filter(file => file.size > maxSize);
|
|
79
|
+
if (oversizedFiles.length > 0) {
|
|
80
|
+
setError(maxSizeError || `File size exceeds the limit of ${maxSize} bytes`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const updatedFiles = [...currentFiles, ...newFiles];
|
|
85
|
+
setValue(updatedFiles);
|
|
86
|
+
onChange?.(updatedFiles);
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line no-param-reassign
|
|
89
|
+
event.target.value = null;
|
|
90
|
+
};
|
|
91
|
+
const handleDelete = _ref2 => {
|
|
92
|
+
let {
|
|
93
|
+
fileIndex,
|
|
94
|
+
identifier
|
|
95
|
+
} = _ref2;
|
|
96
|
+
const updatedFiles = value?.filter((_, i) => i !== fileIndex);
|
|
97
|
+
setValue(updatedFiles);
|
|
98
|
+
handleFileDelete?.({
|
|
99
|
+
fileIndex,
|
|
100
|
+
identifier
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const acceptOptions = Array.isArray(accept) ? accept?.join(',') : accept;
|
|
104
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
105
|
+
id: id,
|
|
106
|
+
className: [baseClassName, componentClassName, userClassName, `preview-${filePreviewAlignment}`, `y-${color}`].filter(e => e).join(' '),
|
|
107
|
+
style: style
|
|
108
|
+
}, /*#__PURE__*/React.createElement("p", null, label), /*#__PURE__*/React.createElement(_common2.FormDescription, {
|
|
109
|
+
className: "s-1",
|
|
110
|
+
description: description,
|
|
111
|
+
name: name
|
|
112
|
+
}), !viewOnly && /*#__PURE__*/React.createElement(_common2.FormLabel, {
|
|
113
|
+
name: name,
|
|
114
|
+
color: labelColor,
|
|
115
|
+
optional: optional
|
|
116
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
117
|
+
id: name,
|
|
118
|
+
className: "file",
|
|
119
|
+
type: "file",
|
|
120
|
+
accept: acceptOptions,
|
|
121
|
+
multiple: multiple || maxCount && maxCount > 0,
|
|
122
|
+
disabled: disabled,
|
|
123
|
+
onChange: handleChange
|
|
124
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
125
|
+
className: "ai-icon"
|
|
126
|
+
}, "U"), /*#__PURE__*/React.createElement("span", null, "Attach file")), value?.length > 0 && /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
className: "attached-files"
|
|
128
|
+
}, /*#__PURE__*/React.createElement("p", null, "Attached files:"), /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
className: "files"
|
|
130
|
+
}, value.map((file, indx) => {
|
|
131
|
+
const isFileObject = file instanceof File;
|
|
132
|
+
return /*#__PURE__*/React.createElement(_common.FilePreview, {
|
|
133
|
+
file: file,
|
|
134
|
+
key: isFileObject ? file.name : file,
|
|
135
|
+
disabled: disabled,
|
|
136
|
+
handleDelete: () => handleDelete({
|
|
137
|
+
fileIndex: indx,
|
|
138
|
+
identifier: isFileObject ? file.name : file?.id
|
|
139
|
+
}),
|
|
140
|
+
uploadStatus: uploadStatus?.[file?.name],
|
|
141
|
+
viewOnly: viewOnly
|
|
142
|
+
});
|
|
143
|
+
}))));
|
|
144
|
+
};
|
|
145
|
+
FileUpload.propTypes = {
|
|
146
|
+
/**
|
|
147
|
+
* The HTML id for this element
|
|
148
|
+
*/
|
|
149
|
+
id: _propTypes.default.string,
|
|
150
|
+
/**
|
|
151
|
+
* The HTML class names for this element
|
|
152
|
+
*/
|
|
153
|
+
className: _propTypes.default.string,
|
|
154
|
+
/**
|
|
155
|
+
* The React-written, css properties for this element.
|
|
156
|
+
*/
|
|
157
|
+
style: _propTypes.default.objectOf(_propTypes.default.string),
|
|
158
|
+
/**
|
|
159
|
+
* The label text for the file input
|
|
160
|
+
*/
|
|
161
|
+
label: _propTypes.default.string,
|
|
162
|
+
/**
|
|
163
|
+
* The description text below the label
|
|
164
|
+
*/
|
|
165
|
+
description: _propTypes.default.string,
|
|
166
|
+
/**
|
|
167
|
+
* The color of the text
|
|
168
|
+
*/
|
|
169
|
+
color: _propTypes.default.string,
|
|
170
|
+
/**
|
|
171
|
+
* The accepted file types (e.g., 'image/*')
|
|
172
|
+
*/
|
|
173
|
+
accept: _propTypes.default.string,
|
|
174
|
+
/**
|
|
175
|
+
* Whether to allow multiple file uploads
|
|
176
|
+
*/
|
|
177
|
+
multiple: _propTypes.default.bool,
|
|
178
|
+
/**
|
|
179
|
+
* The name attribute for the input
|
|
180
|
+
*/
|
|
181
|
+
name: _propTypes.default.string.isRequired,
|
|
182
|
+
/**
|
|
183
|
+
* Whether the the input should be disabled
|
|
184
|
+
*/
|
|
185
|
+
disabled: _propTypes.default.bool,
|
|
186
|
+
/**
|
|
187
|
+
* The maximum number of files allowed
|
|
188
|
+
*/
|
|
189
|
+
maxCount: _propTypes.default.number,
|
|
190
|
+
/**
|
|
191
|
+
* The error message when max count is exceeded
|
|
192
|
+
*/
|
|
193
|
+
maxCountError: _propTypes.default.string,
|
|
194
|
+
/**
|
|
195
|
+
* The maximum size of files allowed (in bytes)
|
|
196
|
+
*/
|
|
197
|
+
maxSize: _propTypes.default.number,
|
|
198
|
+
/**
|
|
199
|
+
* The error message when file size exceeds max size
|
|
200
|
+
*/
|
|
201
|
+
maxSizeError: _propTypes.default.string,
|
|
202
|
+
/**
|
|
203
|
+
* The upload progress value (0-100)
|
|
204
|
+
*/
|
|
205
|
+
// progress:PropTypes.number,
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The function to handle file change events
|
|
209
|
+
*/
|
|
210
|
+
onChange: _propTypes.default.func,
|
|
211
|
+
/**
|
|
212
|
+
* The function to handle file delete events
|
|
213
|
+
*/
|
|
214
|
+
handleFileDelete: _propTypes.default.func,
|
|
215
|
+
/**
|
|
216
|
+
* The upload status of the file with the file name as the key
|
|
217
|
+
*/
|
|
218
|
+
uploadStatus: _propTypes.default.objectOf(_propTypes.default.string),
|
|
219
|
+
/**
|
|
220
|
+
* The alignment for file previews WRT the upload input
|
|
221
|
+
*/
|
|
222
|
+
filePreviewAlignment: _propTypes.default.oneOf(['left', 'right', 'top', 'bottom']),
|
|
223
|
+
/**
|
|
224
|
+
* Whether the file upload is in view only mode
|
|
225
|
+
*/
|
|
226
|
+
viewOnly: _propTypes.default.bool
|
|
227
|
+
};
|
|
228
|
+
FileUpload.defaultProps = {
|
|
229
|
+
disabled: false,
|
|
230
|
+
color: 'paragraph',
|
|
231
|
+
filePreviewAlignment: 'bottom',
|
|
232
|
+
viewOnly: false
|
|
233
|
+
};
|
|
234
|
+
var _default = exports.default = FileUpload;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
10
|
+
var _a = require("../../../../../a");
|
|
11
|
+
require("./styles.scss");
|
|
12
|
+
var _b = require("../../../../../b");
|
|
13
|
+
var _utils = require("../../utils");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
18
|
+
|
|
19
|
+
// Local Definitions
|
|
20
|
+
|
|
21
|
+
const baseClassName = _exports.default.base;
|
|
22
|
+
const componentClassName = 'file-preview';
|
|
23
|
+
const statusColorMap = {
|
|
24
|
+
pending: 'yellow',
|
|
25
|
+
error: 'red',
|
|
26
|
+
success: 'green'
|
|
27
|
+
};
|
|
28
|
+
const FILE_UPLOAD_COMPLETE_PROGRESS = 100;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This is the component description.
|
|
32
|
+
*/
|
|
33
|
+
const FilePreview = _ref => {
|
|
34
|
+
let {
|
|
35
|
+
id,
|
|
36
|
+
className: userClassName,
|
|
37
|
+
style,
|
|
38
|
+
file,
|
|
39
|
+
disabled,
|
|
40
|
+
handleDelete,
|
|
41
|
+
uploadStatus,
|
|
42
|
+
color,
|
|
43
|
+
uploadProgress
|
|
44
|
+
// ...otherProps
|
|
45
|
+
} = _ref;
|
|
46
|
+
const isFileObject = file instanceof File;
|
|
47
|
+
const type = isFileObject ? (0, _utils.getFileType)(file) : (0, _utils.getFileTypeFromUrl)(file?.url);
|
|
48
|
+
const status = uploadStatus?.status;
|
|
49
|
+
const statusColor = statusColorMap[status] ?? color;
|
|
50
|
+
const isPending = status === 'pending';
|
|
51
|
+
// isPreview means the file is uploaded and previewed while other files can still be uploaded
|
|
52
|
+
const isSuccess = status === 'success' || file?.isPreview;
|
|
53
|
+
const handlePreview = () => {
|
|
54
|
+
if (!isFileObject) {
|
|
55
|
+
window.open(file.url, '_blank');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const canDelete = file?.isPreview || isFileObject;
|
|
59
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
60
|
+
id: id,
|
|
61
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
62
|
+
style: style
|
|
63
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
64
|
+
className: "identity"
|
|
65
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
66
|
+
className: ['type', type.toLowerCase()].filter(e => e).join(' ')
|
|
67
|
+
}, type), /*#__PURE__*/React.createElement("span", {
|
|
68
|
+
title: file.name,
|
|
69
|
+
className: "name"
|
|
70
|
+
}, file.name), /*#__PURE__*/React.createElement(_b.Button, {
|
|
71
|
+
isCompact: true,
|
|
72
|
+
isSimple: true,
|
|
73
|
+
onClick: () => canDelete ? handleDelete() : handlePreview()
|
|
74
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
75
|
+
className: "icon x-ui-icons c-x"
|
|
76
|
+
}, canDelete ? 'Y' : '9'))), !disabled && /*#__PURE__*/React.createElement("div", {
|
|
77
|
+
className: `progress-status x-${statusColor}`
|
|
78
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
79
|
+
className: "status"
|
|
80
|
+
}, isPending ? /*#__PURE__*/React.createElement(_a.LoadingCircle, {
|
|
81
|
+
className: `x-${statusColor}`,
|
|
82
|
+
heightWidth: "1rem",
|
|
83
|
+
color: statusColor
|
|
84
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
85
|
+
className: "icon"
|
|
86
|
+
}, isSuccess ? 'I' : 'Y'), /*#__PURE__*/React.createElement("span", null, isSuccess ? 'Uploaded' : 'Error'))), /*#__PURE__*/React.createElement(_a.ProgressBar, {
|
|
87
|
+
color: statusColor,
|
|
88
|
+
progress: isPending ? uploadProgress : FILE_UPLOAD_COMPLETE_PROGRESS,
|
|
89
|
+
height: "3px"
|
|
90
|
+
})));
|
|
91
|
+
};
|
|
92
|
+
FilePreview.propTypes = {
|
|
93
|
+
/**
|
|
94
|
+
* The HTML id for this element
|
|
95
|
+
*/
|
|
96
|
+
id: _propTypes.default.string,
|
|
97
|
+
/**
|
|
98
|
+
* The HTML class names for this element
|
|
99
|
+
*/
|
|
100
|
+
className: _propTypes.default.string,
|
|
101
|
+
/**
|
|
102
|
+
* The React-written, css properties for this element.
|
|
103
|
+
*/
|
|
104
|
+
style: _propTypes.default.objectOf(_propTypes.default.string),
|
|
105
|
+
/**
|
|
106
|
+
* The base color of the file preview
|
|
107
|
+
*/
|
|
108
|
+
color: _propTypes.default.string,
|
|
109
|
+
/**
|
|
110
|
+
* The upload progress of the file
|
|
111
|
+
*/
|
|
112
|
+
uploadProgress: _propTypes.default.number
|
|
113
|
+
};
|
|
114
|
+
FilePreview.defaultProps = {
|
|
115
|
+
color: 'green',
|
|
116
|
+
uploadProgress: 45
|
|
117
|
+
};
|
|
118
|
+
var _default = exports.default = FilePreview;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FilePreview", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _FilePreview.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _FilePreview = _interopRequireDefault(require("./FilePreview"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-padding: 1rem;
|
|
6
|
+
$default-margin: 1rem;
|
|
7
|
+
$files-per-row: 3;
|
|
8
|
+
$total-gaps: $files-per-row - 1;
|
|
9
|
+
$combined-gap: calc(var(--gap) * $total-gaps);
|
|
10
|
+
$width-without-gaps: calc(100% - $combined-gap);
|
|
11
|
+
$default-file-width: calc($width-without-gaps / $files-per-row);
|
|
12
|
+
|
|
13
|
+
.#{bem.$base}.file-preview {
|
|
14
|
+
border: var(--theme-default-border-style) var(--ui-lines);
|
|
15
|
+
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: calc(var(--gap) / 4);
|
|
19
|
+
padding: $default-padding;
|
|
20
|
+
width: $default-file-width;
|
|
21
|
+
|
|
22
|
+
> .identity {
|
|
23
|
+
align-items: center;
|
|
24
|
+
display: flex;
|
|
25
|
+
gap: calc(var(--gap) / 2);
|
|
26
|
+
|
|
27
|
+
> .type {
|
|
28
|
+
padding-block: calc($default-padding / 4);
|
|
29
|
+
padding-inline: calc($default-padding / 2);
|
|
30
|
+
|
|
31
|
+
// TODO: update the colors to use variables. These are colors from the new DS
|
|
32
|
+
&.pdf {
|
|
33
|
+
background-color: #fdead7;
|
|
34
|
+
color: #b93814;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&.file {
|
|
38
|
+
background-color: #eef2f6;
|
|
39
|
+
color: #364151;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&.txt {
|
|
43
|
+
background-color: #d1dfff;
|
|
44
|
+
color: #004eeb;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
&.vid {
|
|
49
|
+
background-color: #ebe9fe;
|
|
50
|
+
color: #5a25dc;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&.img {
|
|
54
|
+
background-color: #cbfbef;
|
|
55
|
+
color: #107569;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&.aud {
|
|
59
|
+
background-color: #fef7c3;
|
|
60
|
+
color: #a15c08;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
> .name {
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
text-overflow: ellipsis;
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
> .#{bem.$base}.button {
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
margin-left: auto;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
> .progress-status {
|
|
77
|
+
> .status {
|
|
78
|
+
align-items: center;
|
|
79
|
+
color: var(--x);
|
|
80
|
+
display: flex;
|
|
81
|
+
gap: calc(var(--gap) / 2);
|
|
82
|
+
margin-bottom: calc($default-margin / 4);
|
|
83
|
+
|
|
84
|
+
> .icon {
|
|
85
|
+
background-color: var(--x);
|
|
86
|
+
border-radius: 50%;
|
|
87
|
+
color: var(--on-x);
|
|
88
|
+
font-size: calc(var(--s-2) * 1rem);
|
|
89
|
+
padding: calc($default-padding / 4);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FilePreview", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _FilePreview.FilePreview;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _FilePreview = require("./FilePreview");
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FileUpload", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _FileUpload.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "fileUploadOptions", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _utils.fileUploadOptions;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "getFileType", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _utils.getFileType;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "getFileTypeFromUrl", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _utils.getFileTypeFromUrl;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _FileUpload = _interopRequireDefault(require("./FileUpload"));
|
|
31
|
+
var _utils = require("./utils");
|
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-padding: 1rem;
|
|
6
|
+
$default-margin: 1rem;
|
|
7
|
+
|
|
8
|
+
.#{bem.$base}.file-upload {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: var(--gap);
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
> p {
|
|
15
|
+
color: var(--y);
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
> .#{bem.$base}.description {
|
|
20
|
+
height: auto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
> .#{bem.$base}.form-label {
|
|
24
|
+
align-items: center;
|
|
25
|
+
border: var(--theme-default-border-style) var(--ui-lines);
|
|
26
|
+
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
27
|
+
color: var(--heading);
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: calc(var(--gap) / 2);
|
|
31
|
+
padding: $default-padding;
|
|
32
|
+
width: fit-content;
|
|
33
|
+
|
|
34
|
+
&:has(>input:disabled) {
|
|
35
|
+
--icon-color: var(--hard-disabled);
|
|
36
|
+
color: var(--hard-disabled);
|
|
37
|
+
cursor: not-allowed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:has(>input:not(:disabled)) {
|
|
41
|
+
&:hover,
|
|
42
|
+
&:active {
|
|
43
|
+
border: var(--theme-hover-input-border);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
> .ai-icon {
|
|
48
|
+
color: var(--icon-color, var(--interactive));
|
|
49
|
+
font-size: calc(var(--s2) * 1rem);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
> input[type="file"] {
|
|
53
|
+
display: none;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
> .attached-files {
|
|
58
|
+
display: flex;
|
|
59
|
+
gap: var(--gap);
|
|
60
|
+
|
|
61
|
+
> p {
|
|
62
|
+
margin: 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
> .files {
|
|
66
|
+
align-items: center;
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-wrap: wrap;
|
|
69
|
+
gap: var(--gap);
|
|
70
|
+
width: 100%;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFileTypeFromUrl = exports.getFileType = exports.fileUploadOptions = void 0;
|
|
7
|
+
const fileUploadOptions = exports.fileUploadOptions = [{
|
|
8
|
+
key: 'FILE',
|
|
9
|
+
value: '.doc,.docx,.odt,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text',
|
|
10
|
+
label: 'Documents'
|
|
11
|
+
}, {
|
|
12
|
+
key: 'TXT',
|
|
13
|
+
value: '.xls,.xlsx,.ods,.csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet,text/csv',
|
|
14
|
+
label: 'Spreadsheets'
|
|
15
|
+
}, {
|
|
16
|
+
key: 'PDF',
|
|
17
|
+
value: '.pdf,application/pdf',
|
|
18
|
+
label: 'PDF'
|
|
19
|
+
}, {
|
|
20
|
+
key: 'VID',
|
|
21
|
+
value: '.mp4,.ogg,.webm,video/mp4,video/ogg,video/webm',
|
|
22
|
+
label: 'Videos'
|
|
23
|
+
}, {
|
|
24
|
+
key: 'IMG',
|
|
25
|
+
value: '.png,.jpeg,.jpg,.gif,.webp,image/png,image/jpeg,image/gif,image/webp',
|
|
26
|
+
label: 'Images'
|
|
27
|
+
}, {
|
|
28
|
+
key: 'AUD',
|
|
29
|
+
value: '.mp3,.ogg,.wav,audio/mpeg,audio/ogg,audio/wav',
|
|
30
|
+
label: 'Audio'
|
|
31
|
+
}];
|
|
32
|
+
const getFileType = file => {
|
|
33
|
+
const mimeType = file?.type;
|
|
34
|
+
const extension = file?.name?.split('.').pop().toLowerCase();
|
|
35
|
+
const fileType = fileUploadOptions.find(option => option.value.includes(mimeType) || option.value.includes(extension));
|
|
36
|
+
return fileType ? fileType.key : 'unknown';
|
|
37
|
+
};
|
|
38
|
+
exports.getFileType = getFileType;
|
|
39
|
+
const getFileTypeFromUrl = url => {
|
|
40
|
+
const urlWithoutParams = url.split('?')[0];
|
|
41
|
+
const extension = urlWithoutParams.split('.').pop().toLowerCase();
|
|
42
|
+
const fileType = fileUploadOptions.find(option => option.value.includes(extension));
|
|
43
|
+
return fileType ? fileType.key : 'unknown';
|
|
44
|
+
};
|
|
45
|
+
exports.getFileTypeFromUrl = getFileTypeFromUrl;
|