@pareto-engineering/design-system 4.2.3 → 4.3.2
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/fields/FileUpload/FileUpload.js +32 -29
- package/dist/cjs/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js} +64 -25
- package/dist/cjs/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +3 -3
- package/{src/ui/f/fields/FileUpload/common/FilePreview → dist/cjs/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
- package/dist/cjs/f/fields/FileUpload/common/index.js +3 -3
- package/dist/cjs/f/fields/FileUpload/index.js +14 -2
- package/dist/cjs/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +19 -2
- package/dist/cjs/f/fields/index.js +12 -0
- package/dist/cjs/g/FormBuilder/FormBuilder.js +11 -3
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +6 -2
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +6 -2
- package/dist/es/f/fields/FileUpload/FileUpload.js +32 -30
- package/dist/es/f/fields/FileUpload/common/Preview/Preview.js +119 -0
- package/dist/es/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
- package/dist/{cjs/f/fields/FileUpload/common/FilePreview → es/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
- package/dist/es/f/fields/FileUpload/common/index.js +1 -1
- package/dist/es/f/fields/FileUpload/index.js +1 -1
- package/dist/es/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +16 -1
- package/dist/es/f/fields/index.js +1 -1
- package/dist/es/g/FormBuilder/FormBuilder.js +11 -3
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +6 -2
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +6 -2
- package/package.json +2 -2
- package/src/stories/f/FileUpload.stories.jsx +13 -0
- package/src/ui/f/fields/FileUpload/FileUpload.jsx +25 -26
- package/src/ui/f/fields/FileUpload/common/Preview/Preview.jsx +185 -0
- package/src/ui/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
- package/{dist/es/f/fields/FileUpload/common/FilePreview → src/ui/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
- package/src/ui/f/fields/FileUpload/common/index.js +1 -1
- package/src/ui/f/fields/FileUpload/index.js +1 -1
- package/src/ui/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +20 -0
- package/src/ui/f/fields/index.js +6 -1
- package/src/ui/g/FormBuilder/FormBuilder.jsx +9 -0
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +4 -0
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +4 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +65 -0
- package/dist/es/f/fields/FileUpload/common/FilePreview/FilePreview.js +0 -80
- package/src/ui/f/fields/FileUpload/common/FilePreview/FilePreview.jsx +0 -115
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
export {
|
|
2
|
+
export { Preview } from './Preview'
|
|
@@ -30,3 +30,23 @@ export const fileUploadOptions = [
|
|
|
30
30
|
label:'Audio',
|
|
31
31
|
},
|
|
32
32
|
]
|
|
33
|
+
|
|
34
|
+
export const getFileType = (file) => {
|
|
35
|
+
const mimeType = file?.type
|
|
36
|
+
const extension = file?.name?.split('.').pop().toLowerCase()
|
|
37
|
+
const fileType = fileUploadOptions.find(
|
|
38
|
+
(option) => option.value.includes(mimeType) || option.value.includes(extension))
|
|
39
|
+
|
|
40
|
+
return fileType ? fileType.key : 'unknown'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const getFileTypeFromUrl = (url) => {
|
|
44
|
+
if (!url) {
|
|
45
|
+
return 'BROKEN'
|
|
46
|
+
}
|
|
47
|
+
const urlWithoutParams = url.split('?')[0]
|
|
48
|
+
const extension = urlWithoutParams.split('.').pop().toLowerCase()
|
|
49
|
+
const fileType = fileUploadOptions.find((option) => option.value.includes(extension))
|
|
50
|
+
|
|
51
|
+
return fileType ? fileType.key : 'UNKNOWN'
|
|
52
|
+
}
|
package/src/ui/f/fields/index.js
CHANGED
|
@@ -9,4 +9,9 @@ export { Checkbox } from './Checkbox'
|
|
|
9
9
|
export { QueryChoices } from './QueryChoices'
|
|
10
10
|
export { LinkInput } from './LinkInput'
|
|
11
11
|
export { EditorInput } from './EditorInput'
|
|
12
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
FileUpload,
|
|
14
|
+
fileUploadOptions,
|
|
15
|
+
getFileType,
|
|
16
|
+
getFileTypeFromUrl,
|
|
17
|
+
} from './FileUpload'
|
|
@@ -33,6 +33,8 @@ const FormBuilder = ({
|
|
|
33
33
|
onRendererFormSave,
|
|
34
34
|
onBuilderValidate,
|
|
35
35
|
initialBuilderValues,
|
|
36
|
+
fileUploadStatus,
|
|
37
|
+
handleFileDelete,
|
|
36
38
|
// ...otherProps
|
|
37
39
|
}) => (
|
|
38
40
|
<div
|
|
@@ -65,6 +67,8 @@ const FormBuilder = ({
|
|
|
65
67
|
readOnly={readOnly}
|
|
66
68
|
shouldSubmit={shouldSubmit}
|
|
67
69
|
onError={onRendererError}
|
|
70
|
+
fileUploadStatus={fileUploadStatus}
|
|
71
|
+
handleFileDelete={handleFileDelete}
|
|
68
72
|
/>
|
|
69
73
|
)}
|
|
70
74
|
</div>
|
|
@@ -119,6 +123,11 @@ FormBuilder.propTypes = {
|
|
|
119
123
|
* Whether the form builder in renderer mode should submit the form values itself
|
|
120
124
|
*/
|
|
121
125
|
shouldSubmit:PropTypes.bool,
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The upload status of files if any
|
|
129
|
+
*/
|
|
130
|
+
fileUploadStatus:PropTypes.objectOf(PropTypes.string),
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
FormBuilder.defaultProps = {
|
|
@@ -62,6 +62,8 @@ const Renderer = ({
|
|
|
62
62
|
onSave,
|
|
63
63
|
onError,
|
|
64
64
|
shouldSubmit,
|
|
65
|
+
fileUploadStatus,
|
|
66
|
+
handleFileDelete,
|
|
65
67
|
// ...otherProps
|
|
66
68
|
}) => {
|
|
67
69
|
const [currentSectionIndex, setCurrentSectionIndex] = useState(0)
|
|
@@ -154,6 +156,8 @@ const Renderer = ({
|
|
|
154
156
|
{...section}
|
|
155
157
|
readOnly={readOnly}
|
|
156
158
|
setUpdatedFormData={setUpdatedFormData}
|
|
159
|
+
fileUploadStatus={fileUploadStatus}
|
|
160
|
+
handleFileDelete={handleFileDelete}
|
|
157
161
|
/>
|
|
158
162
|
)
|
|
159
163
|
))}
|
|
@@ -27,6 +27,8 @@ const Section = ({
|
|
|
27
27
|
description,
|
|
28
28
|
inputs,
|
|
29
29
|
readOnly,
|
|
30
|
+
fileUploadStatus,
|
|
31
|
+
handleFileDelete,
|
|
30
32
|
// ...otherProps
|
|
31
33
|
}) => (
|
|
32
34
|
<div
|
|
@@ -52,6 +54,8 @@ const Section = ({
|
|
|
52
54
|
key={input.name}
|
|
53
55
|
{...input}
|
|
54
56
|
disabled={readOnly}
|
|
57
|
+
uploadStatus={fileUploadStatus}
|
|
58
|
+
handleFileDelete={handleFileDelete}
|
|
55
59
|
/>
|
|
56
60
|
))}
|
|
57
61
|
</div>
|
|
@@ -27553,6 +27553,49 @@ exports[`Storyshots f/fields/FileUpload Multiple 1`] = `
|
|
|
27553
27553
|
</form>
|
|
27554
27554
|
`;
|
|
27555
27555
|
|
|
27556
|
+
exports[`Storyshots f/fields/FileUpload Preview 1`] = `
|
|
27557
|
+
<form
|
|
27558
|
+
action="#"
|
|
27559
|
+
onReset={[Function]}
|
|
27560
|
+
onSubmit={[Function]}
|
|
27561
|
+
>
|
|
27562
|
+
<div
|
|
27563
|
+
className="base file-preview"
|
|
27564
|
+
>
|
|
27565
|
+
<div
|
|
27566
|
+
className="identity"
|
|
27567
|
+
>
|
|
27568
|
+
<span
|
|
27569
|
+
className="type unknown"
|
|
27570
|
+
>
|
|
27571
|
+
UNKNOWN
|
|
27572
|
+
</span>
|
|
27573
|
+
<span
|
|
27574
|
+
className="name"
|
|
27575
|
+
title="test.tar"
|
|
27576
|
+
>
|
|
27577
|
+
test.tar
|
|
27578
|
+
</span>
|
|
27579
|
+
<button
|
|
27580
|
+
className="base button x-ui-icons modifierCompact modifierSimple"
|
|
27581
|
+
onClick={[Function]}
|
|
27582
|
+
type="button"
|
|
27583
|
+
>
|
|
27584
|
+
<span
|
|
27585
|
+
className="modifierUnderlined"
|
|
27586
|
+
>
|
|
27587
|
+
<span
|
|
27588
|
+
className="icon"
|
|
27589
|
+
>
|
|
27590
|
+
9
|
|
27591
|
+
</span>
|
|
27592
|
+
</span>
|
|
27593
|
+
</button>
|
|
27594
|
+
</div>
|
|
27595
|
+
</div>
|
|
27596
|
+
</form>
|
|
27597
|
+
`;
|
|
27598
|
+
|
|
27556
27599
|
exports[`Storyshots f/fields/FileUpload With Limited Count 1`] = `
|
|
27557
27600
|
<form
|
|
27558
27601
|
action="#"
|
|
@@ -32908,6 +32951,28 @@ exports[`Storyshots g/FormBuilder Renderer With Disabled 1`] = `
|
|
|
32908
32951
|
<p>
|
|
32909
32952
|
The file upload
|
|
32910
32953
|
</p>
|
|
32954
|
+
<label
|
|
32955
|
+
className="base form-label x-paragraph"
|
|
32956
|
+
htmlFor="section_0_input_0"
|
|
32957
|
+
>
|
|
32958
|
+
<input
|
|
32959
|
+
accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
|
|
32960
|
+
className="file"
|
|
32961
|
+
disabled={true}
|
|
32962
|
+
id="section_0_input_0"
|
|
32963
|
+
multiple={true}
|
|
32964
|
+
onChange={[Function]}
|
|
32965
|
+
type="file"
|
|
32966
|
+
/>
|
|
32967
|
+
<span
|
|
32968
|
+
className="ai-icon"
|
|
32969
|
+
>
|
|
32970
|
+
U
|
|
32971
|
+
</span>
|
|
32972
|
+
<span>
|
|
32973
|
+
Attach file
|
|
32974
|
+
</span>
|
|
32975
|
+
</label>
|
|
32911
32976
|
</div>
|
|
32912
32977
|
</div>
|
|
32913
32978
|
<div
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import styleNames from '@pareto-engineering/bem/exports';
|
|
5
|
-
|
|
6
|
-
// Local Definitions
|
|
7
|
-
|
|
8
|
-
import "./styles.scss";
|
|
9
|
-
import { ProgressBar } from "../../../../../a";
|
|
10
|
-
import { Button } from "../../../../../b";
|
|
11
|
-
import { fileUploadOptions } from "../../fileUploadOptions";
|
|
12
|
-
const baseClassName = styleNames.base;
|
|
13
|
-
const componentClassName = 'file-preview';
|
|
14
|
-
const getFileType = file => {
|
|
15
|
-
const mimeType = file.type;
|
|
16
|
-
const extension = file.name.split('.').pop().toLowerCase();
|
|
17
|
-
const fileType = fileUploadOptions.find(option => option.value.includes(mimeType) || option.value.includes(extension));
|
|
18
|
-
return fileType ? fileType.key : 'unknown';
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This is the component description.
|
|
23
|
-
*/
|
|
24
|
-
const FilePreview = ({
|
|
25
|
-
id,
|
|
26
|
-
className: userClassName,
|
|
27
|
-
style,
|
|
28
|
-
file,
|
|
29
|
-
disabled,
|
|
30
|
-
handleDelete
|
|
31
|
-
// ...otherProps
|
|
32
|
-
}) => {
|
|
33
|
-
const type = getFileType(file);
|
|
34
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
35
|
-
id: id,
|
|
36
|
-
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
37
|
-
style: style
|
|
38
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
39
|
-
className: "identity"
|
|
40
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
41
|
-
className: ['type', type.toLowerCase()].filter(e => e).join(' ')
|
|
42
|
-
}, type), /*#__PURE__*/React.createElement("span", {
|
|
43
|
-
title: file.name,
|
|
44
|
-
className: "name"
|
|
45
|
-
}, file.name), /*#__PURE__*/React.createElement(Button, {
|
|
46
|
-
isCompact: true,
|
|
47
|
-
isSimple: true,
|
|
48
|
-
onClick: handleDelete
|
|
49
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
50
|
-
className: "icon x-ui-icons c-x"
|
|
51
|
-
}, "Y"))), !disabled && /*#__PURE__*/React.createElement("div", {
|
|
52
|
-
className: "progress-status"
|
|
53
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
54
|
-
className: "status"
|
|
55
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
56
|
-
className: "icon"
|
|
57
|
-
}, "I"), /*#__PURE__*/React.createElement("span", null, "Uploaded")), /*#__PURE__*/React.createElement(ProgressBar, {
|
|
58
|
-
color: "green",
|
|
59
|
-
progress: 100,
|
|
60
|
-
height: "3px"
|
|
61
|
-
})));
|
|
62
|
-
};
|
|
63
|
-
FilePreview.propTypes = {
|
|
64
|
-
/**
|
|
65
|
-
* The HTML id for this element
|
|
66
|
-
*/
|
|
67
|
-
id: PropTypes.string,
|
|
68
|
-
/**
|
|
69
|
-
* The HTML class names for this element
|
|
70
|
-
*/
|
|
71
|
-
className: PropTypes.string,
|
|
72
|
-
/**
|
|
73
|
-
* The React-written, css properties for this element.
|
|
74
|
-
*/
|
|
75
|
-
style: PropTypes.objectOf(PropTypes.string)
|
|
76
|
-
};
|
|
77
|
-
FilePreview.defaultProps = {
|
|
78
|
-
// someProp:false
|
|
79
|
-
};
|
|
80
|
-
export default FilePreview;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
import * as React from 'react'
|
|
3
|
-
|
|
4
|
-
import PropTypes from 'prop-types'
|
|
5
|
-
|
|
6
|
-
import styleNames from '@pareto-engineering/bem/exports'
|
|
7
|
-
|
|
8
|
-
// Local Definitions
|
|
9
|
-
|
|
10
|
-
import './styles.scss'
|
|
11
|
-
|
|
12
|
-
import { ProgressBar } from 'ui/a'
|
|
13
|
-
|
|
14
|
-
import { Button } from 'ui/b'
|
|
15
|
-
|
|
16
|
-
import { fileUploadOptions } from '../../fileUploadOptions'
|
|
17
|
-
|
|
18
|
-
const baseClassName = styleNames.base
|
|
19
|
-
|
|
20
|
-
const componentClassName = 'file-preview'
|
|
21
|
-
|
|
22
|
-
const getFileType = (file) => {
|
|
23
|
-
const mimeType = file.type
|
|
24
|
-
const extension = file.name.split('.').pop().toLowerCase()
|
|
25
|
-
const fileType = fileUploadOptions.find(
|
|
26
|
-
(option) => option.value.includes(mimeType) || option.value.includes(extension))
|
|
27
|
-
|
|
28
|
-
return fileType ? fileType.key : 'unknown'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* This is the component description.
|
|
33
|
-
*/
|
|
34
|
-
const FilePreview = ({
|
|
35
|
-
id,
|
|
36
|
-
className:userClassName,
|
|
37
|
-
style,
|
|
38
|
-
file,
|
|
39
|
-
disabled,
|
|
40
|
-
handleDelete,
|
|
41
|
-
// ...otherProps
|
|
42
|
-
}) => {
|
|
43
|
-
const type = getFileType(file)
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div
|
|
47
|
-
id={id}
|
|
48
|
-
className={[
|
|
49
|
-
|
|
50
|
-
baseClassName,
|
|
51
|
-
|
|
52
|
-
componentClassName,
|
|
53
|
-
userClassName,
|
|
54
|
-
]
|
|
55
|
-
.filter((e) => e)
|
|
56
|
-
.join(' ')}
|
|
57
|
-
style={style}
|
|
58
|
-
>
|
|
59
|
-
<div className="identity">
|
|
60
|
-
<span
|
|
61
|
-
className={
|
|
62
|
-
[
|
|
63
|
-
'type',
|
|
64
|
-
type.toLowerCase(),
|
|
65
|
-
]
|
|
66
|
-
.filter((e) => e)
|
|
67
|
-
.join(' ')
|
|
68
|
-
}
|
|
69
|
-
>
|
|
70
|
-
{type}
|
|
71
|
-
</span>
|
|
72
|
-
<span title={file.name} className="name">{file.name}</span>
|
|
73
|
-
<Button isCompact isSimple onClick={handleDelete}>
|
|
74
|
-
<span className="icon x-ui-icons c-x">Y</span>
|
|
75
|
-
</Button>
|
|
76
|
-
</div>
|
|
77
|
-
{!disabled && (
|
|
78
|
-
<div className="progress-status">
|
|
79
|
-
<div className="status">
|
|
80
|
-
<span className="icon">I</span>
|
|
81
|
-
<span>Uploaded</span>
|
|
82
|
-
</div>
|
|
83
|
-
<ProgressBar
|
|
84
|
-
color="green"
|
|
85
|
-
progress={100}
|
|
86
|
-
height="3px"
|
|
87
|
-
/>
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
</div>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
FilePreview.propTypes = {
|
|
95
|
-
/**
|
|
96
|
-
* The HTML id for this element
|
|
97
|
-
*/
|
|
98
|
-
id:PropTypes.string,
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The HTML class names for this element
|
|
102
|
-
*/
|
|
103
|
-
className:PropTypes.string,
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The React-written, css properties for this element.
|
|
107
|
-
*/
|
|
108
|
-
style:PropTypes.objectOf(PropTypes.string),
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
FilePreview.defaultProps = {
|
|
112
|
-
// someProp:false
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export default FilePreview
|