@transferwise/components 46.84.1 → 46.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/build/avatarLayout/AvatarLayout.js +1 -0
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +1 -0
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/circularButton/CircularButton.js +18 -21
  6. package/build/circularButton/CircularButton.js.map +1 -1
  7. package/build/circularButton/CircularButton.mjs +19 -22
  8. package/build/circularButton/CircularButton.mjs.map +1 -1
  9. package/build/definitionList/DefinitionList.js.map +1 -1
  10. package/build/definitionList/DefinitionList.mjs.map +1 -1
  11. package/build/dimmer/Dimmer.js.map +1 -1
  12. package/build/dimmer/Dimmer.mjs.map +1 -1
  13. package/build/i18n/de.json +1 -0
  14. package/build/i18n/de.json.js +1 -0
  15. package/build/i18n/de.json.js.map +1 -1
  16. package/build/i18n/de.json.mjs +1 -0
  17. package/build/i18n/de.json.mjs.map +1 -1
  18. package/build/i18n/en.json +1 -0
  19. package/build/i18n/en.json.js +1 -0
  20. package/build/i18n/en.json.js.map +1 -1
  21. package/build/i18n/en.json.mjs +1 -0
  22. package/build/i18n/en.json.mjs.map +1 -1
  23. package/build/i18n/es.json +1 -0
  24. package/build/i18n/es.json.js +1 -0
  25. package/build/i18n/es.json.js.map +1 -1
  26. package/build/i18n/es.json.mjs +1 -0
  27. package/build/i18n/es.json.mjs.map +1 -1
  28. package/build/i18n/fr.json +6 -5
  29. package/build/i18n/fr.json.js +6 -5
  30. package/build/i18n/fr.json.js.map +1 -1
  31. package/build/i18n/fr.json.mjs +6 -5
  32. package/build/i18n/fr.json.mjs.map +1 -1
  33. package/build/i18n/hu.json +1 -0
  34. package/build/i18n/hu.json.js +1 -0
  35. package/build/i18n/hu.json.js.map +1 -1
  36. package/build/i18n/hu.json.mjs +1 -0
  37. package/build/i18n/hu.json.mjs.map +1 -1
  38. package/build/i18n/id.json +1 -0
  39. package/build/i18n/id.json.js +1 -0
  40. package/build/i18n/id.json.js.map +1 -1
  41. package/build/i18n/id.json.mjs +1 -0
  42. package/build/i18n/id.json.mjs.map +1 -1
  43. package/build/i18n/it.json +1 -0
  44. package/build/i18n/it.json.js +1 -0
  45. package/build/i18n/it.json.js.map +1 -1
  46. package/build/i18n/it.json.mjs +1 -0
  47. package/build/i18n/it.json.mjs.map +1 -1
  48. package/build/i18n/pl.json +1 -0
  49. package/build/i18n/pl.json.js +1 -0
  50. package/build/i18n/pl.json.js.map +1 -1
  51. package/build/i18n/pl.json.mjs +1 -0
  52. package/build/i18n/pl.json.mjs.map +1 -1
  53. package/build/i18n/ro.json +1 -0
  54. package/build/i18n/ro.json.js +1 -0
  55. package/build/i18n/ro.json.js.map +1 -1
  56. package/build/i18n/ro.json.mjs +1 -0
  57. package/build/i18n/ro.json.mjs.map +1 -1
  58. package/build/i18n/th.json +6 -0
  59. package/build/i18n/th.json.js +6 -0
  60. package/build/i18n/th.json.js.map +1 -1
  61. package/build/i18n/th.json.mjs +6 -0
  62. package/build/i18n/th.json.mjs.map +1 -1
  63. package/build/i18n/tr.json +1 -0
  64. package/build/i18n/tr.json.js +1 -0
  65. package/build/i18n/tr.json.js.map +1 -1
  66. package/build/i18n/tr.json.mjs +1 -0
  67. package/build/i18n/tr.json.mjs.map +1 -1
  68. package/build/i18n/zh-CN.json +11 -0
  69. package/build/i18n/zh-CN.json.js +11 -0
  70. package/build/i18n/zh-CN.json.js.map +1 -1
  71. package/build/i18n/zh-CN.json.mjs +11 -0
  72. package/build/i18n/zh-CN.json.mjs.map +1 -1
  73. package/build/i18n/zh-HK.json +5 -0
  74. package/build/i18n/zh-HK.json.js +5 -0
  75. package/build/i18n/zh-HK.json.js.map +1 -1
  76. package/build/i18n/zh-HK.json.mjs +5 -0
  77. package/build/i18n/zh-HK.json.mjs.map +1 -1
  78. package/build/main.css +17 -158
  79. package/build/moneyInput/MoneyInput.js.map +1 -1
  80. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  81. package/build/stepper/Stepper.js +6 -3
  82. package/build/stepper/Stepper.js.map +1 -1
  83. package/build/stepper/Stepper.mjs +6 -3
  84. package/build/stepper/Stepper.mjs.map +1 -1
  85. package/build/styles/circularButton/CircularButton.css +17 -158
  86. package/build/styles/main.css +17 -158
  87. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  88. package/build/types/circularButton/CircularButton.d.ts +11 -4
  89. package/build/types/circularButton/CircularButton.d.ts.map +1 -1
  90. package/build/types/definitionList/DefinitionList.d.ts +1 -2
  91. package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
  92. package/build/types/dimmer/Dimmer.d.ts +1 -1
  93. package/build/types/dimmer/Dimmer.d.ts.map +1 -1
  94. package/build/types/moneyInput/MoneyInput.d.ts +1 -1
  95. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  96. package/build/types/stepper/Stepper.d.ts +2 -1
  97. package/build/types/stepper/Stepper.d.ts.map +1 -1
  98. package/build/types/test-utils/index.d.ts +2 -0
  99. package/build/types/test-utils/index.d.ts.map +1 -1
  100. package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts +5 -0
  101. package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts.map +1 -1
  102. package/build/uploadInput/uploadButton/UploadButton.js +3 -1
  103. package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
  104. package/build/uploadInput/uploadButton/UploadButton.messages.js +3 -0
  105. package/build/uploadInput/uploadButton/UploadButton.messages.js.map +1 -1
  106. package/build/uploadInput/uploadButton/UploadButton.messages.mjs +3 -0
  107. package/build/uploadInput/uploadButton/UploadButton.messages.mjs.map +1 -1
  108. package/build/uploadInput/uploadButton/UploadButton.mjs +3 -1
  109. package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
  110. package/package.json +5 -5
  111. package/src/avatar/Avatar.story.tsx +4 -1
  112. package/src/avatarLayout/AvatarLayout.story.tsx +2 -0
  113. package/src/avatarLayout/AvatarLayout.tsx +3 -1
  114. package/src/avatarWrapper/AvatarWrapper.story.tsx +4 -0
  115. package/src/badge/Badge.story.tsx +4 -0
  116. package/src/circularButton/CircularButton.css +17 -158
  117. package/src/circularButton/CircularButton.less +22 -91
  118. package/src/circularButton/CircularButton.story.tsx +45 -24
  119. package/src/circularButton/CircularButton.tsx +38 -25
  120. package/src/definitionList/DefinitionList.story.tsx +57 -57
  121. package/src/definitionList/DefinitionList.tsx +1 -1
  122. package/src/dimmer/{Dimmer.rtl.spec.tsx → Dimmer.spec.tsx} +33 -29
  123. package/src/dimmer/Dimmer.tsx +4 -4
  124. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +3 -1
  125. package/src/i18n/de.json +1 -0
  126. package/src/i18n/en.json +1 -0
  127. package/src/i18n/es.json +1 -0
  128. package/src/i18n/fr.json +6 -5
  129. package/src/i18n/hu.json +1 -0
  130. package/src/i18n/id.json +1 -0
  131. package/src/i18n/it.json +1 -0
  132. package/src/i18n/pl.json +1 -0
  133. package/src/i18n/ro.json +1 -0
  134. package/src/i18n/th.json +6 -0
  135. package/src/i18n/tr.json +1 -0
  136. package/src/i18n/zh-CN.json +11 -0
  137. package/src/i18n/zh-HK.json +5 -0
  138. package/src/iconButton/IconButton.story.tsx +6 -6
  139. package/src/main.css +17 -158
  140. package/src/moneyInput/MoneyInput.spec.tsx +468 -0
  141. package/src/moneyInput/MoneyInput.tsx +2 -1
  142. package/src/navigationOption/NavigationOption.spec.tsx +113 -0
  143. package/src/phoneNumberInput/PhoneNumberInput.spec.tsx +283 -0
  144. package/src/radioOption/RadioOption.spec.tsx +73 -0
  145. package/src/slidingPanel/SlidingPanel.spec.tsx +69 -0
  146. package/src/stepper/Stepper.spec.tsx +236 -0
  147. package/src/stepper/Stepper.tests.story.tsx +89 -0
  148. package/src/stepper/Stepper.tsx +9 -4
  149. package/src/stepper/{deviceDetection.spec.js → deviceDetection.spec.ts} +6 -3
  150. package/src/uploadInput/uploadButton/UploadButton.messages.ts +7 -0
  151. package/src/uploadInput/uploadButton/UploadButton.tsx +1 -1
  152. package/src/circularButton/_button-label-states.less +0 -34
  153. package/src/definitionList/DefinitionList.spec.js +0 -91
  154. package/src/dimmer/Dimmer.spec.js +0 -87
  155. package/src/moneyInput/MoneyInput.rtl.spec.tsx +0 -149
  156. package/src/moneyInput/MoneyInput.spec.js +0 -820
  157. package/src/navigationOption/NavigationOption.spec.js +0 -93
  158. package/src/phoneNumberInput/PhoneNumberInput.rtl.spec.tsx +0 -32
  159. package/src/phoneNumberInput/PhoneNumberInput.spec.js +0 -356
  160. package/src/radioOption/RadioOption.spec.js +0 -67
  161. package/src/slidingPanel/SlidingPanel.spec.js +0 -56
  162. package/src/stepper/Stepper.spec.js +0 -233
  163. /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,E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,eAAgB;AAACb,QAAAA,SAAS,EAAC,wBAAwB;QAAAC,QAAA,EACvEG,iBAAiB;AAAE,OAChB,CACN,EAACP,iBAAiB,EAAE,CAAA;KACjB,CACL,eAAAM,cAAA,CAAA,OAAA,EAAA;AACEH,MAAAA,SAAS,EAAC,8CAA8C;AACxDW,MAAAA,IAAI,EAAC,MAAM;AACXtD,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;AACnBmE,MAAAA,IAAI,EAAC,aAAa;MAClB,aAAa1E,EAAAA,gBAAQ,CAAC2E,WAAY;AAClC3D,MAAAA,QAAQ,EAAEqB,aAAAA;AAAc,KAE1B,CAAA,EAACV,UAAU,iBACT+B,eAAA,CAAA,KAAA,EAAA;MACEE,SAAS,EAAEO,SAAI,CACb,oCAAoC,EACpC,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,CACxB;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;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,CAACL,GAAG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B,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;;;;"}
@@ -12,6 +12,9 @@ var MESSAGES = reactIntl.defineMessages({
12
12
  instructions: {
13
13
  id: "neptune.UploadButton.instructions"
14
14
  },
15
+ maximumFiles: {
16
+ id: "neptune.UploadButton.maximumFiles"
17
+ },
15
18
  allFileTypes: {
16
19
  id: "neptune.UploadButton.allFileTypes"
17
20
  },
@@ -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;GAGH;AAEDI,EAAAA,QAAQ,EAAE;IACRJ,EAAE,EAAA,gCAAA;AAGH,GAAA;AACF,CAAA,CAAC;;;;"}
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;;;;"}
@@ -10,6 +10,9 @@ var MESSAGES = defineMessages({
10
10
  instructions: {
11
11
  id: "neptune.UploadButton.instructions"
12
12
  },
13
+ maximumFiles: {
14
+ id: "neptune.UploadButton.maximumFiles"
15
+ },
13
16
  allFileTypes: {
14
17
  id: "neptune.UploadButton.allFileTypes"
15
18
  },
@@ -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;GAGH;AAEDI,EAAAA,QAAQ,EAAE;IACRJ,EAAE,EAAA,gCAAA;AAGH,GAAA;AACF,CAAA,CAAC;;;;"}
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", {}), `Maximum ${maxFiles} files.`]
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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4EYA,SAGX;AAHD,CAAA,UAA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EAAA,cAC7EE,GAAA,CAACJ,IAAI,EAAA;QAACY,IAAI,EAAEC,UAAU,CAACC,eAAgB;AAACb,QAAAA,SAAS,EAAC,wBAAwB;QAAAC,QAAA,EACvEG,iBAAiB;AAAE,OAChB,CACN,EAACP,iBAAiB,EAAE,CAAA;KACjB,CACL,eAAAM,GAAA,CAAA,OAAA,EAAA;AACEH,MAAAA,SAAS,EAAC,8CAA8C;AACxDW,MAAAA,IAAI,EAAC,MAAM;AACXtD,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;AACnBmE,MAAAA,IAAI,EAAC,aAAa;MAClB,aAAa1E,EAAAA,QAAQ,CAAC2E,WAAY;AAClC3D,MAAAA,QAAQ,EAAEqB,aAAAA;AAAc,KAE1B,CAAA,EAACV,UAAU,iBACT+B,IAAA,CAAA,KAAA,EAAA;MACEE,SAAS,EAAEO,IAAI,CACb,oCAAoC,EACpC,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,CACxB;MAAAN,QAAA,EAAA,cAEFE,GAAA,CAACa,UAAQ,EAAA;AAAChB,QAAAA,SAAS,EAAC,OAAO;AAACT,QAAAA,IAAI,EAAE,EAAA;OAClC,CAAA,eAAAY,GAAA,CAAA,KAAA,EAAA;AAAAF,QAAAA,QAAA,EAAMzC,aAAa,CAAC4B,QAAQ,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.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,aAAAA;GAAe,GAAGC,OAAO,EAAE,CAAA;AACnC,EAAA,MAAMC,QAAQ,GAAGC,MA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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.84.1",
3
+ "version": "46.86.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",
94
95
  "@transferwise/neptune-css": "14.20.1",
95
- "@wise/components-theming": "1.6.1",
96
- "@transferwise/less-config": "3.1.0"
96
+ "@wise/components-theming": "1.6.1"
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\"",
@@ -7,6 +7,9 @@ import { storyConfig } from '../test-utils';
7
7
 
8
8
  import Avatar, { AvatarType } from '.';
9
9
 
10
+ /**
11
+ * @deprecated use **`AvatarView`** components instead
12
+ */
10
13
  export default {
11
14
  component: Avatar,
12
15
  title: 'Content/Avatar',
@@ -45,7 +48,7 @@ export const Table: Story = storyConfig(
45
48
  const backgroundColor = '#d6f5e3';
46
49
  const emoji = '✈️';
47
50
  const initials = 'GN';
48
- const Icon = wiseIcons['Check'];
51
+ const Icon = wiseIcons.Check;
49
52
 
50
53
  return (
51
54
  <div>
@@ -197,8 +197,10 @@ export const EdgeInstances: Story = {
197
197
  <AvatarLayout orientation="diagonal" avatars={[{}]} />
198
198
 
199
199
  <AvatarLayout orientation="diagonal" avatars={[{ profileName: 'Jay Jay' }]} />
200
+ <AvatarLayout orientation="diagonal" size={16} avatars={[{ profileName: 'Jay Jay' }]} />
200
201
 
201
202
  <AvatarLayout orientation="diagonal" avatars={[{ asset: <Flag code="gb" /> }]} />
203
+ <AvatarLayout orientation="diagonal" size={24} avatars={[{ asset: <Flag code="gb" /> }]} />
202
204
 
203
205
  <AvatarLayout
204
206
  orientation="diagonal"
@@ -27,7 +27,9 @@ export default function AvatarLayout({
27
27
  const isDiagonal = orientation === 'diagonal';
28
28
  const avatarSize = isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size]?.avatarSize : size;
29
29
  return avatars.length < 1 ? null : avatars.length === 1 ? (
30
- <AvatarView {...avatars[0]}>{avatars[0].asset}</AvatarView>
30
+ <AvatarView {...avatars[0]} size={size}>
31
+ {avatars[0].asset}
32
+ </AvatarView>
31
33
  ) : (
32
34
  <div
33
35
  className={clsx('np-avatar-layout', `np-avatar-layout-${orientation}`, className)}
@@ -4,7 +4,11 @@ import { ProfileType, Sentiment } from '../common';
4
4
 
5
5
  import AvatarWrapper from './AvatarWrapper';
6
6
 
7
+ /**
8
+ * @deprecated use **`AvatarView`** components instead
9
+ */
7
10
  export default {
11
+ tags: ['autodocs'],
8
12
  component: AvatarWrapper,
9
13
  title: 'Content/AvatarWrapper',
10
14
  } satisfies Meta<typeof AvatarWrapper>;
@@ -5,7 +5,11 @@ import { Size, Theme } from '../common';
5
5
 
6
6
  import Badge from './Badge';
7
7
 
8
+ /**
9
+ * @deprecated use **`<AvatarView badge={..} />`** components instead
10
+ */
8
11
  export default {
12
+ tags: ['autodocs'],
9
13
  component: Badge,
10
14
  title: 'Content/Badge',
11
15
  excludeStories: ['ExampleBadgeCss'],
@@ -2,173 +2,32 @@
2
2
  display: inline-flex;
3
3
  flex-direction: column;
4
4
  align-items: center;
5
- text-align: center;
6
5
  cursor: pointer;
7
- position: relative;
8
6
  }
9
- .np-circular-btn .tw-icon {
10
- position: absolute;
11
- top: 16px;
12
- top: var(--size-16);
13
- pointer-events: none;
14
- color: white;
15
- transition: color 0.15s ease-in-out;
16
- width: 100%;
17
- left: 0;
18
- }
19
- [dir="rtl"] .np-circular-btn .tw-icon {
20
- right: 0;
21
- left: auto;
22
- left: initial;
23
- }
24
- @media (max-width: 320px) {
25
- .np-circular-btn .tw-icon {
26
- top: 12px;
27
- top: var(--size-12);
28
- }
29
- }
30
- .np-circular-btn .tw-icon > svg {
31
- margin: 0 auto;
32
- }
33
- .np-theme-personal .np-circular-btn {
34
- /* stylelint-disable-next-line no-duplicate-selectors */
35
- }
36
- .np-theme-personal .np-circular-btn .tw-icon,
37
- .np-theme-personal .np-circular-btn .tw-icon:hover,
38
- .np-theme-personal .np-circular-btn .tw-icon:active {
39
- color: var(--color-interactive-control);
40
- }
41
- .np-theme-personal .np-circular-btn.negative .tw-icon,
42
- .np-theme-personal .np-circular-btn.negative.secondary:not(.disabled):not(:disabled):hover .tw-icon,
43
- .np-theme-personal .np-circular-btn.negative.secondary:not(.disabled):not(:disabled):active .tw-icon {
44
- color: var(--color-contrast) !important;
45
- }
46
- .np-theme-personal .np-circular-btn.negative.secondary:not(.disabled):not(:disabled) .tw-icon {
47
- color: var(--color-sentiment-negative) !important;
48
- }
49
- .np-circular-btn.accent .np-circular-btn__label {
50
- color: #00a2dd;
51
- color: var(--color-interactive-accent);
52
- }
53
- .np-circular-btn.accent:not(.disabled):not(:disabled):hover .np-circular-btn__label {
54
- color: #008fc9;
55
- color: var(--color-interactive-accent-hover);
56
- }
57
- .np-circular-btn.accent:active .np-circular-btn__label,
58
- .np-circular-btn.accent input[type="button"]:active ~ .np-circular-btn__label {
59
- color: #0081ba;
60
- color: var(--color-interactive-accent-active);
61
- }
62
- .np-circular-btn.accent.secondary .tw-icon {
63
- color: #00a2dd;
64
- color: var(--color-interactive-accent);
65
- }
66
- .np-circular-btn.accent.secondary:not(.disabled):not(:disabled):hover .tw-icon,
67
- .np-circular-btn.accent.secondary input[type="button"]:active + .tw-icon {
68
- color: white;
69
- }
70
- .np-circular-btn.positive .np-circular-btn__label {
71
- color: #2ead4b;
72
- color: var(--color-interactive-positive);
73
- }
74
- .np-circular-btn.positive:not(.disabled):not(:disabled):hover .np-circular-btn__label {
75
- color: #069939;
76
- color: var(--color-interactive-positive-hover);
77
- }
78
- .np-circular-btn.positive:active .np-circular-btn__label,
79
- .np-circular-btn.positive input[type="button"]:active ~ .np-circular-btn__label {
80
- color: #008b2b;
81
- color: var(--color-interactive-positive-active);
82
- }
83
- .np-circular-btn.positive.secondary .tw-icon {
84
- color: #2ead4b;
85
- color: var(--color-interactive-positive);
86
- }
87
- .np-circular-btn.positive.secondary:not(.disabled):not(:disabled):hover .tw-icon,
88
- .np-circular-btn.positive.secondary input[type="button"]:active + .tw-icon {
89
- color: white;
90
- }
91
- .np-circular-btn.negative .np-circular-btn__label {
92
- color: #e74848;
93
- color: var(--color-interactive-negative);
94
- }
95
- .np-circular-btn.negative:not(.disabled):not(:disabled):hover .np-circular-btn__label {
96
- color: #d03238;
97
- color: var(--color-interactive-negative-hover);
98
- }
99
- .np-circular-btn.negative:active .np-circular-btn__label,
100
- .np-circular-btn.negative input[type="button"]:active ~ .np-circular-btn__label {
101
- color: #bf1e2c;
102
- color: var(--color-interactive-negative-active);
103
- }
104
- .np-circular-btn.negative.secondary .tw-icon {
105
- color: #e74848;
106
- color: var(--color-interactive-negative);
107
- }
108
- .np-circular-btn.negative.secondary:not(.disabled):not(:disabled):hover .tw-icon,
109
- .np-circular-btn.negative.secondary input[type="button"]:active + .tw-icon {
110
- color: white;
111
- }
112
- .np-theme-personal .np-circular-btn.accent .np-circular-btn__label {
7
+ .np-circular-btn-primary-default .np-circular-btn-label,
8
+ .np-circular-btn-secondary-default .np-circular-btn-label {
113
9
  color: var(--color-interactive-primary);
114
10
  }
115
- .np-theme-personal .np-circular-btn.accent:not(.disabled):not(:disabled):hover .np-circular-btn__label {
11
+ .np-circular-btn-primary-default .np-circular-btn-label:not(.disabled):not(:disabled):hover,
12
+ .np-circular-btn-secondary-default .np-circular-btn-label:not(.disabled):not(:disabled):hover {
116
13
  color: var(--color-interactive-primary-hover);
117
14
  }
118
- .np-theme-personal .np-circular-btn.accent:active .np-circular-btn__label,
119
- .np-theme-personal .np-circular-btn.accent input[type="button"]:active ~ .np-circular-btn__label {
15
+ .np-circular-btn-primary-default .np-circular-btn-label:not(.disabled):not(:disabled):active,
16
+ .np-circular-btn-secondary-default .np-circular-btn-label:not(.disabled):not(:disabled):active {
120
17
  color: var(--color-interactive-primary-active);
121
18
  }
122
- .np-theme-personal .np-circular-btn.accent.secondary .tw-icon {
123
- color: var(--color-interactive-primary);
124
- }
125
- .np-theme-personal .np-circular-btn.accent.secondary:not(.disabled):not(:disabled):hover .tw-icon,
126
- .np-theme-personal .np-circular-btn.accent.secondary input[type="button"]:active + .tw-icon {
127
- color: white;
128
- color: var(--color-interactive-control);
129
- }
130
- .np-theme-personal .np-circular-btn.accent.secondary:active input[type="button"] + .tw-icon {
131
- color: var(--color-interactive-control);
132
- }
133
- .np-theme-personal .np-circular-btn.positive .np-circular-btn__label {
134
- color: var(--color-interactive-primary);
135
- }
136
- .np-theme-personal .np-circular-btn.positive:not(.disabled):not(:disabled):hover .np-circular-btn__label {
137
- color: var(--color-interactive-primary-hover);
138
- }
139
- .np-theme-personal .np-circular-btn.positive:active .np-circular-btn__label,
140
- .np-theme-personal .np-circular-btn.positive input[type="button"]:active ~ .np-circular-btn__label {
141
- color: var(--color-interactive-primary-active);
142
- }
143
- .np-theme-personal .np-circular-btn.positive.secondary .tw-icon {
144
- color: var(--color-interactive-primary);
145
- }
146
- .np-theme-personal .np-circular-btn.positive.secondary:not(.disabled):not(:disabled):hover .tw-icon,
147
- .np-theme-personal .np-circular-btn.positive.secondary input[type="button"]:active + .tw-icon {
148
- color: white;
149
- color: var(--color-interactive-control);
150
- }
151
- .np-theme-personal .np-circular-btn.positive.secondary:active input[type="button"] + .tw-icon {
152
- color: var(--color-interactive-control);
153
- }
154
- .np-theme-personal .np-circular-btn.negative .np-circular-btn__label {
155
- color: var(--color-sentiment-negative);
156
- }
157
- .np-theme-personal .np-circular-btn.negative:not(.disabled):not(:disabled):hover .np-circular-btn__label {
158
- color: var(--color-sentiment-negative-hover);
159
- }
160
- .np-theme-personal .np-circular-btn.negative:active .np-circular-btn__label,
161
- .np-theme-personal .np-circular-btn.negative input[type="button"]:active ~ .np-circular-btn__label {
162
- color: var(--color-sentiment-negative-active);
19
+ .np-circular-btn-primary-negative .np-circular-btn-label,
20
+ .np-circular-btn-secondary-negative .np-circular-btn-label {
21
+ color: var(--color-sentiment-negative-primary);
163
22
  }
164
- .np-theme-personal .np-circular-btn.negative.secondary .tw-icon {
165
- color: var(--color-sentiment-negative);
23
+ .np-circular-btn-primary-negative .np-circular-btn-label:not(.disabled):not(:disabled):hover,
24
+ .np-circular-btn-secondary-negative .np-circular-btn-label:not(.disabled):not(:disabled):hover {
25
+ color: var(--color-sentiment-negative-primary-hover);
166
26
  }
167
- .np-theme-personal .np-circular-btn.negative.secondary:not(.disabled):not(:disabled):hover .tw-icon,
168
- .np-theme-personal .np-circular-btn.negative.secondary input[type="button"]:active + .tw-icon {
169
- color: white;
170
- color: var(--color-interactive-control);
27
+ .np-circular-btn-primary-negative .np-circular-btn-label:not(.disabled):not(:disabled):active,
28
+ .np-circular-btn-secondary-negative .np-circular-btn-label:not(.disabled):not(:disabled):active {
29
+ color: var(--color-sentiment-negative-primary-active);
171
30
  }
172
- .np-theme-personal .np-circular-btn.negative.secondary:active input[type="button"] + .tw-icon {
173
- color: var(--color-interactive-control);
31
+ .np-circular-btn-disabled {
32
+ cursor: not-allowed;
174
33
  }
@@ -1,105 +1,36 @@
1
- @import (reference) "../../node_modules/@transferwise/neptune-css/src/less/mixins/_logical-properties.less";
2
- @import "./_button-label-states.less";
3
-
4
1
  .np-circular-btn {
5
2
  display: inline-flex;
6
3
  flex-direction: column;
7
4
  align-items: center;
8
- text-align: center;
9
5
  cursor: pointer;
10
- position: relative;
11
-
12
- .tw-icon {
13
- position: absolute;
14
- top: var(--size-16);
15
- pointer-events: none;
16
- color: white;
17
- transition: color 0.15s ease-in-out;
18
- width: 100%;
19
- .left(0);
20
6
 
21
- @media (--screen-400-zoom) {
22
- top: var(--size-12);
23
- }
24
-
25
- > svg {
26
- margin: 0 auto;
7
+ &-primary-default,
8
+ &-secondary-default {
9
+ .np-circular-btn-label {
10
+ color: var(--color-interactive-primary);
11
+ &:not(.disabled, :disabled):hover {
12
+ color: var(--color-interactive-primary-hover);
13
+ }
14
+ &:not(.disabled, :disabled):active {
15
+ color: var(--color-interactive-primary-active);
16
+ }
27
17
  }
28
18
  }
29
19
 
30
- .np-theme-personal & {
31
- /* stylelint-disable-next-line no-duplicate-selectors */
32
- .tw-icon {
33
- &,
34
- &:hover,
35
- &:active {
36
- color: var(--color-interactive-control);
20
+ &-primary-negative,
21
+ &-secondary-negative {
22
+ .np-circular-btn-label {
23
+ color: var(--color-sentiment-negative-primary);
24
+ &:not(.disabled, :disabled):hover {
25
+ color: var(--color-sentiment-negative-primary-hover);
26
+ }
27
+ &:not(.disabled, :disabled):active {
28
+ color: var(--color-sentiment-negative-primary-active);
37
29
  }
38
- }
39
-
40
- &.negative .tw-icon,
41
- &.negative.secondary:not(.disabled, :disabled):hover .tw-icon,
42
- &.negative.secondary:not(.disabled, :disabled):active .tw-icon {
43
- // TODO, this will need to be removed when we update our CSS architecture
44
- color: var(--color-contrast) !important;
45
- }
46
-
47
- &.negative.secondary:not(.disabled, :disabled) .tw-icon {
48
- // TODO, this will need to be removed when we update our CSS architecture
49
- color: var(--color-sentiment-negative) !important;
50
30
  }
51
31
  }
52
- }
53
-
54
- .button-label-states(
55
- np-circular-btn,
56
- accent,
57
- var(--color-interactive-accent),
58
- var(--color-interactive-accent-hover),
59
- var(--color-interactive-accent-active)
60
- );
61
-
62
- .button-label-states(
63
- np-circular-btn,
64
- positive,
65
- var(--color-interactive-positive),
66
- var(--color-interactive-positive-hover),
67
- var(--color-interactive-positive-active)
68
- );
69
32
 
70
- .button-label-states(
71
- np-circular-btn,
72
- negative,
73
- var(--color-interactive-negative),
74
- var(--color-interactive-negative-hover),
75
- var(--color-interactive-negative-active)
76
- );
77
-
78
- .np-theme-personal {
79
- .button-label-states(
80
- np-circular-btn,
81
- accent,
82
- var(--color-interactive-primary),
83
- var(--color-interactive-primary-hover),
84
- var(--color-interactive-primary-active),
85
- true
86
- );
87
-
88
- .button-label-states(
89
- np-circular-btn,
90
- positive,
91
- var(--color-interactive-primary),
92
- var(--color-interactive-primary-hover),
93
- var(--color-interactive-primary-active),
94
- true
95
- );
96
-
97
- .button-label-states(
98
- np-circular-btn,
99
- negative,
100
- var(--color-sentiment-negative),
101
- var(--color-sentiment-negative-hover),
102
- var(--color-sentiment-negative-active),
103
- true
104
- );
33
+ &-disabled {
34
+ cursor: not-allowed;
35
+ }
105
36
  }