@performant-software/semantic-components 1.0.3 → 1.0.4-beta.1
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/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/main.css +25 -0
- package/package.json +2 -2
- package/src/components/FileUploadModal.js +294 -319
- package/src/components/FileUploadProgress.css +24 -0
- package/src/components/FileUploadProgress.js +75 -0
- package/src/components/FileUploadStatus.css +3 -0
- package/src/components/FileUploadStatus.js +65 -0
- package/src/i18n/en.json +2 -1
- package/types/components/FileUploadModal.js.flow +294 -319
- package/types/components/FileUploadProgress.js.flow +75 -0
- package/types/components/FileUploadStatus.js.flow +65 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import React, { useMemo, type ComponentType } from 'react';
|
|
4
|
+
import { Header, Icon, Progress } from 'semantic-ui-react';
|
|
5
|
+
import './FileUploadProgress.css';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
completed: number,
|
|
9
|
+
total: number,
|
|
10
|
+
uploading?: boolean
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const FileUploadProgress: ComponentType<any> = (props: Props) => {
|
|
14
|
+
/**
|
|
15
|
+
* Sets the "complete" variable to "true" if the number of completed items is equal to the total and
|
|
16
|
+
* greater than zero.
|
|
17
|
+
*
|
|
18
|
+
* @type {unknown}
|
|
19
|
+
*/
|
|
20
|
+
const complete = useMemo(() => (
|
|
21
|
+
props.completed > 0 && props.completed === props.total
|
|
22
|
+
), [props.completed, props.total]);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Sets the percent of completed items.
|
|
26
|
+
*
|
|
27
|
+
* @type {number|number}
|
|
28
|
+
*/
|
|
29
|
+
const percent = useMemo(() => (
|
|
30
|
+
props.total > 0 ? (props.completed / props.total) : 0
|
|
31
|
+
), [props.completed, props.total]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sets the formatted percent view.
|
|
35
|
+
*/
|
|
36
|
+
const percentView = useMemo(() => (
|
|
37
|
+
Number(percent)
|
|
38
|
+
.toLocaleString(undefined, {
|
|
39
|
+
style: 'percent',
|
|
40
|
+
minimumFractionDigits: 0
|
|
41
|
+
})
|
|
42
|
+
), [percent]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
className='file-upload-progress'
|
|
47
|
+
>
|
|
48
|
+
<Icon
|
|
49
|
+
color='blue'
|
|
50
|
+
name='cloud upload'
|
|
51
|
+
size='big'
|
|
52
|
+
/>
|
|
53
|
+
<div
|
|
54
|
+
className='progress-container'
|
|
55
|
+
>
|
|
56
|
+
<Header>
|
|
57
|
+
<Header.Content
|
|
58
|
+
content={percentView}
|
|
59
|
+
/>
|
|
60
|
+
<Header.Subheader>
|
|
61
|
+
{ !(props.uploading || complete) && 'Getting Started' }
|
|
62
|
+
{ props.uploading && 'Uploading...' }
|
|
63
|
+
{ complete && 'Completed' }
|
|
64
|
+
</Header.Subheader>
|
|
65
|
+
</Header>
|
|
66
|
+
<Progress
|
|
67
|
+
color='blue'
|
|
68
|
+
percent={percent * 100}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default FileUploadProgress;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import React, { useMemo, type ComponentType } from 'react';
|
|
4
|
+
import { Icon, Label, Loader } from 'semantic-ui-react';
|
|
5
|
+
import './FileUploadStatus.css';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
status: string
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const Status = {
|
|
12
|
+
pending: 'pending',
|
|
13
|
+
processing: 'processing',
|
|
14
|
+
complete: 'complete',
|
|
15
|
+
error: 'error'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ColorsByStatus = {
|
|
19
|
+
[Status.processing]: 'black',
|
|
20
|
+
[Status.complete]: 'green',
|
|
21
|
+
[Status.error]: 'red'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const IconsByStatus = {
|
|
25
|
+
[Status.pending]: 'clock outline',
|
|
26
|
+
[Status.complete]: 'checkmark',
|
|
27
|
+
[Status.error]: 'warning circle'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const TextByStatus = {
|
|
31
|
+
[Status.pending]: 'Pending',
|
|
32
|
+
[Status.processing]: 'Processing',
|
|
33
|
+
[Status.complete]: 'Complete',
|
|
34
|
+
[Status.error]: 'Error'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const FileUploadStatus: ComponentType<any> = ({ status = Status.pending }: Props) => {
|
|
38
|
+
const color = useMemo(() => ColorsByStatus[status], [status]);
|
|
39
|
+
const icon = useMemo(() => IconsByStatus[status], [status]);
|
|
40
|
+
const text = useMemo(() => TextByStatus[status], [status]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Label
|
|
44
|
+
className='file-upload-status'
|
|
45
|
+
color={color}
|
|
46
|
+
>
|
|
47
|
+
{ status === Status.processing && (
|
|
48
|
+
<Loader
|
|
49
|
+
active
|
|
50
|
+
inline
|
|
51
|
+
inverted
|
|
52
|
+
size='mini'
|
|
53
|
+
/>
|
|
54
|
+
)}
|
|
55
|
+
{ icon && (
|
|
56
|
+
<Icon
|
|
57
|
+
name={icon}
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
{ text }
|
|
61
|
+
</Label>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default FileUploadStatus;
|