@veeqo/ui 12.4.0-beta-9 → 12.5.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/components/SelectDropdown/SelectDropdown.cjs +27 -19
- package/dist/components/SelectDropdown/SelectDropdown.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.d.ts +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.js +27 -19
- package/dist/components/SelectDropdown/SelectDropdown.js.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.cjs +2 -2
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.js +2 -2
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/components/GridItem/GridItem.cjs +37 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.cjs.map +1 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.js +31 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.js.map +1 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.cjs +9 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.cjs.map +1 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.js +7 -0
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.js.map +1 -0
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.cjs +4 -4
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.d.ts +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.js +4 -4
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.js.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.module.scss.cjs +2 -2
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.module.scss.js +2 -2
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/types.d.ts +2 -0
- package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs +1 -1
- package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ListItem/ListItem.js +2 -2
- package/dist/components/SelectDropdown/components/ListItem/ListItem.js.map +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.cjs +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.js +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.js.map +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.module.scss.cjs +2 -2
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.module.scss.js +2 -2
- package/dist/components/SelectDropdown/components/ListItemSection/ListItemSection.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.cjs +18 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.cjs.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.d.ts +3 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.js +12 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.js.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.cjs +19 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.cjs.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.d.ts +3 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.js +13 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.js.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.cjs +9 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.cjs.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.js +7 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.js.map +1 -0
- package/dist/components/SelectDropdown/components/OptionsContainers/types.d.ts +25 -0
- package/dist/components/SelectDropdown/components/SelectDropdownState.cjs +11 -3
- package/dist/components/SelectDropdown/components/SelectDropdownState.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/SelectDropdownState.js +11 -3
- package/dist/components/SelectDropdown/components/SelectDropdownState.js.map +1 -1
- package/dist/components/SelectDropdown/components/SelectedOption.cjs +2 -2
- package/dist/components/SelectDropdown/components/SelectedOption.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/SelectedOption.js +2 -2
- package/dist/components/SelectDropdown/components/SelectedOption.js.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.cjs +3 -3
- package/dist/components/SelectDropdown/components/item.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.js +3 -3
- package/dist/components/SelectDropdown/components/item.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/types.d.ts +4 -1
- package/dist/components/UploadFile/UploadFile.cjs +82 -71
- package/dist/components/UploadFile/UploadFile.cjs.map +1 -1
- package/dist/components/UploadFile/UploadFile.js +85 -74
- package/dist/components/UploadFile/UploadFile.js.map +1 -1
- package/dist/components/UploadFile/UploadGraphic.cjs +14 -0
- package/dist/components/UploadFile/UploadGraphic.cjs.map +1 -0
- package/dist/components/UploadFile/UploadGraphic.d.ts +2 -0
- package/dist/components/UploadFile/UploadGraphic.js +8 -0
- package/dist/components/UploadFile/UploadGraphic.js.map +1 -0
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs +6 -6
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs.map +1 -1
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js +6 -6
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js.map +1 -1
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs +31 -0
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs.map +1 -0
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.d.ts +7 -0
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js +25 -0
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js.map +1 -0
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs +5 -52
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs.map +1 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.d.ts +3 -7
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js +5 -52
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js.map +1 -1
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs +20 -0
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs.map +1 -0
- package/dist/components/UploadFile/components/UploadedFile/styled.d.ts +2 -0
- package/dist/components/UploadFile/components/UploadedFile/styled.js +13 -0
- package/dist/components/UploadFile/components/UploadedFile/styled.js.map +1 -0
- package/dist/components/UploadFile/constants.cjs +8 -64
- package/dist/components/UploadFile/constants.cjs.map +1 -1
- package/dist/components/UploadFile/constants.d.ts +5 -52
- package/dist/components/UploadFile/constants.js +9 -63
- package/dist/components/UploadFile/constants.js.map +1 -1
- package/dist/components/UploadFile/mocks/files.d.ts +0 -2
- package/dist/components/UploadFile/mocks/utils.d.ts +2 -1
- package/dist/components/UploadFile/styled.cjs +1 -16
- package/dist/components/UploadFile/styled.cjs.map +1 -1
- package/dist/components/UploadFile/styled.d.ts +1 -4
- package/dist/components/UploadFile/styled.js +1 -16
- package/dist/components/UploadFile/styled.js.map +1 -1
- package/dist/components/UploadFile/types.d.ts +1 -14
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs +11 -14
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.d.ts +7 -10
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js +11 -14
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs +30 -16
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js +30 -16
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js.map +1 -1
- package/dist/components/UploadFile/utils/index.d.ts +1 -0
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs +18 -0
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs.map +1 -0
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.d.ts +13 -0
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js +16 -0
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js.map +1 -0
- package/dist/components/ViewsContainer/ViewsContainer.cjs +37 -10
- package/dist/components/ViewsContainer/ViewsContainer.cjs.map +1 -1
- package/dist/components/ViewsContainer/ViewsContainer.js +37 -10
- package/dist/components/ViewsContainer/ViewsContainer.js.map +1 -1
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.cjs +9 -0
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.cjs.map +1 -0
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.js +7 -0
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.js.map +1 -0
- package/dist/components/ViewsContainer/hooks/useSetScrollPosition.cjs +73 -45
- package/dist/components/ViewsContainer/hooks/useSetScrollPosition.cjs.map +1 -1
- package/dist/components/ViewsContainer/hooks/useSetScrollPosition.d.ts +9 -1
- package/dist/components/ViewsContainer/hooks/useSetScrollPosition.js +74 -46
- package/dist/components/ViewsContainer/hooks/useSetScrollPosition.js.map +1 -1
- package/dist/components/ViewsContainer/types.d.ts +18 -0
- package/dist/utils/forms/form.module.scss.cjs +2 -2
- package/dist/utils/forms/form.module.scss.cjs.map +1 -1
- package/dist/utils/forms/form.module.scss.js +2 -2
- package/dist/utils/forms/form.module.scss.js.map +1 -1
- package/package.json +1 -1
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs +0 -28
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs.map +0 -1
- package/dist/components/UploadFile/components/DropCopy/DropCopy.d.ts +0 -2
- package/dist/components/UploadFile/components/DropCopy/DropCopy.js +0 -22
- package/dist/components/UploadFile/components/DropCopy/DropCopy.js.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.cjs +0 -9
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.js +0 -7
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.js.map +0 -1
- package/dist/components/UploadFile/hooks/useFileErrorMessages/index.d.ts +0 -1
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs +0 -39
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs.map +0 -1
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.d.ts +0 -13
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.js +0 -37
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.js.map +0 -1
- package/dist/components/UploadFile/hooks/usePreviewImage/index.d.ts +0 -1
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.cjs +0 -36
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.cjs.map +0 -1
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.d.ts +0 -8
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.js +0 -34
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.js.map +0 -1
- package/dist/components/UploadFile/hooks/useUploadFile/index.d.ts +0 -1
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs +0 -65
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs.map +0 -1
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.d.ts +0 -9
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js +0 -63
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js.map +0 -1
- package/dist/components/UploadFile/hooks/useValidateInput/index.d.ts +0 -1
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs +0 -85
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs.map +0 -1
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.d.ts +0 -13
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js +0 -83
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js.map +0 -1
- package/dist/components/UploadFile/mocks/mockUseUploadFile.d.ts +0 -14
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileExtension.d.ts +0 -1
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.cjs +0 -17
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.cjs.map +0 -1
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.d.ts +0 -1
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.js +0 -15
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.js.map +0 -1
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/index.d.ts +0 -1
- package/dist/components/UploadFile/utils/isImageType/index.d.ts +0 -1
- package/dist/components/UploadFile/utils/isImageType/isImageType.cjs +0 -14
- package/dist/components/UploadFile/utils/isImageType/isImageType.cjs.map +0 -1
- package/dist/components/UploadFile/utils/isImageType/isImageType.d.ts +0 -1
- package/dist/components/UploadFile/utils/isImageType/isImageType.js +0 -12
- package/dist/components/UploadFile/utils/isImageType/isImageType.js.map +0 -1
- package/dist/components/ViewsContainer/styled.cjs +0 -37
- package/dist/components/ViewsContainer/styled.cjs.map +0 -1
- package/dist/components/ViewsContainer/styled.d.ts +0 -34
- package/dist/components/ViewsContainer/styled.js +0 -23
- package/dist/components/ViewsContainer/styled.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item.module.scss.cjs","sources":["../../../../src/components/SelectDropdown/components/item.module.scss"],"sourcesContent":[".item {\n border-radius: var(--radius-base);\n cursor: pointer;\n background-color: #ffffff;\n text-decoration: none;\n\n &.appearance-secondary {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-hovered] > div,\n &[data-hovered] > div:first-of-type[role='gridcell'] > :first-child {\n background-color:
|
|
1
|
+
{"version":3,"file":"item.module.scss.cjs","sources":["../../../../src/components/SelectDropdown/components/item.module.scss"],"sourcesContent":[".item {\n border-radius: var(--radius-base);\n cursor: pointer;\n background-color: #ffffff;\n text-decoration: none;\n\n &.appearance-secondary {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-hovered] > div,\n &[data-hovered] > div:first-of-type[role='gridcell'] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-pressed] > div,\n &[data-pressed] > div:first-of-type[role='gridcell'] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-focused] {\n outline: 0;\n }\n\n &[data-focus-visible] > div,\n &[data-focus-visible] > div:first-of-type[role='gridcell'] > :first-child {\n outline: solid var(--sizes-xs) var(--colors-secondary-blue-light);\n z-index: 1;\n position: relative;\n }\n\n &[data-dragging] {\n background-color: var(--colors-neutral-grey-base);\n border-color: var(--color-secondary-blue-base);\n }\n\n &[data-drop-target] {\n background-color: var(--colors-secondary-green-base);\n border-color: var(--colors-secondary-green-base);\n }\n\n &[data-disabled] {\n cursor: not-allowed;\n background-color: var(--colors-neutral-grey-light);\n opacity: 0.75;\n }\n\n > div,\n > div:first-of-type[role='gridcell'] > :first-child {\n padding: var(--sizes-sm);\n border-radius: var(--radius-base);\n }\n}\n"],"names":[],"mappings":";;;;AACE,eAAA,CAAA,q8CAAA;AACA,iBAAA,CAAA,MAAA,CAAA,eAAA,CAAA,sBAAA,CAAA,+BAAA;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import insertStyle from '../../../_virtual/____insertStyle.js';
|
|
2
2
|
|
|
3
|
-
insertStyle(".
|
|
4
|
-
var
|
|
3
|
+
insertStyle("._item_1dwbl_1 {\n border-radius: var(--radius-base);\n cursor: pointer;\n background-color: #ffffff;\n text-decoration: none;\n}\n._item_1dwbl_1._appearance-secondary_1dwbl_7 {\n background-color: var(--colors-neutral-grey-lightest);\n}\n._item_1dwbl_1[data-hovered] > div, ._item_1dwbl_1[data-hovered] > div:first-of-type[role=gridcell] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n}\n._item_1dwbl_1[data-pressed] > div, ._item_1dwbl_1[data-pressed] > div:first-of-type[role=gridcell] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n}\n._item_1dwbl_1[data-focused] {\n outline: 0;\n}\n._item_1dwbl_1[data-focus-visible] > div, ._item_1dwbl_1[data-focus-visible] > div:first-of-type[role=gridcell] > :first-child {\n outline: solid var(--sizes-xs) var(--colors-secondary-blue-light);\n z-index: 1;\n position: relative;\n}\n._item_1dwbl_1[data-dragging] {\n background-color: var(--colors-neutral-grey-base);\n border-color: var(--color-secondary-blue-base);\n}\n._item_1dwbl_1[data-drop-target] {\n background-color: var(--colors-secondary-green-base);\n border-color: var(--colors-secondary-green-base);\n}\n._item_1dwbl_1[data-disabled] {\n cursor: not-allowed;\n background-color: var(--colors-neutral-grey-light);\n opacity: 0.75;\n}\n._item_1dwbl_1 > div,\n._item_1dwbl_1 > div:first-of-type[role=gridcell] > :first-child {\n padding: var(--sizes-sm);\n border-radius: var(--radius-base);\n}");
|
|
4
|
+
var itemStyles = {"item":"_item_1dwbl_1","appearance-secondary":"_appearance-secondary_1dwbl_7"};
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { itemStyles as default };
|
|
7
7
|
//# sourceMappingURL=item.module.scss.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item.module.scss.js","sources":["../../../../src/components/SelectDropdown/components/item.module.scss"],"sourcesContent":[".item {\n border-radius: var(--radius-base);\n cursor: pointer;\n background-color: #ffffff;\n text-decoration: none;\n\n &.appearance-secondary {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-hovered] > div,\n &[data-hovered] > div:first-of-type[role='gridcell'] > :first-child {\n background-color:
|
|
1
|
+
{"version":3,"file":"item.module.scss.js","sources":["../../../../src/components/SelectDropdown/components/item.module.scss"],"sourcesContent":[".item {\n border-radius: var(--radius-base);\n cursor: pointer;\n background-color: #ffffff;\n text-decoration: none;\n\n &.appearance-secondary {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-hovered] > div,\n &[data-hovered] > div:first-of-type[role='gridcell'] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-pressed] > div,\n &[data-pressed] > div:first-of-type[role='gridcell'] > :first-child {\n background-color: var(--colors-neutral-grey-lightest);\n }\n\n &[data-focused] {\n outline: 0;\n }\n\n &[data-focus-visible] > div,\n &[data-focus-visible] > div:first-of-type[role='gridcell'] > :first-child {\n outline: solid var(--sizes-xs) var(--colors-secondary-blue-light);\n z-index: 1;\n position: relative;\n }\n\n &[data-dragging] {\n background-color: var(--colors-neutral-grey-base);\n border-color: var(--color-secondary-blue-base);\n }\n\n &[data-drop-target] {\n background-color: var(--colors-secondary-green-base);\n border-color: var(--colors-secondary-green-base);\n }\n\n &[data-disabled] {\n cursor: not-allowed;\n background-color: var(--colors-neutral-grey-light);\n opacity: 0.75;\n }\n\n > div,\n > div:first-of-type[role='gridcell'] > :first-child {\n padding: var(--sizes-sm);\n border-radius: var(--radius-base);\n }\n}\n"],"names":["___$insertStyle"],"mappings":";;AACEA,WAAA,CAAA,q8CAAA;AACA,iBAAA,CAAA,MAAA,CAAA,eAAA,CAAA,sBAAA,CAAA,+BAAA;;;;"}
|
|
@@ -3,10 +3,11 @@ import { ReactElement } from 'react';
|
|
|
3
3
|
import { ButtonProps } from '../Button/types';
|
|
4
4
|
import { ListItemProps } from './components/ListItem/types';
|
|
5
5
|
import { ListItemSectionProps } from './components/ListItemSection/ListItemSection';
|
|
6
|
+
import { GridItemProps } from './components/GridItem/types';
|
|
6
7
|
type CTAButtonProps = Omit<ButtonProps, 'variant'> & {
|
|
7
8
|
label: string;
|
|
8
9
|
};
|
|
9
|
-
export type SelectDropdownItem = ListItemProps | ListItemSectionProps;
|
|
10
|
+
export type SelectDropdownItem = ListItemProps | ListItemSectionProps | GridItemProps;
|
|
10
11
|
type ImportedListBoxProps = Pick<ListBoxProps<SelectDropdownItem>, 'children' | 'dragAndDropHooks' | 'onScroll' | 'disabledKeys'>;
|
|
11
12
|
export type SelectDropdownSingleProps = ImportedListBoxProps & {
|
|
12
13
|
multiple?: false;
|
|
@@ -31,6 +32,8 @@ export type SelectDropdownProps = (SelectDropdownSingleProps | SelectDropdownMul
|
|
|
31
32
|
actions?: CTAButtonProps[];
|
|
32
33
|
searchValue?: string;
|
|
33
34
|
onSearchChange?: (value: string) => void;
|
|
35
|
+
topAction?: CTAButtonProps;
|
|
36
|
+
isSelectDropdownOpen?: boolean;
|
|
34
37
|
'aria-label'?: string;
|
|
35
38
|
'aria-labelledby'?: string;
|
|
36
39
|
'aria-describedby'?: string;
|
|
@@ -1,132 +1,143 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
-
var index = require('../../theme/index.cjs');
|
|
5
|
-
var CriticalIcon = require('../../icons/design-system/components/CriticalIcon.cjs');
|
|
6
|
-
var LockIcon = require('../../icons/design-system/components/LockIcon.cjs');
|
|
7
4
|
var styled$1 = require('./styled.cjs');
|
|
8
5
|
var constants = require('./constants.cjs');
|
|
9
6
|
var UploadCopy = require('./components/UploadCopy/UploadCopy.cjs');
|
|
10
|
-
var
|
|
7
|
+
var setInputElFile = require('./utils/setInputElFile/setInputElFile.cjs');
|
|
11
8
|
var getValidTypesString = require('./utils/getValidTypesString/getValidTypesString.cjs');
|
|
12
9
|
var getFileSizeString = require('./utils/getFileSizeString/getFileSizeString.cjs');
|
|
13
10
|
var getTypePropForInputEl = require('./utils/getTypePropForInputEl/getTypePropForInputEl.cjs');
|
|
14
11
|
var styled = require('../../hoc/withLabels/styled.cjs');
|
|
12
|
+
var UploadFileErrors = require('./components/UploadFileErrors/UploadFileErrors.cjs');
|
|
15
13
|
var UploadedFile = require('./components/UploadedFile/UploadedFile.cjs');
|
|
16
14
|
var FlexCol = require('../Flex/FlexCol/FlexCol.cjs');
|
|
17
|
-
var FlexRow = require('../Flex/FlexRow/FlexRow.cjs');
|
|
18
|
-
var useUploadFile = require('./hooks/useUploadFile/useUploadFile.cjs');
|
|
19
|
-
var useValidateInput = require('./hooks/useValidateInput/useValidateInput.cjs');
|
|
20
15
|
|
|
21
16
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
22
17
|
|
|
23
18
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
24
19
|
|
|
25
|
-
const UploadFile = React.forwardRef(({ id, name, maxBytes = 1000000, format = constants.FileSizeUnit.MB, fileTypes,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
fileTypes,
|
|
33
|
-
maxBytes,
|
|
34
|
-
});
|
|
35
|
-
React.useImperativeHandle(outerRef, () => inputRef.current, [inputRef]);
|
|
36
|
-
const [isDragOver, setIsDragOver] = React.useState(false);
|
|
20
|
+
const UploadFile = React.forwardRef(({ id, name, maxBytes = 1000000, format = constants.FileSizeUnit.MB, fileTypes, label = 'Upload file', required, disabled, ...otherProps }, outerRef) => {
|
|
21
|
+
const inputRef = React.useRef(null);
|
|
22
|
+
React.useImperativeHandle(outerRef, () => inputRef.current, []);
|
|
23
|
+
const [file, setFile] = React.useState();
|
|
24
|
+
const [errorState, setErrorState] = React.useState(constants.InputState.VALID);
|
|
25
|
+
const isInvalidFormat = errorState === constants.InputState.INVALID_FORMAT || errorState === constants.InputState.INVALID_FORMAT_AND_SIZE;
|
|
26
|
+
const isOverMaxSize = errorState === constants.InputState.INVALID_SIZE || errorState === constants.InputState.INVALID_FORMAT_AND_SIZE;
|
|
37
27
|
// Computed properties based on params
|
|
38
28
|
const maxSizeCopy = getFileSizeString.getFileSizeString({ maxBytes, format });
|
|
39
29
|
const acceptedTypesCopy = getValidTypesString.getValidTypesString({ fileTypes });
|
|
40
30
|
const acceptedTypesForInputEl = getTypePropForInputEl.getTypePropForInputEl({ fileTypes });
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
const clearFileSelection = () => {
|
|
32
|
+
var _a;
|
|
33
|
+
if ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.value)
|
|
34
|
+
inputRef.current.value = '';
|
|
35
|
+
};
|
|
36
|
+
// Tracks error states within the input element itself, using preset
|
|
37
|
+
// error messages and assigns these to the input component based on the file
|
|
38
|
+
const setInputValidation = ({ overMaxSize, invalidFormat, }) => {
|
|
39
|
+
var _a;
|
|
40
|
+
let error = constants.InputState.VALID;
|
|
41
|
+
if (invalidFormat && !overMaxSize) {
|
|
42
|
+
error = constants.InputState.INVALID_FORMAT;
|
|
46
43
|
}
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
else if (!invalidFormat && overMaxSize) {
|
|
45
|
+
error = constants.InputState.INVALID_SIZE;
|
|
46
|
+
}
|
|
47
|
+
else if (invalidFormat && overMaxSize) {
|
|
48
|
+
error = constants.InputState.INVALID_FORMAT_AND_SIZE;
|
|
49
|
+
}
|
|
50
|
+
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.setCustomValidity(error);
|
|
51
|
+
setErrorState(error);
|
|
52
|
+
};
|
|
49
53
|
// Processes file and updates the UI appropriately:
|
|
50
54
|
const updateFiles = React.useCallback((files) => {
|
|
51
55
|
if (!files.length) {
|
|
56
|
+
setInputValidation({ invalidFormat: true });
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
const [newFile] = files;
|
|
60
|
+
const hasExceededMaxSize = newFile.size > maxBytes;
|
|
61
|
+
const [, extension] = newFile.type.split('/');
|
|
62
|
+
const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
|
|
63
|
+
const hasInvalidFormat = !isTypeValid;
|
|
64
|
+
if (hasExceededMaxSize || hasInvalidFormat) {
|
|
65
|
+
// Empty the inputRef's read-only fileList by clearing the value attribute,
|
|
66
|
+
// since we have an invalid input.
|
|
67
|
+
clearFileSelection();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Update the files attribute of the input el, with the new file(s)
|
|
71
|
+
setInputElFile.setInputElFile({ fileList: files, elementId: id });
|
|
72
|
+
}
|
|
73
|
+
setInputValidation({
|
|
74
|
+
invalidFormat: hasInvalidFormat,
|
|
75
|
+
overMaxSize: hasExceededMaxSize,
|
|
76
|
+
});
|
|
77
|
+
setFile(newFile);
|
|
78
|
+
}, [fileTypes, id, maxBytes]);
|
|
56
79
|
// For focussing of input el and updating drop UI
|
|
57
80
|
const onDragEnter = (event) => {
|
|
58
81
|
var _a;
|
|
59
82
|
event.preventDefault();
|
|
60
|
-
setIsDragOver(true);
|
|
61
83
|
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.focus();
|
|
62
84
|
};
|
|
63
85
|
// For unfocussing of input el and updating drop UI
|
|
64
86
|
const onDragLeave = (event) => {
|
|
87
|
+
var _a;
|
|
65
88
|
event.preventDefault();
|
|
66
|
-
|
|
89
|
+
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.blur();
|
|
67
90
|
};
|
|
68
91
|
// Prevents default browser behaviour
|
|
69
92
|
const onDragOver = (event) => event.preventDefault();
|
|
70
93
|
// Process file when dropped into eligible area
|
|
71
94
|
const onDrop = (event) => {
|
|
72
95
|
event.preventDefault();
|
|
73
|
-
setIsDragOver(false);
|
|
74
96
|
// Prevent reactions on dragging events that do not contain files
|
|
75
97
|
if (!event.dataTransfer.files.length)
|
|
76
98
|
return;
|
|
77
|
-
|
|
78
|
-
if (canUpdateFiles) {
|
|
79
|
-
updateFiles(event.dataTransfer.files);
|
|
80
|
-
}
|
|
99
|
+
updateFiles(event.dataTransfer.files);
|
|
81
100
|
};
|
|
101
|
+
// Removes input el's files, clears errors and removes file from react component
|
|
102
|
+
const resetSelection = React.useCallback(() => {
|
|
103
|
+
clearFileSelection();
|
|
104
|
+
setFile(undefined);
|
|
105
|
+
setInputValidation({
|
|
106
|
+
invalidFormat: false,
|
|
107
|
+
overMaxSize: false,
|
|
108
|
+
});
|
|
109
|
+
}, []);
|
|
82
110
|
// Updates UI based on a native file input change. Attached via useEffect below
|
|
83
|
-
const
|
|
84
|
-
var _a
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
if (canUpdateFiles && files) {
|
|
111
|
+
const onInputChange = React.useCallback(() => {
|
|
112
|
+
var _a;
|
|
113
|
+
const files = (_a = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _a === undefined ? undefined : _a.files;
|
|
114
|
+
if ((files === null || files === undefined ? undefined : files.length) && (files === null || files === undefined ? undefined : files.length) > 0)
|
|
88
115
|
updateFiles(files);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
}, [validateMaximumFiles, inputRef, fileList, updateFiles]);
|
|
116
|
+
else
|
|
117
|
+
resetSelection();
|
|
118
|
+
}, [resetSelection, updateFiles]);
|
|
94
119
|
React.useEffect(() => {
|
|
95
120
|
const ref = inputRef === null || inputRef === undefined ? undefined : inputRef.current;
|
|
96
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('change',
|
|
97
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel',
|
|
121
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('change', onInputChange);
|
|
122
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel', resetSelection);
|
|
98
123
|
return () => {
|
|
99
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('change',
|
|
100
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel',
|
|
124
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('change', onInputChange);
|
|
125
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel', resetSelection);
|
|
101
126
|
};
|
|
102
|
-
}, [
|
|
103
|
-
const hasUserProvidedNoFiles = !(fileList === null || fileList === undefined ? undefined : fileList.length);
|
|
127
|
+
}, [onInputChange, resetSelection]);
|
|
104
128
|
return (React__default.default.createElement(styled.RootStack, { spacing: "xs", alignX: "stretch" },
|
|
105
129
|
React__default.default.createElement(styled.Label, { htmlFor: id },
|
|
106
130
|
label,
|
|
107
131
|
React__default.default.createElement(FlexCol.FlexCol, null,
|
|
108
132
|
React__default.default.createElement(styled.Hint, null,
|
|
109
|
-
|
|
110
|
-
React__default.default.createElement("
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
React__default.default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, disabled: disabled, multiple: multiple, ...otherProps })))),
|
|
133
|
+
React__default.default.createElement("div", null, acceptedTypesCopy),
|
|
134
|
+
React__default.default.createElement("div", null, maxSizeCopy)),
|
|
135
|
+
React__default.default.createElement(styled$1.DropZoneContainer, { "data-testid": "drop-zone-container", onDrop: onDrop, onDragEnter: onDragEnter, onDragOver: onDragOver, onDragLeave: onDragLeave },
|
|
136
|
+
React__default.default.createElement(UploadCopy.UploadCopy, null),
|
|
137
|
+
React__default.default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, required: required, disabled: disabled, ...otherProps })))),
|
|
115
138
|
React__default.default.createElement(FlexCol.FlexCol, null,
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
!!validationCount && (React__default.default.createElement(FlexRow.FlexRow, null,
|
|
119
|
-
React__default.default.createElement(CriticalIcon.ReactComponent, { width: 16, height: 16, color: index.theme.colors.secondary.red.base }),
|
|
120
|
-
React__default.default.createElement(styled.Error, null, (_b = inputRef.current) === null || _b === undefined ? undefined : _b.validationMessage))),
|
|
121
|
-
disabledMessage && (React__default.default.createElement(FlexRow.FlexRow, { id: `${id}-disabled` },
|
|
122
|
-
React__default.default.createElement(LockIcon.ReactComponent, { width: 16, height: 16, color: index.theme.colors.neutral.ink.light }),
|
|
123
|
-
React__default.default.createElement(styled.Disabled, null, disabledMessage))),
|
|
124
|
-
!hideUploadedFiles &&
|
|
125
|
-
fileList && [
|
|
126
|
-
Array.from(fileList).map((file) => {
|
|
127
|
-
return (React__default.default.createElement(UploadedFile.UploadedFile, { key: `${file.name}`, file: file, removeFileFromList: removeFileFromList, disabled: disabled, format: format, maxBytes: maxBytes, fileTypes: fileTypes }));
|
|
128
|
-
}),
|
|
129
|
-
])));
|
|
139
|
+
React__default.default.createElement(UploadedFile.UploadedFile, { file: file, resetSelection: resetSelection, disabled: disabled }),
|
|
140
|
+
React__default.default.createElement(UploadFileErrors.UploadFileErrors, { acceptedTypesCopy: isInvalidFormat ? acceptedTypesCopy : undefined, maxSizeCopy: isOverMaxSize ? maxSizeCopy : undefined }))));
|
|
130
141
|
});
|
|
131
142
|
|
|
132
143
|
exports.UploadFile = UploadFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadFile.cjs","sources":["../../../src/components/UploadFile/UploadFile.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useState,\n DragEvent,\n forwardRef,\n useImperativeHandle,\n} from 'react';\nimport { theme } from 'Theme';\nimport { CriticalIcon, LockIcon } from '../../icons';\nimport { DropZoneContainer } from './styled';\nimport { FileSizeUnit, DEFAULT_MAXIMUM_MULTIPLE_FILES } from './constants';\nimport { UploadCopy } from './components/UploadCopy/UploadCopy';\nimport { DropCopy } from './components/DropCopy/DropCopy';\nimport { getFileSizeString, getTypePropForInputEl, getValidTypesString } from './utils';\nimport { UploadFileProps } from './types';\nimport { Disabled, Error, Hint, Label, RootStack } from '../../hoc/withLabels/styled';\nimport { UploadedFile } from './components/UploadedFile/UploadedFile';\nimport { FlexCol } from '../Flex/FlexCol';\nimport { FlexRow } from '../Flex/FlexRow';\nimport { useUploadFile } from './hooks/useUploadFile';\nimport { useValidateInput } from './hooks/useValidateInput';\n\nexport const UploadFile = forwardRef<HTMLInputElement, UploadFileProps>(\n (\n {\n id,\n name,\n maxBytes = 1000000,\n format = FileSizeUnit.MB,\n fileTypes,\n disabled,\n multiple,\n label = multiple ? 'Upload files' : 'Upload file',\n hideUploadedFiles = false,\n onMaxFilesExceeded,\n maxFiles = DEFAULT_MAXIMUM_MULTIPLE_FILES,\n disabledMessage,\n errorMessage,\n ...otherProps\n }: UploadFileProps,\n outerRef,\n ) => {\n const { inputRef, fileList, setFileList, onCancel, removeFileFromList, clearFileSelection } =\n useUploadFile();\n\n const { validationCount } = useValidateInput({\n customErrorMessage: errorMessage,\n inputRef,\n fileList,\n fileTypes,\n maxBytes,\n });\n\n useImperativeHandle(outerRef, () => inputRef.current!, [inputRef]);\n\n const [isDragOver, setIsDragOver] = useState(false);\n\n // Computed properties based on params\n const maxSizeCopy = getFileSizeString({ maxBytes, format });\n const acceptedTypesCopy = getValidTypesString({ fileTypes });\n const acceptedTypesForInputEl = getTypePropForInputEl({ fileTypes });\n\n const validateMaximumFiles = useCallback(\n (files: FileList | null | undefined) => {\n if (files?.length && files?.length > maxFiles) {\n clearFileSelection();\n onMaxFilesExceeded?.();\n return false;\n }\n return true;\n },\n [clearFileSelection, maxFiles, onMaxFilesExceeded],\n );\n\n // Processes file and updates the UI appropriately:\n const updateFiles = useCallback(\n (files: FileList) => {\n if (!files.length) {\n return;\n }\n\n setFileList(files);\n },\n [setFileList],\n );\n\n // For focussing of input el and updating drop UI\n const onDragEnter = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n setIsDragOver(true);\n inputRef.current?.focus();\n };\n\n // For unfocussing of input el and updating drop UI\n const onDragLeave = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n setIsDragOver(false);\n };\n\n // Prevents default browser behaviour\n const onDragOver = (event: DragEvent<HTMLElement>) => event.preventDefault();\n\n // Process file when dropped into eligible area\n const onDrop = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n setIsDragOver(false);\n // Prevent reactions on dragging events that do not contain files\n if (!event.dataTransfer.files.length) return;\n\n const canUpdateFiles = validateMaximumFiles(event.dataTransfer.files);\n if (canUpdateFiles) {\n updateFiles(event.dataTransfer.files);\n }\n };\n\n // Updates UI based on a native file input change. Attached via useEffect below\n const onChange = useCallback(() => {\n const canUpdateFiles = validateMaximumFiles(inputRef?.current?.files);\n const files = inputRef?.current?.files;\n if (canUpdateFiles && files) {\n updateFiles(files);\n } else if (fileList) {\n updateFiles(fileList);\n }\n }, [validateMaximumFiles, inputRef, fileList, updateFiles]);\n\n useEffect(() => {\n const ref = inputRef?.current;\n ref?.addEventListener('change', onChange);\n ref?.addEventListener('cancel', onCancel);\n\n return () => {\n ref?.removeEventListener('change', onChange);\n ref?.removeEventListener('cancel', onCancel);\n };\n }, [onChange, onCancel, inputRef]);\n\n const hasUserProvidedNoFiles = !fileList?.length;\n\n return (\n <RootStack spacing=\"xs\" alignX=\"stretch\">\n <Label htmlFor={id}>\n {label}\n <FlexCol>\n <Hint>\n {maxSizeCopy}\n <br />\n {acceptedTypesCopy}\n </Hint>\n <DropZoneContainer\n hasUserProvidedNoFiles={hasUserProvidedNoFiles}\n isDragOver={isDragOver}\n data-testid=\"drop-zone-container\"\n onDrop={onDrop}\n onDragEnter={onDragEnter}\n onDragOver={onDragOver}\n onDragLeave={onDragLeave}\n >\n {isDragOver ? <DropCopy /> : <UploadCopy />}\n <input\n ref={inputRef}\n id={id}\n type=\"file\"\n accept={acceptedTypesForInputEl}\n name={name}\n disabled={disabled}\n multiple={multiple}\n {...otherProps}\n />\n </DropZoneContainer>\n </FlexCol>\n </Label>\n <FlexCol>\n {inputRef?.current?.validity.valid === false &&\n hasUserProvidedNoFiles &&\n !!validationCount && (\n <FlexRow>\n <CriticalIcon width={16} height={16} color={theme.colors.secondary.red.base} />\n <Error>{inputRef.current?.validationMessage}</Error>\n </FlexRow>\n )}\n {disabledMessage && (\n <FlexRow id={`${id}-disabled`}>\n <LockIcon width={16} height={16} color={theme.colors.neutral.ink.light} />\n <Disabled>{disabledMessage}</Disabled>\n </FlexRow>\n )}\n {!hideUploadedFiles &&\n fileList && [\n Array.from(fileList).map((file) => {\n return (\n <UploadedFile\n key={`${file.name}`}\n file={file}\n removeFileFromList={removeFileFromList}\n disabled={disabled}\n format={format}\n maxBytes={maxBytes}\n fileTypes={fileTypes}\n />\n );\n }),\n ]}\n </FlexCol>\n </RootStack>\n );\n },\n);\n"],"names":["forwardRef","FileSizeUnit","DEFAULT_MAXIMUM_MULTIPLE_FILES","useUploadFile","useValidateInput","useImperativeHandle","useState","getFileSizeString","getValidTypesString","getTypePropForInputEl","useCallback","useEffect","React","RootStack","Label","FlexCol","Hint","DropZoneContainer","DropCopy","UploadCopy","FlexRow","CriticalIcon","theme","Error","LockIcon","Disabled","UploadedFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBO,MAAM,UAAU,GAAGA,gBAAU,CAClC,CACE,EACE,EAAE,EACF,IAAI,EACJ,QAAQ,GAAG,OAAO,EAClB,MAAM,GAAGC,sBAAY,CAAC,EAAE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,CAAC,GAAG,CAAC,CAAC,IAAI,KAAI;AAChC,oBAAA,QACEb,sBAAC,CAAA,aAAA,CAAAc,yBAAY,EACX,EAAA,GAAG,EAAE,CAAG,EAAA,IAAI,CAAC,IAAI,EAAE,EACnB,IAAI,EAAE,IAAI,EACV,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EAAA,CACpB;AAEN,iBAAC,CAAC;aACH,CACK,CACA;AAEhB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"UploadFile.cjs","sources":["../../../src/components/UploadFile/UploadFile.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useState,\n DragEvent,\n forwardRef,\n useImperativeHandle,\n useRef,\n} from 'react';\nimport { DropZoneContainer } from './styled';\nimport { InputState, FileSizeUnit } from './constants';\nimport { UploadCopy } from './components/UploadCopy/UploadCopy';\nimport { setInputElFile } from './utils/setInputElFile/setInputElFile';\nimport { getFileSizeString, getTypePropForInputEl, getValidTypesString } from './utils';\nimport { UploadFileProps } from './types';\nimport { Hint, Label, RootStack } from '../../hoc/withLabels/styled';\nimport { UploadFileErrors } from './components/UploadFileErrors/UploadFileErrors';\nimport { UploadedFile } from './components/UploadedFile/UploadedFile';\nimport { FlexCol } from '../Flex/FlexCol';\n\nexport const UploadFile = forwardRef<HTMLInputElement, UploadFileProps>(\n (\n {\n id,\n name,\n maxBytes = 1000000,\n format = FileSizeUnit.MB,\n fileTypes,\n label = 'Upload file',\n required,\n disabled,\n ...otherProps\n }: UploadFileProps,\n outerRef,\n ) => {\n const inputRef = useRef<HTMLInputElement | null>(null);\n useImperativeHandle(outerRef, () => inputRef.current!, []);\n\n const [file, setFile] = useState<File>();\n const [errorState, setErrorState] = useState(InputState.VALID);\n\n const isInvalidFormat =\n errorState === InputState.INVALID_FORMAT || errorState === InputState.INVALID_FORMAT_AND_SIZE;\n const isOverMaxSize =\n errorState === InputState.INVALID_SIZE || errorState === InputState.INVALID_FORMAT_AND_SIZE;\n\n // Computed properties based on params\n const maxSizeCopy = getFileSizeString({ maxBytes, format });\n const acceptedTypesCopy = getValidTypesString({ fileTypes });\n const acceptedTypesForInputEl = getTypePropForInputEl({ fileTypes });\n\n const clearFileSelection = () => {\n if (inputRef.current?.value) inputRef.current.value = '';\n };\n\n // Tracks error states within the input element itself, using preset\n // error messages and assigns these to the input component based on the file\n const setInputValidation = ({\n overMaxSize,\n invalidFormat,\n }: {\n overMaxSize?: boolean;\n invalidFormat?: boolean;\n }) => {\n let error = InputState.VALID;\n if (invalidFormat && !overMaxSize) {\n error = InputState.INVALID_FORMAT;\n } else if (!invalidFormat && overMaxSize) {\n error = InputState.INVALID_SIZE;\n } else if (invalidFormat && overMaxSize) {\n error = InputState.INVALID_FORMAT_AND_SIZE;\n }\n inputRef.current?.setCustomValidity(error);\n setErrorState(error);\n };\n\n // Processes file and updates the UI appropriately:\n const updateFiles = useCallback(\n (files: FileList) => {\n if (!files.length) {\n setInputValidation({ invalidFormat: true });\n return;\n }\n\n const [newFile] = files;\n const hasExceededMaxSize = newFile.size > maxBytes;\n\n const [, extension] = newFile.type.split('/');\n const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);\n const hasInvalidFormat = !isTypeValid;\n\n if (hasExceededMaxSize || hasInvalidFormat) {\n // Empty the inputRef's read-only fileList by clearing the value attribute,\n // since we have an invalid input.\n clearFileSelection();\n } else {\n // Update the files attribute of the input el, with the new file(s)\n setInputElFile({ fileList: files, elementId: id });\n }\n setInputValidation({\n invalidFormat: hasInvalidFormat,\n overMaxSize: hasExceededMaxSize,\n });\n setFile(newFile);\n },\n [fileTypes, id, maxBytes],\n );\n\n // For focussing of input el and updating drop UI\n const onDragEnter = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n inputRef.current?.focus();\n };\n\n // For unfocussing of input el and updating drop UI\n const onDragLeave = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n inputRef.current?.blur();\n };\n\n // Prevents default browser behaviour\n const onDragOver = (event: DragEvent<HTMLElement>) => event.preventDefault();\n\n // Process file when dropped into eligible area\n const onDrop = (event: DragEvent<HTMLElement>) => {\n event.preventDefault();\n // Prevent reactions on dragging events that do not contain files\n if (!event.dataTransfer.files.length) return;\n updateFiles(event.dataTransfer.files);\n };\n\n // Removes input el's files, clears errors and removes file from react component\n const resetSelection = useCallback(() => {\n clearFileSelection();\n setFile(undefined);\n setInputValidation({\n invalidFormat: false,\n overMaxSize: false,\n });\n }, []);\n\n // Updates UI based on a native file input change. Attached via useEffect below\n const onInputChange = useCallback(() => {\n const files = inputRef?.current?.files;\n if (files?.length && files?.length > 0) updateFiles(files);\n else resetSelection();\n }, [resetSelection, updateFiles]);\n\n useEffect(() => {\n const ref = inputRef?.current;\n ref?.addEventListener('change', onInputChange);\n ref?.addEventListener('cancel', resetSelection);\n\n return () => {\n ref?.removeEventListener('change', onInputChange);\n ref?.removeEventListener('cancel', resetSelection);\n };\n }, [onInputChange, resetSelection]);\n\n return (\n <RootStack spacing=\"xs\" alignX=\"stretch\">\n <Label htmlFor={id}>\n {label}\n <FlexCol>\n <Hint>\n <div>{acceptedTypesCopy}</div>\n <div>{maxSizeCopy}</div>\n </Hint>\n <DropZoneContainer\n data-testid=\"drop-zone-container\"\n onDrop={onDrop}\n onDragEnter={onDragEnter}\n onDragOver={onDragOver}\n onDragLeave={onDragLeave}\n >\n <UploadCopy />\n <input\n ref={inputRef}\n id={id}\n type=\"file\"\n accept={acceptedTypesForInputEl}\n name={name}\n required={required}\n disabled={disabled}\n {...otherProps}\n />\n </DropZoneContainer>\n </FlexCol>\n </Label>\n <FlexCol>\n <UploadedFile file={file} resetSelection={resetSelection} disabled={disabled} />\n <UploadFileErrors\n acceptedTypesCopy={isInvalidFormat ? acceptedTypesCopy : undefined}\n maxSizeCopy={isOverMaxSize ? maxSizeCopy : undefined}\n />\n </FlexCol>\n </RootStack>\n );\n },\n);\n"],"names":["forwardRef","FileSizeUnit","useRef","useImperativeHandle","useState","InputState","getFileSizeString","getValidTypesString","getTypePropForInputEl","useCallback","setInputElFile","useEffect","React","RootStack","Label","FlexCol","Hint","DropZoneContainer","UploadCopy","UploadedFile","UploadFileErrors"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBa,MAAA,UAAU,GAAGA,gBAAU,CAClC,CACE,EACE,EAAE,EACF,IAAI,EACJ,QAAQ,GAAG,OAAO,EAClB,MAAM,GAAGC,sBAAY,CAAC,EAAE,EACxB,SAAS,EACT,KAAK,GAAG,aAAa,EACrB,QAAQ,EACR,QAAQ,EACR,GAAG,UAAU,EACG,EAClB,QAAQ,KACN;AACF,IAAA,MAAM,QAAQ,GAAGC,YAAM,CAA0B,IAAI,CAAC;AACtD,IAAAC,yBAAmB,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAAC,OAAQ,EAAE,EAAE,CAAC;IAE1D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,cAAQ,EAAQ;AACxC,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,cAAQ,CAACC,oBAAU,CAAC,KAAK,CAAC;AAE9D,IAAA,MAAM,eAAe,GACnB,UAAU,KAAKA,oBAAU,CAAC,cAAc,IAAI,UAAU,KAAKA,oBAAU,CAAC,uBAAuB;AAC/F,IAAA,MAAM,aAAa,GACjB,UAAU,KAAKA,oBAAU,CAAC,YAAY,IAAI,UAAU,KAAKA,oBAAU,CAAC,uBAAuB;;IAG7F,MAAM,WAAW,GAAGC,mCAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAGC,uCAAmB,CAAC,EAAE,SAAS,EAAE,CAAC;IAC5D,MAAM,uBAAuB,GAAGC,2CAAqB,CAAC,EAAE,SAAS,EAAE,CAAC;IAEpE,MAAM,kBAAkB,GAAG,MAAK;;AAC9B,QAAA,IAAI,CAAA,EAAA,GAAA,QAAQ,CA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C,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAI,CAAA;AAChF,YAAAP,sBAAA,CAAA,aAAA,CAACQ,iCAAgB,EAAA,EACf,iBAAiB,EAAE,eAAe,GAAG,iBAAiB,GAAG,SAAS,EAClE,WAAW,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,EAAA,CACpD,CACM,CACA;AAEhB,CAAC;;;;"}
|
|
@@ -1,126 +1,137 @@
|
|
|
1
|
-
import React__default, { forwardRef, useImperativeHandle, useState, useCallback, useEffect } from 'react';
|
|
2
|
-
import { theme } from '../../theme/index.js';
|
|
3
|
-
import { ReactComponent as CriticalIcon } from '../../icons/design-system/components/CriticalIcon.js';
|
|
4
|
-
import { ReactComponent as LockIcon } from '../../icons/design-system/components/LockIcon.js';
|
|
1
|
+
import React__default, { forwardRef, useRef, useImperativeHandle, useState, useCallback, useEffect } from 'react';
|
|
5
2
|
import { DropZoneContainer } from './styled.js';
|
|
6
|
-
import {
|
|
3
|
+
import { InputState, FileSizeUnit } from './constants.js';
|
|
7
4
|
import { UploadCopy } from './components/UploadCopy/UploadCopy.js';
|
|
8
|
-
import {
|
|
5
|
+
import { setInputElFile } from './utils/setInputElFile/setInputElFile.js';
|
|
9
6
|
import { getValidTypesString } from './utils/getValidTypesString/getValidTypesString.js';
|
|
10
7
|
import { getFileSizeString } from './utils/getFileSizeString/getFileSizeString.js';
|
|
11
8
|
import { getTypePropForInputEl } from './utils/getTypePropForInputEl/getTypePropForInputEl.js';
|
|
12
|
-
import { RootStack, Label, Hint
|
|
9
|
+
import { RootStack, Label, Hint } from '../../hoc/withLabels/styled.js';
|
|
10
|
+
import { UploadFileErrors } from './components/UploadFileErrors/UploadFileErrors.js';
|
|
13
11
|
import { UploadedFile } from './components/UploadedFile/UploadedFile.js';
|
|
14
12
|
import { FlexCol } from '../Flex/FlexCol/FlexCol.js';
|
|
15
|
-
import { FlexRow } from '../Flex/FlexRow/FlexRow.js';
|
|
16
|
-
import { useUploadFile } from './hooks/useUploadFile/useUploadFile.js';
|
|
17
|
-
import { useValidateInput } from './hooks/useValidateInput/useValidateInput.js';
|
|
18
13
|
|
|
19
|
-
const UploadFile = forwardRef(({ id, name, maxBytes = 1000000, format = FileSizeUnit.MB, fileTypes,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
fileTypes,
|
|
27
|
-
maxBytes,
|
|
28
|
-
});
|
|
29
|
-
useImperativeHandle(outerRef, () => inputRef.current, [inputRef]);
|
|
30
|
-
const [isDragOver, setIsDragOver] = useState(false);
|
|
14
|
+
const UploadFile = forwardRef(({ id, name, maxBytes = 1000000, format = FileSizeUnit.MB, fileTypes, label = 'Upload file', required, disabled, ...otherProps }, outerRef) => {
|
|
15
|
+
const inputRef = useRef(null);
|
|
16
|
+
useImperativeHandle(outerRef, () => inputRef.current, []);
|
|
17
|
+
const [file, setFile] = useState();
|
|
18
|
+
const [errorState, setErrorState] = useState(InputState.VALID);
|
|
19
|
+
const isInvalidFormat = errorState === InputState.INVALID_FORMAT || errorState === InputState.INVALID_FORMAT_AND_SIZE;
|
|
20
|
+
const isOverMaxSize = errorState === InputState.INVALID_SIZE || errorState === InputState.INVALID_FORMAT_AND_SIZE;
|
|
31
21
|
// Computed properties based on params
|
|
32
22
|
const maxSizeCopy = getFileSizeString({ maxBytes, format });
|
|
33
23
|
const acceptedTypesCopy = getValidTypesString({ fileTypes });
|
|
34
24
|
const acceptedTypesForInputEl = getTypePropForInputEl({ fileTypes });
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
const clearFileSelection = () => {
|
|
26
|
+
var _a;
|
|
27
|
+
if ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.value)
|
|
28
|
+
inputRef.current.value = '';
|
|
29
|
+
};
|
|
30
|
+
// Tracks error states within the input element itself, using preset
|
|
31
|
+
// error messages and assigns these to the input component based on the file
|
|
32
|
+
const setInputValidation = ({ overMaxSize, invalidFormat, }) => {
|
|
33
|
+
var _a;
|
|
34
|
+
let error = InputState.VALID;
|
|
35
|
+
if (invalidFormat && !overMaxSize) {
|
|
36
|
+
error = InputState.INVALID_FORMAT;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
else if (!invalidFormat && overMaxSize) {
|
|
39
|
+
error = InputState.INVALID_SIZE;
|
|
40
|
+
}
|
|
41
|
+
else if (invalidFormat && overMaxSize) {
|
|
42
|
+
error = InputState.INVALID_FORMAT_AND_SIZE;
|
|
43
|
+
}
|
|
44
|
+
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.setCustomValidity(error);
|
|
45
|
+
setErrorState(error);
|
|
46
|
+
};
|
|
43
47
|
// Processes file and updates the UI appropriately:
|
|
44
48
|
const updateFiles = useCallback((files) => {
|
|
45
49
|
if (!files.length) {
|
|
50
|
+
setInputValidation({ invalidFormat: true });
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const [newFile] = files;
|
|
54
|
+
const hasExceededMaxSize = newFile.size > maxBytes;
|
|
55
|
+
const [, extension] = newFile.type.split('/');
|
|
56
|
+
const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
|
|
57
|
+
const hasInvalidFormat = !isTypeValid;
|
|
58
|
+
if (hasExceededMaxSize || hasInvalidFormat) {
|
|
59
|
+
// Empty the inputRef's read-only fileList by clearing the value attribute,
|
|
60
|
+
// since we have an invalid input.
|
|
61
|
+
clearFileSelection();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Update the files attribute of the input el, with the new file(s)
|
|
65
|
+
setInputElFile({ fileList: files, elementId: id });
|
|
66
|
+
}
|
|
67
|
+
setInputValidation({
|
|
68
|
+
invalidFormat: hasInvalidFormat,
|
|
69
|
+
overMaxSize: hasExceededMaxSize,
|
|
70
|
+
});
|
|
71
|
+
setFile(newFile);
|
|
72
|
+
}, [fileTypes, id, maxBytes]);
|
|
50
73
|
// For focussing of input el and updating drop UI
|
|
51
74
|
const onDragEnter = (event) => {
|
|
52
75
|
var _a;
|
|
53
76
|
event.preventDefault();
|
|
54
|
-
setIsDragOver(true);
|
|
55
77
|
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.focus();
|
|
56
78
|
};
|
|
57
79
|
// For unfocussing of input el and updating drop UI
|
|
58
80
|
const onDragLeave = (event) => {
|
|
81
|
+
var _a;
|
|
59
82
|
event.preventDefault();
|
|
60
|
-
|
|
83
|
+
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.blur();
|
|
61
84
|
};
|
|
62
85
|
// Prevents default browser behaviour
|
|
63
86
|
const onDragOver = (event) => event.preventDefault();
|
|
64
87
|
// Process file when dropped into eligible area
|
|
65
88
|
const onDrop = (event) => {
|
|
66
89
|
event.preventDefault();
|
|
67
|
-
setIsDragOver(false);
|
|
68
90
|
// Prevent reactions on dragging events that do not contain files
|
|
69
91
|
if (!event.dataTransfer.files.length)
|
|
70
92
|
return;
|
|
71
|
-
|
|
72
|
-
if (canUpdateFiles) {
|
|
73
|
-
updateFiles(event.dataTransfer.files);
|
|
74
|
-
}
|
|
93
|
+
updateFiles(event.dataTransfer.files);
|
|
75
94
|
};
|
|
95
|
+
// Removes input el's files, clears errors and removes file from react component
|
|
96
|
+
const resetSelection = useCallback(() => {
|
|
97
|
+
clearFileSelection();
|
|
98
|
+
setFile(undefined);
|
|
99
|
+
setInputValidation({
|
|
100
|
+
invalidFormat: false,
|
|
101
|
+
overMaxSize: false,
|
|
102
|
+
});
|
|
103
|
+
}, []);
|
|
76
104
|
// Updates UI based on a native file input change. Attached via useEffect below
|
|
77
|
-
const
|
|
78
|
-
var _a
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
if (canUpdateFiles && files) {
|
|
105
|
+
const onInputChange = useCallback(() => {
|
|
106
|
+
var _a;
|
|
107
|
+
const files = (_a = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _a === undefined ? undefined : _a.files;
|
|
108
|
+
if ((files === null || files === undefined ? undefined : files.length) && (files === null || files === undefined ? undefined : files.length) > 0)
|
|
82
109
|
updateFiles(files);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}, [validateMaximumFiles, inputRef, fileList, updateFiles]);
|
|
110
|
+
else
|
|
111
|
+
resetSelection();
|
|
112
|
+
}, [resetSelection, updateFiles]);
|
|
88
113
|
useEffect(() => {
|
|
89
114
|
const ref = inputRef === null || inputRef === undefined ? undefined : inputRef.current;
|
|
90
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('change',
|
|
91
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel',
|
|
115
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('change', onInputChange);
|
|
116
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel', resetSelection);
|
|
92
117
|
return () => {
|
|
93
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('change',
|
|
94
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel',
|
|
118
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('change', onInputChange);
|
|
119
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel', resetSelection);
|
|
95
120
|
};
|
|
96
|
-
}, [
|
|
97
|
-
const hasUserProvidedNoFiles = !(fileList === null || fileList === undefined ? undefined : fileList.length);
|
|
121
|
+
}, [onInputChange, resetSelection]);
|
|
98
122
|
return (React__default.createElement(RootStack, { spacing: "xs", alignX: "stretch" },
|
|
99
123
|
React__default.createElement(Label, { htmlFor: id },
|
|
100
124
|
label,
|
|
101
125
|
React__default.createElement(FlexCol, null,
|
|
102
126
|
React__default.createElement(Hint, null,
|
|
103
|
-
|
|
104
|
-
React__default.createElement("
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
React__default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, disabled: disabled, multiple: multiple, ...otherProps })))),
|
|
127
|
+
React__default.createElement("div", null, acceptedTypesCopy),
|
|
128
|
+
React__default.createElement("div", null, maxSizeCopy)),
|
|
129
|
+
React__default.createElement(DropZoneContainer, { "data-testid": "drop-zone-container", onDrop: onDrop, onDragEnter: onDragEnter, onDragOver: onDragOver, onDragLeave: onDragLeave },
|
|
130
|
+
React__default.createElement(UploadCopy, null),
|
|
131
|
+
React__default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, required: required, disabled: disabled, ...otherProps })))),
|
|
109
132
|
React__default.createElement(FlexCol, null,
|
|
110
|
-
(
|
|
111
|
-
|
|
112
|
-
!!validationCount && (React__default.createElement(FlexRow, null,
|
|
113
|
-
React__default.createElement(CriticalIcon, { width: 16, height: 16, color: theme.colors.secondary.red.base }),
|
|
114
|
-
React__default.createElement(Error, null, (_b = inputRef.current) === null || _b === undefined ? undefined : _b.validationMessage))),
|
|
115
|
-
disabledMessage && (React__default.createElement(FlexRow, { id: `${id}-disabled` },
|
|
116
|
-
React__default.createElement(LockIcon, { width: 16, height: 16, color: theme.colors.neutral.ink.light }),
|
|
117
|
-
React__default.createElement(Disabled, null, disabledMessage))),
|
|
118
|
-
!hideUploadedFiles &&
|
|
119
|
-
fileList && [
|
|
120
|
-
Array.from(fileList).map((file) => {
|
|
121
|
-
return (React__default.createElement(UploadedFile, { key: `${file.name}`, file: file, removeFileFromList: removeFileFromList, disabled: disabled, format: format, maxBytes: maxBytes, fileTypes: fileTypes }));
|
|
122
|
-
}),
|
|
123
|
-
])));
|
|
133
|
+
React__default.createElement(UploadedFile, { file: file, resetSelection: resetSelection, disabled: disabled }),
|
|
134
|
+
React__default.createElement(UploadFileErrors, { acceptedTypesCopy: isInvalidFormat ? acceptedTypesCopy : undefined, maxSizeCopy: isOverMaxSize ? maxSizeCopy : undefined }))));
|
|
124
135
|
});
|
|
125
136
|
|
|
126
137
|
export { UploadFile };
|