@transferwise/components 46.84.0 → 46.85.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/dimmer/Dimmer.js.map +1 -1
- package/build/dimmer/Dimmer.mjs.map +1 -1
- package/build/i18n/en.json +1 -0
- package/build/i18n/en.json.js +1 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +1 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/i18n/th.json +5 -0
- package/build/i18n/th.json.js +5 -0
- package/build/i18n/th.json.js.map +1 -1
- package/build/i18n/th.json.mjs +5 -0
- package/build/i18n/th.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +10 -0
- package/build/i18n/zh-CN.json.js +10 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +10 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +5 -0
- package/build/i18n/zh-HK.json.js +5 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +5 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/stepper/Stepper.js +6 -3
- package/build/stepper/Stepper.js.map +1 -1
- package/build/stepper/Stepper.mjs +6 -3
- package/build/stepper/Stepper.mjs.map +1 -1
- package/build/types/dimmer/Dimmer.d.ts +1 -1
- package/build/types/dimmer/Dimmer.d.ts.map +1 -1
- package/build/types/stepper/Stepper.d.ts +2 -1
- package/build/types/stepper/Stepper.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +2 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts +5 -0
- package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.js +3 -1
- package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.messages.js +3 -0
- package/build/uploadInput/uploadButton/UploadButton.messages.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.messages.mjs +3 -0
- package/build/uploadInput/uploadButton/UploadButton.messages.mjs.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs +3 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
- package/package.json +5 -5
- package/src/dimmer/{Dimmer.rtl.spec.tsx → Dimmer.spec.tsx} +33 -29
- package/src/dimmer/Dimmer.tsx +4 -4
- package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +3 -1
- package/src/i18n/en.json +1 -0
- package/src/i18n/th.json +5 -0
- package/src/i18n/zh-CN.json +10 -0
- package/src/i18n/zh-HK.json +5 -0
- package/src/inputs/SelectInput.story.tsx +68 -24
- package/src/navigationOption/NavigationOption.spec.tsx +113 -0
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.tests.story.tsx +81 -32
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.tests.story.tsx +124 -42
- package/src/radioOption/RadioOption.spec.tsx +73 -0
- package/src/stepper/Stepper.spec.tsx +236 -0
- package/src/stepper/Stepper.tests.story.tsx +89 -0
- package/src/stepper/Stepper.tsx +9 -4
- package/src/stepper/{deviceDetection.spec.js → deviceDetection.spec.ts} +6 -3
- package/src/uploadInput/uploadButton/UploadButton.messages.ts +7 -0
- package/src/uploadInput/uploadButton/UploadButton.tsx +1 -1
- package/src/dimmer/Dimmer.spec.js +0 -87
- package/src/navigationOption/NavigationOption.spec.js +0 -93
- package/src/radioOption/RadioOption.spec.js +0 -67
- package/src/stepper/Stepper.spec.js +0 -233
- /package/src/alert/{Alert.spec.story.tsx → Alert.tests.story.tsx} +0 -0
|
@@ -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 {`Maximum ${maxFiles} files.`}\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","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EYA,0BAGX;AAHD,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAHWA,gBAAQ,KAARA,gBAAQ,GAGnB,EAAA,CAAA,CAAA,CAAA;AAED,MAAMC,UAAU,GAAIC,KAAgB,IAAU;EAC5CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACxB,CAAC,CAAA;AAED,MAAMC,qBAAqB,GAAG,kBAAkB,CAAA;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,iBAAAA;AAAiB,CAClB,EACDC,GAA0C,KACxC;EACF,MAAM;AAAEC,IAAAA,aAAAA;GAAe,GAAGC,iBAAO,EAAE,CAAA;AACnC,EAAA,MAAMC,QAAQ,GAAGC,YAAM,CAA0B,IAAI,CAAC,CAAA;EAEtDC,yBAAmB,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xB;MAAAN,QAAA,EAAA,cAEFE,cAAA,CAACa,gBAAQ,EAAA;AAAChB,QAAAA,SAAS,EAAC,OAAO;AAACT,QAAAA,IAAI,EAAE,EAAA;OAClC,CAAA,eAAAY,cAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,qBAAQ,CAAC6B,QAAQ,CAAA;AAAC,OAAM,CAC9C,CAAA;AAAA,KAAK,CACN,CAAA;AAAA,GACI,CAAC,CAAA;AAEZ,CAAC,EACF;AAEDxE,YAAY,CAACyE,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 (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,0BAGX;AAHD,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAHWA,gBAAQ,KAARA,gBAAQ,GAGnB,EAAA,CAAA,CAAA,CAAA;AAED,MAAMC,UAAU,GAAIC,KAAgB,IAAU;E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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,IAAA;OAAM,CAAA;AACnCU,MAAAA,GAAG,EAAEG,QAAS;AACdf,MAAAA,QAAQ,EAAEA,QAAS;AACnBoE,MAAAA,IAAI,EAAC,aAAa;MAClB,aAAa3E,EAAAA,gBAAQ,CAAC4E,WAAY;AAClC5D,MAAAA,QAAQ,EAAEqB,aAAAA;AAAc,KAE1B,CAAA,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,EAAA;OAClC,CAAA,eAAAY,cAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,qBAAQ,CAAC8B,QAAQ,CAAA;AAAC,OAAM,CAC9C,CAAA;AAAA,KAAK,CACN,CAAA;AAAA,GACI,CAAC,CAAA;AAEZ,CAAC,EACF;AAEDzE,YAAY,CAAC0E,WAAW,GAAG,cAAc;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadButton.messages.js","sources":["../../../src/uploadInput/uploadButton/UploadButton.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n uploadFile: {\n id: 'neptune.UploadButton.uploadFile',\n defaultMessage: 'Upload file',\n description: 'Main CTA copy in the upload button when only a single file is allowed',\n },\n\n uploadFiles: {\n id: 'neptune.UploadButton.uploadFiles',\n defaultMessage: 'Upload files',\n description: 'Main CTA copy in the upload button when multiple files are allowed',\n },\n\n instructions: {\n id: 'neptune.UploadButton.instructions',\n defaultMessage: '{fileTypes}, less than {size}MB',\n description: 'Description about filetypes and size limit for uploading files',\n },\n\n allFileTypes: {\n id: 'neptune.UploadButton.allFileTypes',\n defaultMessage: 'All file types',\n description: 'Copy to show when all filetypes are allowed to be uploaded',\n },\n\n dropFile: {\n id: 'neptune.UploadButton.dropFiles',\n defaultMessage: 'Drop file to start upload',\n description: 'Copy to show when dragging files over the upload component',\n },\n});\n"],"names":["defineMessages","uploadFile","id","uploadFiles","instructions","allFileTypes","dropFile"],"mappings":";;;;AAEA,eAAeA,wBAAc,CAAC;AAC5BC,EAAAA,UAAU,EAAE;IACVC,EAAE,EAAA,iCAAA;GAGH;AAEDC,EAAAA,WAAW,EAAE;IACXD,EAAE,EAAA,kCAAA;GAGH;AAEDE,EAAAA,YAAY,EAAE;IACZF,EAAE,EAAA,mCAAA;GAGH;AAEDG,EAAAA,YAAY,EAAE;IACZH,EAAE,EAAA,mCAAA;
|
|
1
|
+
{"version":3,"file":"UploadButton.messages.js","sources":["../../../src/uploadInput/uploadButton/UploadButton.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n uploadFile: {\n id: 'neptune.UploadButton.uploadFile',\n defaultMessage: 'Upload file',\n description: 'Main CTA copy in the upload button when only a single file is allowed',\n },\n\n uploadFiles: {\n id: 'neptune.UploadButton.uploadFiles',\n defaultMessage: 'Upload files',\n description: 'Main CTA copy in the upload button when multiple files are allowed',\n },\n\n instructions: {\n id: 'neptune.UploadButton.instructions',\n defaultMessage: '{fileTypes}, less than {size}MB',\n description: 'Description about filetypes and size limit for uploading files',\n },\n\n maximumFiles: {\n id: 'neptune.UploadButton.maximumFiles',\n defaultMessage: 'Maximum {maxFiles} files.',\n description:\n 'When number of files to be uploaded is restricted, this information is displayed within the upload button.',\n },\n\n allFileTypes: {\n id: 'neptune.UploadButton.allFileTypes',\n defaultMessage: 'All file types',\n description: 'Copy to show when all filetypes are allowed to be uploaded',\n },\n\n dropFile: {\n id: 'neptune.UploadButton.dropFiles',\n defaultMessage: 'Drop file to start upload',\n description: 'Copy to show when dragging files over the upload component',\n },\n});\n"],"names":["defineMessages","uploadFile","id","uploadFiles","instructions","maximumFiles","allFileTypes","dropFile"],"mappings":";;;;AAEA,eAAeA,wBAAc,CAAC;AAC5BC,EAAAA,UAAU,EAAE;IACVC,EAAE,EAAA,iCAAA;GAGH;AAEDC,EAAAA,WAAW,EAAE;IACXD,EAAE,EAAA,kCAAA;GAGH;AAEDE,EAAAA,YAAY,EAAE;IACZF,EAAE,EAAA,mCAAA;GAGH;AAEDG,EAAAA,YAAY,EAAE;IACZH,EAAE,EAAA,mCAAA;GAIH;AAEDI,EAAAA,YAAY,EAAE;IACZJ,EAAE,EAAA,mCAAA;GAGH;AAEDK,EAAAA,QAAQ,EAAE;IACRL,EAAE,EAAA,gCAAA;AAGH,GAAA;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadButton.messages.mjs","sources":["../../../src/uploadInput/uploadButton/UploadButton.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n uploadFile: {\n id: 'neptune.UploadButton.uploadFile',\n defaultMessage: 'Upload file',\n description: 'Main CTA copy in the upload button when only a single file is allowed',\n },\n\n uploadFiles: {\n id: 'neptune.UploadButton.uploadFiles',\n defaultMessage: 'Upload files',\n description: 'Main CTA copy in the upload button when multiple files are allowed',\n },\n\n instructions: {\n id: 'neptune.UploadButton.instructions',\n defaultMessage: '{fileTypes}, less than {size}MB',\n description: 'Description about filetypes and size limit for uploading files',\n },\n\n allFileTypes: {\n id: 'neptune.UploadButton.allFileTypes',\n defaultMessage: 'All file types',\n description: 'Copy to show when all filetypes are allowed to be uploaded',\n },\n\n dropFile: {\n id: 'neptune.UploadButton.dropFiles',\n defaultMessage: 'Drop file to start upload',\n description: 'Copy to show when dragging files over the upload component',\n },\n});\n"],"names":["defineMessages","uploadFile","id","uploadFiles","instructions","allFileTypes","dropFile"],"mappings":";;AAEA,eAAeA,cAAc,CAAC;AAC5BC,EAAAA,UAAU,EAAE;IACVC,EAAE,EAAA,iCAAA;GAGH;AAEDC,EAAAA,WAAW,EAAE;IACXD,EAAE,EAAA,kCAAA;GAGH;AAEDE,EAAAA,YAAY,EAAE;IACZF,EAAE,EAAA,mCAAA;GAGH;AAEDG,EAAAA,YAAY,EAAE;IACZH,EAAE,EAAA,mCAAA;
|
|
1
|
+
{"version":3,"file":"UploadButton.messages.mjs","sources":["../../../src/uploadInput/uploadButton/UploadButton.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n uploadFile: {\n id: 'neptune.UploadButton.uploadFile',\n defaultMessage: 'Upload file',\n description: 'Main CTA copy in the upload button when only a single file is allowed',\n },\n\n uploadFiles: {\n id: 'neptune.UploadButton.uploadFiles',\n defaultMessage: 'Upload files',\n description: 'Main CTA copy in the upload button when multiple files are allowed',\n },\n\n instructions: {\n id: 'neptune.UploadButton.instructions',\n defaultMessage: '{fileTypes}, less than {size}MB',\n description: 'Description about filetypes and size limit for uploading files',\n },\n\n maximumFiles: {\n id: 'neptune.UploadButton.maximumFiles',\n defaultMessage: 'Maximum {maxFiles} files.',\n description:\n 'When number of files to be uploaded is restricted, this information is displayed within the upload button.',\n },\n\n allFileTypes: {\n id: 'neptune.UploadButton.allFileTypes',\n defaultMessage: 'All file types',\n description: 'Copy to show when all filetypes are allowed to be uploaded',\n },\n\n dropFile: {\n id: 'neptune.UploadButton.dropFiles',\n defaultMessage: 'Drop file to start upload',\n description: 'Copy to show when dragging files over the upload component',\n },\n});\n"],"names":["defineMessages","uploadFile","id","uploadFiles","instructions","maximumFiles","allFileTypes","dropFile"],"mappings":";;AAEA,eAAeA,cAAc,CAAC;AAC5BC,EAAAA,UAAU,EAAE;IACVC,EAAE,EAAA,iCAAA;GAGH;AAEDC,EAAAA,WAAW,EAAE;IACXD,EAAE,EAAA,kCAAA;GAGH;AAEDE,EAAAA,YAAY,EAAE;IACZF,EAAE,EAAA,mCAAA;GAGH;AAEDG,EAAAA,YAAY,EAAE;IACZH,EAAE,EAAA,mCAAA;GAIH;AAEDI,EAAAA,YAAY,EAAE;IACZJ,EAAE,EAAA,mCAAA;GAGH;AAEDK,EAAAA,QAAQ,EAAE;IACRL,EAAE,EAAA,gCAAA;AAGH,GAAA;AACF,CAAA,CAAC;;;;"}
|
|
@@ -132,7 +132,9 @@ const UploadButton = /*#__PURE__*/forwardRef(({
|
|
|
132
132
|
return /*#__PURE__*/jsxs(Body, {
|
|
133
133
|
className: "np-upload-input__text",
|
|
134
134
|
children: [getDescription(), maxFiles && /*#__PURE__*/jsxs(Fragment, {
|
|
135
|
-
children: [/*#__PURE__*/jsx("br", {}),
|
|
135
|
+
children: [/*#__PURE__*/jsx("br", {}), formatMessage(MESSAGES.maximumFiles, {
|
|
136
|
+
maxFiles
|
|
137
|
+
})]
|
|
136
138
|
})]
|
|
137
139
|
});
|
|
138
140
|
}
|
|
@@ -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 {`Maximum ${maxFiles} files.`}\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","renderButtonTitle","uploadFiles","uploadFile","clsx","htmlFor","UploadIcon","mediaBody","type","Typography","BODY_LARGE_BOLD","name","uploadInput","PlusIcon","dropFile","displayName"],"mapp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ton.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4EYA,SAGX;AAHD,CAAA,UAAYA,QAAQ,EAAA;AAClBA,EAAAA,QAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3BA,EAAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAHWA,QAAQ,KAARA,QAAQ,GAGnB,EAAA,CAAA,CAAA,CAAA;AAED,MAAMC,UAAU,GAAIC,KAAgB,IAAU;EAC5CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACxB,CAAC,CAAA;AAED,MAAMC,qBAAqB,GAAG,kBAAkB,CAAA;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,iBAAAA;AAAiB,CAClB,EACDC,GAA0C,KACxC;EACF,MAAM;AAAEC,IAAAA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AAAc,KAE1B,CAAA,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,EAAA;OAClC,CAAA,eAAAY,GAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,QAAQ,CAAC8B,QAAQ,CAAA;AAAC,OAAM,CAC9C,CAAA;AAAA,KAAK,CACN,CAAA;AAAA,GACI,CAAC,CAAA;AAEZ,CAAC,EACF;AAEDzE,YAAY,CAAC0E,WAAW,GAAG,cAAc;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.85.0",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
"rollup": "^4.18.1",
|
|
92
92
|
"rollup-preserve-directives": "^1.1.1",
|
|
93
93
|
"storybook": "^8.2.2",
|
|
94
|
-
"@transferwise/less-config": "3.1.0",
|
|
95
94
|
"@transferwise/neptune-css": "14.20.1",
|
|
96
|
-
"@wise/components-theming": "1.6.1"
|
|
95
|
+
"@wise/components-theming": "1.6.1",
|
|
96
|
+
"@transferwise/less-config": "3.1.0"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@transferwise/icons": "^3.13.1",
|
|
@@ -144,8 +144,8 @@
|
|
|
144
144
|
"build:copy-css": "cpx 'src/main.css' build/ & cpx 'src/**/*.css' build/styles/",
|
|
145
145
|
"build:copy-lang": "cpx 'src/i18n/*.json' build/i18n && cpx 'src/i18n/index.js' build/i18n",
|
|
146
146
|
"docs": "pnpm build",
|
|
147
|
-
"test": "jest",
|
|
148
|
-
"test:watch": "jest --watch",
|
|
147
|
+
"test": "TZ=UTC jest",
|
|
148
|
+
"test:watch": "TZ=UTC jest --watch",
|
|
149
149
|
"lint": "pnpm run lint:check",
|
|
150
150
|
"lint:check": "npm-run-all --parallel lint:check:*",
|
|
151
151
|
"lint:check:format": "prettier --check --ignore-path ../../.prettierignore . || echo \"Prettier failed. Remove this to make this a failure\"",
|
|
@@ -1,67 +1,61 @@
|
|
|
1
1
|
import { Button } from '..';
|
|
2
2
|
import { addNoScrollClass, removeNoScrollClass } from '../common';
|
|
3
|
-
import {
|
|
4
|
-
render,
|
|
5
|
-
cleanup,
|
|
6
|
-
waitFor,
|
|
7
|
-
screen,
|
|
8
|
-
userEvent,
|
|
9
|
-
waitForElementToBeRemoved,
|
|
10
|
-
} from '../test-utils';
|
|
3
|
+
import { render, waitFor, screen, userEvent, waitForElementToBeRemoved } from '../test-utils';
|
|
11
4
|
|
|
12
5
|
import { Dimmer } from './Dimmer';
|
|
13
6
|
|
|
14
|
-
jest.mock('../common');
|
|
7
|
+
jest.mock('../common/DOMOperations');
|
|
15
8
|
|
|
16
9
|
describe('Dimmer', () => {
|
|
17
10
|
const props = {
|
|
18
11
|
open: true,
|
|
19
12
|
children: <div />,
|
|
13
|
+
onClose: jest.fn(),
|
|
20
14
|
};
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
cleanup();
|
|
16
|
+
beforeEach(() => {
|
|
24
17
|
jest.clearAllMocks();
|
|
25
18
|
});
|
|
26
19
|
|
|
20
|
+
it('should render', () => {
|
|
21
|
+
const myContent = 'My Content';
|
|
22
|
+
render(<Dimmer {...props}>{myContent}</Dimmer>);
|
|
23
|
+
expect(screen.getByText(myContent)).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
27
26
|
describe('closing behaviour', () => {
|
|
28
27
|
it('calls onClose if the dimmer is clicked', async () => {
|
|
29
|
-
|
|
30
|
-
render(<Dimmer {...props} onClose={onClose} />);
|
|
28
|
+
render(<Dimmer {...props} />);
|
|
31
29
|
await userEvent.click(screen.getByRole('presentation'));
|
|
32
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(props.onClose).toHaveBeenCalledTimes(1);
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
it('does not call onClose if the dimmer content is clicked', async () => {
|
|
36
|
-
const onClose = jest.fn();
|
|
37
34
|
render(
|
|
38
|
-
<Dimmer {...props}
|
|
35
|
+
<Dimmer {...props}>
|
|
39
36
|
<Button onClick={() => {}}>McClicky</Button>
|
|
40
37
|
</Dimmer>,
|
|
41
38
|
);
|
|
42
39
|
await userEvent.click(screen.getByRole('button'));
|
|
43
|
-
expect(onClose).toHaveBeenCalledTimes(0);
|
|
40
|
+
expect(props.onClose).toHaveBeenCalledTimes(0);
|
|
44
41
|
});
|
|
45
42
|
|
|
46
43
|
it('does not call onClose when clicked if disableClickToClose is true', async () => {
|
|
47
|
-
|
|
48
|
-
render(<Dimmer {...props} disableClickToClose onClose={onClose} />);
|
|
44
|
+
render(<Dimmer {...props} disableClickToClose />);
|
|
49
45
|
await userEvent.click(screen.getByRole('presentation'));
|
|
50
|
-
expect(onClose).toHaveBeenCalledTimes(0);
|
|
46
|
+
expect(props.onClose).toHaveBeenCalledTimes(0);
|
|
51
47
|
});
|
|
52
48
|
|
|
53
49
|
it('calls onClose if the escape key is pressed', async () => {
|
|
54
|
-
|
|
55
|
-
render(<Dimmer {...props} onClose={onClose} />);
|
|
50
|
+
render(<Dimmer {...props} />);
|
|
56
51
|
await userEvent.keyboard('{Escape}');
|
|
57
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
52
|
+
expect(props.onClose).toHaveBeenCalledTimes(1);
|
|
58
53
|
});
|
|
59
54
|
|
|
60
55
|
it('does not call onClose if the escape key is pressed when disableClickToClose is true', async () => {
|
|
61
|
-
|
|
62
|
-
render(<Dimmer {...props} disableClickToClose onClose={onClose} />);
|
|
56
|
+
render(<Dimmer {...props} disableClickToClose />);
|
|
63
57
|
await userEvent.keyboard('{Escape}');
|
|
64
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(props.onClose).toHaveBeenCalledTimes(1);
|
|
65
59
|
});
|
|
66
60
|
});
|
|
67
61
|
|
|
@@ -83,7 +77,17 @@ describe('Dimmer', () => {
|
|
|
83
77
|
});
|
|
84
78
|
});
|
|
85
79
|
|
|
86
|
-
describe('
|
|
80
|
+
describe('scrolling', () => {
|
|
81
|
+
it('should not have `dimmer--scrollable` class by default', () => {
|
|
82
|
+
render(<Dimmer {...props} />);
|
|
83
|
+
expect(screen.getByRole('presentation')).not.toHaveClass('dimmer--scrollable');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should add 'dimmer--scrollable' class on `scrollable` prop set", () => {
|
|
87
|
+
render(<Dimmer {...props} scrollable />);
|
|
88
|
+
expect(screen.getByRole('presentation')).toHaveClass('dimmer--scrollable');
|
|
89
|
+
});
|
|
90
|
+
|
|
87
91
|
it('calls addNoScrollClass on render', () => {
|
|
88
92
|
expect(addNoScrollClass).not.toHaveBeenCalled();
|
|
89
93
|
|
|
@@ -123,7 +127,7 @@ describe('Dimmer', () => {
|
|
|
123
127
|
});
|
|
124
128
|
|
|
125
129
|
describe('animates out on exit', () => {
|
|
126
|
-
it('
|
|
130
|
+
it("isn't removed until the animation has finished", async () => {
|
|
127
131
|
const { rerender } = render(
|
|
128
132
|
<Dimmer {...props} open={false} fadeContentOnEnter fadeContentOnExit>
|
|
129
133
|
<p>Content</p>
|
|
@@ -138,7 +142,7 @@ describe('Dimmer', () => {
|
|
|
138
142
|
</Dimmer>,
|
|
139
143
|
);
|
|
140
144
|
|
|
141
|
-
await
|
|
145
|
+
expect(await screen.findByText('Content')).toBeInTheDocument();
|
|
142
146
|
|
|
143
147
|
rerender(
|
|
144
148
|
<Dimmer {...props} open={false} fadeContentOnEnter fadeContentOnExit>
|
package/src/dimmer/Dimmer.tsx
CHANGED
|
@@ -5,11 +5,11 @@ import { CSSTransition } from 'react-transition-group';
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
addNoScrollClass,
|
|
8
|
-
CommonProps,
|
|
9
|
-
PositionBottom,
|
|
10
|
-
PositionCenter,
|
|
11
|
-
PositionTop,
|
|
12
8
|
removeNoScrollClass,
|
|
9
|
+
type CommonProps,
|
|
10
|
+
type PositionBottom,
|
|
11
|
+
type PositionCenter,
|
|
12
|
+
type PositionTop,
|
|
13
13
|
} from '../common';
|
|
14
14
|
import { isIosDevice } from '../common/deviceDetection';
|
|
15
15
|
import FocusBoundary from '../common/focusBoundary';
|
|
@@ -92,6 +92,7 @@ exports[`FlowNavigation on mobile renders as expected 1`] = `
|
|
|
92
92
|
>
|
|
93
93
|
<div
|
|
94
94
|
class="progress-bar"
|
|
95
|
+
data-testid="progress-bar"
|
|
95
96
|
/>
|
|
96
97
|
</div>
|
|
97
98
|
<ol
|
|
@@ -207,7 +208,8 @@ exports[`FlowNavigation renders as expected 1`] = `
|
|
|
207
208
|
>
|
|
208
209
|
<div
|
|
209
210
|
class="progress-bar"
|
|
210
|
-
|
|
211
|
+
data-testid="progress-bar"
|
|
212
|
+
style="width: 0%;"
|
|
211
213
|
/>
|
|
212
214
|
</div>
|
|
213
215
|
<ol
|
package/src/i18n/en.json
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"neptune.UploadButton.allFileTypes": "All file types",
|
|
55
55
|
"neptune.UploadButton.dropFiles": "Drop file to start upload",
|
|
56
56
|
"neptune.UploadButton.instructions": "{fileTypes}, less than {size}MB",
|
|
57
|
+
"neptune.UploadButton.maximumFiles": "Maximum {maxFiles} files.",
|
|
57
58
|
"neptune.UploadButton.uploadFile": "Upload file",
|
|
58
59
|
"neptune.UploadButton.uploadFiles": "Upload files",
|
|
59
60
|
"neptune.UploadInput.deleteModalBody": "Removing this file will delete it from our system.",
|
package/src/i18n/th.json
CHANGED
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"neptune.Summary.statusDone": "รายการที่ทำแล้ว",
|
|
36
36
|
"neptune.Summary.statusNotDone": "รายการที่ต้องทำ",
|
|
37
37
|
"neptune.Summary.statusPending": "รายการที่รอดำเนินการ",
|
|
38
|
+
"neptune.Table.actionHeader": "การดำเนินการ",
|
|
39
|
+
"neptune.Table.emptyData": "ไม่พบผลลัพธ์",
|
|
40
|
+
"neptune.Table.loaded": "โหลดข้อมูลตารางแล้ว",
|
|
41
|
+
"neptune.Table.loading": "กำลังโหลดข้อมูลตาราง",
|
|
42
|
+
"neptune.Table.refreshPage": "รีเฟรชหน้า",
|
|
38
43
|
"neptune.Upload.csButtonText": "อัปโหลดไฟล์อื่นหรือไม่",
|
|
39
44
|
"neptune.Upload.csFailureText": "การอัปโหลดล้มเหลว กรุณาลองอีกครั้ง",
|
|
40
45
|
"neptune.Upload.csSuccessText": "อัปโหลดเรียบร้อย!",
|
package/src/i18n/zh-CN.json
CHANGED
|
@@ -27,9 +27,19 @@
|
|
|
27
27
|
"neptune.SelectInput.noResultsFound": "找不到结果",
|
|
28
28
|
"neptune.SelectOption.action.label": "选择",
|
|
29
29
|
"neptune.SelectOption.selected.action.label": "更改所选选项",
|
|
30
|
+
"neptune.StatusIcon.iconLabel.error": "错误:",
|
|
31
|
+
"neptune.StatusIcon.iconLabel.information": "信息:",
|
|
32
|
+
"neptune.StatusIcon.iconLabel.pending": "待处理:",
|
|
33
|
+
"neptune.StatusIcon.iconLabel.success": "成功:",
|
|
34
|
+
"neptune.StatusIcon.iconLabel.warning": "警告:",
|
|
30
35
|
"neptune.Summary.statusDone": "已完成",
|
|
31
36
|
"neptune.Summary.statusNotDone": "未完成",
|
|
32
37
|
"neptune.Summary.statusPending": "待处理",
|
|
38
|
+
"neptune.Table.actionHeader": "操作",
|
|
39
|
+
"neptune.Table.emptyData": "找不到结果",
|
|
40
|
+
"neptune.Table.loaded": "表数据已加载",
|
|
41
|
+
"neptune.Table.loading": "表数据正在加载",
|
|
42
|
+
"neptune.Table.refreshPage": "刷新页面",
|
|
33
43
|
"neptune.Upload.csButtonText": "上传另一个文件?",
|
|
34
44
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
35
45
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
package/src/i18n/zh-HK.json
CHANGED
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"neptune.Summary.statusDone": "已完成事項",
|
|
36
36
|
"neptune.Summary.statusNotDone": "未完成事項",
|
|
37
37
|
"neptune.Summary.statusPending": "待處理事項",
|
|
38
|
+
"neptune.Table.actionHeader": "行動",
|
|
39
|
+
"neptune.Table.emptyData": "找不到任何結果",
|
|
40
|
+
"neptune.Table.loaded": "已載入表格資料",
|
|
41
|
+
"neptune.Table.loading": "正在載入表格資料",
|
|
42
|
+
"neptune.Table.refreshPage": "重新整理頁面",
|
|
38
43
|
"neptune.Upload.csButtonText": "上載另一個檔案?",
|
|
39
44
|
"neptune.Upload.csFailureText": "上載失敗,請重試。",
|
|
40
45
|
"neptune.Upload.csSuccessText": "上載完成!",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { expect, fn, type Mock, screen, userEvent, within } from '@storybook/test';
|
|
2
|
+
import { expect, fn, type Mock, screen, userEvent, within, waitFor } from '@storybook/test';
|
|
3
3
|
import { Calendar, ChevronDown } from '@transferwise/icons';
|
|
4
4
|
import { Flag } from '@wise/art';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
@@ -75,7 +75,7 @@ export const Months: Story<Month | null> = {
|
|
|
75
75
|
|
|
76
76
|
await step('renders placeholder', async () => {
|
|
77
77
|
const triggerButton = canvas.getByRole('combobox');
|
|
78
|
-
await expect(triggerButton).toHaveTextContent('Month');
|
|
78
|
+
await waitFor(async () => expect(triggerButton).toHaveTextContent('Month'));
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
await step('selects option via mouse', async () => {
|
|
@@ -89,7 +89,7 @@ export const Months: Story<Month | null> = {
|
|
|
89
89
|
});
|
|
90
90
|
await userEvent.click(option);
|
|
91
91
|
|
|
92
|
-
await expect(triggerButton).toHaveTextContent('May');
|
|
92
|
+
await waitFor(async () => expect(triggerButton).toHaveTextContent('May'));
|
|
93
93
|
});
|
|
94
94
|
},
|
|
95
95
|
};
|
|
@@ -189,27 +189,61 @@ const CurrenciesArgs = {
|
|
|
189
189
|
export const Currencies: Story<Currency> = {
|
|
190
190
|
args: CurrenciesArgs,
|
|
191
191
|
play: async ({ step }) => {
|
|
192
|
-
await step('
|
|
192
|
+
await step('Tab to the combobox', async () => {
|
|
193
193
|
await userEvent.tab();
|
|
194
|
-
|
|
194
|
+
});
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
await
|
|
196
|
+
await step('Open the combobox', async () => {
|
|
197
|
+
await userEvent.keyboard(' ');
|
|
198
|
+
});
|
|
198
199
|
|
|
199
|
-
|
|
200
|
+
await step('Check if options are displayed', async () => {
|
|
201
|
+
await waitFor(async () => expect(await screen.findAllByRole('option')).toHaveLength(8));
|
|
202
|
+
await waitFor(async () => expect(screen.getByText(/^Can’t find it?/u)).toBeInTheDocument());
|
|
203
|
+
});
|
|
200
204
|
|
|
201
|
-
|
|
205
|
+
await step('Type "huf" in the combobox', async () => {
|
|
206
|
+
// this is workaround for Chromatic: Firefox and Edge tests failing.
|
|
207
|
+
// Unclear on a proper solution
|
|
208
|
+
await wait(750);
|
|
209
|
+
const input = await screen.findByRole('combobox');
|
|
202
210
|
await userEvent.type(input, 'huf');
|
|
203
|
-
|
|
204
|
-
within(screen.getByRole('listbox')).queryByRole('option'),
|
|
205
|
-
).not.toBeInTheDocument();
|
|
206
|
-
await expect(screen.getByText(/^It’s not possible use HUF yet./u)).toBeInTheDocument();
|
|
211
|
+
});
|
|
207
212
|
|
|
213
|
+
await step('Check if no options are displayed', async () => {
|
|
214
|
+
// this is workaround for Chromatic: Firefox and Edge tests failing.
|
|
215
|
+
// Unclear on a proper solution
|
|
216
|
+
await wait(750);
|
|
217
|
+
await expect(await screen.findByText(/^No results found/u)).toBeInTheDocument();
|
|
218
|
+
await expect(await screen.findByText(/^It’s not possible use HUF yet./u)).toBeInTheDocument();
|
|
219
|
+
await waitFor(
|
|
220
|
+
async () => {
|
|
221
|
+
await expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
222
|
+
},
|
|
223
|
+
{ timeout: 1500 },
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
await step('Remove last two characters', async () => {
|
|
228
|
+
await wait(500);
|
|
229
|
+
const input = await screen.findByRole('combobox');
|
|
208
230
|
await userEvent.type(input, '{Backspace}{Backspace}');
|
|
209
|
-
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await step('Check if two options are displayed', async () => {
|
|
234
|
+
await waitFor(async () =>
|
|
235
|
+
expect(within(screen.getByRole('listbox')).queryAllByRole('option')).toHaveLength(2),
|
|
236
|
+
);
|
|
237
|
+
});
|
|
210
238
|
|
|
239
|
+
await step('Type "e" in the combobox', async () => {
|
|
240
|
+
const input = await screen.findByRole('combobox');
|
|
211
241
|
await userEvent.type(input, '{Backspace}e');
|
|
212
|
-
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
await step('Check if aria-activedescendant is not set', async () => {
|
|
245
|
+
const input = screen.getByRole('combobox');
|
|
246
|
+
await waitFor(async () => expect(input).toHaveAttribute('aria-activedescendant'));
|
|
213
247
|
});
|
|
214
248
|
},
|
|
215
249
|
};
|
|
@@ -234,18 +268,24 @@ export const MultipleCurrencies: Story<Currency, true> = {
|
|
|
234
268
|
play: async ({ canvasElement, step }) => {
|
|
235
269
|
const canvas = within(canvasElement);
|
|
236
270
|
|
|
237
|
-
await step('
|
|
271
|
+
await step('Open the combobox', async () => {
|
|
238
272
|
const triggerButton = canvas.getByRole('combobox');
|
|
239
|
-
|
|
240
273
|
await userEvent.click(triggerButton);
|
|
274
|
+
await wait(500);
|
|
241
275
|
await userEvent.unhover(triggerButton);
|
|
276
|
+
});
|
|
242
277
|
|
|
278
|
+
await step('Select EUR option', async () => {
|
|
243
279
|
const option = within(screen.getByRole('listbox')).getAllByRole('option', {
|
|
244
280
|
name: /^EUR/u,
|
|
245
281
|
})[0];
|
|
282
|
+
await wait(500);
|
|
246
283
|
await userEvent.click(option);
|
|
284
|
+
});
|
|
247
285
|
|
|
248
|
-
|
|
286
|
+
await step('Check if selected options are displayed', async () => {
|
|
287
|
+
const triggerButton = document.querySelector('button[role="combobox"]');
|
|
288
|
+
await waitFor(async () => expect(triggerButton).toHaveTextContent('USD, EUR'));
|
|
249
289
|
});
|
|
250
290
|
},
|
|
251
291
|
};
|
|
@@ -270,11 +310,13 @@ export const CustomTrigger: Story<Month> = {
|
|
|
270
310
|
),
|
|
271
311
|
onChange: fn() satisfies Mock,
|
|
272
312
|
},
|
|
273
|
-
play: async ({ canvasElement }) => {
|
|
313
|
+
play: async ({ canvasElement, step }) => {
|
|
274
314
|
const canvas = within(canvasElement);
|
|
275
315
|
|
|
276
|
-
|
|
277
|
-
|
|
316
|
+
await step('Open the combobox', async () => {
|
|
317
|
+
const triggerButton = canvas.getByRole('combobox');
|
|
318
|
+
await userEvent.click(triggerButton);
|
|
319
|
+
});
|
|
278
320
|
},
|
|
279
321
|
};
|
|
280
322
|
|
|
@@ -315,11 +357,13 @@ export const Advanced: Story<Month> = {
|
|
|
315
357
|
filterPlaceholder: 'Type a month’s name',
|
|
316
358
|
onChange: fn() satisfies Mock,
|
|
317
359
|
},
|
|
318
|
-
play: async ({ canvasElement }) => {
|
|
360
|
+
play: async ({ canvasElement, step }) => {
|
|
319
361
|
const canvas = within(canvasElement);
|
|
320
362
|
|
|
321
|
-
|
|
322
|
-
|
|
363
|
+
await step('Open the combobox', async () => {
|
|
364
|
+
const triggerButton = canvas.getByRole('combobox');
|
|
365
|
+
await userEvent.click(triggerButton);
|
|
366
|
+
});
|
|
323
367
|
},
|
|
324
368
|
};
|
|
325
369
|
|