@veeqo/ui 12.5.0 → 13.0.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/Alerts/Alert/Alert.cjs +2 -2
- package/dist/components/Alerts/Alert/Alert.cjs.map +1 -1
- package/dist/components/Alerts/Alert/Alert.js +2 -2
- package/dist/components/Alerts/Alert/Alert.js.map +1 -1
- package/dist/components/Flex/FlexCol/FlexCol.d.ts +3 -3
- package/dist/components/Flex/FlexRow/FlexRow.d.ts +3 -3
- package/dist/components/Flex/types.d.ts +13 -4
- package/dist/components/Pagination/styled.d.ts +3 -3
- 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/ViewsContainer/ViewsContainer.cjs +4 -3
- package/dist/components/ViewsContainer/ViewsContainer.cjs.map +1 -1
- package/dist/components/ViewsContainer/ViewsContainer.js +4 -3
- package/dist/components/ViewsContainer/ViewsContainer.js.map +1 -1
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.cjs +2 -2
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.cjs.map +1 -1
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.js +2 -2
- package/dist/components/ViewsContainer/ViewsContainer.module.scss.js.map +1 -1
- package/dist/components/index.d.ts +3 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -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
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { AcceptedFileTypes, FileSizeUnit } from './constants';
|
|
2
|
+
import { AcceptedFileTypes, ErrorType, FileSizeUnit } from './constants';
|
|
3
3
|
export interface UploadFileProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
4
|
id: string;
|
|
5
5
|
fileTypes: Array<AcceptedFileTypes>;
|
|
6
6
|
label?: string;
|
|
7
7
|
format?: FileSizeUnit;
|
|
8
8
|
maxBytes?: number;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
hideUploadedFiles?: boolean;
|
|
11
|
+
onMaxFilesExceeded?: () => void;
|
|
12
|
+
maxFiles?: number;
|
|
13
|
+
disabledMessage?: string;
|
|
14
|
+
isDirty?: boolean;
|
|
9
15
|
}
|
|
16
|
+
export type UploadFileErrors = {
|
|
17
|
+
criticalErrors: Array<UploadFileError>;
|
|
18
|
+
};
|
|
19
|
+
type UploadFileError = {
|
|
20
|
+
errorType: ErrorType;
|
|
21
|
+
errorMessage: string;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('../../constants.cjs');
|
|
4
|
+
|
|
5
|
+
function getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile, }) {
|
|
6
|
+
// both errors
|
|
7
|
+
if (hasFormatErrors && hasSizeErrors) {
|
|
8
|
+
return constants.InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;
|
|
9
|
+
}
|
|
10
|
+
// only format errors
|
|
11
|
+
if (hasFormatErrors) {
|
|
12
|
+
return isSingleFile
|
|
13
|
+
? constants.InputErrorStateMessages.INVALID_FORMAT
|
|
14
|
+
: constants.InputErrorStateMessages.INVALID_FORMATS;
|
|
15
|
+
}
|
|
16
|
+
// only size errors
|
|
17
|
+
if (hasSizeErrors) {
|
|
18
|
+
return isSingleFile
|
|
19
|
+
? constants.InputErrorStateMessages.INVALID_SIZE
|
|
20
|
+
: constants.InputErrorStateMessages.INVALID_SIZES;
|
|
21
|
+
}
|
|
22
|
+
// no errors
|
|
23
|
+
return constants.InputErrorStateMessages.VALID;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.getErrorMessage = getErrorMessage;
|
|
27
|
+
//# sourceMappingURL=getErrorMessage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorMessage.cjs","sources":["../../../../../src/components/UploadFile/utils/getErrorMessage/getErrorMessage.ts"],"sourcesContent":["import { InputErrorStateMessages } from '../../constants';\n\ntype GetErrorMessageProps = {\n hasFormatErrors: boolean;\n hasSizeErrors: boolean;\n isSingleFile: boolean;\n};\nexport function getErrorMessage({\n hasFormatErrors,\n hasSizeErrors,\n isSingleFile,\n}: GetErrorMessageProps) {\n // both errors\n if (hasFormatErrors && hasSizeErrors) {\n return InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;\n }\n\n // only format errors\n if (hasFormatErrors) {\n return isSingleFile\n ? InputErrorStateMessages.INVALID_FORMAT\n : InputErrorStateMessages.INVALID_FORMATS;\n }\n\n // only size errors\n if (hasSizeErrors) {\n return isSingleFile\n ? InputErrorStateMessages.INVALID_SIZE\n : InputErrorStateMessages.INVALID_SIZES;\n }\n\n // no errors\n return InputErrorStateMessages.VALID;\n}\n"],"names":["InputErrorStateMessages"],"mappings":";;;;AAOM,SAAU,eAAe,CAAC,EAC9B,eAAe,EACf,aAAa,EACb,YAAY,GACS,EAAA;;IAErB,IAAI,eAAe,IAAI,aAAa,EAAE;QACpC,OAAOA,iCAAuB,CAAC,uBAAuB;AACvD;;AAGD,IAAA,IAAI,eAAe,EAAE;AACnB,QAAA,OAAO;cACHA,iCAAuB,CAAC;AAC1B,cAAEA,iCAAuB,CAAC,eAAe;AAC5C;;AAGD,IAAA,IAAI,aAAa,EAAE;AACjB,QAAA,OAAO;cACHA,iCAAuB,CAAC;AAC1B,cAAEA,iCAAuB,CAAC,aAAa;AAC1C;;IAGD,OAAOA,iCAAuB,CAAC,KAAK;AACtC;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InputErrorStateMessages } from '../../constants';
|
|
2
|
+
type GetErrorMessageProps = {
|
|
3
|
+
hasFormatErrors: boolean;
|
|
4
|
+
hasSizeErrors: boolean;
|
|
5
|
+
isSingleFile: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile, }: GetErrorMessageProps): InputErrorStateMessages;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { InputErrorStateMessages } from '../../constants.js';
|
|
2
|
+
|
|
3
|
+
function getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile, }) {
|
|
4
|
+
// both errors
|
|
5
|
+
if (hasFormatErrors && hasSizeErrors) {
|
|
6
|
+
return InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;
|
|
7
|
+
}
|
|
8
|
+
// only format errors
|
|
9
|
+
if (hasFormatErrors) {
|
|
10
|
+
return isSingleFile
|
|
11
|
+
? InputErrorStateMessages.INVALID_FORMAT
|
|
12
|
+
: InputErrorStateMessages.INVALID_FORMATS;
|
|
13
|
+
}
|
|
14
|
+
// only size errors
|
|
15
|
+
if (hasSizeErrors) {
|
|
16
|
+
return isSingleFile
|
|
17
|
+
? InputErrorStateMessages.INVALID_SIZE
|
|
18
|
+
: InputErrorStateMessages.INVALID_SIZES;
|
|
19
|
+
}
|
|
20
|
+
// no errors
|
|
21
|
+
return InputErrorStateMessages.VALID;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { getErrorMessage };
|
|
25
|
+
//# sourceMappingURL=getErrorMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorMessage.js","sources":["../../../../../src/components/UploadFile/utils/getErrorMessage/getErrorMessage.ts"],"sourcesContent":["import { InputErrorStateMessages } from '../../constants';\n\ntype GetErrorMessageProps = {\n hasFormatErrors: boolean;\n hasSizeErrors: boolean;\n isSingleFile: boolean;\n};\nexport function getErrorMessage({\n hasFormatErrors,\n hasSizeErrors,\n isSingleFile,\n}: GetErrorMessageProps) {\n // both errors\n if (hasFormatErrors && hasSizeErrors) {\n return InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;\n }\n\n // only format errors\n if (hasFormatErrors) {\n return isSingleFile\n ? InputErrorStateMessages.INVALID_FORMAT\n : InputErrorStateMessages.INVALID_FORMATS;\n }\n\n // only size errors\n if (hasSizeErrors) {\n return isSingleFile\n ? InputErrorStateMessages.INVALID_SIZE\n : InputErrorStateMessages.INVALID_SIZES;\n }\n\n // no errors\n return InputErrorStateMessages.VALID;\n}\n"],"names":[],"mappings":";;AAOM,SAAU,eAAe,CAAC,EAC9B,eAAe,EACf,aAAa,EACb,YAAY,GACS,EAAA;;IAErB,IAAI,eAAe,IAAI,aAAa,EAAE;QACpC,OAAO,uBAAuB,CAAC,uBAAuB;AACvD;;AAGD,IAAA,IAAI,eAAe,EAAE;AACnB,QAAA,OAAO;cACH,uBAAuB,CAAC;AAC1B,cAAE,uBAAuB,CAAC,eAAe;AAC5C;;AAGD,IAAA,IAAI,aAAa,EAAE;AACjB,QAAA,OAAO;cACH,uBAAuB,CAAC;AAC1B,cAAE,uBAAuB,CAAC,aAAa;AAC1C;;IAGD,OAAO,uBAAuB,CAAC,KAAK;AACtC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getErrorMessage } from './getErrorMessage';
|
|
@@ -3,30 +3,33 @@
|
|
|
3
3
|
var constants = require('../../constants.cjs');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* should go inside the accept property
|
|
6
|
+
* Converts a file size in bytes to a human-readable string with the specified format unit.
|
|
8
7
|
*
|
|
9
8
|
* E.g.
|
|
10
9
|
*
|
|
11
10
|
* const maxSizeCopy = getFileSizeString({
|
|
12
|
-
* maxBytes:
|
|
11
|
+
* maxBytes: 10000000,
|
|
13
12
|
* format: FileSizeUnit.MB
|
|
14
13
|
* });
|
|
15
14
|
*
|
|
16
|
-
* Where @constant maxSizeCopy would equal "
|
|
15
|
+
* Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
|
|
17
16
|
*
|
|
18
|
-
* @param
|
|
19
|
-
*
|
|
17
|
+
* @param maxBytes - The file size in bytes to convert
|
|
18
|
+
* @param format - The unit format to display (KB or MB)
|
|
19
|
+
* @param baseString - Optional prefix string, defaults to "Maximum file size: "
|
|
20
|
+
* @param digits - Number of decimal places to show, defaults to 2 (strips any leading zeros)
|
|
21
|
+
* @returns A formatted string representing the file size
|
|
20
22
|
*/
|
|
21
|
-
const getFileSizeString = ({ maxBytes, format, baseString }) => {
|
|
22
|
-
const base = baseString
|
|
23
|
+
const getFileSizeString = ({ maxBytes, format, baseString, digits = 2, }) => {
|
|
24
|
+
const base = baseString !== null && baseString !== undefined ? baseString : 'Maximum file size: ';
|
|
25
|
+
const getValue = (divisor) => parseFloat((maxBytes / divisor).toFixed(digits));
|
|
23
26
|
switch (format) {
|
|
24
27
|
case constants.FileSizeUnit.KB:
|
|
25
|
-
return `${base}${
|
|
28
|
+
return `${base}${getValue(1000)} KB`;
|
|
26
29
|
case constants.FileSizeUnit.MB:
|
|
27
|
-
return `${base}${
|
|
30
|
+
return `${base}${getValue(1000000)} MB`;
|
|
28
31
|
default:
|
|
29
|
-
return `${base}${
|
|
32
|
+
return `${base}${getValue(1000)} KB`;
|
|
30
33
|
}
|
|
31
34
|
};
|
|
32
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileSizeString.cjs","sources":["../../../../../src/components/UploadFile/utils/getFileSizeString/getFileSizeString.ts"],"sourcesContent":["import { FileSizeUnit } from '../../constants';\n\ntype GetFileSizeStringProps = {\n maxBytes: number;\n format: FileSizeUnit;\n baseString?: string;\n};\n/**\n *
|
|
1
|
+
{"version":3,"file":"getFileSizeString.cjs","sources":["../../../../../src/components/UploadFile/utils/getFileSizeString/getFileSizeString.ts"],"sourcesContent":["import { FileSizeUnit } from '../../constants';\n\ntype GetFileSizeStringProps = {\n maxBytes: number;\n format: FileSizeUnit;\n baseString?: string;\n digits?: number;\n};\n/**\n * Converts a file size in bytes to a human-readable string with the specified format unit.\n *\n * E.g.\n *\n * const maxSizeCopy = getFileSizeString({\n * maxBytes: 10000000,\n * format: FileSizeUnit.MB\n * });\n *\n * Where @constant maxSizeCopy would equal \"Maximum file size: 10 MB\"\n *\n * @param maxBytes - The file size in bytes to convert\n * @param format - The unit format to display (KB or MB)\n * @param baseString - Optional prefix string, defaults to \"Maximum file size: \"\n * @param digits - Number of decimal places to show, defaults to 2 (strips any leading zeros)\n * @returns A formatted string representing the file size\n */\nexport const getFileSizeString = ({\n maxBytes,\n format,\n baseString,\n digits = 2,\n}: GetFileSizeStringProps) => {\n const base = baseString ?? 'Maximum file size: ';\n const getValue = (divisor: number) => parseFloat((maxBytes / divisor).toFixed(digits));\n switch (format) {\n case FileSizeUnit.KB:\n return `${base}${getValue(1000)} KB`;\n case FileSizeUnit.MB:\n return `${base}${getValue(1000000)} MB`;\n default:\n return `${base}${getValue(1000)} KB`;\n }\n};\n"],"names":["FileSizeUnit"],"mappings":";;;;AAQA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,iBAAiB,GAAG,CAAC,EAChC,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,GAAG,CAAC,GACa,KAAI;IAC3B,MAAM,IAAI,GAAG,UAAU,KAAA,IAAA,IAAV,UAAU,KAAV,SAAA,GAAA,UAAU,GAAI,qBAAqB;IAChD,MAAM,QAAQ,GAAG,CAAC,OAAe,KAAK,UAAU,CAAC,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AACtF,IAAA,QAAQ,MAAM;QACZ,KAAKA,sBAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,IAAI,CAAC,KAAK;QACtC,KAAKA,sBAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,OAAO,CAAC,KAAK;AACzC,QAAA;YACE,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,IAAI,CAAC,KAAK;AACvC;AACH;;;;"}
|
|
@@ -3,22 +3,25 @@ type GetFileSizeStringProps = {
|
|
|
3
3
|
maxBytes: number;
|
|
4
4
|
format: FileSizeUnit;
|
|
5
5
|
baseString?: string;
|
|
6
|
+
digits?: number;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
* should go inside the accept property
|
|
9
|
+
* Converts a file size in bytes to a human-readable string with the specified format unit.
|
|
10
10
|
*
|
|
11
11
|
* E.g.
|
|
12
12
|
*
|
|
13
13
|
* const maxSizeCopy = getFileSizeString({
|
|
14
|
-
* maxBytes:
|
|
14
|
+
* maxBytes: 10000000,
|
|
15
15
|
* format: FileSizeUnit.MB
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
|
-
* Where @constant maxSizeCopy would equal "
|
|
18
|
+
* Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
21
|
-
*
|
|
20
|
+
* @param maxBytes - The file size in bytes to convert
|
|
21
|
+
* @param format - The unit format to display (KB or MB)
|
|
22
|
+
* @param baseString - Optional prefix string, defaults to "Maximum file size: "
|
|
23
|
+
* @param digits - Number of decimal places to show, defaults to 2 (strips any leading zeros)
|
|
24
|
+
* @returns A formatted string representing the file size
|
|
22
25
|
*/
|
|
23
|
-
export declare const getFileSizeString: ({ maxBytes, format, baseString }: GetFileSizeStringProps) => string;
|
|
26
|
+
export declare const getFileSizeString: ({ maxBytes, format, baseString, digits, }: GetFileSizeStringProps) => string;
|
|
24
27
|
export {};
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { FileSizeUnit } from '../../constants.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* should go inside the accept property
|
|
4
|
+
* Converts a file size in bytes to a human-readable string with the specified format unit.
|
|
6
5
|
*
|
|
7
6
|
* E.g.
|
|
8
7
|
*
|
|
9
8
|
* const maxSizeCopy = getFileSizeString({
|
|
10
|
-
* maxBytes:
|
|
9
|
+
* maxBytes: 10000000,
|
|
11
10
|
* format: FileSizeUnit.MB
|
|
12
11
|
* });
|
|
13
12
|
*
|
|
14
|
-
* Where @constant maxSizeCopy would equal "
|
|
13
|
+
* Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
|
|
15
14
|
*
|
|
16
|
-
* @param
|
|
17
|
-
*
|
|
15
|
+
* @param maxBytes - The file size in bytes to convert
|
|
16
|
+
* @param format - The unit format to display (KB or MB)
|
|
17
|
+
* @param baseString - Optional prefix string, defaults to "Maximum file size: "
|
|
18
|
+
* @param digits - Number of decimal places to show, defaults to 2 (strips any leading zeros)
|
|
19
|
+
* @returns A formatted string representing the file size
|
|
18
20
|
*/
|
|
19
|
-
const getFileSizeString = ({ maxBytes, format, baseString }) => {
|
|
20
|
-
const base = baseString
|
|
21
|
+
const getFileSizeString = ({ maxBytes, format, baseString, digits = 2, }) => {
|
|
22
|
+
const base = baseString !== null && baseString !== undefined ? baseString : 'Maximum file size: ';
|
|
23
|
+
const getValue = (divisor) => parseFloat((maxBytes / divisor).toFixed(digits));
|
|
21
24
|
switch (format) {
|
|
22
25
|
case FileSizeUnit.KB:
|
|
23
|
-
return `${base}${
|
|
26
|
+
return `${base}${getValue(1000)} KB`;
|
|
24
27
|
case FileSizeUnit.MB:
|
|
25
|
-
return `${base}${
|
|
28
|
+
return `${base}${getValue(1000000)} MB`;
|
|
26
29
|
default:
|
|
27
|
-
return `${base}${
|
|
30
|
+
return `${base}${getValue(1000)} KB`;
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
33
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileSizeString.js","sources":["../../../../../src/components/UploadFile/utils/getFileSizeString/getFileSizeString.ts"],"sourcesContent":["import { FileSizeUnit } from '../../constants';\n\ntype GetFileSizeStringProps = {\n maxBytes: number;\n format: FileSizeUnit;\n baseString?: string;\n};\n/**\n *
|
|
1
|
+
{"version":3,"file":"getFileSizeString.js","sources":["../../../../../src/components/UploadFile/utils/getFileSizeString/getFileSizeString.ts"],"sourcesContent":["import { FileSizeUnit } from '../../constants';\n\ntype GetFileSizeStringProps = {\n maxBytes: number;\n format: FileSizeUnit;\n baseString?: string;\n digits?: number;\n};\n/**\n * Converts a file size in bytes to a human-readable string with the specified format unit.\n *\n * E.g.\n *\n * const maxSizeCopy = getFileSizeString({\n * maxBytes: 10000000,\n * format: FileSizeUnit.MB\n * });\n *\n * Where @constant maxSizeCopy would equal \"Maximum file size: 10 MB\"\n *\n * @param maxBytes - The file size in bytes to convert\n * @param format - The unit format to display (KB or MB)\n * @param baseString - Optional prefix string, defaults to \"Maximum file size: \"\n * @param digits - Number of decimal places to show, defaults to 2 (strips any leading zeros)\n * @returns A formatted string representing the file size\n */\nexport const getFileSizeString = ({\n maxBytes,\n format,\n baseString,\n digits = 2,\n}: GetFileSizeStringProps) => {\n const base = baseString ?? 'Maximum file size: ';\n const getValue = (divisor: number) => parseFloat((maxBytes / divisor).toFixed(digits));\n switch (format) {\n case FileSizeUnit.KB:\n return `${base}${getValue(1000)} KB`;\n case FileSizeUnit.MB:\n return `${base}${getValue(1000000)} MB`;\n default:\n return `${base}${getValue(1000)} KB`;\n }\n};\n"],"names":[],"mappings":";;AAQA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,iBAAiB,GAAG,CAAC,EAChC,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,GAAG,CAAC,GACa,KAAI;IAC3B,MAAM,IAAI,GAAG,UAAU,KAAA,IAAA,IAAV,UAAU,KAAV,SAAA,GAAA,UAAU,GAAI,qBAAqB;IAChD,MAAM,QAAQ,GAAG,CAAC,OAAe,KAAK,UAAU,CAAC,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AACtF,IAAA,QAAQ,MAAM;QACZ,KAAK,YAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,IAAI,CAAC,KAAK;QACtC,KAAK,YAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,OAAO,CAAC,KAAK;AACzC,QAAA;YACE,OAAO,CAAA,EAAG,IAAI,CAAG,EAAA,QAAQ,CAAC,IAAI,CAAC,KAAK;AACvC;AACH;;;;"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var constants = require('../../constants.cjs');
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Constructs a user-friendly string of accepted types valid for the UploadFile component based on the
|
|
7
5
|
* fileTypes list passed as parameter.
|
|
@@ -21,34 +19,22 @@ var constants = require('../../constants.cjs');
|
|
|
21
19
|
* the returned string
|
|
22
20
|
*/
|
|
23
21
|
const getValidTypesString = ({ fileTypes, baseString }) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
break;
|
|
41
|
-
case constants.AcceptedFileTypes.JPG:
|
|
42
|
-
base += 'JPG';
|
|
43
|
-
break;
|
|
44
|
-
case constants.AcceptedFileTypes.PNG:
|
|
45
|
-
base += 'PNG';
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
if (!isPenultimate && !isLast && list.length > 2)
|
|
49
|
-
base += ', ';
|
|
50
|
-
});
|
|
51
|
-
return base;
|
|
22
|
+
// Remove leading dot and uppercase for display
|
|
23
|
+
const getDisplayType = (fileType) => fileType.replace(/^\./, '').toUpperCase();
|
|
24
|
+
if (!fileTypes.length)
|
|
25
|
+
return baseString !== null && baseString !== undefined ? baseString : '';
|
|
26
|
+
const displayTypes = fileTypes.map(getDisplayType);
|
|
27
|
+
let result = baseString == null ? 'Valid file types: ' : baseString;
|
|
28
|
+
if (displayTypes.length === 1) {
|
|
29
|
+
result += displayTypes[0];
|
|
30
|
+
}
|
|
31
|
+
else if (displayTypes.length === 2) {
|
|
32
|
+
result += `${displayTypes[0]} and ${displayTypes[1]}`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result += `${displayTypes.slice(0, -1).join(', ')} and ${displayTypes[displayTypes.length - 1]}`;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
52
38
|
};
|
|
53
39
|
|
|
54
40
|
exports.getValidTypesString = getValidTypesString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getValidTypesString.cjs","sources":["../../../../../src/components/UploadFile/utils/getValidTypesString/getValidTypesString.ts"],"sourcesContent":["import { AcceptedFileTypes } from '../../constants';\n\ntype GetValidTypesStringProps = {\n fileTypes: Array<AcceptedFileTypes>;\n baseString?: string;\n};\n\n/**\n * Constructs a user-friendly string of accepted types valid for the UploadFile component based on the\n * fileTypes list passed as parameter.\n *\n * E.g.\n *\n * const validTypesCopy = getValidTypesString({\n * fileTypes: [\n * AcceptedFileTypes.CSV,\n * ]\n * });\n *\n * Where @constant validTypesCopy would equal \"Valid types: CSV\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * @param baseString - An optional string to override the default value of 'Valid types: ' prefixed to\n * the returned string\n */\nexport const getValidTypesString = ({ fileTypes, baseString }: GetValidTypesStringProps) => {\n
|
|
1
|
+
{"version":3,"file":"getValidTypesString.cjs","sources":["../../../../../src/components/UploadFile/utils/getValidTypesString/getValidTypesString.ts"],"sourcesContent":["import { AcceptedFileTypes } from '../../constants';\n\ntype GetValidTypesStringProps = {\n fileTypes: Array<AcceptedFileTypes>;\n baseString?: string;\n};\n\n/**\n * Constructs a user-friendly string of accepted types valid for the UploadFile component based on the\n * fileTypes list passed as parameter.\n *\n * E.g.\n *\n * const validTypesCopy = getValidTypesString({\n * fileTypes: [\n * AcceptedFileTypes.CSV,\n * ]\n * });\n *\n * Where @constant validTypesCopy would equal \"Valid types: CSV\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * @param baseString - An optional string to override the default value of 'Valid types: ' prefixed to\n * the returned string\n */\nexport const getValidTypesString = ({ fileTypes, baseString }: GetValidTypesStringProps) => {\n // Remove leading dot and uppercase for display\n const getDisplayType = (fileType: AcceptedFileTypes) => fileType.replace(/^\\./, '').toUpperCase();\n\n if (!fileTypes.length) return baseString ?? '';\n\n const displayTypes = fileTypes.map(getDisplayType);\n\n let result = baseString == null ? 'Valid file types: ' : baseString;\n\n if (displayTypes.length === 1) {\n result += displayTypes[0];\n } else if (displayTypes.length === 2) {\n result += `${displayTypes[0]} and ${displayTypes[1]}`;\n } else {\n result += `${displayTypes.slice(0, -1).join(', ')} and ${displayTypes[displayTypes.length - 1]}`;\n }\n\n return result;\n};\n"],"names":[],"mappings":";;AAOA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,mBAAmB,GAAG,CAAC,EAAE,SAAS,EAAE,UAAU,EAA4B,KAAI;;AAEzF,IAAA,MAAM,cAAc,GAAG,CAAC,QAA2B,KAAK,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE;IAEjG,IAAI,CAAC,SAAS,CAAC,MAAM;AAAE,QAAA,OAAO,UAAU,KAAV,IAAA,IAAA,UAAU,iBAAV,UAAU,GAAI,EAAE;IAE9C,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;AAElD,IAAA,IAAI,MAAM,GAAG,UAAU,IAAI,IAAI,GAAG,oBAAoB,GAAG,UAAU;AAEnE,IAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7B,QAAA,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC;AAC1B;AAAM,SAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AACpC,QAAA,MAAM,IAAI,CAAA,EAAG,YAAY,CAAC,CAAC,CAAC,CAAQ,KAAA,EAAA,YAAY,CAAC,CAAC,CAAC,CAAA,CAAE;AACtD;AAAM,SAAA;QACL,MAAM,IAAI,CAAG,EAAA,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAQ,KAAA,EAAA,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA,CAAE;AACjG;AAED,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AcceptedFileTypes } from '../../constants.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Constructs a user-friendly string of accepted types valid for the UploadFile component based on the
|
|
5
3
|
* fileTypes list passed as parameter.
|
|
@@ -19,34 +17,22 @@ import { AcceptedFileTypes } from '../../constants.js';
|
|
|
19
17
|
* the returned string
|
|
20
18
|
*/
|
|
21
19
|
const getValidTypesString = ({ fileTypes, baseString }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
break;
|
|
39
|
-
case AcceptedFileTypes.JPG:
|
|
40
|
-
base += 'JPG';
|
|
41
|
-
break;
|
|
42
|
-
case AcceptedFileTypes.PNG:
|
|
43
|
-
base += 'PNG';
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
if (!isPenultimate && !isLast && list.length > 2)
|
|
47
|
-
base += ', ';
|
|
48
|
-
});
|
|
49
|
-
return base;
|
|
20
|
+
// Remove leading dot and uppercase for display
|
|
21
|
+
const getDisplayType = (fileType) => fileType.replace(/^\./, '').toUpperCase();
|
|
22
|
+
if (!fileTypes.length)
|
|
23
|
+
return baseString !== null && baseString !== undefined ? baseString : '';
|
|
24
|
+
const displayTypes = fileTypes.map(getDisplayType);
|
|
25
|
+
let result = baseString == null ? 'Valid file types: ' : baseString;
|
|
26
|
+
if (displayTypes.length === 1) {
|
|
27
|
+
result += displayTypes[0];
|
|
28
|
+
}
|
|
29
|
+
else if (displayTypes.length === 2) {
|
|
30
|
+
result += `${displayTypes[0]} and ${displayTypes[1]}`;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
result += `${displayTypes.slice(0, -1).join(', ')} and ${displayTypes[displayTypes.length - 1]}`;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
50
36
|
};
|
|
51
37
|
|
|
52
38
|
export { getValidTypesString };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getValidTypesString.js","sources":["../../../../../src/components/UploadFile/utils/getValidTypesString/getValidTypesString.ts"],"sourcesContent":["import { AcceptedFileTypes } from '../../constants';\n\ntype GetValidTypesStringProps = {\n fileTypes: Array<AcceptedFileTypes>;\n baseString?: string;\n};\n\n/**\n * Constructs a user-friendly string of accepted types valid for the UploadFile component based on the\n * fileTypes list passed as parameter.\n *\n * E.g.\n *\n * const validTypesCopy = getValidTypesString({\n * fileTypes: [\n * AcceptedFileTypes.CSV,\n * ]\n * });\n *\n * Where @constant validTypesCopy would equal \"Valid types: CSV\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * @param baseString - An optional string to override the default value of 'Valid types: ' prefixed to\n * the returned string\n */\nexport const getValidTypesString = ({ fileTypes, baseString }: GetValidTypesStringProps) => {\n
|
|
1
|
+
{"version":3,"file":"getValidTypesString.js","sources":["../../../../../src/components/UploadFile/utils/getValidTypesString/getValidTypesString.ts"],"sourcesContent":["import { AcceptedFileTypes } from '../../constants';\n\ntype GetValidTypesStringProps = {\n fileTypes: Array<AcceptedFileTypes>;\n baseString?: string;\n};\n\n/**\n * Constructs a user-friendly string of accepted types valid for the UploadFile component based on the\n * fileTypes list passed as parameter.\n *\n * E.g.\n *\n * const validTypesCopy = getValidTypesString({\n * fileTypes: [\n * AcceptedFileTypes.CSV,\n * ]\n * });\n *\n * Where @constant validTypesCopy would equal \"Valid types: CSV\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * @param baseString - An optional string to override the default value of 'Valid types: ' prefixed to\n * the returned string\n */\nexport const getValidTypesString = ({ fileTypes, baseString }: GetValidTypesStringProps) => {\n // Remove leading dot and uppercase for display\n const getDisplayType = (fileType: AcceptedFileTypes) => fileType.replace(/^\\./, '').toUpperCase();\n\n if (!fileTypes.length) return baseString ?? '';\n\n const displayTypes = fileTypes.map(getDisplayType);\n\n let result = baseString == null ? 'Valid file types: ' : baseString;\n\n if (displayTypes.length === 1) {\n result += displayTypes[0];\n } else if (displayTypes.length === 2) {\n result += `${displayTypes[0]} and ${displayTypes[1]}`;\n } else {\n result += `${displayTypes.slice(0, -1).join(', ')} and ${displayTypes[displayTypes.length - 1]}`;\n }\n\n return result;\n};\n"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,mBAAmB,GAAG,CAAC,EAAE,SAAS,EAAE,UAAU,EAA4B,KAAI;;AAEzF,IAAA,MAAM,cAAc,GAAG,CAAC,QAA2B,KAAK,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE;IAEjG,IAAI,CAAC,SAAS,CAAC,MAAM;AAAE,QAAA,OAAO,UAAU,KAAV,IAAA,IAAA,UAAU,iBAAV,UAAU,GAAI,EAAE;IAE9C,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;AAElD,IAAA,IAAI,MAAM,GAAG,UAAU,IAAI,IAAI,GAAG,oBAAoB,GAAG,UAAU;AAEnE,IAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7B,QAAA,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC;AAC1B;AAAM,SAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AACpC,QAAA,MAAM,IAAI,CAAA,EAAG,YAAY,CAAC,CAAC,CAAC,CAAQ,KAAA,EAAA,YAAY,CAAC,CAAC,CAAC,CAAA,CAAE;AACtD;AAAM,SAAA;QACL,MAAM,IAAI,CAAG,EAAA,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAQ,KAAA,EAAA,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA,CAAE;AACjG;AAED,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { getValidTypesString } from './getValidTypesString/getValidTypesString';
|
|
2
2
|
export { getFileSizeString } from './getFileSizeString/getFileSizeString';
|
|
3
3
|
export { getTypePropForInputEl } from './getTypePropForInputEl/getTypePropForInputEl';
|
|
4
|
-
export { setInputElFile } from './setInputElFile/setInputElFile';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var index = require('../../theme/index.cjs');
|
|
5
|
+
var Button = require('../Button/Button.cjs');
|
|
6
|
+
var CriticalIcon = require('../../icons/design-system/components/CriticalIcon.cjs');
|
|
7
|
+
var CrossIcon = require('../../icons/design-system/components/CrossIcon.cjs');
|
|
8
|
+
var Text = require('../Text/Text.cjs');
|
|
9
|
+
var Image = require('../Image/Image.cjs');
|
|
10
|
+
var FlexCol = require('../Flex/FlexCol/FlexCol.cjs');
|
|
11
|
+
var FlexRow = require('../Flex/FlexRow/FlexRow.cjs');
|
|
12
|
+
var styled = require('../../hoc/withLabels/styled.cjs');
|
|
13
|
+
var usePreviewImage = require('./hooks/usePreviewImage/usePreviewImage.cjs');
|
|
14
|
+
var UploadedFile_module = require('./UploadedFile.module.scss.cjs');
|
|
15
|
+
var useFileErrorMessages = require('./hooks/useFileErrorMessages/useFileErrorMessages.cjs');
|
|
16
|
+
var getFileSizeString = require('../UploadFile/utils/getFileSizeString/getFileSizeString.cjs');
|
|
17
|
+
var Skeleton = require('../Skeleton/Skeleton.cjs');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
20
|
+
|
|
21
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
22
|
+
|
|
23
|
+
const UploadedFile = ({ file, onRemoveFile, disabled, format, maxBytes, fileTypes, isLoading, }) => {
|
|
24
|
+
const { previewSrc, shouldShowPreview } = usePreviewImage.usePreviewImage({ file });
|
|
25
|
+
const { errorMessages, hasCriticalErrors } = useFileErrorMessages.useFileErrorMessages({
|
|
26
|
+
file,
|
|
27
|
+
maxBytes,
|
|
28
|
+
fileTypes,
|
|
29
|
+
});
|
|
30
|
+
const fileSizeCopy = getFileSizeString.getFileSizeString({ maxBytes: (file === null || file === undefined ? undefined : file.size) || 0, format, baseString: '' });
|
|
31
|
+
if (isLoading) {
|
|
32
|
+
return React__default.default.createElement(Skeleton.Skeleton, { height: "40px", "aria-label": "Loading file" });
|
|
33
|
+
}
|
|
34
|
+
if (!file)
|
|
35
|
+
return null;
|
|
36
|
+
const RemoveButton = (React__default.default.createElement(Button.Button, { size: "sm", variant: "flat", onClick: () => onRemoveFile && onRemoveFile(file), iconSlot: React__default.default.createElement(CrossIcon.ReactComponent, null), "aria-label": `Remove file ${file.name}`, disabled: disabled }));
|
|
37
|
+
const ErrorMessages = hasCriticalErrors && (React__default.default.createElement(FlexRow.FlexRow, { alignItems: "flex-start" },
|
|
38
|
+
React__default.default.createElement(CriticalIcon.ReactComponent, { width: index.theme.sizes.base, height: index.theme.sizes.base, color: index.theme.colors.secondary.red.base }),
|
|
39
|
+
React__default.default.createElement("div", { className: UploadedFile_module.singleLineWrapper },
|
|
40
|
+
React__default.default.createElement(styled.Error, { className: UploadedFile_module.singleLineTextWithoutFlex }, errorMessages.criticalErrors.map((error, index, array) => {
|
|
41
|
+
const isNotLast = !!(array.length > index + 1);
|
|
42
|
+
return `${error.errorMessage}${isNotLast ? ', ' : ''}`;
|
|
43
|
+
})))));
|
|
44
|
+
if (!shouldShowPreview) {
|
|
45
|
+
return (React__default.default.createElement("div", { className: hasCriticalErrors
|
|
46
|
+
? UploadedFile_module.uploadedFileContainerCriticalError
|
|
47
|
+
: UploadedFile_module.uploadedFileContainer },
|
|
48
|
+
React__default.default.createElement(FlexRow.FlexRow, { justifyContent: "space-between", alignItems: "center" },
|
|
49
|
+
React__default.default.createElement(FlexCol.FlexCol, { style: { flex: 1, minWidth: 0 } },
|
|
50
|
+
React__default.default.createElement("div", { className: UploadedFile_module.standardFileTextWrapper },
|
|
51
|
+
React__default.default.createElement(Text.Text, { className: UploadedFile_module.singleLineText, variant: "body", style: {
|
|
52
|
+
minWidth: 0,
|
|
53
|
+
overflow: 'hidden',
|
|
54
|
+
textOverflow: 'ellipsis',
|
|
55
|
+
whiteSpace: 'nowrap',
|
|
56
|
+
} }, file.name),
|
|
57
|
+
React__default.default.createElement(Text.Text, { variant: "body", className: UploadedFile_module.fileSizeText, style: { color: index.theme.colors.neutral.ink.light } }, fileSizeCopy)),
|
|
58
|
+
ErrorMessages),
|
|
59
|
+
onRemoveFile && (React__default.default.createElement("div", { style: { display: 'flex', alignItems: 'center', marginLeft: 12 } }, RemoveButton)))));
|
|
60
|
+
}
|
|
61
|
+
return (React__default.default.createElement("div", { className: hasCriticalErrors
|
|
62
|
+
? UploadedFile_module.uploadedFileContainerCriticalError
|
|
63
|
+
: UploadedFile_module.uploadedFileContainer },
|
|
64
|
+
React__default.default.createElement(FlexRow.FlexRow, { style: { flexWrap: 'nowrap' }, justifyContent: "space-between" },
|
|
65
|
+
React__default.default.createElement(FlexCol.FlexCol, null,
|
|
66
|
+
React__default.default.createElement(FlexRow.FlexRow, { alignItems: "center", style: { flex: 1, minWidth: 0, gap: index.theme.sizes.base }, flexWrap: "nowrap" },
|
|
67
|
+
React__default.default.createElement(Image.Image, { className: UploadedFile_module.previewImage, height: "44", width: "44", src: previewSrc }),
|
|
68
|
+
React__default.default.createElement("div", { className: UploadedFile_module.singleLineWrapper },
|
|
69
|
+
React__default.default.createElement(Text.Text, { className: UploadedFile_module.singleLineTextWithoutFlex, variant: "body" }, file === null || file === undefined ? undefined : file.name),
|
|
70
|
+
React__default.default.createElement(Text.Text, { variant: "body", className: UploadedFile_module.singleLineTextWithoutFlex, style: {
|
|
71
|
+
color: index.theme.colors.neutral.ink.light,
|
|
72
|
+
} }, fileSizeCopy))),
|
|
73
|
+
ErrorMessages),
|
|
74
|
+
onRemoveFile && RemoveButton)));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.UploadedFile = UploadedFile;
|
|
78
|
+
//# sourceMappingURL=UploadedFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadedFile.cjs","sources":["../../../src/components/UploadedFile/UploadedFile.tsx"],"sourcesContent":["import React from 'react';\nimport { theme } from 'Theme';\nimport { Button } from '../Button';\nimport { CriticalIcon, CrossIcon } from '../../icons';\nimport { Text } from '../Text';\nimport { Image } from '../Image';\nimport { FlexCol } from '../Flex/FlexCol';\nimport { FlexRow } from '../Flex/FlexRow';\nimport { Error } from '../../hoc/withLabels/styled';\nimport { usePreviewImage } from './hooks/usePreviewImage';\nimport uploadedFileStyles from './UploadedFile.module.scss';\nimport { useFileErrorMessages } from './hooks/useFileErrorMessages';\nimport { AcceptedFileTypes, FileSizeUnit } from '../UploadFile/constants';\nimport { getFileSizeString } from '../UploadFile/utils';\nimport { Skeleton } from '../Skeleton';\n\nexport type UploadedFileProps = {\n file?: File | null;\n onRemoveFile?: (file: File) => void;\n disabled?: boolean;\n format: FileSizeUnit;\n maxBytes: number;\n fileTypes: Array<AcceptedFileTypes>;\n isLoading?: boolean;\n};\n\nexport const UploadedFile = ({\n file,\n onRemoveFile,\n disabled,\n format,\n maxBytes,\n fileTypes,\n isLoading,\n}: UploadedFileProps) => {\n const { previewSrc, shouldShowPreview } = usePreviewImage({ file });\n\n const { errorMessages, hasCriticalErrors } = useFileErrorMessages({\n file,\n maxBytes,\n fileTypes,\n });\n\n const fileSizeCopy = getFileSizeString({ maxBytes: file?.size || 0, format, baseString: '' });\n\n if (isLoading) {\n return <Skeleton height=\"40px\" aria-label=\"Loading file\" />;\n }\n\n if (!file) return null;\n\n const RemoveButton = (\n <Button\n size=\"sm\"\n variant=\"flat\"\n onClick={() => onRemoveFile && onRemoveFile(file)}\n iconSlot={<CrossIcon />}\n aria-label={`Remove file ${file.name}`}\n disabled={disabled}\n />\n );\n\n const ErrorMessages = hasCriticalErrors && (\n <FlexRow alignItems=\"flex-start\">\n <CriticalIcon\n width={theme.sizes.base}\n height={theme.sizes.base}\n color={theme.colors.secondary.red.base}\n />\n <div className={uploadedFileStyles.singleLineWrapper}>\n <Error className={uploadedFileStyles.singleLineTextWithoutFlex}>\n {errorMessages.criticalErrors.map((error, index, array) => {\n const isNotLast = !!(array.length > index + 1);\n return `${error.errorMessage}${isNotLast ? ', ' : ''}`;\n })}\n </Error>\n </div>\n </FlexRow>\n );\n\n if (!shouldShowPreview) {\n return (\n <div\n className={\n hasCriticalErrors\n ? uploadedFileStyles.uploadedFileContainerCriticalError\n : uploadedFileStyles.uploadedFileContainer\n }\n >\n <FlexRow justifyContent=\"space-between\" alignItems=\"center\">\n <FlexCol style={{ flex: 1, minWidth: 0 }}>\n <div className={uploadedFileStyles.standardFileTextWrapper}>\n <Text\n className={uploadedFileStyles.singleLineText}\n variant=\"body\"\n style={{\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n }}\n >\n {file.name}\n </Text>\n <Text\n variant=\"body\"\n className={uploadedFileStyles.fileSizeText}\n style={{ color: theme.colors.neutral.ink.light }}\n >\n {fileSizeCopy}\n </Text>\n </div>\n {ErrorMessages}\n </FlexCol>\n {onRemoveFile && (\n <div style={{ display: 'flex', alignItems: 'center', marginLeft: 12 }}>\n {RemoveButton}\n </div>\n )}\n </FlexRow>\n </div>\n );\n }\n\n return (\n <div\n className={\n hasCriticalErrors\n ? uploadedFileStyles.uploadedFileContainerCriticalError\n : uploadedFileStyles.uploadedFileContainer\n }\n >\n <FlexRow style={{ flexWrap: 'nowrap' }} justifyContent=\"space-between\">\n <FlexCol>\n <FlexRow\n alignItems=\"center\"\n style={{ flex: 1, minWidth: 0, gap: theme.sizes.base }}\n flexWrap=\"nowrap\"\n >\n <Image\n className={uploadedFileStyles.previewImage}\n height=\"44\"\n width=\"44\"\n src={previewSrc}\n />\n <div className={uploadedFileStyles.singleLineWrapper}>\n <Text className={uploadedFileStyles.singleLineTextWithoutFlex} variant=\"body\">\n {file?.name}\n </Text>\n <Text\n variant=\"body\"\n className={uploadedFileStyles.singleLineTextWithoutFlex}\n style={{\n color: theme.colors.neutral.ink.light,\n }}\n >\n {fileSizeCopy}\n </Text>\n </div>\n </FlexRow>\n {ErrorMessages}\n </FlexCol>\n {onRemoveFile && RemoveButton}\n </FlexRow>\n </div>\n );\n};\n"],"names":["usePreviewImage","useFileErrorMessages","getFileSizeString","React","Skeleton","Button","CrossIcon","FlexRow","CriticalIcon","theme","uploadedFileStyles","Error","FlexCol","Text","Image"],"mappings":";;;;;;;;;;;;;;;;;;;;;;MA0Ba,YAAY,GAAG,CAAC,EAC3B,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,GACS,KAAI;AACtB,IAAA,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAGA,+BAAe,CAAC,EAAE,IAAI,EAAE,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K,SAAS,EAAEO,mBAAkB,CAAC,iBAAiB,EAAA;AAClD,wBAAAP,sBAAA,CAAA,aAAA,CAACU,SAAI,EAAC,EAAA,SAAS,EAAEH,mBAAkB,CAAC,yBAAyB,EAAE,OAAO,EAAC,MAAM,EAAA,EAC1E,IAAI,KAAJ,IAAA,IAAA,IAAI,6BAAJ,IAAI,CAAE,IAAI,CACN;AACP,wBAAAP,sBAAA,CAAA,aAAA,CAACU,SAAI,EAAA,EACH,OAAO,EAAC,MAAM,EACd,SAAS,EAAEH,mBAAkB,CAAC,yBAAyB,EACvD,KAAK,EAAE;gCACL,KAAK,EAAED,WAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK;6BACtC,EAEA,EAAA,YAAY,CACR,CACH,CACE;AACT,gBAAA,aAAa,CACN;AACT,YAAA,YAAY,IAAI,YAAY,CACrB,CACN;AAEV;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AcceptedFileTypes, FileSizeUnit } from '../UploadFile/constants';
|
|
3
|
+
export type UploadedFileProps = {
|
|
4
|
+
file?: File | null;
|
|
5
|
+
onRemoveFile?: (file: File) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
format: FileSizeUnit;
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
fileTypes: Array<AcceptedFileTypes>;
|
|
10
|
+
isLoading?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const UploadedFile: ({ file, onRemoveFile, disabled, format, maxBytes, fileTypes, isLoading, }: UploadedFileProps) => React.JSX.Element | null;
|