@transferwise/components 46.100.2 → 46.102.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/build/common/initials.js +4 -1
- package/build/common/initials.js.map +1 -1
- package/build/common/initials.mjs +4 -1
- package/build/common/initials.mjs.map +1 -1
- package/build/i18n/de.json +2 -0
- package/build/i18n/de.json.js +2 -0
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +2 -0
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/en.json +2 -0
- package/build/i18n/en.json.js +2 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +2 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/i18n/fr.json +2 -0
- package/build/i18n/fr.json.js +2 -0
- package/build/i18n/fr.json.js.map +1 -1
- package/build/i18n/fr.json.mjs +2 -0
- package/build/i18n/fr.json.mjs.map +1 -1
- package/build/i18n/hu.json +2 -0
- package/build/i18n/hu.json.js +2 -0
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +2 -0
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/it.json +2 -0
- package/build/i18n/it.json.js +2 -0
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +2 -0
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +2 -0
- package/build/i18n/ja.json.js +2 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +2 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pl.json +2 -0
- package/build/i18n/pl.json.js +2 -0
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +2 -0
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/ro.json +2 -0
- package/build/i18n/ro.json.js +2 -0
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +2 -0
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +2 -0
- package/build/i18n/ru.json.js +2 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +2 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/tr.json +2 -0
- package/build/i18n/tr.json.js +2 -0
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +2 -0
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +2 -0
- package/build/i18n/zh-CN.json.js +2 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +2 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +2 -0
- package/build/i18n/zh-HK.json.js +2 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +2 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/types/common/initials.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +6 -2
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/Upload.messages.d.ts +8 -0
- package/build/types/upload/Upload.messages.d.ts.map +1 -1
- package/build/types/uploadInput/UploadInput.d.ts +1 -1
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts +4 -2
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
- package/build/upload/Upload.js +16 -9
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.messages.js +6 -0
- package/build/upload/Upload.messages.js.map +1 -1
- package/build/upload/Upload.messages.mjs +6 -0
- package/build/upload/Upload.messages.mjs.map +1 -1
- package/build/upload/Upload.mjs +16 -9
- package/build/upload/Upload.mjs.map +1 -1
- package/build/uploadInput/UploadInput.js +1 -1
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.js +7 -4
- package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs +7 -4
- package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
- package/package.json +3 -3
- package/src/common/initials.spec.tsx +13 -0
- package/src/common/initials.ts +5 -0
- package/src/i18n/de.json +2 -0
- package/src/i18n/en.json +2 -0
- package/src/i18n/fr.json +2 -0
- package/src/i18n/hu.json +2 -0
- package/src/i18n/it.json +2 -0
- package/src/i18n/ja.json +2 -0
- package/src/i18n/pl.json +2 -0
- package/src/i18n/ro.json +2 -0
- package/src/i18n/ru.json +2 -0
- package/src/i18n/tr.json +2 -0
- package/src/i18n/zh-CN.json +2 -0
- package/src/i18n/zh-HK.json +2 -0
- package/src/upload/Upload.messages.ts +8 -0
- package/src/upload/Upload.spec.tsx +6 -0
- package/src/upload/Upload.story.tsx +118 -3
- package/src/upload/Upload.tests.story.tsx +5 -3
- package/src/upload/Upload.tsx +24 -15
- package/src/uploadInput/UploadInput.tests.story.tsx +7 -0
- package/src/uploadInput/UploadInput.tsx +2 -2
- package/src/uploadInput/uploadButton/UploadButton.spec.tsx +6 -0
- package/src/uploadInput/uploadButton/UploadButton.tsx +12 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadButton.js","sources":["../../../src/uploadInput/uploadButton/UploadButton.tsx"],"sourcesContent":["import { PlusCircle as PlusIcon, Upload as UploadIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport {\n ChangeEvent,\n DragEvent,\n useRef,\n useState,\n forwardRef,\n useImperativeHandle,\n ForwardedRef,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../../body';\nimport { FileType, Typography } from '../../common';\n\nimport MESSAGES from './UploadButton.messages';\nimport { DEFAULT_SIZE_LIMIT, imageFileTypes } from './defaults';\nimport getAllowedFileTypes from './getAllowedFileTypes';\n\ntype AllowedFileTypes = string | readonly string[] | readonly FileType[];\nexport type UploadButtonProps = {\n /**\n * Disable the upload button if your app is not yet ready to accept uploads\n */\n disabled?: boolean;\n\n /**\n * Should be true, if the UploadInput has at least 1\n * file (valid or invalid) listed.\n */\n withEntries?: boolean;\n\n /**\n * Allow multiple file uploads\n */\n multiple?: boolean;\n\n /**\n * List of allowed filetypes, eg. '*' | '.zip,application/zip' | ['.jpg,.jpeg,image/jpeg', '.png,image/png'] (default: image files + PDF)\n */\n fileTypes?: AllowedFileTypes;\n\n /**\n * Size limit in KBs 1000 KB = 1 MB (default: 5000 KB)\n */\n sizeLimit?: number;\n\n /**\n * Description for the upload button\n */\n description?: string | undefined;\n\n /**\n * Maximum number of files allowed, if provided, shows error below file item\n */\n maxFiles?: number;\n\n /**\n * Called when some files were successfully selected\n *\n * @param files\n */\n onChange: (files: FileList) => void;\n\n /**\n * Id for the upload input\n */\n id?: string;\n\n /**\n * Title for the upload button\n */\n uploadButtonTitle?: string;\n};\n\nexport enum TEST_IDS {\n uploadInput = 'uploadInput',\n mediaBody = 'mediaBody',\n}\n\nconst onDragOver = (event: DragEvent): void => {\n event.preventDefault();\n};\n\nconst DEFAULT_FILE_INPUT_ID = 'np-upload-button';\nconst UploadButton = forwardRef<HTMLInputElement | null, UploadButtonProps>(\n (\n {\n disabled,\n withEntries,\n multiple,\n description,\n fileTypes = imageFileTypes,\n sizeLimit = DEFAULT_SIZE_LIMIT,\n maxFiles,\n onChange,\n id = DEFAULT_FILE_INPUT_ID,\n uploadButtonTitle,\n },\n ref: ForwardedRef<HTMLInputElement | null>,\n ) => {\n const { formatMessage } = useIntl();\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n useImperativeHandle(ref, () => {\n if (!inputRef.current) {\n throw new Error('inputRef.current is null');\n }\n return inputRef.current;\n }, []);\n\n const [isDropping, setIsDropping] = useState(false);\n\n const dragCounter = useRef(0);\n\n const reset = (): void => {\n dragCounter.current = 0;\n setIsDropping(false);\n };\n\n const onDragLeave = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current -= 1;\n if (dragCounter.current === 0) {\n setIsDropping(false);\n }\n };\n\n const onDragEnter = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current += 1;\n if (dragCounter.current === 1) {\n setIsDropping(true);\n }\n };\n\n const onDrop = (event: DragEvent): void => {\n event.preventDefault();\n reset();\n if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {\n onChange(event.dataTransfer.files);\n }\n };\n\n const filesSelected = (event: ChangeEvent<HTMLInputElement>): void => {\n const { files } = event.target;\n\n if (files) {\n onChange(files);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }\n };\n\n const getFileTypesDescription = (): string => {\n if (fileTypes === '*') {\n return fileTypes;\n }\n\n return getAllowedFileTypes(Array.isArray(fileTypes) ? fileTypes : [fileTypes]).join(', ');\n };\n\n function getDescription() {\n if (description) {\n return description;\n }\n\n const fileTypesDescription = getFileTypesDescription();\n\n const derivedFileDescription =\n fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;\n\n return formatMessage(MESSAGES.instructions, {\n fileTypes: derivedFileDescription,\n size: Math.round(sizeLimit / 1000),\n });\n }\n\n function getAcceptedTypes(): Pick<React.ComponentPropsWithoutRef<'input'>, 'accept'> {\n const areAllFilesAllowed = getFileTypesDescription() === '*';\n\n if (areAllFilesAllowed) {\n return {}; // file input by default allows all files\n }\n\n if (Array.isArray(fileTypes)) {\n return { accept: fileTypes.join(',') };\n }\n\n return { accept: fileTypes as string };\n }\n\n function renderDescription() {\n return (\n <Body className=\"np-upload-input__text\">\n {getDescription()}\n {maxFiles && (\n <>\n <br />\n {formatMessage(MESSAGES.maximumFiles, { maxFiles })}\n </>\n )}\n </Body>\n );\n }\n\n function renderButtonTitle() {\n if (uploadButtonTitle) {\n return uploadButtonTitle;\n }\n return formatMessage(multiple ? MESSAGES.uploadFiles : MESSAGES.uploadFile);\n }\n\n return (\n <label\n className={clsx(\n 'np-upload-input__upload-button',\n `np-upload-input__upload-button--${disabled ? 'disabled' : 'enabled'}`,\n `np-upload-input__upload-button--${withEntries ? 'with-entries' : 'without-entries'}`,\n {\n 'is-dropping': isDropping,\n },\n )}\n htmlFor={id}\n {...(!disabled && { onDragEnter, onDragLeave, onDrop, onDragOver })}\n >\n <span className=\"np-upload-input__icon\">\n <UploadIcon size={24} className=\"text-link\" />\n </span>\n <div className=\"np-upload-input__item-content\" data-testid={TEST_IDS.mediaBody}>\n <Body type={Typography.BODY_LARGE_BOLD} className=\"np-upload-input__title\">\n {renderButtonTitle()}\n </Body>\n {renderDescription()}\n </div>\n <input\n className=\"np-upload-input__upload-button-input sr-only\"\n type=\"file\"\n id={id}\n {...getAcceptedTypes()}\n {...(multiple && { multiple: true })}\n ref={inputRef}\n disabled={disabled}\n name=\"file-upload\"\n data-testid={TEST_IDS.uploadInput}\n onChange={filesSelected}\n />\n {isDropping && (\n <div\n className={clsx(\n 'np-upload-input__drop-file-overlay',\n 'droppable-card',\n 'droppable-dropping-card',\n 'droppable-card-content',\n )}\n >\n <PlusIcon className=\"m-x-1\" size={24} />\n <div>{formatMessage(MESSAGES.dropFile)}</div>\n </div>\n )}\n </label>\n );\n },\n);\n\nUploadButton.displayName = 'UploadButton';\n\nexport default UploadButton;\n"],"names":["TEST_IDS","onDragOver","event","preventDefault","DEFAULT_FILE_INPUT_ID","UploadButton","forwardRef","disabled","withEntries","multiple","description","fileTypes","imageFileTypes","sizeLimit","DEFAULT_SIZE_LIMIT","maxFiles","onChange","id","uploadButtonTitle","ref","formatMessage","useIntl","inputRef","useRef","useImperativeHandle","current","Error","isDropping","setIsDropping","useState","dragCounter","reset","onDragLeave","onDragEnter","onDrop","dataTransfer","files","filesSelected","target","value","getFileTypesDescription","getAllowedFileTypes","Array","isArray","join","getDescription","fileTypesDescription","derivedFileDescription","MESSAGES","allFileTypes","instructions","size","Math","round","getAcceptedTypes","areAllFilesAllowed","accept","renderDescription","_jsxs","Body","className","children","_Fragment","_jsx","maximumFiles","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EYA;AAAZ,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACzB,CAAC,EAHWA,gBAAQ,KAARA,gBAAQ,GAAA,EAAA,CAAA,CAAA;AAKpB,MAAMC,UAAU,GAAIC,KAAgB,IAAU;EAC5CA,KAAK,CAACC,cAAc,EAAE;AACxB,CAAC;AAED,MAAMC,qBAAqB,GAAG,kBAAkB;AAChD,MAAMC,YAAY,gBAAGC,gBAAU,CAC7B,CACE;EACEC,QAAQ;EACRC,WAAW;EACXC,QAAQ;EACRC,WAAW;AACXC,EAAAA,SAAS,GAAGC,uBAAc;AAC1BC,EAAAA,SAAS,GAAGC,2BAAkB;EAC9BC,QAAQ;EACRC,QAAQ;AACRC,EAAAA,EAAE,GAAGb,qBAAqB;AAC1Bc,EAAAA;AAAiB,CAClB,EACDC,GAA0C,KACxC;EACF,MAAM;AAAEC,IAAAA;GAAe,GAAGC,iBAAO,EAAE;AACnC,EAAA,MAAMC,QAAQ,GAAGC,YAAM,CAA0B,IAAI,CAAC;EAEtDC,yBAAmB,CAACL,GAAG,EAAE,MAAK;AAC5B,IAAA,IAAI,CAACG,QAAQ,CAACG,OAAO,EAAE;AACrB,MAAA,MAAM,IAAIC,KAAK,CAAC,0BAA0B,CAAC;AAC7C,IAAA;IACA,OAAOJ,QAAQ,CAACG,OAAO;EACzB,CAAC,EAAE,EAAE,CAAC;EAEN,MAAM,CAACE,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AAEnD,EAAA,MAAMC,W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EAAEC,qBAAU,CAACC,eAAgB;AAACd,QAAAA,SAAS,EAAC,wBAAwB;QAAAC,QAAA,EACvEI,iBAAiB;AAAE,OAChB,CACN,EAACR,iBAAiB,EAAE;KACjB,CACL,eAAAM,cAAA,CAAA,OAAA,EAAA;AACEH,MAAAA,SAAS,EAAC,8CAA8C;AACxDY,MAAAA,IAAI,EAAC,MAAM;AACXvD,MAAAA,EAAE,EAAEA,EAAG;MAAA,GACHqC,gBAAgB,EAAE;AAAA,MAAA,IACjB7C,QAAQ,IAAI;AAAEA,QAAAA,QAAQ,EAAE;OAAM,CAAA;AACnCU,MAAAA,GAAG,EAAEG,QAAS;AACdf,MAAAA,QAAQ,EAAEA,QAAS;AACnBoE,MAAAA,IAAI,EAAC,aAAa;MAClB,aAAA,EAAa3E,gBAAQ,CAAC4E,WAAY;AAClC5D,MAAAA,QAAQ,EAAEqB;AAAc,KAAA,CAE1B,EAACV,UAAU,iBACT+B,eAAA,CAAA,KAAA,EAAA;MACEE,SAAS,EAAEQ,SAAI,CACb,oCAAoC,EACpC,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,CACxB;MAAAP,QAAA,EAAA,cAEFE,cAAA,CAACc,gBAAQ,EAAA;AAACjB,QAAAA,SAAS,EAAC,OAAO;AAACT,QAAAA,IAAI,EAAE;OAAG,CACrC,eAAAY,cAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,6BAAQ,CAAC8B,QAAQ;AAAC,OAAM,CAC9C;AAAA,KAAK,CACN;AAAA,GACI,CAAC;AAEZ,CAAC;AAGHzE,YAAY,CAAC0E,WAAW,GAAG,cAAc;;;;"}
|
|
1
|
+
{"version":3,"file":"UploadButton.js","sources":["../../../src/uploadInput/uploadButton/UploadButton.tsx"],"sourcesContent":["import { PlusCircle as PlusIcon, Upload as UploadIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport {\n ChangeEvent,\n DragEvent,\n useRef,\n useState,\n forwardRef,\n useImperativeHandle,\n ForwardedRef,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../../body';\nimport { FileType, Typography } from '../../common';\n\nimport MESSAGES from './UploadButton.messages';\nimport { DEFAULT_SIZE_LIMIT, imageFileTypes } from './defaults';\nimport getAllowedFileTypes from './getAllowedFileTypes';\n\ntype AllowedFileTypes = string | readonly string[] | readonly FileType[];\nexport type UploadButtonProps = {\n /**\n * Disable the upload button if your app is not yet ready to accept uploads\n */\n disabled?: boolean;\n\n /**\n * Should be true, if the UploadInput has at least 1\n * file (valid or invalid) listed.\n */\n withEntries?: boolean;\n\n /**\n * Allow multiple file uploads\n */\n multiple?: boolean;\n\n /**\n * List of allowed filetypes, eg. '*' | '.zip,application/zip' | ['.jpg,.jpeg,image/jpeg', '.png,image/png'] (default: image files + PDF)\n */\n fileTypes?: AllowedFileTypes;\n\n /**\n * Size limit in KBs (1000 KB = 1 MB).\n * If set to `null`, no size limit will be applied.\n * @default 5000\n */\n sizeLimit?: number | null;\n\n /**\n * Description for the upload button\n */\n description?: string | undefined;\n\n /**\n * Maximum number of files allowed, if provided, shows error below file item\n */\n maxFiles?: number;\n\n /**\n * Called when some files were successfully selected\n *\n * @param files\n */\n onChange: (files: FileList) => void;\n\n /**\n * Id for the upload input\n */\n id?: string;\n\n /**\n * Title for the upload button\n */\n uploadButtonTitle?: string;\n};\n\nexport enum TEST_IDS {\n uploadInput = 'uploadInput',\n mediaBody = 'mediaBody',\n}\n\nconst onDragOver = (event: DragEvent): void => {\n event.preventDefault();\n};\n\nconst DEFAULT_FILE_INPUT_ID = 'np-upload-button';\nconst UploadButton = forwardRef<HTMLInputElement | null, UploadButtonProps>(\n (\n {\n disabled,\n withEntries,\n multiple,\n description,\n fileTypes = imageFileTypes,\n sizeLimit = DEFAULT_SIZE_LIMIT,\n maxFiles,\n onChange,\n id = DEFAULT_FILE_INPUT_ID,\n uploadButtonTitle,\n },\n ref: ForwardedRef<HTMLInputElement | null>,\n ) => {\n const { formatMessage } = useIntl();\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n useImperativeHandle(ref, () => {\n if (!inputRef.current) {\n throw new Error('inputRef.current is null');\n }\n return inputRef.current;\n }, []);\n\n const [isDropping, setIsDropping] = useState(false);\n\n const dragCounter = useRef(0);\n\n const reset = (): void => {\n dragCounter.current = 0;\n setIsDropping(false);\n };\n\n const onDragLeave = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current -= 1;\n if (dragCounter.current === 0) {\n setIsDropping(false);\n }\n };\n\n const onDragEnter = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current += 1;\n if (dragCounter.current === 1) {\n setIsDropping(true);\n }\n };\n\n const onDrop = (event: DragEvent): void => {\n event.preventDefault();\n reset();\n if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {\n onChange(event.dataTransfer.files);\n }\n };\n\n const filesSelected = (event: ChangeEvent<HTMLInputElement>): void => {\n const { files } = event.target;\n\n if (files) {\n onChange(files);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }\n };\n\n const getFileTypesDescription = (): string => {\n if (fileTypes === '*') {\n return fileTypes;\n }\n\n return getAllowedFileTypes(Array.isArray(fileTypes) ? fileTypes : [fileTypes]).join(', ');\n };\n\n function getDescription() {\n if (description) {\n return description;\n }\n\n const fileTypesDescription = getFileTypesDescription();\n\n const derivedFileDescription =\n fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;\n\n if (typeof sizeLimit === 'number') {\n return formatMessage(MESSAGES.instructions, {\n fileTypes: derivedFileDescription,\n size: Math.round(sizeLimit / 1000),\n });\n }\n\n return derivedFileDescription;\n }\n\n function getAcceptedTypes(): Pick<React.ComponentPropsWithoutRef<'input'>, 'accept'> {\n const areAllFilesAllowed = getFileTypesDescription() === '*';\n\n if (areAllFilesAllowed) {\n return {}; // file input by default allows all files\n }\n\n if (Array.isArray(fileTypes)) {\n return { accept: fileTypes.join(',') };\n }\n\n return { accept: fileTypes as string };\n }\n\n function renderDescription() {\n return (\n <Body className=\"np-upload-input__text\">\n {getDescription()}\n {maxFiles && (\n <>\n <br />\n {formatMessage(MESSAGES.maximumFiles, { maxFiles })}\n </>\n )}\n </Body>\n );\n }\n\n function renderButtonTitle() {\n if (uploadButtonTitle) {\n return uploadButtonTitle;\n }\n return formatMessage(multiple ? MESSAGES.uploadFiles : MESSAGES.uploadFile);\n }\n\n return (\n <label\n className={clsx(\n 'np-upload-input__upload-button',\n `np-upload-input__upload-button--${disabled ? 'disabled' : 'enabled'}`,\n `np-upload-input__upload-button--${withEntries ? 'with-entries' : 'without-entries'}`,\n {\n 'is-dropping': isDropping,\n },\n )}\n htmlFor={id}\n {...(!disabled && { onDragEnter, onDragLeave, onDrop, onDragOver })}\n >\n <span className=\"np-upload-input__icon\">\n <UploadIcon size={24} className=\"text-link\" />\n </span>\n <div className=\"np-upload-input__item-content\" data-testid={TEST_IDS.mediaBody}>\n <Body type={Typography.BODY_LARGE_BOLD} className=\"np-upload-input__title\">\n {renderButtonTitle()}\n </Body>\n {renderDescription()}\n </div>\n <input\n className=\"np-upload-input__upload-button-input sr-only\"\n type=\"file\"\n id={id}\n {...getAcceptedTypes()}\n {...(multiple && { multiple: true })}\n ref={inputRef}\n disabled={disabled}\n name=\"file-upload\"\n data-testid={TEST_IDS.uploadInput}\n onChange={filesSelected}\n />\n {isDropping && (\n <div\n className={clsx(\n 'np-upload-input__drop-file-overlay',\n 'droppable-card',\n 'droppable-dropping-card',\n 'droppable-card-content',\n )}\n >\n <PlusIcon className=\"m-x-1\" size={24} />\n <div>{formatMessage(MESSAGES.dropFile)}</div>\n </div>\n )}\n </label>\n );\n },\n);\n\nUploadButton.displayName = 'UploadButton';\n\nexport default UploadButton;\n"],"names":["TEST_IDS","onDragOver","event","preventDefault","DEFAULT_FILE_INPUT_ID","UploadButton","forwardRef","disabled","withEntries","multiple","description","fileTypes","imageFileTypes","sizeLimit","DEFAULT_SIZE_LIMIT","maxFiles","onChange","id","uploadButtonTitle","ref","formatMessage","useIntl","inputRef","useRef","useImperativeHandle","current","Error","isDropping","setIsDropping","useState","dragCounter","reset","onDragLeave","onDragEnter","onDrop","dataTransfer","files","filesSelected","target","value","getFileTypesDescription","getAllowedFileTypes","Array","isArray","join","getDescription","fileTypesDescription","derivedFileDescription","MESSAGES","allFileTypes","instructions","size","Math","round","getAcceptedTypes","areAllFilesAllowed","accept","renderDescription","_jsxs","Body","className","children","_Fragment","_jsx","maximumFiles","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EYA;AAAZ,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACzB,CAAC,EAHWA,gBAAQ,KAARA,gBAAQ,GAAA,EAAA,CAAA,CAAA;AAKpB,MAAMC,UAAU,GAAIC,KAAgB,IAAU;EAC5CA,KAAK,CAACC,cAAc,EAAE;AACxB,CAAC;AAED,MAAMC,qBAAqB,GAAG,kBAAkB;AAChD,MAAMC,YAAY,gBAAGC,gBAAU,CAC7B,CACE;EACEC,QAAQ;EACRC,WAAW;EACXC,QAAQ;EACRC,WAAW;AACXC,EAAAA,SAAS,GAAGC,uBAAc;AAC1BC,EAAAA,SAAS,GAAGC,2BAAkB;EAC9BC,QAAQ;EACRC,QAAQ;AACRC,EAAAA,EAAE,GAAGb,qBAAqB;AAC1Bc,EAAAA;AAAiB,CAClB,EACDC,GAA0C,KACxC;EACF,MAAM;AAAEC,IAAAA;GAAe,GAAGC,iBAAO,EAAE;AACnC,EAAA,MAAMC,QAAQ,GAAGC,YAAM,CAA0B,IAAI,CAAC;EAEtDC,yBAAmB,CAACL,GAAG,EAAE,MAAK;AAC5B,IAAA,I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C,aAAa,CAAC4B,6BAAQ,CAAC8B,QAAQ;AAAC,OAAM,CAC9C;AAAA,KAAK,CACN;AAAA,GACI,CAAC;AAEZ,CAAC;AAGHzE,YAAY,CAAC0E,WAAW,GAAG,cAAc;;;;"}
|
|
@@ -109,10 +109,13 @@ const UploadButton = /*#__PURE__*/forwardRef(({
|
|
|
109
109
|
}
|
|
110
110
|
const fileTypesDescription = getFileTypesDescription();
|
|
111
111
|
const derivedFileDescription = fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
if (typeof sizeLimit === 'number') {
|
|
113
|
+
return formatMessage(MESSAGES.instructions, {
|
|
114
|
+
fileTypes: derivedFileDescription,
|
|
115
|
+
size: Math.round(sizeLimit / 1000)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return derivedFileDescription;
|
|
116
119
|
}
|
|
117
120
|
function getAcceptedTypes() {
|
|
118
121
|
const areAllFilesAllowed = getFileTypesDescription() === '*';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadButton.mjs","sources":["../../../src/uploadInput/uploadButton/UploadButton.tsx"],"sourcesContent":["import { PlusCircle as PlusIcon, Upload as UploadIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport {\n ChangeEvent,\n DragEvent,\n useRef,\n useState,\n forwardRef,\n useImperativeHandle,\n ForwardedRef,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../../body';\nimport { FileType, Typography } from '../../common';\n\nimport MESSAGES from './UploadButton.messages';\nimport { DEFAULT_SIZE_LIMIT, imageFileTypes } from './defaults';\nimport getAllowedFileTypes from './getAllowedFileTypes';\n\ntype AllowedFileTypes = string | readonly string[] | readonly FileType[];\nexport type UploadButtonProps = {\n /**\n * Disable the upload button if your app is not yet ready to accept uploads\n */\n disabled?: boolean;\n\n /**\n * Should be true, if the UploadInput has at least 1\n * file (valid or invalid) listed.\n */\n withEntries?: boolean;\n\n /**\n * Allow multiple file uploads\n */\n multiple?: boolean;\n\n /**\n * List of allowed filetypes, eg. '*' | '.zip,application/zip' | ['.jpg,.jpeg,image/jpeg', '.png,image/png'] (default: image files + PDF)\n */\n fileTypes?: AllowedFileTypes;\n\n /**\n * Size limit in KBs 1000 KB = 1 MB (default: 5000 KB)\n */\n sizeLimit?: number;\n\n /**\n * Description for the upload button\n */\n description?: string | undefined;\n\n /**\n * Maximum number of files allowed, if provided, shows error below file item\n */\n maxFiles?: number;\n\n /**\n * Called when some files were successfully selected\n *\n * @param files\n */\n onChange: (files: FileList) => void;\n\n /**\n * Id for the upload input\n */\n id?: string;\n\n /**\n * Title for the upload button\n */\n uploadButtonTitle?: string;\n};\n\nexport enum TEST_IDS {\n uploadInput = 'uploadInput',\n mediaBody = 'mediaBody',\n}\n\nconst onDragOver = (event: DragEvent): void => {\n event.preventDefault();\n};\n\nconst DEFAULT_FILE_INPUT_ID = 'np-upload-button';\nconst UploadButton = forwardRef<HTMLInputElement | null, UploadButtonProps>(\n (\n {\n disabled,\n withEntries,\n multiple,\n description,\n fileTypes = imageFileTypes,\n sizeLimit = DEFAULT_SIZE_LIMIT,\n maxFiles,\n onChange,\n id = DEFAULT_FILE_INPUT_ID,\n uploadButtonTitle,\n },\n ref: ForwardedRef<HTMLInputElement | null>,\n ) => {\n const { formatMessage } = useIntl();\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n useImperativeHandle(ref, () => {\n if (!inputRef.current) {\n throw new Error('inputRef.current is null');\n }\n return inputRef.current;\n }, []);\n\n const [isDropping, setIsDropping] = useState(false);\n\n const dragCounter = useRef(0);\n\n const reset = (): void => {\n dragCounter.current = 0;\n setIsDropping(false);\n };\n\n const onDragLeave = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current -= 1;\n if (dragCounter.current === 0) {\n setIsDropping(false);\n }\n };\n\n const onDragEnter = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current += 1;\n if (dragCounter.current === 1) {\n setIsDropping(true);\n }\n };\n\n const onDrop = (event: DragEvent): void => {\n event.preventDefault();\n reset();\n if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {\n onChange(event.dataTransfer.files);\n }\n };\n\n const filesSelected = (event: ChangeEvent<HTMLInputElement>): void => {\n const { files } = event.target;\n\n if (files) {\n onChange(files);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }\n };\n\n const getFileTypesDescription = (): string => {\n if (fileTypes === '*') {\n return fileTypes;\n }\n\n return getAllowedFileTypes(Array.isArray(fileTypes) ? fileTypes : [fileTypes]).join(', ');\n };\n\n function getDescription() {\n if (description) {\n return description;\n }\n\n const fileTypesDescription = getFileTypesDescription();\n\n const derivedFileDescription =\n fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;\n\n return formatMessage(MESSAGES.instructions, {\n fileTypes: derivedFileDescription,\n size: Math.round(sizeLimit / 1000),\n });\n }\n\n function getAcceptedTypes(): Pick<React.ComponentPropsWithoutRef<'input'>, 'accept'> {\n const areAllFilesAllowed = getFileTypesDescription() === '*';\n\n if (areAllFilesAllowed) {\n return {}; // file input by default allows all files\n }\n\n if (Array.isArray(fileTypes)) {\n return { accept: fileTypes.join(',') };\n }\n\n return { accept: fileTypes as string };\n }\n\n function renderDescription() {\n return (\n <Body className=\"np-upload-input__text\">\n {getDescription()}\n {maxFiles && (\n <>\n <br />\n {formatMessage(MESSAGES.maximumFiles, { maxFiles })}\n </>\n )}\n </Body>\n );\n }\n\n function renderButtonTitle() {\n if (uploadButtonTitle) {\n return uploadButtonTitle;\n }\n return formatMessage(multiple ? MESSAGES.uploadFiles : MESSAGES.uploadFile);\n }\n\n return (\n <label\n className={clsx(\n 'np-upload-input__upload-button',\n `np-upload-input__upload-button--${disabled ? 'disabled' : 'enabled'}`,\n `np-upload-input__upload-button--${withEntries ? 'with-entries' : 'without-entries'}`,\n {\n 'is-dropping': isDropping,\n },\n )}\n htmlFor={id}\n {...(!disabled && { onDragEnter, onDragLeave, onDrop, onDragOver })}\n >\n <span className=\"np-upload-input__icon\">\n <UploadIcon size={24} className=\"text-link\" />\n </span>\n <div className=\"np-upload-input__item-content\" data-testid={TEST_IDS.mediaBody}>\n <Body type={Typography.BODY_LARGE_BOLD} className=\"np-upload-input__title\">\n {renderButtonTitle()}\n </Body>\n {renderDescription()}\n </div>\n <input\n className=\"np-upload-input__upload-button-input sr-only\"\n type=\"file\"\n id={id}\n {...getAcceptedTypes()}\n {...(multiple && { multiple: true })}\n ref={inputRef}\n disabled={disabled}\n name=\"file-upload\"\n data-testid={TEST_IDS.uploadInput}\n onChange={filesSelected}\n />\n {isDropping && (\n <div\n className={clsx(\n 'np-upload-input__drop-file-overlay',\n 'droppable-card',\n 'droppable-dropping-card',\n 'droppable-card-content',\n )}\n >\n <PlusIcon className=\"m-x-1\" size={24} />\n <div>{formatMessage(MESSAGES.dropFile)}</div>\n </div>\n )}\n </label>\n );\n },\n);\n\nUploadButton.displayName = 'UploadButton';\n\nexport default UploadButton;\n"],"names":["TEST_IDS","onDragOver","event","preventDefault","DEFAULT_FILE_INPUT_ID","UploadButton","forwardRef","disabled","withEntries","multiple","description","fileTypes","imageFileTypes","sizeLimit","DEFAULT_SIZE_LIMIT","maxFiles","onChange","id","uploadButtonTitle","ref","formatMessage","useIntl","inputRef","useRef","useImperativeHandle","current","Error","isDropping","setIsDropping","useState","dragCounter","reset","onDragLeave","onDragEnter","onDrop","dataTransfer","files","filesSelected","target","value","getFileTypesDescription","getAllowedFileTypes","Array","isArray","join","getDescription","fileTypesDescription","derivedFileDescription","MESSAGES","allFileTypes","instructions","size","Math","round","getAcceptedTypes","areAllFilesAllowed","accept","renderDescription","_jsxs","Body","className","children","_Fragment","_jsx","maximumFiles","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mappings":";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ACEH,MAAAA,SAAS,EAAC,8CAA8C;AACxDY,MAAAA,IAAI,EAAC,MAAM;AACXvD,MAAAA,EAAE,EAAEA,EAAG;MAAA,GACHqC,gBAAgB,EAAE;AAAA,MAAA,IACjB7C,QAAQ,IAAI;AAAEA,QAAAA,QAAQ,EAAE;OAAM,CAAA;AACnCU,MAAAA,GAAG,EAAEG,QAAS;AACdf,MAAAA,QAAQ,EAAEA,QAAS;AACnBoE,MAAAA,IAAI,EAAC,aAAa;MAClB,aAAA,EAAa3E,QAAQ,CAAC4E,WAAY;AAClC5D,MAAAA,QAAQ,EAAEqB;AAAc,KAAA,CAE1B,EAACV,UAAU,iBACT+B,IAAA,CAAA,KAAA,EAAA;MACEE,SAAS,EAAEQ,IAAI,CACb,oCAAoC,EACpC,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,CACxB;MAAAP,QAAA,EAAA,cAEFE,GAAA,CAACc,UAAQ,EAAA;AAACjB,QAAAA,SAAS,EAAC,OAAO;AAACT,QAAAA,IAAI,EAAE;OAAG,CACrC,eAAAY,GAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,QAAQ,CAAC8B,QAAQ;AAAC,OAAM,CAC9C;AAAA,KAAK,CACN;AAAA,GACI,CAAC;AAEZ,CAAC;AAGHzE,YAAY,CAAC0E,WAAW,GAAG,cAAc;;;;"}
|
|
1
|
+
{"version":3,"file":"UploadButton.mjs","sources":["../../../src/uploadInput/uploadButton/UploadButton.tsx"],"sourcesContent":["import { PlusCircle as PlusIcon, Upload as UploadIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport {\n ChangeEvent,\n DragEvent,\n useRef,\n useState,\n forwardRef,\n useImperativeHandle,\n ForwardedRef,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../../body';\nimport { FileType, Typography } from '../../common';\n\nimport MESSAGES from './UploadButton.messages';\nimport { DEFAULT_SIZE_LIMIT, imageFileTypes } from './defaults';\nimport getAllowedFileTypes from './getAllowedFileTypes';\n\ntype AllowedFileTypes = string | readonly string[] | readonly FileType[];\nexport type UploadButtonProps = {\n /**\n * Disable the upload button if your app is not yet ready to accept uploads\n */\n disabled?: boolean;\n\n /**\n * Should be true, if the UploadInput has at least 1\n * file (valid or invalid) listed.\n */\n withEntries?: boolean;\n\n /**\n * Allow multiple file uploads\n */\n multiple?: boolean;\n\n /**\n * List of allowed filetypes, eg. '*' | '.zip,application/zip' | ['.jpg,.jpeg,image/jpeg', '.png,image/png'] (default: image files + PDF)\n */\n fileTypes?: AllowedFileTypes;\n\n /**\n * Size limit in KBs (1000 KB = 1 MB).\n * If set to `null`, no size limit will be applied.\n * @default 5000\n */\n sizeLimit?: number | null;\n\n /**\n * Description for the upload button\n */\n description?: string | undefined;\n\n /**\n * Maximum number of files allowed, if provided, shows error below file item\n */\n maxFiles?: number;\n\n /**\n * Called when some files were successfully selected\n *\n * @param files\n */\n onChange: (files: FileList) => void;\n\n /**\n * Id for the upload input\n */\n id?: string;\n\n /**\n * Title for the upload button\n */\n uploadButtonTitle?: string;\n};\n\nexport enum TEST_IDS {\n uploadInput = 'uploadInput',\n mediaBody = 'mediaBody',\n}\n\nconst onDragOver = (event: DragEvent): void => {\n event.preventDefault();\n};\n\nconst DEFAULT_FILE_INPUT_ID = 'np-upload-button';\nconst UploadButton = forwardRef<HTMLInputElement | null, UploadButtonProps>(\n (\n {\n disabled,\n withEntries,\n multiple,\n description,\n fileTypes = imageFileTypes,\n sizeLimit = DEFAULT_SIZE_LIMIT,\n maxFiles,\n onChange,\n id = DEFAULT_FILE_INPUT_ID,\n uploadButtonTitle,\n },\n ref: ForwardedRef<HTMLInputElement | null>,\n ) => {\n const { formatMessage } = useIntl();\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n useImperativeHandle(ref, () => {\n if (!inputRef.current) {\n throw new Error('inputRef.current is null');\n }\n return inputRef.current;\n }, []);\n\n const [isDropping, setIsDropping] = useState(false);\n\n const dragCounter = useRef(0);\n\n const reset = (): void => {\n dragCounter.current = 0;\n setIsDropping(false);\n };\n\n const onDragLeave = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current -= 1;\n if (dragCounter.current === 0) {\n setIsDropping(false);\n }\n };\n\n const onDragEnter = (event: DragEvent): void => {\n event.preventDefault();\n dragCounter.current += 1;\n if (dragCounter.current === 1) {\n setIsDropping(true);\n }\n };\n\n const onDrop = (event: DragEvent): void => {\n event.preventDefault();\n reset();\n if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {\n onChange(event.dataTransfer.files);\n }\n };\n\n const filesSelected = (event: ChangeEvent<HTMLInputElement>): void => {\n const { files } = event.target;\n\n if (files) {\n onChange(files);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }\n };\n\n const getFileTypesDescription = (): string => {\n if (fileTypes === '*') {\n return fileTypes;\n }\n\n return getAllowedFileTypes(Array.isArray(fileTypes) ? fileTypes : [fileTypes]).join(', ');\n };\n\n function getDescription() {\n if (description) {\n return description;\n }\n\n const fileTypesDescription = getFileTypesDescription();\n\n const derivedFileDescription =\n fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;\n\n if (typeof sizeLimit === 'number') {\n return formatMessage(MESSAGES.instructions, {\n fileTypes: derivedFileDescription,\n size: Math.round(sizeLimit / 1000),\n });\n }\n\n return derivedFileDescription;\n }\n\n function getAcceptedTypes(): Pick<React.ComponentPropsWithoutRef<'input'>, 'accept'> {\n const areAllFilesAllowed = getFileTypesDescription() === '*';\n\n if (areAllFilesAllowed) {\n return {}; // file input by default allows all files\n }\n\n if (Array.isArray(fileTypes)) {\n return { accept: fileTypes.join(',') };\n }\n\n return { accept: fileTypes as string };\n }\n\n function renderDescription() {\n return (\n <Body className=\"np-upload-input__text\">\n {getDescription()}\n {maxFiles && (\n <>\n <br />\n {formatMessage(MESSAGES.maximumFiles, { maxFiles })}\n </>\n )}\n </Body>\n );\n }\n\n function renderButtonTitle() {\n if (uploadButtonTitle) {\n return uploadButtonTitle;\n }\n return formatMessage(multiple ? MESSAGES.uploadFiles : MESSAGES.uploadFile);\n }\n\n return (\n <label\n className={clsx(\n 'np-upload-input__upload-button',\n `np-upload-input__upload-button--${disabled ? 'disabled' : 'enabled'}`,\n `np-upload-input__upload-button--${withEntries ? 'with-entries' : 'without-entries'}`,\n {\n 'is-dropping': isDropping,\n },\n )}\n htmlFor={id}\n {...(!disabled && { onDragEnter, onDragLeave, onDrop, onDragOver })}\n >\n <span className=\"np-upload-input__icon\">\n <UploadIcon size={24} className=\"text-link\" />\n </span>\n <div className=\"np-upload-input__item-content\" data-testid={TEST_IDS.mediaBody}>\n <Body type={Typography.BODY_LARGE_BOLD} className=\"np-upload-input__title\">\n {renderButtonTitle()}\n </Body>\n {renderDescription()}\n </div>\n <input\n className=\"np-upload-input__upload-button-input sr-only\"\n type=\"file\"\n id={id}\n {...getAcceptedTypes()}\n {...(multiple && { multiple: true })}\n ref={inputRef}\n disabled={disabled}\n name=\"file-upload\"\n data-testid={TEST_IDS.uploadInput}\n onChange={filesSelected}\n />\n {isDropping && (\n <div\n className={clsx(\n 'np-upload-input__drop-file-overlay',\n 'droppable-card',\n 'droppable-dropping-card',\n 'droppable-card-content',\n )}\n >\n <PlusIcon className=\"m-x-1\" size={24} />\n <div>{formatMessage(MESSAGES.dropFile)}</div>\n </div>\n )}\n </label>\n );\n },\n);\n\nUploadButton.displayName = 'UploadButton';\n\nexport default UploadButton;\n"],"names":["TEST_IDS","onDragOver","event","preventDefault","DEFAULT_FILE_INPUT_ID","UploadButton","forwardRef","disabled","withEntries","multiple","description","fileTypes","imageFileTypes","sizeLimit","DEFAULT_SIZE_LIMIT","maxFiles","onChange","id","uploadButtonTitle","ref","formatMessage","useIntl","inputRef","useRef","useImperativeHandle","current","Error","isDropping","setIsDropping","useState","dragCounter","reset","onDragLeave","onDragEnter","onDrop","dataTransfer","files","filesSelected","target","value","getFileTypesDescription","getAllowedFileTypes","Array","isArray","join","getDescription","fileTypesDescription","derivedFileDescription","MESSAGES","allFileTypes","instructions","size","Math","round","getAcceptedTypes","areAllFilesAllowed","accept","renderDescription","_jsxs","Body","className","children","_Fragment","_jsx","maximumFiles","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8EYA;AAAZ,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACzB,CAAC,EAHWA,QAAQ,KAARA,QAAQ,GAAA,EAAA,CAAA,CAAA;AAKpB,MAAMC,UAAU,GAAIC,KAAgB,IAAU;EAC5CA,KAAK,CAACC,cAAc,EAAE;AACxB,CAAC;AAED,MAAMC,qBAAqB,GAAG,kBAAkB;AAChD,MAAMC,YAAY,gBAAGC,UAAU,CAC7B,CACE;EACEC,QAAQ;EACRC,WAAW;EACXC,QAAQ;EACRC,WAAW;AACXC,EAAAA,SAAS,GAAGC,cAAc;AAC1BC,EAAAA,SAAS,GAAGC,kBAAkB;EAC9BC,QAAQ;EACRC,QAAQ;AACRC,EAAAA,EAAE,GAAGb,qBAAqB;AAC1Bc,EAAAA;AAAiB,CAClB,EACDC,GAA0C,KACxC;EACF,MAAM;AAAEC,IAAAA;GAAe,GAAGC,OAAO,EAAE;AACnC,EAAA,MAAMC,QAAQ,GAAGC,MAAM,CAA0B,IAAI,CAAC;EAEtDC,mBAAmB,CAACL,GAAG,EAAE,MAAK;AAC5B,IAAA,IAAI,CAACG,QAAQ,CAACG,OAAO,EAAE;AACrB,MAAA,MAAM,IAAIC,KAAK,CAAC,0BAA0B,CAAC;AAC7C,IAAA;IACA,OAAOJ,QAAQ,CAACG,OAAO;EACzB,CAAC,EAAE,EAAE,CAAC;EAEN,MAAM,CAACE,U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|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.102.0",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"storybook-addon-tag-badges": "^2.0.1",
|
|
85
85
|
"storybook-addon-test-codegen": "^2.0.1",
|
|
86
86
|
"@transferwise/less-config": "3.1.2",
|
|
87
|
+
"@wise/wds-configs": "0.0.0",
|
|
87
88
|
"@wise/components-theming": "1.6.4",
|
|
88
|
-
"@transferwise/neptune-css": "14.24.5"
|
|
89
|
-
"@wise/wds-configs": "0.0.0"
|
|
89
|
+
"@transferwise/neptune-css": "14.24.5"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"@transferwise/icons": "^3.22.3",
|
|
@@ -39,4 +39,17 @@ describe('getInitials', () => {
|
|
|
39
39
|
it('handles single character', () => {
|
|
40
40
|
expect(getInitials('Q')).toBe('Q');
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
it('handles names with (parenthesized) values', () => {
|
|
44
|
+
expect(getInitials('Squirrel (GBP)')).toBe('S');
|
|
45
|
+
expect(getInitials('Fantastic Squirrel (USD)')).toBe('FS');
|
|
46
|
+
expect(getInitials('Squirrel [GBP]')).toBe('S');
|
|
47
|
+
expect(getInitials('Fantastic Squirrel [USD]')).toBe('FS');
|
|
48
|
+
expect(getInitials('Squirrel {GBP}')).toBe('S');
|
|
49
|
+
expect(getInitials('Fantastic Squirrel {USD}')).toBe('FS');
|
|
50
|
+
expect(getInitials('Squirrel <GBP>')).toBe('S');
|
|
51
|
+
expect(getInitials('Fantastic Squirrel <USD>')).toBe('FS');
|
|
52
|
+
expect(getInitials('(Super) Fantastic Squirrel')).toBe('FS');
|
|
53
|
+
expect(getInitials('Super (Fantastic) Squirrel')).toBe('SS');
|
|
54
|
+
});
|
|
42
55
|
});
|
package/src/common/initials.ts
CHANGED
|
@@ -5,6 +5,7 @@ export function getInitials(name: string) {
|
|
|
5
5
|
|
|
6
6
|
const allInitials = name
|
|
7
7
|
.split(' ')
|
|
8
|
+
.filter((part) => !startsWithParenthesis(part))
|
|
8
9
|
.map((part) => part[0])
|
|
9
10
|
.join('')
|
|
10
11
|
.toUpperCase();
|
|
@@ -14,4 +15,8 @@ export function getInitials(name: string) {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
return allInitials[0] + allInitials.slice(-1);
|
|
18
|
+
|
|
19
|
+
function startsWithParenthesis(part: string) {
|
|
20
|
+
return /^[({[<]/.test(part);
|
|
21
|
+
}
|
|
17
22
|
}
|
package/src/i18n/de.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Hochladen fehlgeschlagen. Bitte versuche es erneut",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Fertig hochgeladen!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Bitte wähle eine Datei aus, die kleiner als {maxSize} MB ist",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Bitte stelle eine kleinere Datei zur Verfügung",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Dateityp wird nicht unterstützt. Bitte versuche es erneut mit einer anderen Datei",
|
|
49
50
|
"neptune.Upload.psButtonText": "Abbrechen",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Wird hochgeladen...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Oder wähle eine Datei aus",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Datei zum Hochladen in dieses Feld ziehen",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Zieh eine Datei in dieses Feld, die kleiner als {maxSize} MB ist",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Ziehe eine Datei hierher",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Alle Dateiformate",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Datei zum Hochladen in dieses Feld ziehen",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, kleiner als {size} MB",
|
package/src/i18n/en.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Upload failed. Please, try again",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Upload complete!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Please provide a file smaller than {maxSize}MB",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Please provide a smaller file",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "File type not supported. Please try again with a different file",
|
|
49
50
|
"neptune.Upload.psButtonText": "Cancel",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Uploading...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Or select a file",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Drop file to start upload",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Drag and drop a file less than {maxSize}MB",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Drag and drop a file",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "All file types",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Drop file to start upload",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, less than {size}MB",
|
package/src/i18n/fr.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Échec du téléchargement. Veuillez réessayer",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Téléchargement terminé !",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Veuillez fournir un fichier de moins de {maxSize} Mo",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Veuillez fournir un fichier plus petit",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Format non pris en charge. Veuillez réessayer avec un fichier différent",
|
|
49
50
|
"neptune.Upload.psButtonText": "Annuler",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Téléchargement...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Ou sélectionnez un fichier",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Déposer un fichier pour démarrer le téléchargement",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Glissez-déposez un fichier de moins de {maxSize} Mo",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Glissez et déposez un fichier",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Tous types de fichiers",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Déposer un fichier pour démarrer le téléchargement",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, inférieur à {size} Mo",
|
package/src/i18n/hu.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Feltöltés sikertelen. Kérünk, próbáld újra",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Feltöltés sikeres",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Kérünk, olyan fájlt küldj el, amely kisebb mint {maxSize}MB",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Kérünk, egy kisebb fájlt küldj",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Nem támogatott fájltípus. Kérünk, próbáld újra másik fájllal",
|
|
49
50
|
"neptune.Upload.psButtonText": "Mégsem",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Feltöltés...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Vagy válaszd ki a fájlt",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Húzd ide a fájlokat a feltöltéshez",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Húzz ide egy legfeljebb {maxSize}MB méretű fájlt",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Húzd át a fájlt",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Összes fájltípus",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Húzd a fájlokat ide a feltöltéshez",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, legfeljebb {size}MB",
|
package/src/i18n/it.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Caricamento fallito. Per favore riprova",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Caricamento completato!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Carica un file inferiore a {maxSize}MB",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Fornisci un file più piccolo",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Formato del documento non supportato. Riprova con un formato diverso",
|
|
49
50
|
"neptune.Upload.psButtonText": "Annulla",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Caricamento...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "O seleziona un documento",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Rilascia il documento per iniziare il caricamento",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Trascina e rilascia un file inferiore a {maxSize}MB",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Trascina e rilascia un file",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Tutti i tipi di file",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Rilascia file per iniziare a caricare",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, minore di {size}MB",
|
package/src/i18n/ja.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "アップロードに失敗しました。もう一度やり直してください。",
|
|
46
46
|
"neptune.Upload.csSuccessText": "アップロードが完了しました。",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "{maxSize}MB以下のファイルをアップロードしてください",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "より小さいファイルをご提供ください",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "ファイルの種類はサポートされていません。別のファイルで再度お試しください",
|
|
49
50
|
"neptune.Upload.psButtonText": "キャンセルする",
|
|
50
51
|
"neptune.Upload.psProcessingText": "アップロードしています…",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "またはファイルを選択する",
|
|
53
54
|
"neptune.Upload.usDropMessage": "ファイルをドロップしてアップロードする",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "{maxSize}MB以下のファイルをドラッグ&ドロップしてください",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "ファイルをドラッグ&ドロップ",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "すべてのファイル種類",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "ファイルをドロップしてアップロードする",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}、{size}MB以下",
|
package/src/i18n/pl.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Przesyłanie nie powiodło się. Proszę spróbować ponownie",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Przesyłanie zakończone!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Prosimy przesłać plik mniejszy niż {maxSize} MB",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Prosimy przesłać mniejszy plik",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Nieobsługiwany typ pliku. Spróbuj ponownie z innym plikiem",
|
|
49
50
|
"neptune.Upload.psButtonText": "Anuluj",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Przesyłanie...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Lub wybierz plik",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Upuść plik, aby rozpocząć przesyłanie",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Przeciągnij i upuść plik nie większy niż {maxSize} MB",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Przeciągnij i upuść plik",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Wszystkie typy plików",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Upuść plik, żeby rozpocząć przesyłanie",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, mniejsze niż {size}MB",
|
package/src/i18n/ro.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Încărcare eșuată. Te rugăm să încerci din nou",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Încărcare completă!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Te rugăm să furnizezi un fișier mai mic de {maxSize} MB",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Te rugăm să furnizezi un fișier mai mic",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Tipul de fișier nu a fost acceptat. Te rugăm să încerci din nou cu un alt fișier",
|
|
49
50
|
"neptune.Upload.psButtonText": "Anulează",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Se încarcă...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Sau selectează un fișier",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Atașează fișierul pentru a începe încărcarea",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Glisează și atașează un fișier mai mic de {maxSize} MB",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Glisează și lipește un fișier",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Toate tipurile de fișiere",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Trage fișierul pentru a începe încărcarea",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, de maximum {size}MB",
|
package/src/i18n/ru.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Загрузка не удалась. Пожалуйста, попробуйте снова",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Загрузка завершена!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Пожалуйста, загрузите файл размером менее {maxSize} Мб",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Пожалуйста, загрузите файл меньшего размера",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Тип файла не поддерживается. Пожалуйста, попробуйте еще раз с другим файлом",
|
|
49
50
|
"neptune.Upload.psButtonText": "Отменить",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Загружаем...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Или выберите файл",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Перетащите файл, чтобы начать загрузку",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "Перетащите файл размером не более {maxSize} Mб",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Перетащите файл",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Все типы файлов",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Перетащите файл, чтобы начать загрузку",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, не превышающий {size} MB",
|
package/src/i18n/tr.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "Yükleme başarısız. Lütfen yine deneyin",
|
|
46
46
|
"neptune.Upload.csSuccessText": "Yükleme tamamlandı!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "Lütfen {maxSize} MB'den küçük bir dosya sağlayın",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "Lütfen daha küçük bir dosya gönderin",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "Desteklenmeyen dosya biçimi. Lütfen başka bir dosyayla tekrar deneyin",
|
|
49
50
|
"neptune.Upload.psButtonText": "İptal edin",
|
|
50
51
|
"neptune.Upload.psProcessingText": "Yükleniyor...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "Veya bir dosya seçin",
|
|
53
54
|
"neptune.Upload.usDropMessage": "Yüklemeyi başlatmak için dosyayı bırakın",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "{maxSize} MB'den küçük bir dosya sürükleyin ve bırakın",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "Dosyayı sürükleyip bırakın",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "Tüm belge tipleri",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "Yüklemeyi başlatmak için dosyayı bırakın",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes}, en fazla {size}MB",
|
package/src/i18n/zh-CN.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
46
46
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "请提供一个小于 {maxSize} MB 的文件",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "请提供更小的文件。",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "不支持该文件类型,请试试其他文件",
|
|
49
50
|
"neptune.Upload.psButtonText": "取消",
|
|
50
51
|
"neptune.Upload.psProcessingText": "正在上传…",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "或选择文件",
|
|
53
54
|
"neptune.Upload.usDropMessage": "拖放文件开始上传",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "拖放一个不超过 {maxSize} MB 的文件",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "拖放文件",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "所有文件类型",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "拖放文件开始上传",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes},小于 {size} MB",
|
package/src/i18n/zh-HK.json
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"neptune.Upload.csFailureText": "上載失敗,請重試。",
|
|
46
46
|
"neptune.Upload.csSuccessText": "上載完成!",
|
|
47
47
|
"neptune.Upload.csTooLargeMessage": "請提供一個小於{maxSize}MB的檔案",
|
|
48
|
+
"neptune.Upload.csTooLargeNoLimitMessage": "請提供較小的檔案",
|
|
48
49
|
"neptune.Upload.csWrongTypeMessage": "不支持檔案類型,請使用其他檔案重試",
|
|
49
50
|
"neptune.Upload.psButtonText": "取消",
|
|
50
51
|
"neptune.Upload.psProcessingText": "上載中...",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"neptune.Upload.usButtonText": "或者選擇一個檔案",
|
|
53
54
|
"neptune.Upload.usDropMessage": "拖放檔案以開始上載",
|
|
54
55
|
"neptune.Upload.usPlaceholder": "拖放一個不超過{maxSize}MB的檔案",
|
|
56
|
+
"neptune.Upload.usPlaceholderNoLimit": "拖放檔案",
|
|
55
57
|
"neptune.UploadButton.allFileTypes": "所有檔案類型",
|
|
56
58
|
"neptune.UploadButton.dropFiles": "拖放檔案以開始上載",
|
|
57
59
|
"neptune.UploadButton.instructions": "{fileTypes},小於{size}MB",
|
|
@@ -17,6 +17,10 @@ export default defineMessages({
|
|
|
17
17
|
id: 'neptune.Upload.csTooLargeMessage',
|
|
18
18
|
defaultMessage: 'Please provide a file smaller than {maxSize}MB',
|
|
19
19
|
},
|
|
20
|
+
csTooLargeNoLimitMessage: {
|
|
21
|
+
id: 'neptune.Upload.csTooLargeNoLimitMessage',
|
|
22
|
+
defaultMessage: 'Please provide a smaller file',
|
|
23
|
+
},
|
|
20
24
|
csWrongTypeMessage: {
|
|
21
25
|
id: 'neptune.Upload.csWrongTypeMessage',
|
|
22
26
|
defaultMessage: 'File type not supported. Please try again with a different file',
|
|
@@ -41,6 +45,10 @@ export default defineMessages({
|
|
|
41
45
|
id: 'neptune.Upload.usPlaceholder',
|
|
42
46
|
defaultMessage: 'Drag and drop a file less than {maxSize}MB',
|
|
43
47
|
},
|
|
48
|
+
usPlaceholderNoLimit: {
|
|
49
|
+
id: 'neptune.Upload.usPlaceholderNoLimit',
|
|
50
|
+
defaultMessage: 'Drag and drop a file',
|
|
51
|
+
},
|
|
44
52
|
retry: {
|
|
45
53
|
id: 'neptune.Upload.retry',
|
|
46
54
|
defaultMessage: 'Retry',
|
|
@@ -355,4 +355,10 @@ describe('Upload Component', () => {
|
|
|
355
355
|
expect(container.querySelector('.droppable-processing')).not.toBeInTheDocument();
|
|
356
356
|
expect(props.onStart).not.toHaveBeenCalled();
|
|
357
357
|
});
|
|
358
|
+
|
|
359
|
+
test('should remove max size limit, when maxSize is the `null`', async () => {
|
|
360
|
+
render(<Upload {...props} usPlaceholder={undefined} maxSize={null} />);
|
|
361
|
+
expect(await screen.findByText(/Drag and drop a file/i)).toBeInTheDocument();
|
|
362
|
+
expect(screen.queryByText(/less than/i)).not.toBeInTheDocument();
|
|
363
|
+
});
|
|
358
364
|
});
|
|
@@ -3,18 +3,134 @@ import { fn } from 'storybook/test';
|
|
|
3
3
|
|
|
4
4
|
import Upload from '.';
|
|
5
5
|
import { MAX_SIZE_DEFAULT } from './Upload';
|
|
6
|
-
import { Field } from '../field/Field';
|
|
7
6
|
|
|
8
7
|
const meta = {
|
|
9
8
|
component: Upload,
|
|
10
9
|
title: 'Forms/Upload',
|
|
11
|
-
|
|
10
|
+
args: {
|
|
11
|
+
// Set all props to undefined so Storybook can auto-detect them
|
|
12
|
+
animationDelay: undefined,
|
|
13
|
+
csButtonText: undefined,
|
|
14
|
+
csFailureText: undefined,
|
|
15
|
+
csSuccessText: undefined,
|
|
16
|
+
csTooLargeMessage: undefined,
|
|
17
|
+
csWrongTypeMessage: undefined,
|
|
18
|
+
httpOptions: undefined,
|
|
19
|
+
fetcher: undefined,
|
|
20
|
+
maxSize: undefined,
|
|
21
|
+
psButtonText: undefined,
|
|
22
|
+
psButtonDisabled: undefined,
|
|
23
|
+
psProcessingText: undefined,
|
|
24
|
+
size: undefined,
|
|
25
|
+
usAccept: undefined,
|
|
26
|
+
usButtonText: undefined,
|
|
27
|
+
usButtonRetryText: undefined,
|
|
28
|
+
usDisabled: undefined,
|
|
29
|
+
usDropMessage: undefined,
|
|
30
|
+
usHelpImage: undefined,
|
|
31
|
+
usLabel: undefined,
|
|
32
|
+
usPlaceholder: undefined,
|
|
33
|
+
errorIconLabel: undefined,
|
|
34
|
+
onCancel: undefined,
|
|
35
|
+
onFailure: undefined,
|
|
36
|
+
onStart: undefined,
|
|
37
|
+
onSuccess: undefined,
|
|
38
|
+
uploadStep: undefined,
|
|
39
|
+
},
|
|
12
40
|
argTypes: {
|
|
13
41
|
maxSize: {
|
|
14
42
|
control: {
|
|
15
43
|
type: 'number',
|
|
16
44
|
min: 0,
|
|
17
45
|
},
|
|
46
|
+
description:
|
|
47
|
+
'Filesize expressed in Bytes.<br />If set to `null`, no size limit will be applied.',
|
|
48
|
+
table: {
|
|
49
|
+
type: {
|
|
50
|
+
summary: 'number | null',
|
|
51
|
+
},
|
|
52
|
+
defaultValue: {
|
|
53
|
+
summary: MAX_SIZE_DEFAULT.toString(),
|
|
54
|
+
detail: '5 MB',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
fetcher: {
|
|
59
|
+
description:
|
|
60
|
+
'You can provide a fetcher function with the same interface as the global fetch function, which is used by default.',
|
|
61
|
+
table: {
|
|
62
|
+
type: {
|
|
63
|
+
summary: 'PostDataFetcher',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
control: false,
|
|
67
|
+
},
|
|
68
|
+
usAccept: {
|
|
69
|
+
description:
|
|
70
|
+
'You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".\nUsing "*" will allow every file type to be uploaded.',
|
|
71
|
+
},
|
|
72
|
+
errorIconLabel: {
|
|
73
|
+
description:
|
|
74
|
+
"Override for the InlineAlert icon's default, accessible name announced by the screen readers",
|
|
75
|
+
},
|
|
76
|
+
usHelpImage: {
|
|
77
|
+
control: false,
|
|
78
|
+
table: {
|
|
79
|
+
type: {
|
|
80
|
+
summary: 'ReactNode',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
httpOptions: {
|
|
85
|
+
table: {
|
|
86
|
+
type: {
|
|
87
|
+
summary:
|
|
88
|
+
'PostDataHTTPOptions & { fileInputName?: string; data?: Record<string, string | Blob>; }',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
size: {
|
|
93
|
+
table: {
|
|
94
|
+
type: {
|
|
95
|
+
summary: `Size.SMALL | Size.MEDIUM | Size.LARGE`,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
uploadStep: {
|
|
100
|
+
description: '**@deprecated** Only a single variant exists, please remove this prop.',
|
|
101
|
+
table: {
|
|
102
|
+
type: {
|
|
103
|
+
summary: '"uploadImageStep"',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
onCancel: {
|
|
108
|
+
table: {
|
|
109
|
+
type: {
|
|
110
|
+
summary: '() => void',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
onFailure: {
|
|
115
|
+
table: {
|
|
116
|
+
type: {
|
|
117
|
+
summary: '(error: unknown) => void',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
onStart: {
|
|
122
|
+
table: {
|
|
123
|
+
type: {
|
|
124
|
+
summary: '(file: File) => void',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
onSuccess: {
|
|
129
|
+
table: {
|
|
130
|
+
type: {
|
|
131
|
+
summary: '(response: string | Response, fileName: string) => void',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
18
134
|
},
|
|
19
135
|
},
|
|
20
136
|
} satisfies Meta<typeof Upload>;
|
|
@@ -24,7 +140,6 @@ type Story = StoryObj<typeof meta>;
|
|
|
24
140
|
|
|
25
141
|
export const Basic: Story = {
|
|
26
142
|
args: {
|
|
27
|
-
maxSize: MAX_SIZE_DEFAULT,
|
|
28
143
|
usAccept: 'image/*',
|
|
29
144
|
usLabel: 'Front of your ID document',
|
|
30
145
|
usDisabled: false,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { Meta
|
|
2
|
-
import { fn } from 'storybook/test';
|
|
1
|
+
import type { Meta } from '@storybook/react-webpack5';
|
|
3
2
|
|
|
4
3
|
import Upload from '.';
|
|
5
|
-
import { MAX_SIZE_DEFAULT } from './Upload';
|
|
6
4
|
import { Field } from '../field/Field';
|
|
7
5
|
|
|
8
6
|
const meta = {
|
|
@@ -59,6 +57,10 @@ export const MaxSizes = () => {
|
|
|
59
57
|
<Upload usLabel="Pick a file, any file" maxSize={maxSize} />
|
|
60
58
|
</Field>
|
|
61
59
|
))}
|
|
60
|
+
|
|
61
|
+
<Field label="Max size: null (no limit)">
|
|
62
|
+
<Upload usLabel="Pick a file, any file" maxSize={null} />
|
|
63
|
+
</Field>
|
|
62
64
|
</div>
|
|
63
65
|
<div style={{ flex: 1 }}>
|
|
64
66
|
{decimalSizes.map((maxSize) => (
|