@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.
Files changed (178) hide show
  1. package/dist/components/PhoneInput/PhoneInput.cjs +50 -0
  2. package/dist/components/PhoneInput/PhoneInput.cjs.map +1 -0
  3. package/dist/components/PhoneInput/PhoneInput.d.ts +3 -0
  4. package/dist/components/PhoneInput/PhoneInput.js +44 -0
  5. package/dist/components/PhoneInput/PhoneInput.js.map +1 -0
  6. package/dist/components/PhoneInput/PhoneInput.module.scss.cjs +9 -0
  7. package/dist/components/PhoneInput/PhoneInput.module.scss.cjs.map +1 -0
  8. package/dist/components/PhoneInput/PhoneInput.module.scss.js +7 -0
  9. package/dist/components/PhoneInput/PhoneInput.module.scss.js.map +1 -0
  10. package/dist/components/PhoneInput/components/SelectedCountry.cjs +18 -0
  11. package/dist/components/PhoneInput/components/SelectedCountry.cjs.map +1 -0
  12. package/dist/components/PhoneInput/components/SelectedCountry.d.ts +5 -0
  13. package/dist/components/PhoneInput/components/SelectedCountry.js +12 -0
  14. package/dist/components/PhoneInput/components/SelectedCountry.js.map +1 -0
  15. package/dist/components/PhoneInput/constants.cjs +1243 -0
  16. package/dist/components/PhoneInput/constants.cjs.map +1 -0
  17. package/dist/components/PhoneInput/constants.d.ts +4 -0
  18. package/dist/components/PhoneInput/constants.js +1239 -0
  19. package/dist/components/PhoneInput/constants.js.map +1 -0
  20. package/dist/components/PhoneInput/hooks/useApplyCountryCode.cjs +48 -0
  21. package/dist/components/PhoneInput/hooks/useApplyCountryCode.cjs.map +1 -0
  22. package/dist/components/PhoneInput/hooks/useApplyCountryCode.d.ts +11 -0
  23. package/dist/components/PhoneInput/hooks/useApplyCountryCode.js +46 -0
  24. package/dist/components/PhoneInput/hooks/useApplyCountryCode.js.map +1 -0
  25. package/dist/components/PhoneInput/index.cjs +11 -0
  26. package/dist/components/PhoneInput/index.cjs.map +1 -0
  27. package/dist/components/PhoneInput/index.d.ts +308 -0
  28. package/dist/components/PhoneInput/index.js +9 -0
  29. package/dist/components/PhoneInput/index.js.map +1 -0
  30. package/dist/components/PhoneInput/types.d.ts +25 -0
  31. package/dist/components/PhoneInput/utils/utils.cjs +69 -0
  32. package/dist/components/PhoneInput/utils/utils.cjs.map +1 -0
  33. package/dist/components/PhoneInput/utils/utils.d.ts +14 -0
  34. package/dist/components/PhoneInput/utils/utils.js +60 -0
  35. package/dist/components/PhoneInput/utils/utils.js.map +1 -0
  36. package/dist/components/SelectDropdown/SelectDropdown.cjs +2 -3
  37. package/dist/components/SelectDropdown/SelectDropdown.cjs.map +1 -1
  38. package/dist/components/SelectDropdown/SelectDropdown.d.ts +1 -1
  39. package/dist/components/SelectDropdown/SelectDropdown.js +2 -3
  40. package/dist/components/SelectDropdown/SelectDropdown.js.map +1 -1
  41. package/dist/components/SelectDropdown/components/ItemContent/ItemContent.cjs +2 -2
  42. package/dist/components/SelectDropdown/components/ItemContent/ItemContent.cjs.map +1 -1
  43. package/dist/components/SelectDropdown/components/ItemContent/ItemContent.d.ts +1 -1
  44. package/dist/components/SelectDropdown/components/ItemContent/ItemContent.js +2 -2
  45. package/dist/components/SelectDropdown/components/ItemContent/ItemContent.js.map +1 -1
  46. package/dist/components/SelectDropdown/components/ItemContent/SelectionType.cjs +5 -3
  47. package/dist/components/SelectDropdown/components/ItemContent/SelectionType.cjs.map +1 -1
  48. package/dist/components/SelectDropdown/components/ItemContent/SelectionType.d.ts +2 -1
  49. package/dist/components/SelectDropdown/components/ItemContent/SelectionType.js +5 -3
  50. package/dist/components/SelectDropdown/components/ItemContent/SelectionType.js.map +1 -1
  51. package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs +2 -2
  52. package/dist/components/SelectDropdown/components/ListItem/ListItem.cjs.map +1 -1
  53. package/dist/components/SelectDropdown/components/ListItem/ListItem.d.ts +1 -1
  54. package/dist/components/SelectDropdown/components/ListItem/ListItem.js +2 -2
  55. package/dist/components/SelectDropdown/components/ListItem/ListItem.js.map +1 -1
  56. package/dist/components/SelectDropdown/components/types.d.ts +1 -0
  57. package/dist/components/SelectDropdown/types.d.ts +2 -1
  58. package/dist/components/UploadFile/UploadFile.cjs +64 -83
  59. package/dist/components/UploadFile/UploadFile.cjs.map +1 -1
  60. package/dist/components/UploadFile/UploadFile.js +67 -86
  61. package/dist/components/UploadFile/UploadFile.js.map +1 -1
  62. package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs +28 -0
  63. package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs.map +1 -0
  64. package/dist/components/UploadFile/components/DropCopy/DropCopy.d.ts +2 -0
  65. package/dist/components/UploadFile/components/DropCopy/DropCopy.js +22 -0
  66. package/dist/components/UploadFile/components/DropCopy/DropCopy.js.map +1 -0
  67. package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs +6 -6
  68. package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs.map +1 -1
  69. package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js +6 -6
  70. package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js.map +1 -1
  71. package/dist/components/UploadFile/constants.cjs +71 -8
  72. package/dist/components/UploadFile/constants.cjs.map +1 -1
  73. package/dist/components/UploadFile/constants.d.ts +57 -5
  74. package/dist/components/UploadFile/constants.js +69 -9
  75. package/dist/components/UploadFile/constants.js.map +1 -1
  76. package/dist/components/UploadFile/hooks/useUploadFile/index.d.ts +1 -0
  77. package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs +65 -0
  78. package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs.map +1 -0
  79. package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.d.ts +9 -0
  80. package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js +63 -0
  81. package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js.map +1 -0
  82. package/dist/components/UploadFile/hooks/useValidateInput/index.d.ts +1 -0
  83. package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs +48 -0
  84. package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs.map +1 -0
  85. package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.d.ts +11 -0
  86. package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js +46 -0
  87. package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js.map +1 -0
  88. package/dist/components/UploadFile/index.d.ts +0 -1
  89. package/dist/components/UploadFile/mocks/files.d.ts +2 -0
  90. package/dist/components/UploadFile/mocks/mockUseUploadFile.d.ts +14 -0
  91. package/dist/components/UploadFile/mocks/utils.d.ts +1 -2
  92. package/dist/components/UploadFile/styled.cjs +40 -1
  93. package/dist/components/UploadFile/styled.cjs.map +1 -1
  94. package/dist/components/UploadFile/styled.d.ts +4 -1
  95. package/dist/components/UploadFile/styled.js +40 -1
  96. package/dist/components/UploadFile/styled.js.map +1 -1
  97. package/dist/components/UploadFile/types.d.ts +15 -1
  98. package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.cjs +27 -0
  99. package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.cjs.map +1 -0
  100. package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.d.ts +8 -0
  101. package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.js +25 -0
  102. package/dist/components/UploadFile/utils/getErrorMessage/getErrorMessage.js.map +1 -0
  103. package/dist/components/UploadFile/utils/getErrorMessage/index.d.ts +1 -0
  104. package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs +14 -11
  105. package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs.map +1 -1
  106. package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.d.ts +10 -7
  107. package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js +14 -11
  108. package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js.map +1 -1
  109. package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs +16 -30
  110. package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs.map +1 -1
  111. package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js +16 -30
  112. package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js.map +1 -1
  113. package/dist/components/UploadFile/utils/index.d.ts +0 -1
  114. package/dist/components/UploadedFile/UploadedFile.cjs +78 -0
  115. package/dist/components/UploadedFile/UploadedFile.cjs.map +1 -0
  116. package/dist/components/UploadedFile/UploadedFile.d.ts +12 -0
  117. package/dist/components/UploadedFile/UploadedFile.js +72 -0
  118. package/dist/components/UploadedFile/UploadedFile.js.map +1 -0
  119. package/dist/components/UploadedFile/UploadedFile.module.scss.cjs +9 -0
  120. package/dist/components/UploadedFile/UploadedFile.module.scss.cjs.map +1 -0
  121. package/dist/components/UploadedFile/UploadedFile.module.scss.js +7 -0
  122. package/dist/components/UploadedFile/UploadedFile.module.scss.js.map +1 -0
  123. package/dist/components/UploadedFile/hooks/useFileErrorMessages/index.d.ts +1 -0
  124. package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs +38 -0
  125. package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs.map +1 -0
  126. package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.d.ts +18 -0
  127. package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.js +36 -0
  128. package/dist/components/UploadedFile/hooks/useFileErrorMessages/useFileErrorMessages.js.map +1 -0
  129. package/dist/components/UploadedFile/hooks/usePreviewImage/index.d.ts +1 -0
  130. package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.cjs +36 -0
  131. package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.cjs.map +1 -0
  132. package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.d.ts +8 -0
  133. package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.js +34 -0
  134. package/dist/components/UploadedFile/hooks/usePreviewImage/usePreviewImage.js.map +1 -0
  135. package/dist/components/UploadedFile/index.d.ts +1 -0
  136. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.cjs +17 -0
  137. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.cjs.map +1 -0
  138. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.d.ts +1 -0
  139. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.js +15 -0
  140. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/convertFileTypeToAcceptedFileType.js.map +1 -0
  141. package/dist/components/UploadedFile/utils/convertFileTypeToAcceptedFileType/index.d.ts +1 -0
  142. package/dist/components/UploadedFile/utils/isImageType/index.d.ts +1 -0
  143. package/dist/components/UploadedFile/utils/isImageType/isImageType.cjs +14 -0
  144. package/dist/components/UploadedFile/utils/isImageType/isImageType.cjs.map +1 -0
  145. package/dist/components/UploadedFile/utils/isImageType/isImageType.d.ts +1 -0
  146. package/dist/components/UploadedFile/utils/isImageType/isImageType.js +12 -0
  147. package/dist/components/UploadedFile/utils/isImageType/isImageType.js.map +1 -0
  148. package/dist/components/index.d.ts +4 -1
  149. package/dist/index.cjs +6 -2
  150. package/dist/index.cjs.map +1 -1
  151. package/dist/index.js +2 -0
  152. package/dist/index.js.map +1 -1
  153. package/package.json +1 -1
  154. package/dist/components/UploadFile/UploadGraphic.cjs +0 -14
  155. package/dist/components/UploadFile/UploadGraphic.cjs.map +0 -1
  156. package/dist/components/UploadFile/UploadGraphic.d.ts +0 -2
  157. package/dist/components/UploadFile/UploadGraphic.js +0 -8
  158. package/dist/components/UploadFile/UploadGraphic.js.map +0 -1
  159. package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs +0 -31
  160. package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs.map +0 -1
  161. package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.d.ts +0 -7
  162. package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js +0 -25
  163. package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js.map +0 -1
  164. package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs +0 -21
  165. package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs.map +0 -1
  166. package/dist/components/UploadFile/components/UploadedFile/UploadedFile.d.ts +0 -8
  167. package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js +0 -15
  168. package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js.map +0 -1
  169. package/dist/components/UploadFile/components/UploadedFile/styled.cjs +0 -20
  170. package/dist/components/UploadFile/components/UploadedFile/styled.cjs.map +0 -1
  171. package/dist/components/UploadFile/components/UploadedFile/styled.d.ts +0 -2
  172. package/dist/components/UploadFile/components/UploadedFile/styled.js +0 -13
  173. package/dist/components/UploadFile/components/UploadedFile/styled.js.map +0 -1
  174. package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs +0 -18
  175. package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs.map +0 -1
  176. package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.d.ts +0 -13
  177. package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js +0 -16
  178. package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js.map +0 -1
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var constants = require('../../constants.cjs');
5
+ var getErrorMessage = require('../../utils/getErrorMessage/getErrorMessage.cjs');
6
+
7
+ const useValidateInput = ({ fileList, fileTypes, inputRef, maxBytes, errorMessage: customErrorMessage, }) => {
8
+ // Tracks error states within the input element itself, using preset
9
+ // error messages and assigns these to the input component based on the file
10
+ const setInputValidation = React.useCallback(() => {
11
+ var _a, _b, _c, _d;
12
+ let errorMessage = customErrorMessage || constants.InputErrorStateMessages.VALID;
13
+ if (!((_b = (_a = inputRef.current) === null || _a === undefined ? undefined : _a.files) === null || _b === undefined ? undefined : _b.length)) {
14
+ (_c = inputRef.current) === null || _c === undefined ? undefined : _c.setCustomValidity(errorMessage);
15
+ return;
16
+ }
17
+ const results = {
18
+ numberOfInvalidFormatFiles: 0,
19
+ numberOfInvalidSizeFiles: 0,
20
+ totalFiles: inputRef.current.files.length,
21
+ };
22
+ Array.from(inputRef.current.files).forEach((file) => {
23
+ // Check file size
24
+ if (file.size > maxBytes) {
25
+ results.numberOfInvalidSizeFiles += 1;
26
+ }
27
+ // Check file type/format
28
+ const [, extension] = file.type.split('/');
29
+ const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
30
+ if (!isTypeValid) {
31
+ results.numberOfInvalidFormatFiles += 1;
32
+ }
33
+ });
34
+ // Determine appropriate error message based on validation results
35
+ const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;
36
+ const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;
37
+ const isSingleFile = results.totalFiles === 1;
38
+ errorMessage = getErrorMessage.getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile });
39
+ (_d = inputRef.current) === null || _d === undefined ? undefined : _d.setCustomValidity(errorMessage);
40
+ }, [customErrorMessage, inputRef, maxBytes, fileTypes]);
41
+ // Validate input whenever fileList changes
42
+ React.useEffect(() => {
43
+ setInputValidation();
44
+ }, [fileList, setInputValidation, customErrorMessage]);
45
+ };
46
+
47
+ exports.useValidateInput = useValidateInput;
48
+ //# sourceMappingURL=useValidateInput.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useValidateInput.cjs","sources":["../../../../../src/components/UploadFile/hooks/useValidateInput/useValidateInput.ts"],"sourcesContent":["import { useEffect, useCallback } from 'react';\nimport { AcceptedFileTypes, InputErrorStateMessages } from '../../constants';\nimport { getErrorMessage } from '../../utils/getErrorMessage';\n\ntype UseValidateInputProps = {\n fileTypes: Array<AcceptedFileTypes>;\n maxBytes: number;\n fileList: FileList | undefined;\n inputRef: React.MutableRefObject<HTMLInputElement | null>;\n errorMessage?: string;\n};\n\nexport const useValidateInput = ({\n fileList,\n fileTypes,\n inputRef,\n maxBytes,\n errorMessage: customErrorMessage,\n}: UseValidateInputProps) => {\n // Tracks error states within the input element itself, using preset\n // error messages and assigns these to the input component based on the file\n const setInputValidation = useCallback(() => {\n let errorMessage = customErrorMessage || InputErrorStateMessages.VALID;\n\n if (!inputRef.current?.files?.length) {\n inputRef.current?.setCustomValidity(errorMessage);\n return;\n }\n\n const results = {\n numberOfInvalidFormatFiles: 0,\n numberOfInvalidSizeFiles: 0,\n totalFiles: inputRef.current.files.length,\n };\n\n Array.from(inputRef.current.files).forEach((file) => {\n // Check file size\n if (file.size > maxBytes) {\n results.numberOfInvalidSizeFiles += 1;\n }\n\n // Check file type/format\n const [, extension] = file.type.split('/');\n const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);\n if (!isTypeValid) {\n results.numberOfInvalidFormatFiles += 1;\n }\n });\n\n // Determine appropriate error message based on validation results\n const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;\n const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;\n const isSingleFile = results.totalFiles === 1;\n\n errorMessage = getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile });\n\n inputRef.current?.setCustomValidity(errorMessage);\n }, [customErrorMessage, inputRef, maxBytes, fileTypes]);\n\n // Validate input whenever fileList changes\n useEffect(() => {\n setInputValidation();\n }, [fileList, setInputValidation, customErrorMessage]);\n};\n"],"names":["useCallback","InputErrorStateMessages","getErrorMessage","useEffect"],"mappings":";;;;;;AAYa,MAAA,gBAAgB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EAAE,kBAAkB,GACV,KAAI;;;AAG1B,IAAA,MAAM,kBAAkB,GAAGA,iBAAW,CAAC,MAAK;;AAC1C,QAAA,IAAI,YAAY,GAAG,kBAAkB,IAAIC,iCAAuB,CAAC,KAAK;AA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GAAG,OAAO,CAAC,UAAU,KAAK,CAAC;QAE7C,YAAY,GAAGC,+BAAe,CAAC,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;QAEhF,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAAC;KAClD,EAAE,CAAC,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;IAGvDC,eAAS,CAAC,MAAK;AACb,QAAA,kBAAkB,EAAE;KACrB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AACxD;;;;"}
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { AcceptedFileTypes } from '../../constants';
3
+ type UseValidateInputProps = {
4
+ fileTypes: Array<AcceptedFileTypes>;
5
+ maxBytes: number;
6
+ fileList: FileList | undefined;
7
+ inputRef: React.MutableRefObject<HTMLInputElement | null>;
8
+ errorMessage?: string;
9
+ };
10
+ export declare const useValidateInput: ({ fileList, fileTypes, inputRef, maxBytes, errorMessage: customErrorMessage, }: UseValidateInputProps) => void;
11
+ export {};
@@ -0,0 +1,46 @@
1
+ import { useCallback, useEffect } from 'react';
2
+ import { InputErrorStateMessages } from '../../constants.js';
3
+ import { getErrorMessage } from '../../utils/getErrorMessage/getErrorMessage.js';
4
+
5
+ const useValidateInput = ({ fileList, fileTypes, inputRef, maxBytes, errorMessage: customErrorMessage, }) => {
6
+ // Tracks error states within the input element itself, using preset
7
+ // error messages and assigns these to the input component based on the file
8
+ const setInputValidation = useCallback(() => {
9
+ var _a, _b, _c, _d;
10
+ let errorMessage = customErrorMessage || InputErrorStateMessages.VALID;
11
+ if (!((_b = (_a = inputRef.current) === null || _a === undefined ? undefined : _a.files) === null || _b === undefined ? undefined : _b.length)) {
12
+ (_c = inputRef.current) === null || _c === undefined ? undefined : _c.setCustomValidity(errorMessage);
13
+ return;
14
+ }
15
+ const results = {
16
+ numberOfInvalidFormatFiles: 0,
17
+ numberOfInvalidSizeFiles: 0,
18
+ totalFiles: inputRef.current.files.length,
19
+ };
20
+ Array.from(inputRef.current.files).forEach((file) => {
21
+ // Check file size
22
+ if (file.size > maxBytes) {
23
+ results.numberOfInvalidSizeFiles += 1;
24
+ }
25
+ // Check file type/format
26
+ const [, extension] = file.type.split('/');
27
+ const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
28
+ if (!isTypeValid) {
29
+ results.numberOfInvalidFormatFiles += 1;
30
+ }
31
+ });
32
+ // Determine appropriate error message based on validation results
33
+ const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;
34
+ const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;
35
+ const isSingleFile = results.totalFiles === 1;
36
+ errorMessage = getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile });
37
+ (_d = inputRef.current) === null || _d === undefined ? undefined : _d.setCustomValidity(errorMessage);
38
+ }, [customErrorMessage, inputRef, maxBytes, fileTypes]);
39
+ // Validate input whenever fileList changes
40
+ useEffect(() => {
41
+ setInputValidation();
42
+ }, [fileList, setInputValidation, customErrorMessage]);
43
+ };
44
+
45
+ export { useValidateInput };
46
+ //# sourceMappingURL=useValidateInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useValidateInput.js","sources":["../../../../../src/components/UploadFile/hooks/useValidateInput/useValidateInput.ts"],"sourcesContent":["import { useEffect, useCallback } from 'react';\nimport { AcceptedFileTypes, InputErrorStateMessages } from '../../constants';\nimport { getErrorMessage } from '../../utils/getErrorMessage';\n\ntype UseValidateInputProps = {\n fileTypes: Array<AcceptedFileTypes>;\n maxBytes: number;\n fileList: FileList | undefined;\n inputRef: React.MutableRefObject<HTMLInputElement | null>;\n errorMessage?: string;\n};\n\nexport const useValidateInput = ({\n fileList,\n fileTypes,\n inputRef,\n maxBytes,\n errorMessage: customErrorMessage,\n}: UseValidateInputProps) => {\n // Tracks error states within the input element itself, using preset\n // error messages and assigns these to the input component based on the file\n const setInputValidation = useCallback(() => {\n let errorMessage = customErrorMessage || InputErrorStateMessages.VALID;\n\n if (!inputRef.current?.files?.length) {\n inputRef.current?.setCustomValidity(errorMessage);\n return;\n }\n\n const results = {\n numberOfInvalidFormatFiles: 0,\n numberOfInvalidSizeFiles: 0,\n totalFiles: inputRef.current.files.length,\n };\n\n Array.from(inputRef.current.files).forEach((file) => {\n // Check file size\n if (file.size > maxBytes) {\n results.numberOfInvalidSizeFiles += 1;\n }\n\n // Check file type/format\n const [, extension] = file.type.split('/');\n const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);\n if (!isTypeValid) {\n results.numberOfInvalidFormatFiles += 1;\n }\n });\n\n // Determine appropriate error message based on validation results\n const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;\n const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;\n const isSingleFile = results.totalFiles === 1;\n\n errorMessage = getErrorMessage({ hasFormatErrors, hasSizeErrors, isSingleFile });\n\n inputRef.current?.setCustomValidity(errorMessage);\n }, [customErrorMessage, inputRef, maxBytes, fileTypes]);\n\n // Validate input whenever fileList changes\n useEffect(() => {\n setInputValidation();\n }, [fileList, setInputValidation, customErrorMessage]);\n};\n"],"names":[],"mappings":";;;;AAYa,MAAA,gBAAgB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EAAE,kBAAkB,GACV,KAAI;;;AAG1B,IAAA,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAK;;AAC1C,QAAA,IAAI,YAAY,GAAG,kBAAkB,IAAI,uBAAuB,CAAC,KAAK;AAEtE,QAAA,IAAI,EAAC,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,KAAK,MAAA,IAAA,IAAA,EAA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IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAAC;KAClD,EAAE,CAAC,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;IAGvD,SAAS,CAAC,MAAK;AACb,QAAA,kBAAkB,EAAE;KACrB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AACxD;;;;"}
@@ -1,2 +1 @@
1
1
  export { UploadFile } from './UploadFile';
2
- export { AcceptedFileTypes, FileSizeUnit } from './constants';
@@ -1,2 +1,4 @@
1
1
  export declare const mockImageFile: File;
2
2
  export declare const mockCsvFile: File;
3
+ export declare const mockOtherCsvFile: File;
4
+ export declare const mockAnotherCsvFile: File;
@@ -0,0 +1,14 @@
1
+ /// <reference types="jest" />
2
+ export declare const mockUseRemoveUploadFile: () => {
3
+ mockRemoveFileFromList: jest.Mock<any, any, any>;
4
+ };
5
+ export declare const mockUseUploadFile: () => {
6
+ mockRemoveFileFromList: jest.Mock<any, any, any>;
7
+ mockClearFileSelection: jest.Mock<any, any, any>;
8
+ mockInputRef: {
9
+ current: null;
10
+ };
11
+ mockOnCancel: jest.Mock<any, any, any>;
12
+ mockSetFileList: jest.Mock<any, any, any>;
13
+ mockFileList: undefined;
14
+ };
@@ -4,7 +4,6 @@ type MockHelperProps = {
4
4
  };
5
5
  export declare const mockDrop: ({ file, label }: MockHelperProps) => void;
6
6
  export declare const mockDragOver: ({ file, label }: MockHelperProps) => void;
7
- export declare const getDefaultInput: () => HTMLElement;
7
+ export declare const getDefaultInput: () => HTMLInputElement;
8
8
  export declare const getStyledDropzoneContainer: () => HTMLElement;
9
- export declare const getUploadGraphic: () => HTMLElement;
10
9
  export {};
@@ -9,7 +9,46 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
9
9
 
10
10
  var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
11
11
 
12
- const DropZoneContainer = styled__default.default.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.sizes.md};border-radius:${radius.radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.colors.neutral.ink.lightest};background-color:${colors.colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.colors.secondary.blue.base};background-color:${colors.colors.secondary.blue.lightest};}:active{border:2px dashed ${colors.colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.colors.secondary.blue.light};background-color:${colors.colors.secondary.blue.lightest};}:focus-within{border:2px dashed ${colors.colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.colors.secondary.blue.light};background-color:${colors.colors.secondary.blue.lightest};}&:has(input:invalid){border:2px dashed ${colors.colors.secondary.red.base};:hover{border:2px dashed ${colors.colors.secondary.red.base};background-color:${colors.colors.secondary.red.lightest};}:active{border:2px dashed ${colors.colors.secondary.red.base};box-shadow:0 0 0 4px ${colors.colors.secondary.red.light};background-color:${colors.colors.secondary.red.lightest};}:focus-within{border:2px dashed ${colors.colors.secondary.red.base};box-shadow:0 0 0 4px ${colors.colors.secondary.red.light};background-color:${colors.colors.secondary.red.lightest};}}&:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.colors.neutral.grey.light};border-color:${colors.colors.neutral.ink.lightest};color:${colors.colors.neutral.ink.light};}`;
12
+ const DropZoneContainer = styled__default.default.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.sizes.base};border-radius:${radius.radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.colors.neutral.ink.lightest};background-color:${colors.colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.colors.secondary.blue.base};background-color:${colors.colors.secondary.blue.lightest};svg{color:${colors.colors.secondary.blue.base};}}:active,:focus-within{border:2px dashed ${colors.colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.colors.secondary.blue.light};background-color:${colors.colors.secondary.blue.lightest};svg{color:${colors.colors.secondary.blue.base};}}${({ isDragOver }) => isDragOver &&
13
+ `
14
+ border: 2px dashed ${colors.colors.secondary.blue.base};
15
+ box-shadow: 0 0 0 4px ${colors.colors.secondary.blue.light};
16
+ background-color: ${colors.colors.secondary.blue.lightest};
17
+
18
+ svg {
19
+ color: ${colors.colors.secondary.blue.base};
20
+ }
21
+ `} ${({ hasError, isDragOver }) => hasError &&
22
+ `
23
+ border: 2px dashed ${colors.colors.secondary.red.base};
24
+
25
+ :hover {
26
+ border: 2px dashed ${colors.colors.secondary.red.base};
27
+ background-color: ${colors.colors.secondary.red.lightest};
28
+
29
+ svg {
30
+ color: ${colors.colors.secondary.red.base};
31
+ }
32
+ }
33
+
34
+ :active, :focus-within {
35
+ border: 2px dashed ${colors.colors.secondary.red.base};
36
+ box-shadow: 0 0 0 4px ${colors.colors.secondary.red.light};
37
+ background-color: ${colors.colors.secondary.red.lightest};
38
+
39
+ svg {
40
+ color: ${colors.colors.secondary.red.base};
41
+ }
42
+ }
43
+
44
+ ${isDragOver
45
+ ? `
46
+ border: 2px dashed ${colors.colors.secondary.red.base};
47
+ box-shadow: 0 0 0 4px ${colors.colors.secondary.red.light};
48
+ background-color: ${colors.colors.secondary.red.lightest};
49
+ `
50
+ : ''}
51
+ `} &:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.colors.neutral.grey.light};border-color:${colors.colors.neutral.ink.lightest};color:${colors.colors.neutral.ink.light};svg{color:${colors.colors.neutral.ink.lightest};}}`;
13
52
 
14
53
  exports.DropZoneContainer = DropZoneContainer;
15
54
  //# sourceMappingURL=styled.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"styled.cjs","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.md};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n }\n :active {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n }\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n }\n\n &:has(input:invalid) {\n border: 2px dashed ${colors.secondary.red.base};\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n }\n\n :active {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n }\n\n :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n }\n }\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n }\n`;\n"],"names":["styled","sizes","radius","colors"],"mappings":";;;;;;;;;;;MAKa,iBAAiB,GAAGA,uBAAM,CAAC,GAAG,sJAK9BC,WAAK,CAAC,EAAE,CACF,eAAA,EAAAC,aAAM,CAAC,IAAI,CAAA,sHAAA,EAYPC,aAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,kBAAA,EAAAA,aAAM,CAA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EAAA;;;;"}
1
+ {"version":3,"file":"styled.cjs","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div<{\n hasError: boolean;\n isDragOver?: boolean;\n}>`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.base};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n :active,\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n\n ${({ isDragOver }) =>\n isDragOver &&\n `\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n `}\n\n ${({ hasError, isDragOver }) =>\n hasError &&\n `\n border: 2px dashed ${colors.secondary.red.base};\n\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n :active, :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n ${\n isDragOver\n ? `\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n `\n : ''\n }\n `}\n\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n\n svg {\n color: ${colors.neutral.ink.lightest};\n }\n }\n`;\n"],"names":["styled","sizes","radius","colors"],"mappings":";;;;;;;;;;;MAKa,iBAAiB,GAAGA,uBAAM,CAAC,GAAG,sJAQ9BC,WAAK,CAAC,IAAI,CACJ,eAAA,EAAAC,aAAM,CAAC,IAAI,CAAA,sHAAA,EAYPC,aAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,kBAAA,EAAAA,aAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,6BAGzBA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,kBAAA,EAC3BA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,cAGvCA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,2CAAA,EAKhBA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CACvB,sBAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA,kBAAA,EAC/BA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAGvC,WAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAIrC,CAAC,EAAE,UAAU,EAAE,KACf,UAAU;AACV,IAAA;AACqB,uBAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA;AACvB,0BAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA;AAC/B,sBAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;;;AAGvC,aAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAA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const DropZoneContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
1
+ export declare const DropZoneContainer: import("styled-components").StyledComponent<"div", any, {
2
+ hasError: boolean;
3
+ isDragOver?: boolean | undefined;
4
+ }, never>;
@@ -3,7 +3,46 @@ import { colors } from '../../theme/modules/colors.js';
3
3
  import { radius } from '../../theme/modules/radius.js';
4
4
  import { sizes } from '../../theme/modules/sizes.js';
5
5
 
6
- const DropZoneContainer = styled.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.md};border-radius:${radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.neutral.ink.lightest};background-color:${colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.secondary.blue.base};background-color:${colors.secondary.blue.lightest};}:active{border:2px dashed ${colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.secondary.blue.light};background-color:${colors.secondary.blue.lightest};}:focus-within{border:2px dashed ${colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.secondary.blue.light};background-color:${colors.secondary.blue.lightest};}&:has(input:invalid){border:2px dashed ${colors.secondary.red.base};:hover{border:2px dashed ${colors.secondary.red.base};background-color:${colors.secondary.red.lightest};}:active{border:2px dashed ${colors.secondary.red.base};box-shadow:0 0 0 4px ${colors.secondary.red.light};background-color:${colors.secondary.red.lightest};}:focus-within{border:2px dashed ${colors.secondary.red.base};box-shadow:0 0 0 4px ${colors.secondary.red.light};background-color:${colors.secondary.red.lightest};}}&:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.neutral.grey.light};border-color:${colors.neutral.ink.lightest};color:${colors.neutral.ink.light};}`;
6
+ const DropZoneContainer = styled.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.base};border-radius:${radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.neutral.ink.lightest};background-color:${colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.secondary.blue.base};background-color:${colors.secondary.blue.lightest};svg{color:${colors.secondary.blue.base};}}:active,:focus-within{border:2px dashed ${colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.secondary.blue.light};background-color:${colors.secondary.blue.lightest};svg{color:${colors.secondary.blue.base};}}${({ isDragOver }) => isDragOver &&
7
+ `
8
+ border: 2px dashed ${colors.secondary.blue.base};
9
+ box-shadow: 0 0 0 4px ${colors.secondary.blue.light};
10
+ background-color: ${colors.secondary.blue.lightest};
11
+
12
+ svg {
13
+ color: ${colors.secondary.blue.base};
14
+ }
15
+ `} ${({ hasError, isDragOver }) => hasError &&
16
+ `
17
+ border: 2px dashed ${colors.secondary.red.base};
18
+
19
+ :hover {
20
+ border: 2px dashed ${colors.secondary.red.base};
21
+ background-color: ${colors.secondary.red.lightest};
22
+
23
+ svg {
24
+ color: ${colors.secondary.red.base};
25
+ }
26
+ }
27
+
28
+ :active, :focus-within {
29
+ border: 2px dashed ${colors.secondary.red.base};
30
+ box-shadow: 0 0 0 4px ${colors.secondary.red.light};
31
+ background-color: ${colors.secondary.red.lightest};
32
+
33
+ svg {
34
+ color: ${colors.secondary.red.base};
35
+ }
36
+ }
37
+
38
+ ${isDragOver
39
+ ? `
40
+ border: 2px dashed ${colors.secondary.red.base};
41
+ box-shadow: 0 0 0 4px ${colors.secondary.red.light};
42
+ background-color: ${colors.secondary.red.lightest};
43
+ `
44
+ : ''}
45
+ `} &:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.neutral.grey.light};border-color:${colors.neutral.ink.lightest};color:${colors.neutral.ink.light};svg{color:${colors.neutral.ink.lightest};}}`;
7
46
 
8
47
  export { DropZoneContainer };
9
48
  //# sourceMappingURL=styled.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styled.js","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.md};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n }\n :active {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n }\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n }\n\n &:has(input:invalid) {\n border: 2px dashed ${colors.secondary.red.base};\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n }\n\n :active {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n }\n\n :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n }\n }\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n }\n`;\n"],"names":[],"mappings":";;;;;MAKa,iBAAiB,GAAG,MAAM,CAAC,GAAG,sJAK9B,KAAK,CAAC,EAAE,CACF,eAAA,EAAA,MAAM,CAAC,IAAI,CAAA,sHAAA,EAYP,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,k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AA;;;;"}
1
+ {"version":3,"file":"styled.js","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div<{\n hasError: boolean;\n isDragOver?: boolean;\n}>`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.base};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n :active,\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n\n ${({ isDragOver }) =>\n isDragOver &&\n `\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n `}\n\n ${({ hasError, isDragOver }) =>\n hasError &&\n `\n border: 2px dashed ${colors.secondary.red.base};\n\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n :active, :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n ${\n isDragOver\n ? `\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n `\n : ''\n }\n `}\n\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n\n svg {\n color: ${colors.neutral.ink.lightest};\n }\n }\n`;\n"],"names":[],"mappings":";;;;;MAKa,iBAAiB,GAAG,MAAM,CAAC,GAAG,sJAQ9B,KAAK,CAAC,IAAI,CACJ,eAAA,EAAA,MAAM,CAAC,IAAI,CAAA,sHAAA,EAYP,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,kBAAA,EAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,6BAGzB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,kBAAA,EAC3B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,cAGvC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,2CAAA,EAKhB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CACvB,sBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA,kBAAA,EAC/B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAGvC,WAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAIrC,CAAC,EAAE,UAAU,EAAE,KACf,UAAU;AACV,IAAA;AACqB,uBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA;AACvB,0BAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA;AAC/B,sBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;;;AAGvC,aAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA;;GAEtC,CAEC,CAAA,EAAA,C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ileTypes, 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
- * Constructs a string intended to be consumed by an <input> element of type "file". This string
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: 10000,
11
+ * maxBytes: 10000000,
13
12
  * format: FileSizeUnit.MB
14
13
  * });
15
14
  *
16
- * Where @constant maxSizeCopy would equal "Max size: 1 MB"
15
+ * Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
17
16
  *
18
- * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes
19
- * the returned string
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 == null ? 'Max size: ' : 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}${Number(maxBytes) / 1000} KB`;
28
+ return `${base}${getValue(1000)} KB`;
26
29
  case constants.FileSizeUnit.MB:
27
- return `${base}${Number(maxBytes) / 1000000} MB`;
30
+ return `${base}${getValue(1000000)} MB`;
28
31
  default:
29
- return `${base}${Number(maxBytes) / 1000} KB`;
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 * Constructs a string intended to be consumed by an <input> element of type \"file\". This string\n * should go inside the accept property \n *\n * E.g.\n *\n * const maxSizeCopy = getFileSizeString({\n * maxBytes: 10000,\n * format: FileSizeUnit.MB\n * });\n *\n * Where @constant maxSizeCopy would equal \"Max size: 1 MB\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * the returned string\n */\nexport const getFileSizeString = ({ maxBytes, format, baseString }: GetFileSizeStringProps) => {\n const base = baseString == null ? 'Max size: ' : baseString;\n switch (format) {\n case FileSizeUnit.KB:\n return `${base}${Number(maxBytes) / 1000} KB`;\n case FileSizeUnit.MB:\n return `${base}${Number(maxBytes) / 1000000} MB`;\n default:\n return `${base}${Number(maxBytes) / 1000} KB`;\n }\n};\n"],"names":["FileSizeUnit"],"mappings":";;;;AAOA;;;;;;;;;;;;;;;AAeG;AACI,MAAM,iBAAiB,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAA0B,KAAI;AAC5F,IAAA,MAAM,IAAI,GAAG,UAAU,IAAI,IAAI,GAAG,YAAY,GAAG,UAAU;AAC3D,IAAA,QAAQ,MAAM;QACZ,KAAKA,sBAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA,GAAA,CAAK;QAC/C,KAAKA,sBAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAA,GAAA,CAAK;AAClD,QAAA;YACE,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA,GAAA,CAAK;AAChD;AACH;;;;"}
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
- * Constructs a string intended to be consumed by an <input> element of type "file". This string
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: 10000,
14
+ * maxBytes: 10000000,
15
15
  * format: FileSizeUnit.MB
16
16
  * });
17
17
  *
18
- * Where @constant maxSizeCopy would equal "Max size: 1 MB"
18
+ * Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
19
19
  *
20
- * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes
21
- * the returned string
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
- * Constructs a string intended to be consumed by an <input> element of type "file". This string
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: 10000,
9
+ * maxBytes: 10000000,
11
10
  * format: FileSizeUnit.MB
12
11
  * });
13
12
  *
14
- * Where @constant maxSizeCopy would equal "Max size: 1 MB"
13
+ * Where @constant maxSizeCopy would equal "Maximum file size: 10 MB"
15
14
  *
16
- * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes
17
- * the returned string
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 == null ? 'Max size: ' : 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}${Number(maxBytes) / 1000} KB`;
26
+ return `${base}${getValue(1000)} KB`;
24
27
  case FileSizeUnit.MB:
25
- return `${base}${Number(maxBytes) / 1000000} MB`;
28
+ return `${base}${getValue(1000000)} MB`;
26
29
  default:
27
- return `${base}${Number(maxBytes) / 1000} KB`;
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 * Constructs a string intended to be consumed by an <input> element of type \"file\". This string\n * should go inside the accept property \n *\n * E.g.\n *\n * const maxSizeCopy = getFileSizeString({\n * maxBytes: 10000,\n * format: FileSizeUnit.MB\n * });\n *\n * Where @constant maxSizeCopy would equal \"Max size: 1 MB\"\n *\n * @param fileTypes - A list of file types, each value being of @type AcceptedFileTypes\n * the returned string\n */\nexport const getFileSizeString = ({ maxBytes, format, baseString }: GetFileSizeStringProps) => {\n const base = baseString == null ? 'Max size: ' : baseString;\n switch (format) {\n case FileSizeUnit.KB:\n return `${base}${Number(maxBytes) / 1000} KB`;\n case FileSizeUnit.MB:\n return `${base}${Number(maxBytes) / 1000000} MB`;\n default:\n return `${base}${Number(maxBytes) / 1000} KB`;\n }\n};\n"],"names":[],"mappings":";;AAOA;;;;;;;;;;;;;;;AAeG;AACI,MAAM,iBAAiB,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAA0B,KAAI;AAC5F,IAAA,MAAM,IAAI,GAAG,UAAU,IAAI,IAAI,GAAG,YAAY,GAAG,UAAU;AAC3D,IAAA,QAAQ,MAAM;QACZ,KAAK,YAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA,GAAA,CAAK;QAC/C,KAAK,YAAY,CAAC,EAAE;YAClB,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAA,GAAA,CAAK;AAClD,QAAA;YACE,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA,GAAA,CAAK;AAChD;AACH;;;;"}
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;;;;"}