@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
|
@@ -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,CAAC;AAEnE,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O,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;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { theme } from '../../theme/index.js';
|
|
3
|
+
import { Button } from '../Button/Button.js';
|
|
4
|
+
import { ReactComponent as CriticalIcon } from '../../icons/design-system/components/CriticalIcon.js';
|
|
5
|
+
import { ReactComponent as CrossIcon } from '../../icons/design-system/components/CrossIcon.js';
|
|
6
|
+
import { Text } from '../Text/Text.js';
|
|
7
|
+
import { Image } from '../Image/Image.js';
|
|
8
|
+
import { FlexCol } from '../Flex/FlexCol/FlexCol.js';
|
|
9
|
+
import { FlexRow } from '../Flex/FlexRow/FlexRow.js';
|
|
10
|
+
import { Error } from '../../hoc/withLabels/styled.js';
|
|
11
|
+
import { usePreviewImage } from './hooks/usePreviewImage/usePreviewImage.js';
|
|
12
|
+
import uploadedFileStyles from './UploadedFile.module.scss.js';
|
|
13
|
+
import { useFileErrorMessages } from './hooks/useFileErrorMessages/useFileErrorMessages.js';
|
|
14
|
+
import { getFileSizeString } from '../UploadFile/utils/getFileSizeString/getFileSizeString.js';
|
|
15
|
+
import { Skeleton } from '../Skeleton/Skeleton.js';
|
|
16
|
+
|
|
17
|
+
const UploadedFile = ({ file, onRemoveFile, disabled, format, maxBytes, fileTypes, isLoading, }) => {
|
|
18
|
+
const { previewSrc, shouldShowPreview } = usePreviewImage({ file });
|
|
19
|
+
const { errorMessages, hasCriticalErrors } = useFileErrorMessages({
|
|
20
|
+
file,
|
|
21
|
+
maxBytes,
|
|
22
|
+
fileTypes,
|
|
23
|
+
});
|
|
24
|
+
const fileSizeCopy = getFileSizeString({ maxBytes: (file === null || file === undefined ? undefined : file.size) || 0, format, baseString: '' });
|
|
25
|
+
if (isLoading) {
|
|
26
|
+
return React__default.createElement(Skeleton, { height: "40px", "aria-label": "Loading file" });
|
|
27
|
+
}
|
|
28
|
+
if (!file)
|
|
29
|
+
return null;
|
|
30
|
+
const RemoveButton = (React__default.createElement(Button, { size: "sm", variant: "flat", onClick: () => onRemoveFile && onRemoveFile(file), iconSlot: React__default.createElement(CrossIcon, null), "aria-label": `Remove file ${file.name}`, disabled: disabled }));
|
|
31
|
+
const ErrorMessages = hasCriticalErrors && (React__default.createElement(FlexRow, { alignItems: "flex-start" },
|
|
32
|
+
React__default.createElement(CriticalIcon, { width: theme.sizes.base, height: theme.sizes.base, color: theme.colors.secondary.red.base }),
|
|
33
|
+
React__default.createElement("div", { className: uploadedFileStyles.singleLineWrapper },
|
|
34
|
+
React__default.createElement(Error, { className: uploadedFileStyles.singleLineTextWithoutFlex }, errorMessages.criticalErrors.map((error, index, array) => {
|
|
35
|
+
const isNotLast = !!(array.length > index + 1);
|
|
36
|
+
return `${error.errorMessage}${isNotLast ? ', ' : ''}`;
|
|
37
|
+
})))));
|
|
38
|
+
if (!shouldShowPreview) {
|
|
39
|
+
return (React__default.createElement("div", { className: hasCriticalErrors
|
|
40
|
+
? uploadedFileStyles.uploadedFileContainerCriticalError
|
|
41
|
+
: uploadedFileStyles.uploadedFileContainer },
|
|
42
|
+
React__default.createElement(FlexRow, { justifyContent: "space-between", alignItems: "center" },
|
|
43
|
+
React__default.createElement(FlexCol, { style: { flex: 1, minWidth: 0 } },
|
|
44
|
+
React__default.createElement("div", { className: uploadedFileStyles.standardFileTextWrapper },
|
|
45
|
+
React__default.createElement(Text, { className: uploadedFileStyles.singleLineText, variant: "body", style: {
|
|
46
|
+
minWidth: 0,
|
|
47
|
+
overflow: 'hidden',
|
|
48
|
+
textOverflow: 'ellipsis',
|
|
49
|
+
whiteSpace: 'nowrap',
|
|
50
|
+
} }, file.name),
|
|
51
|
+
React__default.createElement(Text, { variant: "body", className: uploadedFileStyles.fileSizeText, style: { color: theme.colors.neutral.ink.light } }, fileSizeCopy)),
|
|
52
|
+
ErrorMessages),
|
|
53
|
+
onRemoveFile && (React__default.createElement("div", { style: { display: 'flex', alignItems: 'center', marginLeft: 12 } }, RemoveButton)))));
|
|
54
|
+
}
|
|
55
|
+
return (React__default.createElement("div", { className: hasCriticalErrors
|
|
56
|
+
? uploadedFileStyles.uploadedFileContainerCriticalError
|
|
57
|
+
: uploadedFileStyles.uploadedFileContainer },
|
|
58
|
+
React__default.createElement(FlexRow, { style: { flexWrap: 'nowrap' }, justifyContent: "space-between" },
|
|
59
|
+
React__default.createElement(FlexCol, null,
|
|
60
|
+
React__default.createElement(FlexRow, { alignItems: "center", style: { flex: 1, minWidth: 0, gap: theme.sizes.base }, flexWrap: "nowrap" },
|
|
61
|
+
React__default.createElement(Image, { className: uploadedFileStyles.previewImage, height: "44", width: "44", src: previewSrc }),
|
|
62
|
+
React__default.createElement("div", { className: uploadedFileStyles.singleLineWrapper },
|
|
63
|
+
React__default.createElement(Text, { className: uploadedFileStyles.singleLineTextWithoutFlex, variant: "body" }, file === null || file === undefined ? undefined : file.name),
|
|
64
|
+
React__default.createElement(Text, { variant: "body", className: uploadedFileStyles.singleLineTextWithoutFlex, style: {
|
|
65
|
+
color: theme.colors.neutral.ink.light,
|
|
66
|
+
} }, fileSizeCopy))),
|
|
67
|
+
ErrorMessages),
|
|
68
|
+
onRemoveFile && RemoveButton)));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { UploadedFile };
|
|
72
|
+
//# sourceMappingURL=UploadedFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadedFile.js","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":["React"],"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,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC;AAEnE,IAAA,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,oBAAoB,CAAC;QAChE,IAAI;QACJ,QAAQ;QACR,SAAS;AACV,KAAA,CAAC;IAEF,MAAM,YAAY,GAAG,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAA,IAAI,KAAA,IAAA,IAAJ,IAAI,KAAA,SAAA,GAAA,SAAA,GAAJ,IAAI,CAAE,IAAI,KAAI,CAAC,EAAE,MAAM,EAAE,UAAU,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gCACL,KAAK,EAAE,KAAK,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,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ___$insertStyle = require('../../_virtual/____insertStyle.cjs');
|
|
4
|
+
|
|
5
|
+
___$insertStyle("._uploadedFileContainer_17uzv_1 {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n._uploadedFileContainerCriticalError_17uzv_7 {\n border: 1px solid var(--colors-secondary-red-base);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n._singleLineText_17uzv_13 {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: 0 1 80%;\n min-width: 0;\n}\n\n._singleLineTextWithoutFlex_17uzv_21 {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: none;\n min-width: 0;\n}\n\n._fileSizeText_17uzv_29 {\n white-space: nowrap;\n flex: 0 0 20%;\n text-align: right;\n}\n\n._previewImage_17uzv_35 img {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--sizes-xs);\n}\n\n._singleLineWrapper_17uzv_40 {\n display: grid;\n min-width: 0;\n flex: 1;\n}\n\n._standardFileTextWrapper_17uzv_46 {\n display: grid;\n grid-template-columns: 1fr auto;\n gap: var(--sizes-xs);\n}");
|
|
6
|
+
var uploadedFileStyles = {"uploadedFileContainer":"_uploadedFileContainer_17uzv_1","uploadedFileContainerCriticalError":"_uploadedFileContainerCriticalError_17uzv_7","singleLineText":"_singleLineText_17uzv_13","singleLineTextWithoutFlex":"_singleLineTextWithoutFlex_17uzv_21","fileSizeText":"_fileSizeText_17uzv_29","previewImage":"_previewImage_17uzv_35","singleLineWrapper":"_singleLineWrapper_17uzv_40","standardFileTextWrapper":"_standardFileTextWrapper_17uzv_46"};
|
|
7
|
+
|
|
8
|
+
module.exports = uploadedFileStyles;
|
|
9
|
+
//# sourceMappingURL=UploadedFile.module.scss.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadedFile.module.scss.cjs","sources":["../../../src/components/UploadedFile/UploadedFile.module.scss"],"sourcesContent":[".uploadedFileContainer {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n.uploadedFileContainerCriticalError {\n border: 1px solid var(--colors-secondary-red-base);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n.singleLineText {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: 0 1 80%;\n min-width: 0;\n}\n\n.singleLineTextWithoutFlex {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: none;\n min-width: 0;\n}\n\n.fileSizeText {\n white-space: nowrap;\n flex: 0 0 20%;\n text-align: right;\n}\n\n.previewImage {\n img {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--sizes-xs);\n }\n}\n\n.singleLineWrapper {\n display: grid;\n min-width: 0;\n flex: 1;\n}\n\n.standardFileTextWrapper {\n display: grid;\n grid-template-columns: 1fr auto;\n gap: var(--sizes-xs);\n}\n"],"names":[],"mappings":";;;;AACE,eAAA,CAAA,iiCAAA;AACA,yBAAA,CAAA,uBAAA,CAAA,gCAAA,CAAA,oCAAA,CAAA,6CAAA,CAAA,gBAAA,CAAA,0BAAA,CAAA,2BAAA,CAAA,qCAAA,CAAA,cAAA,CAAA,wBAAA,CAAA,cAAA,CAAA,wBAAA,CAAA,mBAAA,CAAA,6BAAA,CAAA,yBAAA,CAAA,mCAAA;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import insertStyle from '../../_virtual/____insertStyle.js';
|
|
2
|
+
|
|
3
|
+
insertStyle("._uploadedFileContainer_17uzv_1 {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n._uploadedFileContainerCriticalError_17uzv_7 {\n border: 1px solid var(--colors-secondary-red-base);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n._singleLineText_17uzv_13 {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: 0 1 80%;\n min-width: 0;\n}\n\n._singleLineTextWithoutFlex_17uzv_21 {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: none;\n min-width: 0;\n}\n\n._fileSizeText_17uzv_29 {\n white-space: nowrap;\n flex: 0 0 20%;\n text-align: right;\n}\n\n._previewImage_17uzv_35 img {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--sizes-xs);\n}\n\n._singleLineWrapper_17uzv_40 {\n display: grid;\n min-width: 0;\n flex: 1;\n}\n\n._standardFileTextWrapper_17uzv_46 {\n display: grid;\n grid-template-columns: 1fr auto;\n gap: var(--sizes-xs);\n}");
|
|
4
|
+
var uploadedFileStyles = {"uploadedFileContainer":"_uploadedFileContainer_17uzv_1","uploadedFileContainerCriticalError":"_uploadedFileContainerCriticalError_17uzv_7","singleLineText":"_singleLineText_17uzv_13","singleLineTextWithoutFlex":"_singleLineTextWithoutFlex_17uzv_21","fileSizeText":"_fileSizeText_17uzv_29","previewImage":"_previewImage_17uzv_35","singleLineWrapper":"_singleLineWrapper_17uzv_40","standardFileTextWrapper":"_standardFileTextWrapper_17uzv_46"};
|
|
5
|
+
|
|
6
|
+
export { uploadedFileStyles as default };
|
|
7
|
+
//# sourceMappingURL=UploadedFile.module.scss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadedFile.module.scss.js","sources":["../../../src/components/UploadedFile/UploadedFile.module.scss"],"sourcesContent":[".uploadedFileContainer {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n.uploadedFileContainerCriticalError {\n border: 1px solid var(--colors-secondary-red-base);\n border-radius: var(--radius-base);\n padding: var(--sizes-3);\n}\n\n.singleLineText {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: 0 1 80%;\n min-width: 0;\n}\n\n.singleLineTextWithoutFlex {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex: none;\n min-width: 0;\n}\n\n.fileSizeText {\n white-space: nowrap;\n flex: 0 0 20%;\n text-align: right;\n}\n\n.previewImage {\n img {\n border: 1px solid var(--colors-neutral-ink-lightest);\n border-radius: var(--sizes-xs);\n }\n}\n\n.singleLineWrapper {\n display: grid;\n min-width: 0;\n flex: 1;\n}\n\n.standardFileTextWrapper {\n display: grid;\n grid-template-columns: 1fr auto;\n gap: var(--sizes-xs);\n}\n"],"names":["___$insertStyle"],"mappings":";;AACEA,WAAA,CAAA,iiCAAA;AACA,yBAAA,CAAA,uBAAA,CAAA,gCAAA,CAAA,oCAAA,CAAA,6CAAA,CAAA,gBAAA,CAAA,0BAAA,CAAA,2BAAA,CAAA,qCAAA,CAAA,cAAA,CAAA,wBAAA,CAAA,cAAA,CAAA,wBAAA,CAAA,mBAAA,CAAA,6BAAA,CAAA,yBAAA,CAAA,mCAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFileErrorMessages } from './useFileErrorMessages';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var convertFileTypeToAcceptedFileType = require('../../utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.cjs');
|
|
5
|
+
var constants = require('../../../UploadFile/constants.cjs');
|
|
6
|
+
|
|
7
|
+
const useFileErrorMessages = ({ maxBytes, fileTypes, file }) => {
|
|
8
|
+
const errorMessages = React.useMemo(() => {
|
|
9
|
+
if (!file)
|
|
10
|
+
return { criticalErrors: [] };
|
|
11
|
+
const extension = convertFileTypeToAcceptedFileType.convertFileTypeToAcceptedFileType(file.type);
|
|
12
|
+
const isTypeValid = fileTypes.includes(extension);
|
|
13
|
+
const hasInvalidFormat = !isTypeValid;
|
|
14
|
+
const hasExceededMaxSize = file.size > maxBytes;
|
|
15
|
+
const errors = { criticalErrors: [] };
|
|
16
|
+
if (hasExceededMaxSize) {
|
|
17
|
+
errors.criticalErrors.push({
|
|
18
|
+
errorType: constants.ErrorType.critical,
|
|
19
|
+
errorMessage: constants.CriticalErrorMessages.FILE_IS_TOO_BIG,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (hasInvalidFormat) {
|
|
23
|
+
errors.criticalErrors.push({
|
|
24
|
+
errorType: constants.ErrorType.critical,
|
|
25
|
+
errorMessage: constants.CriticalErrorMessages.INVALID_FORMAT,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return errors;
|
|
29
|
+
}, [file, fileTypes, maxBytes]);
|
|
30
|
+
const hasCriticalErrors = !!errorMessages.criticalErrors.length;
|
|
31
|
+
return {
|
|
32
|
+
hasCriticalErrors,
|
|
33
|
+
errorMessages,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.useFileErrorMessages = useFileErrorMessages;
|
|
38
|
+
//# sourceMappingURL=useFileErrorMessages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileErrorMessages.cjs","sources":["../../../../../src/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { convertFileTypeToAcceptedFileType } from '../../utils/convertFileTypeToAcceptedFileType';\nimport { AcceptedFileTypes, CriticalErrorMessages, ErrorType } from '../../../UploadFile/constants';\n\ntype UploadFileErrors = {\n criticalErrors: Array<UploadFileError>;\n};\n\ntype UploadFileError = {\n errorType: ErrorType;\n errorMessage: string;\n};\n\ntype UseFileErrorMessagesProps = {\n file?: File | null;\n maxBytes: number;\n fileTypes: Array<AcceptedFileTypes>;\n};\n\nexport const useFileErrorMessages = ({ maxBytes, fileTypes, file }: UseFileErrorMessagesProps) => {\n const errorMessages = useMemo(() => {\n if (!file) return { criticalErrors: [] };\n\n const extension = convertFileTypeToAcceptedFileType(file.type);\n const isTypeValid = (fileTypes as string[]).includes(extension);\n const hasInvalidFormat = !isTypeValid;\n\n const hasExceededMaxSize = file.size > maxBytes;\n\n const errors: UploadFileErrors = { criticalErrors: [] };\n if (hasExceededMaxSize) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: CriticalErrorMessages.FILE_IS_TOO_BIG,\n });\n }\n if (hasInvalidFormat) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: CriticalErrorMessages.INVALID_FORMAT,\n });\n }\n return errors;\n }, [file, fileTypes, maxBytes]);\n\n const hasCriticalErrors = !!errorMessages.criticalErrors.length;\n\n return {\n hasCriticalErrors,\n errorMessages,\n };\n};\n"],"names":["useMemo","convertFileTypeToAcceptedFileType","ErrorType","CriticalErrorMessages"],"mappings":";;;;;;AAmBO,MAAM,oBAAoB,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAA6B,KAAI;AAC/F,IAAA,MAAM,aAAa,GAAGA,aAAO,CAAC,MAAK;AACjC,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE;QAExC,MAAM,SAAS,GAAGC,mEAAiC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9D,MAAM,WAAW,GAAI,SAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC/D,QAAA,MAAM,gBAAgB,GAAG,CAAC,WAAW;AAErC,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,GAAG,QAAQ;AAE/C,QAAA,MAAM,MAAM,GAAqB,EAAE,cAAc,EAAE,EAAE,EAAE;AACvD,QAAA,IAAI,kBAAkB,EAAE;AACtB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAEC,mBAAS,CAAC,QAAQ;gBAC7B,YAAY,EAAEC,+BAAqB,CAAC,eAAe;AACpD,aAAA,CAAC;AACH;AACD,QAAA,IAAI,gBAAgB,EAAE;AACpB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAED,mBAAS,CAAC,QAAQ;gBAC7B,YAAY,EAAEC,+BAAqB,CAAC,cAAc;AACnD,aAAA,CAAC;AACH;AACD,QAAA,OAAO,MAAM;KACd,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE/B,MAAM,iBAAiB,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM;IAE/D,OAAO;QACL,iBAAiB;QACjB,aAAa;KACd;AACH;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AcceptedFileTypes, ErrorType } from '../../../UploadFile/constants';
|
|
2
|
+
type UploadFileErrors = {
|
|
3
|
+
criticalErrors: Array<UploadFileError>;
|
|
4
|
+
};
|
|
5
|
+
type UploadFileError = {
|
|
6
|
+
errorType: ErrorType;
|
|
7
|
+
errorMessage: string;
|
|
8
|
+
};
|
|
9
|
+
type UseFileErrorMessagesProps = {
|
|
10
|
+
file?: File | null;
|
|
11
|
+
maxBytes: number;
|
|
12
|
+
fileTypes: Array<AcceptedFileTypes>;
|
|
13
|
+
};
|
|
14
|
+
export declare const useFileErrorMessages: ({ maxBytes, fileTypes, file }: UseFileErrorMessagesProps) => {
|
|
15
|
+
hasCriticalErrors: boolean;
|
|
16
|
+
errorMessages: UploadFileErrors;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { convertFileTypeToAcceptedFileType } from '../../utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.js';
|
|
3
|
+
import { ErrorType, CriticalErrorMessages } from '../../../UploadFile/constants.js';
|
|
4
|
+
|
|
5
|
+
const useFileErrorMessages = ({ maxBytes, fileTypes, file }) => {
|
|
6
|
+
const errorMessages = useMemo(() => {
|
|
7
|
+
if (!file)
|
|
8
|
+
return { criticalErrors: [] };
|
|
9
|
+
const extension = convertFileTypeToAcceptedFileType(file.type);
|
|
10
|
+
const isTypeValid = fileTypes.includes(extension);
|
|
11
|
+
const hasInvalidFormat = !isTypeValid;
|
|
12
|
+
const hasExceededMaxSize = file.size > maxBytes;
|
|
13
|
+
const errors = { criticalErrors: [] };
|
|
14
|
+
if (hasExceededMaxSize) {
|
|
15
|
+
errors.criticalErrors.push({
|
|
16
|
+
errorType: ErrorType.critical,
|
|
17
|
+
errorMessage: CriticalErrorMessages.FILE_IS_TOO_BIG,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (hasInvalidFormat) {
|
|
21
|
+
errors.criticalErrors.push({
|
|
22
|
+
errorType: ErrorType.critical,
|
|
23
|
+
errorMessage: CriticalErrorMessages.INVALID_FORMAT,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return errors;
|
|
27
|
+
}, [file, fileTypes, maxBytes]);
|
|
28
|
+
const hasCriticalErrors = !!errorMessages.criticalErrors.length;
|
|
29
|
+
return {
|
|
30
|
+
hasCriticalErrors,
|
|
31
|
+
errorMessages,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { useFileErrorMessages };
|
|
36
|
+
//# sourceMappingURL=useFileErrorMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileErrorMessages.js","sources":["../../../../../src/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { convertFileTypeToAcceptedFileType } from '../../utils/convertFileTypeToAcceptedFileType';\nimport { AcceptedFileTypes, CriticalErrorMessages, ErrorType } from '../../../UploadFile/constants';\n\ntype UploadFileErrors = {\n criticalErrors: Array<UploadFileError>;\n};\n\ntype UploadFileError = {\n errorType: ErrorType;\n errorMessage: string;\n};\n\ntype UseFileErrorMessagesProps = {\n file?: File | null;\n maxBytes: number;\n fileTypes: Array<AcceptedFileTypes>;\n};\n\nexport const useFileErrorMessages = ({ maxBytes, fileTypes, file }: UseFileErrorMessagesProps) => {\n const errorMessages = useMemo(() => {\n if (!file) return { criticalErrors: [] };\n\n const extension = convertFileTypeToAcceptedFileType(file.type);\n const isTypeValid = (fileTypes as string[]).includes(extension);\n const hasInvalidFormat = !isTypeValid;\n\n const hasExceededMaxSize = file.size > maxBytes;\n\n const errors: UploadFileErrors = { criticalErrors: [] };\n if (hasExceededMaxSize) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: CriticalErrorMessages.FILE_IS_TOO_BIG,\n });\n }\n if (hasInvalidFormat) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: CriticalErrorMessages.INVALID_FORMAT,\n });\n }\n return errors;\n }, [file, fileTypes, maxBytes]);\n\n const hasCriticalErrors = !!errorMessages.criticalErrors.length;\n\n return {\n hasCriticalErrors,\n errorMessages,\n };\n};\n"],"names":[],"mappings":";;;;AAmBO,MAAM,oBAAoB,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAA6B,KAAI;AAC/F,IAAA,MAAM,aAAa,GAAG,OAAO,CAAC,MAAK;AACjC,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE;QAExC,MAAM,SAAS,GAAG,iCAAiC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9D,MAAM,WAAW,GAAI,SAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC/D,QAAA,MAAM,gBAAgB,GAAG,CAAC,WAAW;AAErC,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,GAAG,QAAQ;AAE/C,QAAA,MAAM,MAAM,GAAqB,EAAE,cAAc,EAAE,EAAE,EAAE;AACvD,QAAA,IAAI,kBAAkB,EAAE;AACtB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAE,SAAS,CAAC,QAAQ;gBAC7B,YAAY,EAAE,qBAAqB,CAAC,eAAe;AACpD,aAAA,CAAC;AACH;AACD,QAAA,IAAI,gBAAgB,EAAE;AACpB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAE,SAAS,CAAC,QAAQ;gBAC7B,YAAY,EAAE,qBAAqB,CAAC,cAAc;AACnD,aAAA,CAAC;AACH;AACD,QAAA,OAAO,MAAM;KACd,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE/B,MAAM,iBAAiB,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM;IAE/D,OAAO;QACL,iBAAiB;QACjB,aAAa;KACd;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePreviewImage } from './usePreviewImage';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var isImageType = require('../../utils/isImageType/isImageType.cjs');
|
|
5
|
+
|
|
6
|
+
const usePreviewImage = ({ file }) => {
|
|
7
|
+
const [previewSrc, setPreviewSrc] = React.useState('');
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (!file) {
|
|
10
|
+
setPreviewSrc('');
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (!isImageType.isImageType(file)) {
|
|
14
|
+
setPreviewSrc('');
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const fileReader = new FileReader();
|
|
18
|
+
fileReader.onload = (event) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const imageUrl = (_a = event.target) === null || _a === undefined ? undefined : _a.result;
|
|
21
|
+
setPreviewSrc(String(imageUrl));
|
|
22
|
+
};
|
|
23
|
+
fileReader.readAsDataURL(file);
|
|
24
|
+
return () => {
|
|
25
|
+
fileReader.abort();
|
|
26
|
+
};
|
|
27
|
+
}, [file]);
|
|
28
|
+
const shouldShowPreview = file ? isImageType.isImageType(file) : false;
|
|
29
|
+
return {
|
|
30
|
+
previewSrc,
|
|
31
|
+
shouldShowPreview,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.usePreviewImage = usePreviewImage;
|
|
36
|
+
//# sourceMappingURL=usePreviewImage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviewImage.cjs","sources":["../../../../../src/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { isImageType } from '../../utils/isImageType';\n\ntype UsePreviewImageProps = {\n file?: File | null;\n};\n\nexport const usePreviewImage = ({ file }: UsePreviewImageProps) => {\n const [previewSrc, setPreviewSrc] = useState('');\n\n useEffect(() => {\n if (!file) {\n setPreviewSrc('');\n return undefined;\n }\n\n if (!isImageType(file)) {\n setPreviewSrc('');\n return undefined;\n }\n\n const fileReader = new FileReader();\n\n fileReader.onload = (event) => {\n const imageUrl = event.target?.result;\n setPreviewSrc(String(imageUrl));\n };\n\n fileReader.readAsDataURL(file);\n\n return () => {\n fileReader.abort();\n };\n }, [file]);\n\n const shouldShowPreview = file ? isImageType(file) : false;\n\n return {\n previewSrc,\n shouldShowPreview,\n };\n};\n"],"names":["useState","useEffect","isImageType"],"mappings":";;;;;MAOa,eAAe,GAAG,CAAC,EAAE,IAAI,EAAwB,KAAI;IAChE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC;IAEhDC,eAAS,CAAC,MAAK;QACb,IAAI,CAAC,IAAI,EAAE;YACT,aAAa,CAAC,EAAE,CAAC;AACjB,YAAA,OAAO,SAAS;AACjB;AAED,QAAA,IAAI,CAACC,uBAAW,CAAC,IAAI,CAAC,EAAE;YACtB,aAAa,CAAC,EAAE,CAAC;AACjB,YAAA,OAAO,SAAS;AACjB;AAED,QAAA,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE;AAEnC,QAAA,UAAU,CAAC,MAAM,GAAG,CAAC,KAAK,KAAI;;YAC5B,MAAM,QAAQ,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,MAAM,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,MAAM;AACrC,YAAA,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjC,SAAC;AAED,QAAA,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC;AAE9B,QAAA,OAAO,MAAK;YACV,UAAU,CAAC,KAAK,EAAE;AACpB,SAAC;AACH,KAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEV,IAAA,MAAM,iBAAiB,GAAG,IAAI,GAAGA,uBAAW,CAAC,IAAI,CAAC,GAAG,KAAK;IAE1D,OAAO;QACL,UAAU;QACV,iBAAiB;KAClB;AACH;;;;"}
|