@veeqo/ui 12.5.1 → 13.1.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/PhoneInput/PhoneInput.cjs +50 -0
- package/dist/components/PhoneInput/PhoneInput.cjs.map +1 -0
- package/dist/components/PhoneInput/PhoneInput.d.ts +3 -0
- package/dist/components/PhoneInput/PhoneInput.js +44 -0
- package/dist/components/PhoneInput/PhoneInput.js.map +1 -0
- package/dist/components/PhoneInput/PhoneInput.module.scss.cjs +9 -0
- package/dist/components/PhoneInput/PhoneInput.module.scss.cjs.map +1 -0
- package/dist/components/PhoneInput/PhoneInput.module.scss.js +7 -0
- package/dist/components/PhoneInput/PhoneInput.module.scss.js.map +1 -0
- package/dist/components/PhoneInput/components/SelectedCountry.cjs +18 -0
- package/dist/components/PhoneInput/components/SelectedCountry.cjs.map +1 -0
- package/dist/components/PhoneInput/components/SelectedCountry.d.ts +5 -0
- package/dist/components/PhoneInput/components/SelectedCountry.js +12 -0
- package/dist/components/PhoneInput/components/SelectedCountry.js.map +1 -0
- package/dist/components/PhoneInput/constants.cjs +1243 -0
- package/dist/components/PhoneInput/constants.cjs.map +1 -0
- package/dist/components/PhoneInput/constants.d.ts +4 -0
- package/dist/components/PhoneInput/constants.js +1239 -0
- package/dist/components/PhoneInput/constants.js.map +1 -0
- package/dist/components/PhoneInput/hooks/useApplyCountryCode.cjs +48 -0
- package/dist/components/PhoneInput/hooks/useApplyCountryCode.cjs.map +1 -0
- package/dist/components/PhoneInput/hooks/useApplyCountryCode.d.ts +11 -0
- package/dist/components/PhoneInput/hooks/useApplyCountryCode.js +46 -0
- package/dist/components/PhoneInput/hooks/useApplyCountryCode.js.map +1 -0
- package/dist/components/PhoneInput/index.cjs +11 -0
- package/dist/components/PhoneInput/index.cjs.map +1 -0
- package/dist/components/PhoneInput/index.d.ts +308 -0
- package/dist/components/PhoneInput/index.js +9 -0
- package/dist/components/PhoneInput/index.js.map +1 -0
- package/dist/components/PhoneInput/types.d.ts +25 -0
- package/dist/components/PhoneInput/utils/utils.cjs +69 -0
- package/dist/components/PhoneInput/utils/utils.cjs.map +1 -0
- package/dist/components/PhoneInput/utils/utils.d.ts +14 -0
- package/dist/components/PhoneInput/utils/utils.js +60 -0
- package/dist/components/PhoneInput/utils/utils.js.map +1 -0
- package/dist/components/SelectDropdown/SelectDropdown.cjs +2 -3
- package/dist/components/SelectDropdown/SelectDropdown.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.d.ts +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.js +2 -3
- package/dist/components/SelectDropdown/SelectDropdown.js.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.cjs +2 -2
- 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 +2 -2
- package/dist/components/SelectDropdown/components/ItemContent/ItemContent.js.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/SelectionType.cjs +5 -3
- package/dist/components/SelectDropdown/components/ItemContent/SelectionType.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ItemContent/SelectionType.d.ts +2 -1
- package/dist/components/SelectDropdown/components/ItemContent/SelectionType.js +5 -3
- package/dist/components/SelectDropdown/components/ItemContent/SelectionType.js.map +1 -1
- package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs +2 -2
- package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/ListItem/ListItem.d.ts +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/types.d.ts +1 -0
- package/dist/components/SelectDropdown/types.d.ts +2 -1
- package/dist/components/UploadFile/UploadFile.cjs +64 -83
- package/dist/components/UploadFile/UploadFile.cjs.map +1 -1
- package/dist/components/UploadFile/UploadFile.js +67 -86
- package/dist/components/UploadFile/UploadFile.js.map +1 -1
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs +28 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs.map +1 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.d.ts +2 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.js +22 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.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/constants.cjs +71 -8
- package/dist/components/UploadFile/constants.cjs.map +1 -1
- package/dist/components/UploadFile/constants.d.ts +57 -5
- package/dist/components/UploadFile/constants.js +69 -9
- package/dist/components/UploadFile/constants.js.map +1 -1
- package/dist/components/UploadFile/hooks/useUploadFile/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs +65 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.d.ts +9 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js +63 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js.map +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs +48 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.d.ts +11 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js +46 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js.map +1 -0
- package/dist/components/UploadFile/index.d.ts +0 -1
- package/dist/components/UploadFile/mocks/files.d.ts +2 -0
- package/dist/components/UploadFile/mocks/mockUseUploadFile.d.ts +14 -0
- package/dist/components/UploadFile/mocks/utils.d.ts +1 -2
- package/dist/components/UploadFile/styled.cjs +40 -1
- package/dist/components/UploadFile/styled.cjs.map +1 -1
- package/dist/components/UploadFile/styled.d.ts +4 -1
- package/dist/components/UploadFile/styled.js +40 -1
- package/dist/components/UploadFile/styled.js.map +1 -1
- package/dist/components/UploadFile/types.d.ts +15 -1
- package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.cjs +27 -0
- package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.cjs.map +1 -0
- package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.d.ts +8 -0
- package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.js +25 -0
- package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.js.map +1 -0
- package/dist/components/UploadFile/utils/getErrorMessage/index.d.ts +1 -0
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs +14 -11
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.d.ts +10 -7
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js +14 -11
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs +16 -30
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js +16 -30
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js.map +1 -1
- package/dist/components/UploadFile/utils/index.d.ts +0 -1
- package/dist/components/UploadedFile/UploadedFile.cjs +78 -0
- package/dist/components/UploadedFile/UploadedFile.cjs.map +1 -0
- package/dist/components/UploadedFile/UploadedFile.d.ts +12 -0
- package/dist/components/UploadedFile/UploadedFile.js +72 -0
- package/dist/components/UploadedFile/UploadedFile.js.map +1 -0
- package/dist/components/UploadedFile/UploadedFile.module.scss.cjs +9 -0
- package/dist/components/UploadedFile/UploadedFile.module.scss.cjs.map +1 -0
- package/dist/components/UploadedFile/UploadedFile.module.scss.js +7 -0
- package/dist/components/UploadedFile/UploadedFile.module.scss.js.map +1 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/index.d.ts +1 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs +38 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs.map +1 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.d.ts +18 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.js +36 -0
- package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.js.map +1 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/index.d.ts +1 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.cjs +36 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.cjs.map +1 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.d.ts +8 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.js +34 -0
- package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.js.map +1 -0
- package/dist/components/UploadedFile/index.d.ts +1 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.cjs +17 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.cjs.map +1 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.d.ts +1 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.js +15 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.js.map +1 -0
- package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/index.d.ts +1 -0
- package/dist/components/UploadedFile/utils/isImageType/index.d.ts +1 -0
- package/dist/components/UploadedFile/utils/isImageType/isImageType.cjs +14 -0
- package/dist/components/UploadedFile/utils/isImageType/isImageType.cjs.map +1 -0
- package/dist/components/UploadedFile/utils/isImageType/isImageType.d.ts +1 -0
- package/dist/components/UploadedFile/utils/isImageType/isImageType.js +12 -0
- package/dist/components/UploadedFile/utils/isImageType/isImageType.js.map +1 -0
- package/dist/components/index.d.ts +4 -1
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/components/UploadFile/UploadGraphic.cjs +0 -14
- package/dist/components/UploadFile/UploadGraphic.cjs.map +0 -1
- package/dist/components/UploadFile/UploadGraphic.d.ts +0 -2
- package/dist/components/UploadFile/UploadGraphic.js +0 -8
- package/dist/components/UploadFile/UploadGraphic.js.map +0 -1
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs +0 -31
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.d.ts +0 -7
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js +0 -25
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs +0 -21
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.d.ts +0 -8
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js +0 -15
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs +0 -20
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/styled.d.ts +0 -2
- package/dist/components/UploadFile/components/UploadedFile/styled.js +0 -13
- package/dist/components/UploadFile/components/UploadedFile/styled.js.map +0 -1
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs +0 -18
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs.map +0 -1
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.d.ts +0 -13
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js +0 -16
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js.map +0 -1
|
@@ -8,9 +8,9 @@ import { buildClassnames } from '../../../../utils/buildClassnames.js';
|
|
|
8
8
|
import 'uid/secure';
|
|
9
9
|
import itemStyles from '../item.module.scss.js';
|
|
10
10
|
|
|
11
|
-
const ListItem = ({ id, label, href, appearance = 'primary', className, ...props }) => {
|
|
11
|
+
const ListItem = ({ id, label, href, appearance = 'primary', shouldDisableSelectionRender = false, className, ...props }) => {
|
|
12
12
|
const idComputed = useId({ id, prefix: 'list-item' });
|
|
13
|
-
return (React__default.createElement(ListBoxItem, { id: idComputed, textValue: label, href: href, className: buildClassnames([itemStyles.item, itemStyles[`appearance-${appearance}`], className]), ...props }, ({ selectionMode, allowsDragging, isSelected, isHovered }) => (React__default.createElement(ItemContent, { selectionMode: selectionMode, allowsDragging: allowsDragging, isSelected: isSelected, isHovered: isHovered, label: label, isLink: Boolean(href), appearance: appearance, itemType: "list", ...props }))));
|
|
13
|
+
return (React__default.createElement(ListBoxItem, { id: idComputed, textValue: label, href: href, className: buildClassnames([itemStyles.item, itemStyles[`appearance-${appearance}`], className]), ...props }, ({ selectionMode, allowsDragging, isSelected, isHovered }) => (React__default.createElement(ItemContent, { selectionMode: selectionMode, allowsDragging: allowsDragging, isSelected: isSelected, isHovered: isHovered, label: label, isLink: Boolean(href), appearance: appearance, itemType: "list", shouldDisableSelectionRender: shouldDisableSelectionRender, ...props }))));
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export { ListItem };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItem.js","sources":["../../../../../src/components/SelectDropdown/components/ListItem/ListItem.tsx"],"sourcesContent":["import React from 'react';\nimport { ListBoxItem, ListBoxItemRenderProps } from 'react-aria-components';\nimport { useId } from '../../../../hooks';\nimport { ListItemProps } from './types';\nimport { ItemContent } from '../ItemContent';\nimport { buildClassnames } from '../../../../utils';\n\nimport styles from '../item.module.scss';\n\nexport const ListItem = ({\n id,\n label,\n href,\n appearance = 'primary',\n className,\n ...props\n}: ListItemProps) => {\n const idComputed = useId({ id, prefix: 'list-item' });\n\n return (\n <ListBoxItem\n id={idComputed}\n textValue={label}\n href={href}\n className={buildClassnames([styles.item, styles[`appearance-${appearance}`], className])}\n {...props}\n >\n {/* use react aria's render props to add more such as isHovered */}\n {({ selectionMode, allowsDragging, isSelected, isHovered }: ListBoxItemRenderProps) => (\n <ItemContent\n selectionMode={selectionMode}\n allowsDragging={allowsDragging}\n isSelected={isSelected}\n isHovered={isHovered}\n label={label}\n isLink={Boolean(href)}\n appearance={appearance}\n itemType=\"list\"\n {...props}\n />\n )}\n </ListBoxItem>\n );\n};\n"],"names":["React","styles"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ListItem.js","sources":["../../../../../src/components/SelectDropdown/components/ListItem/ListItem.tsx"],"sourcesContent":["import React from 'react';\nimport { ListBoxItem, ListBoxItemRenderProps } from 'react-aria-components';\nimport { useId } from '../../../../hooks';\nimport { ListItemProps } from './types';\nimport { ItemContent } from '../ItemContent';\nimport { buildClassnames } from '../../../../utils';\n\nimport styles from '../item.module.scss';\n\nexport const ListItem = ({\n id,\n label,\n href,\n appearance = 'primary',\n shouldDisableSelectionRender = false,\n className,\n ...props\n}: ListItemProps) => {\n const idComputed = useId({ id, prefix: 'list-item' });\n\n return (\n <ListBoxItem\n id={idComputed}\n textValue={label}\n href={href}\n className={buildClassnames([styles.item, styles[`appearance-${appearance}`], className])}\n {...props}\n >\n {/* use react aria's render props to add more such as isHovered */}\n {({ selectionMode, allowsDragging, isSelected, isHovered }: ListBoxItemRenderProps) => (\n <ItemContent\n selectionMode={selectionMode}\n allowsDragging={allowsDragging}\n isSelected={isSelected}\n isHovered={isHovered}\n label={label}\n isLink={Boolean(href)}\n appearance={appearance}\n itemType=\"list\"\n shouldDisableSelectionRender={shouldDisableSelectionRender}\n {...props}\n />\n )}\n </ListBoxItem>\n );\n};\n"],"names":["React","styles"],"mappings":";;;;;;;;;;AASa,MAAA,QAAQ,GAAG,CAAC,EACvB,EAAE,EACF,KAAK,EACL,IAAI,EACJ,UAAU,GAAG,SAAS,EACtB,4BAA4B,GAAG,KAAK,EACpC,SAAS,EACT,GAAG,KAAK,EACM,KAAI;AAClB,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAErD,QACEA,6BAAC,WAAW,EAAA,EACV,EAAE,EAAE,UAAU,EACd,SAAS,EAAE,KAAK,EAChB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,eAAe,CAAC,CAACC,UAAM,CAAC,IAAI,EAAEA,UAAM,CAAC,CAAc,WAAA,EAAA,UAAU,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,EAAA,GACpF,KAAK,EAGR,EAAA,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAA0B,MAChFD,6BAAC,WAAW,EAAA,EACV,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EACrB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAC,MAAM,EACf,4BAA4B,EAAE,4BAA4B,EAAA,GACtD,KAAK,EACT,CAAA,CACH,CACW;AAElB;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Key, ListBoxProps } from 'react-aria-components';
|
|
2
|
-
import { ReactElement } from 'react';
|
|
2
|
+
import { ReactNode, 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';
|
|
@@ -34,6 +34,7 @@ export type SelectDropdownProps = (SelectDropdownSingleProps | SelectDropdownMul
|
|
|
34
34
|
onSearchChange?: (value: string) => void;
|
|
35
35
|
topAction?: CTAButtonProps;
|
|
36
36
|
isSelectDropdownOpen?: boolean;
|
|
37
|
+
selectedSlot?: ReactNode;
|
|
37
38
|
'aria-label'?: string;
|
|
38
39
|
'aria-labelledby'?: string;
|
|
39
40
|
'aria-describedby'?: string;
|
|
@@ -1,143 +1,124 @@
|
|
|
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');
|
|
4
7
|
var styled$1 = require('./styled.cjs');
|
|
5
8
|
var constants = require('./constants.cjs');
|
|
6
9
|
var UploadCopy = require('./components/UploadCopy/UploadCopy.cjs');
|
|
7
|
-
var
|
|
10
|
+
var DropCopy = require('./components/DropCopy/DropCopy.cjs');
|
|
8
11
|
var getValidTypesString = require('./utils/getValidTypesString/getValidTypesString.cjs');
|
|
9
12
|
var getFileSizeString = require('./utils/getFileSizeString/getFileSizeString.cjs');
|
|
10
13
|
var getTypePropForInputEl = require('./utils/getTypePropForInputEl/getTypePropForInputEl.cjs');
|
|
11
14
|
var styled = require('../../hoc/withLabels/styled.cjs');
|
|
12
|
-
var
|
|
13
|
-
var UploadedFile = require('./components/UploadedFile/UploadedFile.cjs');
|
|
15
|
+
var UploadedFile = require('../UploadedFile/UploadedFile.cjs');
|
|
14
16
|
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');
|
|
15
20
|
|
|
16
21
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
17
22
|
|
|
18
23
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
19
24
|
|
|
20
|
-
const UploadFile = React.forwardRef(({ id, name, maxBytes =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const isOverMaxSize = errorState === constants.InputState.INVALID_SIZE || errorState === constants.InputState.INVALID_FORMAT_AND_SIZE;
|
|
25
|
+
const UploadFile = React.forwardRef(({ id, name, maxBytes = constants.DEFAULT_MAXIMUM_FILE_BYTES, format = constants.FileSizeUnit.MB, fileTypes, disabled, multiple, label = multiple ? 'Upload files' : 'Upload file', hideUploadedFiles = false, onMaxFilesExceeded, maxFiles = constants.DEFAULT_MAXIMUM_MULTIPLE_FILES, disabledMessage, isDirty, errorMessage = '', ...otherProps }, outerRef) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { inputRef, fileList, setFileList, onCancel, removeFileFromList, clearFileSelection } = useUploadFile.useUploadFile();
|
|
28
|
+
useValidateInput.useValidateInput({ inputRef, fileList, fileTypes, maxBytes, errorMessage });
|
|
29
|
+
React.useImperativeHandle(outerRef, () => inputRef.current, [inputRef]);
|
|
30
|
+
const [isDragOver, setIsDragOver] = React.useState(false);
|
|
27
31
|
// Computed properties based on params
|
|
28
32
|
const maxSizeCopy = getFileSizeString.getFileSizeString({ maxBytes, format });
|
|
29
33
|
const acceptedTypesCopy = getValidTypesString.getValidTypesString({ fileTypes });
|
|
30
34
|
const acceptedTypesForInputEl = getTypePropForInputEl.getTypePropForInputEl({ fileTypes });
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
43
|
-
}
|
|
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;
|
|
35
|
+
const validateMaximumFiles = React.useCallback((files) => {
|
|
36
|
+
if ((files === null || files === undefined ? undefined : files.length) && (files === null || files === undefined ? undefined : files.length) > maxFiles) {
|
|
37
|
+
clearFileSelection();
|
|
38
|
+
onMaxFilesExceeded === null || onMaxFilesExceeded === undefined ? undefined : onMaxFilesExceeded();
|
|
39
|
+
return false;
|
|
49
40
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
41
|
+
return true;
|
|
42
|
+
}, [clearFileSelection, maxFiles, onMaxFilesExceeded]);
|
|
53
43
|
// Processes file and updates the UI appropriately:
|
|
54
44
|
const updateFiles = React.useCallback((files) => {
|
|
55
45
|
if (!files.length) {
|
|
56
|
-
setInputValidation({ invalidFormat: true });
|
|
57
46
|
return;
|
|
58
47
|
}
|
|
59
|
-
|
|
60
|
-
|
|
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]);
|
|
48
|
+
setFileList(files);
|
|
49
|
+
}, [setFileList]);
|
|
79
50
|
// For focussing of input el and updating drop UI
|
|
80
51
|
const onDragEnter = (event) => {
|
|
81
52
|
var _a;
|
|
82
53
|
event.preventDefault();
|
|
54
|
+
setIsDragOver(true);
|
|
83
55
|
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.focus();
|
|
84
56
|
};
|
|
85
57
|
// For unfocussing of input el and updating drop UI
|
|
86
58
|
const onDragLeave = (event) => {
|
|
87
|
-
var _a;
|
|
88
59
|
event.preventDefault();
|
|
89
|
-
(
|
|
60
|
+
setIsDragOver(false);
|
|
90
61
|
};
|
|
91
62
|
// Prevents default browser behaviour
|
|
92
63
|
const onDragOver = (event) => event.preventDefault();
|
|
93
64
|
// Process file when dropped into eligible area
|
|
94
65
|
const onDrop = (event) => {
|
|
95
66
|
event.preventDefault();
|
|
67
|
+
setIsDragOver(false);
|
|
96
68
|
// Prevent reactions on dragging events that do not contain files
|
|
97
69
|
if (!event.dataTransfer.files.length)
|
|
98
70
|
return;
|
|
99
|
-
|
|
71
|
+
const canUpdateFiles = validateMaximumFiles(event.dataTransfer.files);
|
|
72
|
+
if (canUpdateFiles) {
|
|
73
|
+
updateFiles(event.dataTransfer.files);
|
|
74
|
+
}
|
|
100
75
|
};
|
|
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
|
-
}, []);
|
|
110
76
|
// Updates UI based on a native file input change. Attached via useEffect below
|
|
111
|
-
const
|
|
112
|
-
var _a;
|
|
113
|
-
const
|
|
114
|
-
|
|
77
|
+
const onChange = React.useCallback(() => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const canUpdateFiles = validateMaximumFiles((_a = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _a === undefined ? undefined : _a.files);
|
|
80
|
+
const files = (_b = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _b === undefined ? undefined : _b.files;
|
|
81
|
+
if (canUpdateFiles && files) {
|
|
115
82
|
updateFiles(files);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
83
|
+
}
|
|
84
|
+
else if (fileList) {
|
|
85
|
+
updateFiles(fileList);
|
|
86
|
+
}
|
|
87
|
+
}, [validateMaximumFiles, inputRef, fileList, updateFiles]);
|
|
119
88
|
React.useEffect(() => {
|
|
120
89
|
const ref = inputRef === null || inputRef === undefined ? undefined : inputRef.current;
|
|
121
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('change',
|
|
122
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel',
|
|
90
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('change', onChange);
|
|
91
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel', onCancel);
|
|
123
92
|
return () => {
|
|
124
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('change',
|
|
125
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel',
|
|
93
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('change', onChange);
|
|
94
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel', onCancel);
|
|
126
95
|
};
|
|
127
|
-
}, [
|
|
96
|
+
}, [onChange, onCancel, inputRef]);
|
|
97
|
+
const hasError = !!((errorMessage || ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.validationMessage)) && !(fileList === null || fileList === undefined ? undefined : fileList.length));
|
|
128
98
|
return (React__default.default.createElement(styled.RootStack, { spacing: "xs", alignX: "stretch" },
|
|
129
99
|
React__default.default.createElement(styled.Label, { htmlFor: id },
|
|
130
100
|
label,
|
|
131
101
|
React__default.default.createElement(FlexCol.FlexCol, null,
|
|
132
102
|
React__default.default.createElement(styled.Hint, null,
|
|
133
|
-
|
|
134
|
-
React__default.default.createElement("
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
React__default.default.createElement(
|
|
103
|
+
maxSizeCopy,
|
|
104
|
+
React__default.default.createElement("br", null),
|
|
105
|
+
acceptedTypesCopy),
|
|
106
|
+
React__default.default.createElement(styled$1.DropZoneContainer, { hasError: hasError, isDragOver: isDragOver, "data-testid": "drop-zone-container", onDrop: onDrop, onDragEnter: onDragEnter, onDragOver: onDragOver, onDragLeave: onDragLeave },
|
|
107
|
+
isDragOver ? React__default.default.createElement(DropCopy.DropCopy, null) : React__default.default.createElement(UploadCopy.UploadCopy, null),
|
|
108
|
+
React__default.default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, disabled: disabled, multiple: multiple, ...otherProps })))),
|
|
138
109
|
React__default.default.createElement(FlexCol.FlexCol, null,
|
|
139
|
-
React__default.default.createElement(
|
|
140
|
-
|
|
110
|
+
hasError && (React__default.default.createElement(FlexRow.FlexRow, null,
|
|
111
|
+
React__default.default.createElement(CriticalIcon.ReactComponent, { width: index.theme.sizes.base, height: index.theme.sizes.base, color: index.theme.colors.secondary.red.base }),
|
|
112
|
+
React__default.default.createElement(styled.Error, null, errorMessage || ((_b = inputRef.current) === null || _b === undefined ? undefined : _b.validationMessage)))),
|
|
113
|
+
disabledMessage && (React__default.default.createElement(FlexRow.FlexRow, { id: `${id}-disabled` },
|
|
114
|
+
React__default.default.createElement(LockIcon.ReactComponent, { width: index.theme.sizes.base, height: index.theme.sizes.base, color: index.theme.colors.neutral.ink.light }),
|
|
115
|
+
React__default.default.createElement(styled.Disabled, null, disabledMessage))),
|
|
116
|
+
!hideUploadedFiles &&
|
|
117
|
+
fileList && [
|
|
118
|
+
Array.from(fileList).map((file) => {
|
|
119
|
+
return (React__default.default.createElement(UploadedFile.UploadedFile, { key: `${file.name}`, file: file, onRemoveFile: removeFileFromList, disabled: disabled, format: format, maxBytes: maxBytes, fileTypes: fileTypes }));
|
|
120
|
+
}),
|
|
121
|
+
])));
|
|
141
122
|
});
|
|
142
123
|
|
|
143
124
|
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 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,u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,CAAA,CACgB,CACZ,CACJ;AACR,QAAAA,sBAAA,CAAA,aAAA,CAACG,eAAO,EAAA,IAAA;AACN,YAAAH,sBAAA,CAAA,aAAA,CAACO,yBAAY,EAAA,EAAC,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
|
+
{"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 {\n FileSizeUnit,\n DEFAULT_MAXIMUM_MULTIPLE_FILES,\n DEFAULT_MAXIMUM_FILE_BYTES,\n} 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 '../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 = DEFAULT_MAXIMUM_FILE_BYTES,\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 isDirty,\n errorMessage = '',\n ...otherProps\n }: UploadFileProps,\n outerRef,\n ) => {\n const { inputRef, fileList, setFileList, onCancel, removeFileFromList, clearFileSelection } =\n useUploadFile();\n\n useValidateInput({ inputRef, fileList, fileTypes, maxBytes, errorMessage });\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 hasError = !!((errorMessage || inputRef.current?.validationMessage) && !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 hasError={hasError}\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 {hasError && (\n <FlexRow>\n <CriticalIcon\n width={theme.sizes.base}\n height={theme.sizes.base}\n color={theme.colors.secondary.red.base}\n />\n <Error>{errorMessage || inputRef.current?.validationMessage}</Error>\n </FlexRow>\n )}\n {disabledMessage && (\n <FlexRow id={`${id}-disabled`}>\n <LockIcon\n width={theme.sizes.base}\n height={theme.sizes.base}\n color={theme.colors.neutral.ink.light}\n />\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 onRemoveFile={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","DEFAULT_MAXIMUM_FILE_BYTES","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":";;;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,UAAU,GAAGA,gBAAU,CAClC,CACE,EACE,EAAE,EACF,IAAI,EACJ,QAAQ,GAAGC,oCAA0B,EACrC,MAAM,GAAGC,sBAAY,CAAC,EAAE,EACxB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,QAAQ,GAAG,cAAc,GAAG,aAAa,EACjD,iBAAiB,GAAG,KAAK,EACzB,kBAAkB,EAClB,QAAQ,GAAGC,wCAA8B,EACzC,eAAe,EACf,OAAO,EACP,YAAY,GAAG,EAAE,EACjB,GAAG,UAAU,EACG,EAClB,QAAQ,KACN;;AACF,IAAA,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GACzFC,2BAAa,EAAE;AAEjB,IAAAC,iCAAgB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;AAE3E,IAAAC,yBAAmB,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAAC,OAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;IAElE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;;IAGnD,MAAM,WAAW,GAAGC,mCAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM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AA,CAAS,CAC5D,CACX;YACA,eAAe,KACdX,sBAAC,CAAA,aAAA,CAAAQ,eAAO,IAAC,EAAE,EAAE,CAAG,EAAA,EAAE,CAAW,SAAA,CAAA,EAAA;AAC3B,gBAAAR,sBAAA,CAAA,aAAA,CAACY,uBAAQ,EAAA,EACP,KAAK,EAAEF,WAAK,CAAC,KAAK,CAAC,IAAI,EACvB,MAAM,EAAEA,WAAK,CAAC,KAAK,CAAC,IAAI,EACxB,KAAK,EAAEA,WAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EACrC,CAAA;AACF,gBAAAV,sBAAA,CAAA,aAAA,CAACa,eAAQ,EAAA,IAAA,EAAE,eAAe,CAAY,CAC9B,CACX;AACA,YAAA,CAAC,iBAAiB;AACjB,gBAAA,QAAQ,IAAI;gBACV,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,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,YAAY,EAAE,kBAAkB,EAChC,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,137 +1,118 @@
|
|
|
1
|
-
import React__default, { forwardRef,
|
|
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';
|
|
2
5
|
import { DropZoneContainer } from './styled.js';
|
|
3
|
-
import {
|
|
6
|
+
import { DEFAULT_MAXIMUM_FILE_BYTES, FileSizeUnit, DEFAULT_MAXIMUM_MULTIPLE_FILES } from './constants.js';
|
|
4
7
|
import { UploadCopy } from './components/UploadCopy/UploadCopy.js';
|
|
5
|
-
import {
|
|
8
|
+
import { DropCopy } from './components/DropCopy/DropCopy.js';
|
|
6
9
|
import { getValidTypesString } from './utils/getValidTypesString/getValidTypesString.js';
|
|
7
10
|
import { getFileSizeString } from './utils/getFileSizeString/getFileSizeString.js';
|
|
8
11
|
import { getTypePropForInputEl } from './utils/getTypePropForInputEl/getTypePropForInputEl.js';
|
|
9
|
-
import { RootStack, Label, Hint } from '../../hoc/withLabels/styled.js';
|
|
10
|
-
import {
|
|
11
|
-
import { UploadedFile } from './components/UploadedFile/UploadedFile.js';
|
|
12
|
+
import { RootStack, Label, Hint, Error, Disabled } from '../../hoc/withLabels/styled.js';
|
|
13
|
+
import { UploadedFile } from '../UploadedFile/UploadedFile.js';
|
|
12
14
|
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';
|
|
13
18
|
|
|
14
|
-
const UploadFile = forwardRef(({ id, name, maxBytes =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const isOverMaxSize = errorState === InputState.INVALID_SIZE || errorState === InputState.INVALID_FORMAT_AND_SIZE;
|
|
19
|
+
const UploadFile = forwardRef(({ id, name, maxBytes = DEFAULT_MAXIMUM_FILE_BYTES, format = FileSizeUnit.MB, fileTypes, disabled, multiple, label = multiple ? 'Upload files' : 'Upload file', hideUploadedFiles = false, onMaxFilesExceeded, maxFiles = DEFAULT_MAXIMUM_MULTIPLE_FILES, disabledMessage, isDirty, errorMessage = '', ...otherProps }, outerRef) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const { inputRef, fileList, setFileList, onCancel, removeFileFromList, clearFileSelection } = useUploadFile();
|
|
22
|
+
useValidateInput({ inputRef, fileList, fileTypes, maxBytes, errorMessage });
|
|
23
|
+
useImperativeHandle(outerRef, () => inputRef.current, [inputRef]);
|
|
24
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
21
25
|
// Computed properties based on params
|
|
22
26
|
const maxSizeCopy = getFileSizeString({ maxBytes, format });
|
|
23
27
|
const acceptedTypesCopy = getValidTypesString({ fileTypes });
|
|
24
28
|
const acceptedTypesForInputEl = getTypePropForInputEl({ fileTypes });
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
37
|
-
}
|
|
38
|
-
else if (!invalidFormat && overMaxSize) {
|
|
39
|
-
error = InputState.INVALID_SIZE;
|
|
40
|
-
}
|
|
41
|
-
else if (invalidFormat && overMaxSize) {
|
|
42
|
-
error = InputState.INVALID_FORMAT_AND_SIZE;
|
|
29
|
+
const validateMaximumFiles = useCallback((files) => {
|
|
30
|
+
if ((files === null || files === undefined ? undefined : files.length) && (files === null || files === undefined ? undefined : files.length) > maxFiles) {
|
|
31
|
+
clearFileSelection();
|
|
32
|
+
onMaxFilesExceeded === null || onMaxFilesExceeded === undefined ? undefined : onMaxFilesExceeded();
|
|
33
|
+
return false;
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
35
|
+
return true;
|
|
36
|
+
}, [clearFileSelection, maxFiles, onMaxFilesExceeded]);
|
|
47
37
|
// Processes file and updates the UI appropriately:
|
|
48
38
|
const updateFiles = useCallback((files) => {
|
|
49
39
|
if (!files.length) {
|
|
50
|
-
setInputValidation({ invalidFormat: true });
|
|
51
40
|
return;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
|
-
|
|
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]);
|
|
42
|
+
setFileList(files);
|
|
43
|
+
}, [setFileList]);
|
|
73
44
|
// For focussing of input el and updating drop UI
|
|
74
45
|
const onDragEnter = (event) => {
|
|
75
46
|
var _a;
|
|
76
47
|
event.preventDefault();
|
|
48
|
+
setIsDragOver(true);
|
|
77
49
|
(_a = inputRef.current) === null || _a === undefined ? undefined : _a.focus();
|
|
78
50
|
};
|
|
79
51
|
// For unfocussing of input el and updating drop UI
|
|
80
52
|
const onDragLeave = (event) => {
|
|
81
|
-
var _a;
|
|
82
53
|
event.preventDefault();
|
|
83
|
-
(
|
|
54
|
+
setIsDragOver(false);
|
|
84
55
|
};
|
|
85
56
|
// Prevents default browser behaviour
|
|
86
57
|
const onDragOver = (event) => event.preventDefault();
|
|
87
58
|
// Process file when dropped into eligible area
|
|
88
59
|
const onDrop = (event) => {
|
|
89
60
|
event.preventDefault();
|
|
61
|
+
setIsDragOver(false);
|
|
90
62
|
// Prevent reactions on dragging events that do not contain files
|
|
91
63
|
if (!event.dataTransfer.files.length)
|
|
92
64
|
return;
|
|
93
|
-
|
|
65
|
+
const canUpdateFiles = validateMaximumFiles(event.dataTransfer.files);
|
|
66
|
+
if (canUpdateFiles) {
|
|
67
|
+
updateFiles(event.dataTransfer.files);
|
|
68
|
+
}
|
|
94
69
|
};
|
|
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
|
-
}, []);
|
|
104
70
|
// Updates UI based on a native file input change. Attached via useEffect below
|
|
105
|
-
const
|
|
106
|
-
var _a;
|
|
107
|
-
const
|
|
108
|
-
|
|
71
|
+
const onChange = useCallback(() => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const canUpdateFiles = validateMaximumFiles((_a = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _a === undefined ? undefined : _a.files);
|
|
74
|
+
const files = (_b = inputRef === null || inputRef === undefined ? undefined : inputRef.current) === null || _b === undefined ? undefined : _b.files;
|
|
75
|
+
if (canUpdateFiles && files) {
|
|
109
76
|
updateFiles(files);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
77
|
+
}
|
|
78
|
+
else if (fileList) {
|
|
79
|
+
updateFiles(fileList);
|
|
80
|
+
}
|
|
81
|
+
}, [validateMaximumFiles, inputRef, fileList, updateFiles]);
|
|
113
82
|
useEffect(() => {
|
|
114
83
|
const ref = inputRef === null || inputRef === undefined ? undefined : inputRef.current;
|
|
115
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('change',
|
|
116
|
-
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel',
|
|
84
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('change', onChange);
|
|
85
|
+
ref === null || ref === undefined ? undefined : ref.addEventListener('cancel', onCancel);
|
|
117
86
|
return () => {
|
|
118
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('change',
|
|
119
|
-
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel',
|
|
87
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('change', onChange);
|
|
88
|
+
ref === null || ref === undefined ? undefined : ref.removeEventListener('cancel', onCancel);
|
|
120
89
|
};
|
|
121
|
-
}, [
|
|
90
|
+
}, [onChange, onCancel, inputRef]);
|
|
91
|
+
const hasError = !!((errorMessage || ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.validationMessage)) && !(fileList === null || fileList === undefined ? undefined : fileList.length));
|
|
122
92
|
return (React__default.createElement(RootStack, { spacing: "xs", alignX: "stretch" },
|
|
123
93
|
React__default.createElement(Label, { htmlFor: id },
|
|
124
94
|
label,
|
|
125
95
|
React__default.createElement(FlexCol, null,
|
|
126
96
|
React__default.createElement(Hint, null,
|
|
127
|
-
|
|
128
|
-
React__default.createElement("
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
React__default.createElement(
|
|
97
|
+
maxSizeCopy,
|
|
98
|
+
React__default.createElement("br", null),
|
|
99
|
+
acceptedTypesCopy),
|
|
100
|
+
React__default.createElement(DropZoneContainer, { hasError: hasError, isDragOver: isDragOver, "data-testid": "drop-zone-container", onDrop: onDrop, onDragEnter: onDragEnter, onDragOver: onDragOver, onDragLeave: onDragLeave },
|
|
101
|
+
isDragOver ? React__default.createElement(DropCopy, null) : React__default.createElement(UploadCopy, null),
|
|
102
|
+
React__default.createElement("input", { ref: inputRef, id: id, type: "file", accept: acceptedTypesForInputEl, name: name, disabled: disabled, multiple: multiple, ...otherProps })))),
|
|
132
103
|
React__default.createElement(FlexCol, null,
|
|
133
|
-
React__default.createElement(
|
|
134
|
-
|
|
104
|
+
hasError && (React__default.createElement(FlexRow, null,
|
|
105
|
+
React__default.createElement(CriticalIcon, { width: theme.sizes.base, height: theme.sizes.base, color: theme.colors.secondary.red.base }),
|
|
106
|
+
React__default.createElement(Error, null, errorMessage || ((_b = inputRef.current) === null || _b === undefined ? undefined : _b.validationMessage)))),
|
|
107
|
+
disabledMessage && (React__default.createElement(FlexRow, { id: `${id}-disabled` },
|
|
108
|
+
React__default.createElement(LockIcon, { width: theme.sizes.base, height: theme.sizes.base, color: theme.colors.neutral.ink.light }),
|
|
109
|
+
React__default.createElement(Disabled, null, disabledMessage))),
|
|
110
|
+
!hideUploadedFiles &&
|
|
111
|
+
fileList && [
|
|
112
|
+
Array.from(fileList).map((file) => {
|
|
113
|
+
return (React__default.createElement(UploadedFile, { key: `${file.name}`, file: file, onRemoveFile: removeFileFromList, disabled: disabled, format: format, maxBytes: maxBytes, fileTypes: fileTypes }));
|
|
114
|
+
}),
|
|
115
|
+
])));
|
|
135
116
|
});
|
|
136
117
|
|
|
137
118
|
export { UploadFile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadFile.js","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":["React"],"mappings":";;;;;;;;;;;;;AAoBa,MAAA,UAAU,GAAG,UAAU,CAClC,CACE,EACE,EAAE,EACF,IAAI,EACJ,QAAQ,GAAG,OAAO,EAClB,MAAM,GAAG,YAAY,CAAC,EAAE,EACxB,SAAS,EACT,KAAK,GAAG,aAAa,EACrB,QAAQ,EACR,QAAQ,EACR,GAAG,UAAU,EACG,EAClB,QAAQ,KACN;AACF,IAAA,MAAM,QAAQ,GAAG,MAAM,CAA0B,IAAI,CAAC;AACtD,IAAA,mBAAmB,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAAC,OAAQ,EAAE,EAAE,CAAC;IAE1D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,EAAQ;AACxC,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;AAE9D,IAAA,MAAM,eAAe,GACnB,UAAU,KAAK,UAAU,CAAC,cAAc,IAAI,UAAU,KAAK,UAAU,CAAC,uBAAuB;AAC/F,IAAA,MAAM,aAAa,GACjB,UAAU,KAAK,UAAU,CAAC,YAAY,IAAI,UAAU,KAAK,UAAU,CAAC,uBAAuB;;IAG7F,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,EAAE,SAAS,EAAE,CAAC;IAC5D,MAAM,uBAAuB,GAAG,qBAAqB,CAAC,EAAE,SAAS,EAAE,CAAC;IAEpE,MAAM,kBAAkB,GAAG,MAAK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,EAAA,EAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAI,CAAA;AAChF,YAAAA,cAAA,CAAA,aAAA,CAAC,gBAAgB,EAAA,EACf,iBAAiB,EAAE,eAAe,GAAG,iBAAiB,GAAG,SAAS,EAClE,WAAW,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,EAAA,CACpD,CACM,CACA;AAEhB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"UploadFile.js","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 {\n FileSizeUnit,\n DEFAULT_MAXIMUM_MULTIPLE_FILES,\n DEFAULT_MAXIMUM_FILE_BYTES,\n} 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 '../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 = DEFAULT_MAXIMUM_FILE_BYTES,\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 isDirty,\n errorMessage = '',\n ...otherProps\n }: UploadFileProps,\n outerRef,\n ) => {\n const { inputRef, fileList, setFileList, onCancel, removeFileFromList, clearFileSelection } =\n useUploadFile();\n\n useValidateInput({ inputRef, fileList, fileTypes, maxBytes, errorMessage });\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 hasError = !!((errorMessage || inputRef.current?.validationMessage) && !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 hasError={hasError}\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 {hasError && (\n <FlexRow>\n <CriticalIcon\n width={theme.sizes.base}\n height={theme.sizes.base}\n color={theme.colors.secondary.red.base}\n />\n <Error>{errorMessage || inputRef.current?.validationMessage}</Error>\n </FlexRow>\n )}\n {disabledMessage && (\n <FlexRow id={`${id}-disabled`}>\n <LockIcon\n width={theme.sizes.base}\n height={theme.sizes.base}\n color={theme.colors.neutral.ink.light}\n />\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 onRemoveFile={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":["React"],"mappings":";;;;;;;;;;;;;;;;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