@cashub/ui-elv 1.0.2 → 1.0.4
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/datetimePicker/index.js +2 -37
- package/esm/Tab/Tab.js +21 -0
- package/esm/Tab/TabList.js +160 -0
- package/esm/Tab/TabPanel.js +42 -0
- package/esm/Tab/TabTab.js +98 -0
- package/esm/Tab/index.js +23 -0
- package/esm/Tab/subComponent/TabContext.js +3 -0
- package/esm/Tab/subComponent/TabListV2.js +18 -0
- package/esm/Tab/subComponent/TabPanelV2.js +45 -0
- package/esm/Tab/subComponent/TabTabV2.js +56 -0
- package/esm/VerticalTab/TabList.js +20 -0
- package/esm/VerticalTab/TabPanel.js +45 -0
- package/esm/VerticalTab/TabTab.js +63 -0
- package/esm/VerticalTab/VerticalTab.js +34 -0
- package/esm/VerticalTab/index.js +9 -0
- package/esm/VerticalTab/subComponent/TabContext.js +3 -0
- package/esm/alert/Alert.js +22 -0
- package/esm/alert/index.js +1 -0
- package/esm/animate/Collapse.js +65 -0
- package/esm/animate/Loader.js +51 -0
- package/esm/animate/NumberCounter.js +45 -0
- package/esm/animate/PulseRing.js +26 -0
- package/esm/animate/Spinner.js +11 -0
- package/esm/animate/index.js +5 -0
- package/esm/assets/css/autocomplete.css +16 -0
- package/esm/assets/css/font.css +4 -0
- package/esm/assets/css/global.css +2 -0
- package/esm/assets/font/helvetica/Helvetica.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
- package/esm/assets/icons/app-management.png +0 -0
- package/esm/assets/icons/burger-black.png +0 -0
- package/esm/assets/icons/burger-white.png +0 -0
- package/esm/assets/icons/burger.png +0 -0
- package/esm/assets/icons/file.svg +1 -0
- package/esm/assets/icons/map_icon1.png +0 -0
- package/esm/assets/icons/map_icon4.png +0 -0
- package/esm/assets/images/bg-aside.png +0 -0
- package/esm/assets/images/bg-chart-circle.png +0 -0
- package/esm/assets/images/bg-chart-triangle.png +0 -0
- package/esm/assets/images/cashub-logo-only.png +0 -0
- package/esm/assets/images/default-user.jpg +0 -0
- package/esm/assets/images/logo-cashub.png +0 -0
- package/esm/assets/images/map.png +0 -0
- package/esm/assets/images/qrcode.png +0 -0
- package/esm/backdrop/BaseBackdrop.js +11 -0
- package/esm/backdrop/LoadingBackdrop.js +10 -0
- package/esm/backdrop/ModalBackdrop.js +8 -0
- package/esm/backdrop/index.js +3 -0
- package/esm/badge/Badge.js +19 -0
- package/esm/badge/BadgeDot.js +11 -0
- package/esm/badge/BadgeFill.js +42 -0
- package/esm/badge/BadgeFillTriangle.js +138 -0
- package/esm/badge/BadgeWithText.js +24 -0
- package/esm/badge/index.js +5 -0
- package/esm/billing/BarChart.js +45 -0
- package/esm/billing/Grid.js +38 -0
- package/esm/billing/Header2.js +19 -0
- package/esm/billing/Header3.js +31 -0
- package/esm/billing/Paragraph.js +27 -0
- package/esm/billing/ParagraphGroup.js +16 -0
- package/esm/billing/ParagraphText.js +20 -0
- package/esm/billing/Section.js +44 -0
- package/esm/billing/SectionBody.js +11 -0
- package/esm/billing/SectionHeader.js +20 -0
- package/esm/billing/__stories__/BarChart.stories.js_bak +46 -0
- package/esm/billing/__stories__/Grid.stories.js_bak +57 -0
- package/esm/billing/__stories__/Header2.stories.js_bak +62 -0
- package/esm/billing/__stories__/Header3.stories.js_bak +69 -0
- package/esm/billing/__stories__/Paragraph.stories.js_bak +84 -0
- package/esm/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
- package/esm/billing/__stories__/ParagraphText.stories.js_bak +64 -0
- package/esm/billing/__stories__/Section.stories.js_bak +115 -0
- package/esm/billing/__stories__/SectionBody.stories.js_bak +62 -0
- package/esm/billing/__stories__/SectionHeader.stories.js-bak +68 -0
- package/esm/breadcrumb/Breadcrumb.js +71 -0
- package/esm/breadcrumb/index.js +1 -0
- package/esm/button/Button.js +145 -0
- package/esm/button/ButtonGroup.js +54 -0
- package/esm/button/IconButton.js +64 -0
- package/esm/button/ScrollToTopButton.js +47 -0
- package/esm/button/index.js +4 -0
- package/esm/callout/Callout.js +45 -0
- package/esm/callout/index.js +1 -0
- package/esm/chart/BarChart.js +147 -0
- package/esm/chart/DoughnutChart.js +110 -0
- package/esm/chart/LineChart.js +140 -0
- package/esm/chart/SingleBarChart.js +35 -0
- package/esm/chart/index.js +5 -0
- package/esm/chart/utils/centerTextPlugin.js +56 -0
- package/esm/chart/utils/customTooltip.js +84 -0
- package/esm/chart/utils/customTooltipLifecyclePlugin.js +16 -0
- package/esm/chart/utils/htmlLegendPlugin.js +83 -0
- package/esm/chart/utils/index.js +3 -0
- package/esm/chart/utils/padEmptyChartBar.js +47 -0
- package/esm/chart/utils/tooltipElement.js +17 -0
- package/esm/chart/utils/xAxisLabelTooltipPlugin.js +101 -0
- package/esm/chart/utils/yAxisTopTitlePlugin.js +43 -0
- package/esm/container/FlexContainer.js +33 -0
- package/esm/container/index.js +1 -0
- package/esm/cropper/Cropper.js +47 -0
- package/esm/cropper/CropperModalHandler.js +34 -0
- package/esm/cropper/index.js +2 -0
- package/esm/cropper/subComponent/CropImageModal.js +72 -0
- package/{datetimePicker/DatetimePicker.js → esm/datetimePicker/DatetimePickerV3.js} +63 -31
- package/esm/datetimePicker/TimeInput.js +49 -0
- package/esm/datetimePicker/TimePickerStyle.js +58 -0
- package/esm/datetimePicker/TimePickerV2.js +199 -0
- package/esm/datetimePicker/accordion/Month.js +245 -0
- package/esm/datetimePicker/accordion/Year.js +275 -0
- package/esm/datetimePicker/index.js +4 -0
- package/esm/datetimePicker/provider/constant.js +38 -0
- package/esm/datetimePicker/subComponent/DateTimePickerContext.js +3 -0
- package/esm/datetimePicker/utils/GMTDate.js +9 -0
- package/esm/datetimePicker/utils/pad.js +7 -0
- package/esm/datetimePicker/utils/toUTC0.js +7 -0
- package/esm/descriptionList/DescriptionDetail.js +21 -0
- package/esm/descriptionList/DescriptionList.js +18 -0
- package/esm/descriptionList/DescriptionTerm.js +7 -0
- package/esm/descriptionList/index.js +3 -0
- package/esm/divider/Divider.js +24 -0
- package/esm/divider/index.js +1 -0
- package/esm/dropdown/Dropdown.js +48 -0
- package/esm/dropdown/DropdownButtonOption.js +36 -0
- package/esm/dropdown/DropdownContent.js +83 -0
- package/esm/dropdown/DropdownDivOption.js +19 -0
- package/esm/dropdown/DropdownItem.js +19 -0
- package/esm/dropdown/DropdownLinkOption.js +17 -0
- package/esm/dropdown/DropdownToggle.js +31 -0
- package/esm/dropdown/index.js +11 -0
- package/esm/dropdown/subComponent/DropdownContext.js +3 -0
- package/esm/dropzone/FileDropzone.js +472 -0
- package/esm/dropzone/ImageDropzone.js +327 -0
- package/esm/dropzone/index.js +2 -0
- package/esm/dropzone/subComponent/Message.js +19 -0
- package/esm/figure/IconFigure.js +35 -0
- package/esm/figure/ImageFigure.js +31 -0
- package/esm/figure/index.js +2 -0
- package/esm/file/HiddenFileInput.js +8 -0
- package/esm/file/index.js +1 -0
- package/esm/form/Checkbox.js +157 -0
- package/esm/form/Fieldset.js +11 -0
- package/esm/form/FormItem.js +15 -0
- package/esm/form/Input.js +59 -0
- package/esm/form/Label.js +54 -0
- package/esm/form/MutedText.js +14 -0
- package/esm/form/PasswordInput.js +40 -0
- package/esm/form/RadioButton.js +94 -0
- package/esm/form/SearchSelect.js +174 -0
- package/esm/form/Searchbox.js +91 -0
- package/esm/form/Slider.js +39 -0
- package/esm/form/SwitchButton.js +97 -0
- package/esm/form/Textarea.js +34 -0
- package/esm/form/TreeView.js +66 -0
- package/esm/form/index.js +14 -0
- package/esm/grid/Column.js +39 -0
- package/esm/grid/Grid.js +28 -0
- package/esm/grid/index.js +2 -0
- package/esm/heading/Heading1.js +14 -0
- package/esm/heading/Heading2.js +21 -0
- package/esm/heading/Heading3.js +42 -0
- package/esm/heading/index.js +3 -0
- package/esm/helmet/Helmet.js +17 -0
- package/esm/helmet/index.js +3 -0
- package/esm/iconbox/ApplicationIconBox.js +74 -0
- package/esm/iconbox/IconBox.js +60 -0
- package/esm/iconbox/IconBoxV2.js +63 -0
- package/esm/iconbox/index.js +3 -0
- package/esm/iconbox/subComponent/IconBoxFigure.js +43 -0
- package/esm/iconbox/subComponent/IconBoxImage.js +35 -0
- package/esm/image/ImageFluid.js +10 -0
- package/esm/image/UploadImage.js +243 -0
- package/esm/image/index.js +2 -0
- package/esm/index.js +47 -0
- package/esm/keyframe/Pulse.js +15 -0
- package/esm/keyframe/Spin.js +7 -0
- package/esm/layout/Aside.js +39 -0
- package/esm/layout/AsideHeader.jsx +27 -0
- package/esm/layout/Backdrop.js +16 -0
- package/esm/layout/Container.js +30 -0
- package/esm/layout/Footer.js +36 -0
- package/esm/layout/Header.jsx +55 -0
- package/esm/layout/Layout.jsx +84 -0
- package/esm/layout/Logo.jsx +17 -0
- package/esm/layout/MenuIcon.jsx +27 -0
- package/esm/layout/Sidebar.jsx +271 -0
- package/esm/layout/index.js +1 -0
- package/esm/link/LinkSpan.js +62 -0
- package/esm/link/index.js +1 -0
- package/esm/map/GoogleMap.js +439 -0
- package/esm/map/GoogleReverseGeolocation.js +193 -0
- package/esm/map/LeafletMap.js +224 -0
- package/esm/map/LeafletReverseGeolocation.js +94 -0
- package/esm/map/index.js +4 -0
- package/esm/map/subComponent/BasicLeafletMap.js +27 -0
- package/esm/map/subComponent/GoogleMapContainer.js +22 -0
- package/esm/map/subComponent/GoogleMapPopup.js +103 -0
- package/esm/map/subComponent/GoogleMapWrapper.js +34 -0
- package/esm/map/subComponent/LeafletDrawControl.js +116 -0
- package/esm/map/subComponent/LeafletMapContainer.js +166 -0
- package/esm/map/subComponent/MapSearchBoxControl.js +47 -0
- package/esm/modal/StateModal.js +169 -0
- package/esm/modal/TitleModal.js +241 -0
- package/esm/modal/index.js +2 -0
- package/esm/page/Disclaimer.js +121 -0
- package/esm/page/index.js +1 -0
- package/esm/paginate/Paginate.js +129 -0
- package/esm/paginate/index.js +1 -0
- package/esm/popover/Popover.js +82 -0
- package/esm/popover/index.js +1 -0
- package/esm/qrcode/QRCode.js +51 -0
- package/esm/qrcode/QRCodeContainter.js +27 -0
- package/esm/qrcode/index.js +2 -0
- package/esm/ribbon/Ribbon.js +35 -0
- package/esm/ribbon/index.js +1 -0
- package/esm/section/Section.js +126 -0
- package/esm/section/SectionBody.js +43 -0
- package/esm/section/SectionHeader.js +61 -0
- package/esm/section/SectionToolbar.js +11 -0
- package/esm/section/SectionToolbarItem.js +10 -0
- package/esm/section/index.js +5 -0
- package/esm/select/InputSelect.js +263 -0
- package/esm/select/Select.js +811 -0
- package/esm/select/index.js +2 -0
- package/esm/select/subComponent/Checkbox.js +40 -0
- package/esm/select/subComponent/Footer.js +6 -0
- package/esm/select/subComponent/ListBox.js +23 -0
- package/esm/select/subComponent/Option.js +37 -0
- package/esm/select/subComponent/OptionGroup.js +16 -0
- package/esm/select/subComponent/Options.js +25 -0
- package/esm/select/subComponent/SearchBox.js +51 -0
- package/esm/select/subComponent/SelectedMultipleCount.js +32 -0
- package/esm/select/subComponent/SelectedMultipleTags.js +47 -0
- package/esm/select/subComponent/SelectedMultipleText.js +63 -0
- package/esm/select/subComponent/SelectedSingle.js +10 -0
- package/esm/styles/GlobalStyle.js +328 -0
- package/esm/styles/config/breakpoint.style.js +7 -0
- package/esm/styles/config/header.style.js +4 -0
- package/esm/styles/config/sidebar.style.js +11 -0
- package/esm/styles/index.js +2 -0
- package/esm/styles/mixin/backgroundColor.js +38 -0
- package/esm/styles/mixin/borderColor.js +31 -0
- package/esm/styles/mixin/color.js +31 -0
- package/esm/styles/mixin/colorOnBackground.js +31 -0
- package/esm/styles/mixin/inputPlaceholder.js +24 -0
- package/esm/styles/mixin/media.js +15 -0
- package/esm/styles/mixin/rounded.js +24 -0
- package/esm/styles/mixin/scrollbar.js +26 -0
- package/esm/styles/theme/dark.theme.js +91 -0
- package/esm/styles/theme/light.theme.js +91 -0
- package/esm/styles/theme/white.theme.js +91 -0
- package/esm/styles/themes.js +9 -0
- package/esm/table/GridTable.js +329 -0
- package/esm/table/ImageBox.js +38 -0
- package/esm/table/InfiniteGridTable.js +396 -0
- package/esm/table/PermissionTable.js +57 -0
- package/esm/table/SimpleGridTable.js +136 -0
- package/esm/table/Table.js +559 -0
- package/esm/table/__mock__/columns.js +64 -0
- package/esm/table/__mock__/data.js +530 -0
- package/esm/table/hooks/index.js +2 -0
- package/esm/table/hooks/useCalculateDataRange.js +22 -0
- package/esm/table/hooks/useGenerateSort.js +32 -0
- package/esm/table/index.js +6 -0
- package/esm/table/subComponent/BaseTableHeadCell.js +54 -0
- package/esm/table/subComponent/GridTableFooter.js +17 -0
- package/esm/table/subComponent/GridTableHeadCell.js +13 -0
- package/esm/table/subComponent/Resizer.js +70 -0
- package/esm/table/subComponent/TableFooter.js +24 -0
- package/esm/table/subComponent/TableFooterInfo.js +6 -0
- package/esm/table/subComponent/TableFooterPager.js +26 -0
- package/esm/table/subComponent/TableHeadCell.js +12 -0
- package/esm/table/subComponent/TableSort.js +31 -0
- package/esm/tagify/TagifyStyle.js +54 -0
- package/esm/tagify/Tags.js +49 -0
- package/esm/tagify/index.js +3 -0
- package/esm/tagify/templates/getCreateButtonTemplate.js +12 -0
- package/esm/text/Paragraph.js +79 -0
- package/esm/text/index.js +1 -0
- package/esm/timeline/Timeline.js +132 -0
- package/esm/timeline/index.js +1 -0
- package/esm/toast/CustomToastContainer.js +38 -0
- package/esm/toast/MessageContainer.js +44 -0
- package/esm/toast/index.js +3 -0
- package/esm/toast/show.js +29 -0
- package/esm/toast/style.css +1 -0
- package/esm/tooltip/Tooltip.js +133 -0
- package/esm/tooltip/index.js +1 -0
- package/esm/treeView/TreeViewV2.js +32 -0
- package/esm/treeView/TreeflexStyle.js +43 -0
- package/esm/treeView/index.js +2 -0
- package/esm/wizard/Wizard.js +244 -0
- package/esm/wizard/index.js +1 -0
- package/helmet/index.js +3 -7
- package/index.js +0 -12
- package/layout/Sidebar.jsx +1 -1
- package/package.json +5 -4
- package/datetimePicker/DatePicker.js +0 -363
- package/datetimePicker/DatePickerV2.js +0 -407
- package/datetimePicker/DatetimePickerV2.js +0 -395
- package/datetimePicker/TimePicker.js +0 -317
- package/datetimePicker/hooks/index.js +0 -27
- package/datetimePicker/hooks/useChangeNumber.js +0 -42
- package/datetimePicker/hooks/useDecrease.js +0 -38
- package/datetimePicker/hooks/useIncrease.js +0 -38
- package/datetimePicker/subComponent/Accordion.js +0 -373
- package/datetimePicker/subComponent/CustomTimeInput.js +0 -47
- package/jsoneditor/JsonEditor.js +0 -142
- package/jsoneditor/index.js +0 -13
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { FiUpload } from 'react-icons/fi/index.esm';
|
|
4
|
+
import { FaTimes, FaPause, FaPlay, FaRedo } from 'react-icons/fa/index.esm';
|
|
5
|
+
import { formatSize, KEY_CODE } from '@cashub/utils';
|
|
6
|
+
import media from '../styles/mixin/media';
|
|
7
|
+
import fileIcon from '../assets/icons/file.svg';
|
|
8
|
+
import HiddenFileInput from '../file/HiddenFileInput';
|
|
9
|
+
import Message from './subComponent/Message';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const FileDropzone = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
message,
|
|
14
|
+
accept,
|
|
15
|
+
translation,
|
|
16
|
+
state,
|
|
17
|
+
chunking = true,
|
|
18
|
+
chunkSize = 6000000,
|
|
19
|
+
onAddedFile,
|
|
20
|
+
onRemovedFile,
|
|
21
|
+
onPausedUpload,
|
|
22
|
+
onCanceledFile,
|
|
23
|
+
onUploading,
|
|
24
|
+
onCompleted,
|
|
25
|
+
onError
|
|
26
|
+
} = _ref;
|
|
27
|
+
const inputRef = useRef(null);
|
|
28
|
+
const [dragging, setDragging] = useState(false);
|
|
29
|
+
const [files, setFiles] = useState([]);
|
|
30
|
+
const [percentage, setPercentage] = useState(0);
|
|
31
|
+
const [isPausing, setIsPausing] = useState(false);
|
|
32
|
+
const [total, setTotal] = useState(0);
|
|
33
|
+
const [index, setIndex] = useState(0);
|
|
34
|
+
const [successCount, setSuccessCount] = useState(0);
|
|
35
|
+
const [hasFail, setHasFail] = useState(false);
|
|
36
|
+
const [isCompleted, setIsCompleted] = useState(false);
|
|
37
|
+
const [failUploadIndexes, setFailUploadIndexes] = useState([]);
|
|
38
|
+
const texts = useMemo(() => {
|
|
39
|
+
const defaultTexts = {
|
|
40
|
+
Cancel: 'Cancel Upload',
|
|
41
|
+
FileIcon: 'File Icon',
|
|
42
|
+
Pause: 'Pause Upload',
|
|
43
|
+
RemoveFile: 'Remove File',
|
|
44
|
+
Resume: 'Resume Upload',
|
|
45
|
+
Retry: 'Retry Upload'
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
...defaultTexts,
|
|
49
|
+
...translation
|
|
50
|
+
};
|
|
51
|
+
}, [translation]);
|
|
52
|
+
const handleClick = useCallback(() => {
|
|
53
|
+
if (files.length > 0) return;
|
|
54
|
+
inputRef.current.click();
|
|
55
|
+
}, [files]);
|
|
56
|
+
const handleReset = useCallback(() => {
|
|
57
|
+
setFiles([]);
|
|
58
|
+
setPercentage(0);
|
|
59
|
+
setIsPausing(false);
|
|
60
|
+
setTotal(0);
|
|
61
|
+
setIndex(0);
|
|
62
|
+
setSuccessCount(0);
|
|
63
|
+
setHasFail(false);
|
|
64
|
+
setIsCompleted(false);
|
|
65
|
+
setFailUploadIndexes([]);
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
// handle keyboard interaction
|
|
69
|
+
const handleKeyUp = useCallback(event => {
|
|
70
|
+
const key = event.keyCode;
|
|
71
|
+
switch (key) {
|
|
72
|
+
case KEY_CODE.ENTER:
|
|
73
|
+
handleClick();
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}, [handleClick]);
|
|
79
|
+
const handleKeyDown = useCallback(event => {
|
|
80
|
+
const key = event.keyCode;
|
|
81
|
+
switch (key) {
|
|
82
|
+
case KEY_CODE.ENTER:
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}, []);
|
|
89
|
+
const handleFileChange = useCallback(event => {
|
|
90
|
+
const {
|
|
91
|
+
files: newFiles
|
|
92
|
+
} = event.target;
|
|
93
|
+
if (newFiles.length > 0 && files.length === 0) {
|
|
94
|
+
if (onAddedFile) {
|
|
95
|
+
onAddedFile(newFiles[0]);
|
|
96
|
+
}
|
|
97
|
+
setFiles([newFiles[0]]);
|
|
98
|
+
setTotal(chunking ? Math.ceil(newFiles[0].size / chunkSize) : 1);
|
|
99
|
+
}
|
|
100
|
+
inputRef.current.value = '';
|
|
101
|
+
}, [files, onAddedFile, chunking, chunkSize]);
|
|
102
|
+
const handleDragEnter = useCallback(event => {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
event.stopPropagation();
|
|
105
|
+
if (files.length === 0) setDragging(true);
|
|
106
|
+
}, [files]);
|
|
107
|
+
const handleDragOver = useCallback(event => {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
if (files.length === 0) setDragging(true);
|
|
111
|
+
}, [files]);
|
|
112
|
+
const handleDragLeave = useCallback(event => {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
event.stopPropagation();
|
|
115
|
+
setDragging(false);
|
|
116
|
+
}, []);
|
|
117
|
+
const handleDrop = useCallback(event => {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
if (files.length === 0) {
|
|
121
|
+
setDragging(false);
|
|
122
|
+
const {
|
|
123
|
+
dataTransfer
|
|
124
|
+
} = event;
|
|
125
|
+
const {
|
|
126
|
+
files: newFiles
|
|
127
|
+
} = dataTransfer;
|
|
128
|
+
if (newFiles.length > 0) {
|
|
129
|
+
if (onAddedFile) {
|
|
130
|
+
onAddedFile(newFiles[0]);
|
|
131
|
+
}
|
|
132
|
+
setFiles([newFiles[0]]);
|
|
133
|
+
setTotal(chunking ? Math.ceil(newFiles[0].size / chunkSize) : 1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}, [files, onAddedFile, chunkSize, chunking]);
|
|
137
|
+
const handleUpload = useCallback(async function (index) {
|
|
138
|
+
let setNext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
139
|
+
const [file] = files;
|
|
140
|
+
if (!chunking) {
|
|
141
|
+
if (onUploading) {
|
|
142
|
+
try {
|
|
143
|
+
await onUploading(file, file.name, index);
|
|
144
|
+
setSuccessCount(1);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
setHasFail(true);
|
|
147
|
+
setFailUploadIndexes(previous => {
|
|
148
|
+
return [...previous, index];
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
const start = index * chunkSize;
|
|
154
|
+
const end = Math.min(start + chunkSize, file.size);
|
|
155
|
+
const chunkData = file.slice(start, end);
|
|
156
|
+
if (onUploading) {
|
|
157
|
+
try {
|
|
158
|
+
await onUploading(chunkData, file.name, index);
|
|
159
|
+
setSuccessCount(previous => {
|
|
160
|
+
return previous + 1;
|
|
161
|
+
});
|
|
162
|
+
if (setNext) {
|
|
163
|
+
setIndex(previous => {
|
|
164
|
+
return previous + 1;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error.message !== 'canceled') {
|
|
169
|
+
setHasFail(true);
|
|
170
|
+
setFailUploadIndexes(previous => {
|
|
171
|
+
return [...previous, index];
|
|
172
|
+
});
|
|
173
|
+
if (setNext) {
|
|
174
|
+
setIndex(previous => {
|
|
175
|
+
return previous + 1;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, [files, chunking, chunkSize, onUploading]);
|
|
183
|
+
const handlePauseUpload = useCallback(() => {
|
|
184
|
+
if (onPausedUpload) onPausedUpload();
|
|
185
|
+
setIsPausing(true);
|
|
186
|
+
}, [onPausedUpload]);
|
|
187
|
+
const handleResumeUpload = useCallback(() => {
|
|
188
|
+
setIsPausing(false);
|
|
189
|
+
}, []);
|
|
190
|
+
const handleRetryUpload = useCallback(() => {
|
|
191
|
+
const retryIndexes = [...failUploadIndexes];
|
|
192
|
+
setHasFail(false);
|
|
193
|
+
setFailUploadIndexes([]);
|
|
194
|
+
retryIndexes.forEach(index => {
|
|
195
|
+
handleUpload(index, false);
|
|
196
|
+
});
|
|
197
|
+
}, [failUploadIndexes, handleUpload]);
|
|
198
|
+
const handleCancelUpload = useCallback(event => {
|
|
199
|
+
event.stopPropagation();
|
|
200
|
+
if (onCanceledFile) onCanceledFile(files[0]);
|
|
201
|
+
handleReset();
|
|
202
|
+
}, [files, onCanceledFile, handleReset]);
|
|
203
|
+
const handleRemoveFile = useCallback(event => {
|
|
204
|
+
if (event) event.stopPropagation();
|
|
205
|
+
if (onRemovedFile) onRemovedFile(files[0]);
|
|
206
|
+
handleReset();
|
|
207
|
+
}, [files, onRemovedFile, handleReset]);
|
|
208
|
+
const handleComplete = useCallback(() => {
|
|
209
|
+
if (onCompleted) {
|
|
210
|
+
onCompleted();
|
|
211
|
+
setIsCompleted(true);
|
|
212
|
+
}
|
|
213
|
+
}, [onCompleted]);
|
|
214
|
+
const handleError = useCallback(() => {
|
|
215
|
+
if (onError) onError();
|
|
216
|
+
}, [onError]);
|
|
217
|
+
const messageItem = useMemo(() => {
|
|
218
|
+
return /*#__PURE__*/_jsxs(Message, {
|
|
219
|
+
dragging: dragging,
|
|
220
|
+
children: [/*#__PURE__*/_jsx(FiUpload, {
|
|
221
|
+
role: "img",
|
|
222
|
+
"aria-hidden": "true",
|
|
223
|
+
"data-icon": "upload"
|
|
224
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
225
|
+
children: message
|
|
226
|
+
})]
|
|
227
|
+
});
|
|
228
|
+
}, [dragging, message]);
|
|
229
|
+
const previewItem = useMemo(() => {
|
|
230
|
+
if (files.length === 0) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return /*#__PURE__*/_jsxs(Preview, {
|
|
234
|
+
children: [/*#__PURE__*/_jsx(PreviewImage, {
|
|
235
|
+
children: /*#__PURE__*/_jsx("img", {
|
|
236
|
+
crossOrigin: "anonymous",
|
|
237
|
+
src: fileIcon,
|
|
238
|
+
alt: texts.FileIcon,
|
|
239
|
+
"aria-hidden": "true"
|
|
240
|
+
})
|
|
241
|
+
}), /*#__PURE__*/_jsxs(PreviewDetails, {
|
|
242
|
+
children: [/*#__PURE__*/_jsx("p", {
|
|
243
|
+
children: formatSize(files[0].size)
|
|
244
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
245
|
+
className: "ellipsis",
|
|
246
|
+
children: files[0].name
|
|
247
|
+
}), /*#__PURE__*/_jsxs(Progress, {
|
|
248
|
+
children: [(state.isUploading || percentage > 0) && /*#__PURE__*/_jsx(ProgressBar, {
|
|
249
|
+
percentage: percentage,
|
|
250
|
+
"data-testid": "progress-bar",
|
|
251
|
+
children: /*#__PURE__*/_jsxs("span", {
|
|
252
|
+
children: [percentage, "%"]
|
|
253
|
+
})
|
|
254
|
+
}), state.isUploading ? /*#__PURE__*/_jsx(Button, {
|
|
255
|
+
danger: true,
|
|
256
|
+
title: texts.Cancel,
|
|
257
|
+
onClick: handleCancelUpload,
|
|
258
|
+
children: /*#__PURE__*/_jsx(FaTimes, {})
|
|
259
|
+
}) : /*#__PURE__*/_jsx(Button, {
|
|
260
|
+
danger: true,
|
|
261
|
+
title: texts.RemoveFile,
|
|
262
|
+
onClick: handleRemoveFile,
|
|
263
|
+
children: /*#__PURE__*/_jsx(FaTimes, {})
|
|
264
|
+
}), !state.isUploading && hasFail && /*#__PURE__*/_jsx(Button, {
|
|
265
|
+
title: texts.Retry,
|
|
266
|
+
onClick: handleRetryUpload,
|
|
267
|
+
children: /*#__PURE__*/_jsx(FaRedo, {})
|
|
268
|
+
}), chunking && state.isUploading && !isPausing && /*#__PURE__*/_jsx(PauseButton, {
|
|
269
|
+
title: texts.Pause,
|
|
270
|
+
onClick: handlePauseUpload,
|
|
271
|
+
children: /*#__PURE__*/_jsx(FaPause, {})
|
|
272
|
+
}), chunking && state.isUploading && isPausing && /*#__PURE__*/_jsx(ResumeButton, {
|
|
273
|
+
title: texts.Resume,
|
|
274
|
+
onClick: handleResumeUpload,
|
|
275
|
+
children: /*#__PURE__*/_jsx(FaPlay, {})
|
|
276
|
+
})]
|
|
277
|
+
})]
|
|
278
|
+
})]
|
|
279
|
+
});
|
|
280
|
+
}, [texts, files, percentage, chunking, isPausing, state.isUploading, hasFail, handleCancelUpload, handlePauseUpload, handleRemoveFile, handleResumeUpload, handleRetryUpload]);
|
|
281
|
+
|
|
282
|
+
// uploading
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
if (state.isUploading && !isPausing) {
|
|
285
|
+
if (index < total) {
|
|
286
|
+
handleUpload(index);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}, [state.isUploading, isPausing, total, index, handleUpload]);
|
|
290
|
+
|
|
291
|
+
// removing
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
if (state.isRemoving) {
|
|
294
|
+
handleRemoveFile();
|
|
295
|
+
}
|
|
296
|
+
}, [state.isRemoving, handleRemoveFile]);
|
|
297
|
+
|
|
298
|
+
// set percentage and check complete
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
if (total <= 0) return;
|
|
301
|
+
setPercentage(Math.ceil(successCount / total * 100));
|
|
302
|
+
if (!isCompleted && successCount === total) {
|
|
303
|
+
handleComplete();
|
|
304
|
+
}
|
|
305
|
+
}, [total, isCompleted, successCount, handleComplete]);
|
|
306
|
+
|
|
307
|
+
// check has upload fail
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (hasFail && successCount + failUploadIndexes.length === total) {
|
|
310
|
+
handleError();
|
|
311
|
+
}
|
|
312
|
+
}, [hasFail, successCount, failUploadIndexes.length, total, handleError]);
|
|
313
|
+
return /*#__PURE__*/_jsxs(Dropzone, {
|
|
314
|
+
tabIndex: "0",
|
|
315
|
+
dragging: dragging,
|
|
316
|
+
onClick: handleClick,
|
|
317
|
+
onKeyUp: handleKeyUp,
|
|
318
|
+
onKeyDown: handleKeyDown,
|
|
319
|
+
onDragEnter: handleDragEnter,
|
|
320
|
+
onDragLeave: handleDragLeave,
|
|
321
|
+
onDragOver: handleDragOver,
|
|
322
|
+
onDrop: handleDrop,
|
|
323
|
+
reachedLimit: files.length > 0,
|
|
324
|
+
children: [/*#__PURE__*/_jsx(HiddenFileInput, {
|
|
325
|
+
ref: inputRef,
|
|
326
|
+
accept: accept,
|
|
327
|
+
onChange: handleFileChange
|
|
328
|
+
}), files.length === 0 ? messageItem : previewItem]
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const Dropzone = styled.div`
|
|
332
|
+
min-height: 200px;
|
|
333
|
+
border: 4px dashed var(--border-color);
|
|
334
|
+
border-radius: var(--border-radius);
|
|
335
|
+
color: var(--font-on-background);
|
|
336
|
+
display: flex;
|
|
337
|
+
flex-direction: column;
|
|
338
|
+
justify-content: center;
|
|
339
|
+
align-items: center;
|
|
340
|
+
padding: 0 var(--spacing-s);
|
|
341
|
+
cursor: ${_ref2 => {
|
|
342
|
+
let {
|
|
343
|
+
reachedLimit
|
|
344
|
+
} = _ref2;
|
|
345
|
+
return reachedLimit ? 'default' : 'pointer';
|
|
346
|
+
}};
|
|
347
|
+
|
|
348
|
+
${_ref3 => {
|
|
349
|
+
let {
|
|
350
|
+
dragging
|
|
351
|
+
} = _ref3;
|
|
352
|
+
return dragging && 'border-color: var(--color-primary);';
|
|
353
|
+
}};
|
|
354
|
+
|
|
355
|
+
&:focus {
|
|
356
|
+
border-color: var(--color-primary);
|
|
357
|
+
}
|
|
358
|
+
`;
|
|
359
|
+
Dropzone.displayName = 'Dropzone';
|
|
360
|
+
const Preview = styled.div`
|
|
361
|
+
max-width: 50%;
|
|
362
|
+
display: flex;
|
|
363
|
+
align-items: center;
|
|
364
|
+
text-align: center;
|
|
365
|
+
|
|
366
|
+
${media.laptop`
|
|
367
|
+
max-width: 75%;
|
|
368
|
+
`}
|
|
369
|
+
|
|
370
|
+
${media.tablet`
|
|
371
|
+
max-width: 100%;
|
|
372
|
+
`}
|
|
373
|
+
`;
|
|
374
|
+
Preview.displayName = 'Preview';
|
|
375
|
+
const PreviewImage = styled.div`
|
|
376
|
+
margin-right: var(--spacing-xs);
|
|
377
|
+
|
|
378
|
+
> img {
|
|
379
|
+
width: 120px;
|
|
380
|
+
margin-bottom: var(--spacing-xs);
|
|
381
|
+
}
|
|
382
|
+
`;
|
|
383
|
+
PreviewImage.displayName = 'PreviewImage';
|
|
384
|
+
const PreviewDetails = styled.div`
|
|
385
|
+
overflow: hidden;
|
|
386
|
+
min-width: 200px;
|
|
387
|
+
|
|
388
|
+
> * {
|
|
389
|
+
margin-bottom: var(--spacing-xs);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
> .ellipsis {
|
|
393
|
+
overflow: hidden;
|
|
394
|
+
white-space: nowrap;
|
|
395
|
+
text-overflow: ellipsis;
|
|
396
|
+
}
|
|
397
|
+
`;
|
|
398
|
+
PreviewDetails.displayName = 'PreviewDetails';
|
|
399
|
+
const Progress = styled.div`
|
|
400
|
+
display: flex;
|
|
401
|
+
justify-content: center;
|
|
402
|
+
align-items: center;
|
|
403
|
+
`;
|
|
404
|
+
|
|
405
|
+
// fix:color
|
|
406
|
+
const ProgressBar = styled.div`
|
|
407
|
+
flex: 1;
|
|
408
|
+
height: 1.25rem;
|
|
409
|
+
border-radius: var(--border-radius);
|
|
410
|
+
position: relative;
|
|
411
|
+
overflow: hidden;
|
|
412
|
+
border: 1px solid var(--color-primary);
|
|
413
|
+
|
|
414
|
+
&::before {
|
|
415
|
+
position: absolute;
|
|
416
|
+
content: '';
|
|
417
|
+
width: ${_ref4 => {
|
|
418
|
+
let {
|
|
419
|
+
percentage
|
|
420
|
+
} = _ref4;
|
|
421
|
+
return percentage;
|
|
422
|
+
}}%;
|
|
423
|
+
top: 0;
|
|
424
|
+
bottom: 0;
|
|
425
|
+
left: 0;
|
|
426
|
+
right: 0;
|
|
427
|
+
background: linear-gradient(to bottom, #00bdff, #597ef7);
|
|
428
|
+
transition: width 300ms ease-in-out;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
> span {
|
|
432
|
+
position: absolute;
|
|
433
|
+
width: 100%;
|
|
434
|
+
top: 0;
|
|
435
|
+
bottom: 0;
|
|
436
|
+
left: 0;
|
|
437
|
+
right: 0;
|
|
438
|
+
}
|
|
439
|
+
`;
|
|
440
|
+
ProgressBar.displayName = 'ProgressBar';
|
|
441
|
+
const Button = styled.span.attrs(() => ({
|
|
442
|
+
role: 'button'
|
|
443
|
+
}))`
|
|
444
|
+
display: flex;
|
|
445
|
+
justify-content: center;
|
|
446
|
+
align-items: center;
|
|
447
|
+
flex: 0 0 auto;
|
|
448
|
+
cursor: pointer;
|
|
449
|
+
width: 1.25rem;
|
|
450
|
+
height: 1.25rem;
|
|
451
|
+
color: var(--font-on-primary);
|
|
452
|
+
background: var(--color-primary);
|
|
453
|
+
border-radius: var(--border-radius);
|
|
454
|
+
margin-left: var(--spacing-xs);
|
|
455
|
+
padding: 0.25rem;
|
|
456
|
+
|
|
457
|
+
${_ref5 => {
|
|
458
|
+
let {
|
|
459
|
+
danger
|
|
460
|
+
} = _ref5;
|
|
461
|
+
return danger && `
|
|
462
|
+
background: var(--color-danger);
|
|
463
|
+
`;
|
|
464
|
+
}}
|
|
465
|
+
`;
|
|
466
|
+
const PauseButton = styled(Button)`
|
|
467
|
+
padding: 5px;
|
|
468
|
+
`;
|
|
469
|
+
const ResumeButton = styled(Button)`
|
|
470
|
+
padding: 5px 5px 5px 6px;
|
|
471
|
+
`;
|
|
472
|
+
export default FileDropzone;
|