@juspay/blend-design-system 0.0.37-beta.7 → 0.0.37

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 (290) hide show
  1. package/dist/{node-C_DmV86X.js → breadcrumbV2.tokens-CovJEwot.js} +16 -0
  2. package/dist/components/Accordion/index.d.ts +2 -0
  3. package/dist/components/AccordionV2/accordionV2.animations.d.ts +1 -1
  4. package/dist/components/Alert/index.d.ts +1 -0
  5. package/dist/components/Avatar/index.d.ts +1 -0
  6. package/dist/components/Breadcrumb/index.d.ts +1 -0
  7. package/dist/components/Button/index.d.ts +1 -0
  8. package/dist/components/ButtonGroup/index.d.ts +1 -0
  9. package/dist/components/Card/index.d.ts +1 -0
  10. package/dist/components/CardV2/CardV2.d.ts +45 -0
  11. package/dist/components/CardV2/CardV2.utils.d.ts +14 -0
  12. package/dist/components/CardV2/CardV2Components.d.ts +8 -0
  13. package/dist/components/CardV2/CardV2Context.d.ts +14 -0
  14. package/dist/components/CardV2/CardV2Skeleton.d.ts +6 -0
  15. package/dist/components/CardV2/accessibility/CardV2AccessibilityReport.d.ts +2 -0
  16. package/dist/components/CardV2/accessibility/index.d.ts +1 -0
  17. package/dist/components/CardV2/cardV2.dark.tokens.d.ts +3 -0
  18. package/dist/components/CardV2/cardV2.light.tokens.d.ts +3 -0
  19. package/dist/components/CardV2/cardV2.tokens.d.ts +5 -0
  20. package/dist/components/CardV2/cardV2.tokens.types.d.ts +92 -0
  21. package/dist/components/CardV2/cardV2.types.d.ts +106 -0
  22. package/dist/components/CardV2/index.d.ts +5 -0
  23. package/dist/components/Charts/index.d.ts +10 -0
  24. package/dist/components/Charts/types.d.ts +2 -0
  25. package/dist/components/ChatInput/index.d.ts +1 -0
  26. package/dist/components/Checkbox/index.d.ts +1 -0
  27. package/dist/components/CodeEditor/index.d.ts +1 -0
  28. package/dist/components/CodeEditor/types.d.ts +22 -2
  29. package/dist/components/CodeEditorV2/CodeEditorV2.d.ts +1 -1
  30. package/dist/components/CodeEditorV2/codeEditorV2.types.d.ts +23 -2
  31. package/dist/components/DataTable/PivotTableModal/pivotModal.styled.d.ts +184 -0
  32. package/dist/components/DataTable/TableBody/types.d.ts +3 -1
  33. package/dist/components/DataTable/hooks/index.d.ts +2 -0
  34. package/dist/components/DataTable/hooks/useReducedMotion.d.ts +1 -0
  35. package/dist/components/DataTable/hooks/useRowFlip.d.ts +6 -0
  36. package/dist/components/DataTable/types.d.ts +26 -0
  37. package/dist/components/DateRangePicker/CalendarGrid.d.ts +5 -2
  38. package/dist/components/DateRangePicker/types.d.ts +3 -1
  39. package/dist/components/DateRangePicker/utils.d.ts +5 -5
  40. package/dist/components/Directory/Directory.d.ts +1 -1
  41. package/dist/components/Directory/NavItem.d.ts +1 -1
  42. package/dist/components/Directory/Section.d.ts +1 -1
  43. package/dist/components/Directory/VirtualizedDirectory.d.ts +3 -0
  44. package/dist/components/Directory/directory.tokens.d.ts +7 -0
  45. package/dist/components/Directory/types.d.ts +38 -1
  46. package/dist/components/Directory/utils.d.ts +3 -1
  47. package/dist/components/Drawer/index.d.ts +1 -0
  48. package/dist/components/Inputs/MultiValueInput/index.d.ts +1 -0
  49. package/dist/components/Inputs/NumberInput/index.d.ts +1 -0
  50. package/dist/components/Inputs/OTPInput/index.d.ts +1 -0
  51. package/dist/components/Inputs/SearchInput/index.d.ts +1 -0
  52. package/dist/components/Inputs/TextArea/index.d.ts +1 -0
  53. package/dist/components/Inputs/TextInput/index.d.ts +1 -0
  54. package/dist/components/InputsV2/TextAreaV2/utils.d.ts +2 -1
  55. package/dist/components/InputsV2/TextInputV2/utils.d.ts +2 -1
  56. package/dist/components/InputsV2/UploadV2/UploadContainerV2.d.ts +24 -0
  57. package/dist/components/InputsV2/UploadV2/UploadV2.d.ts +31 -0
  58. package/dist/components/InputsV2/UploadV2/UploadV2.dark.tokens.d.ts +3 -0
  59. package/dist/components/InputsV2/UploadV2/UploadV2.light.tokens.d.ts +3 -0
  60. package/dist/components/InputsV2/UploadV2/UploadV2.tokens.d.ts +5 -0
  61. package/dist/components/InputsV2/UploadV2/UploadV2.tokens.types.d.ts +115 -0
  62. package/dist/components/InputsV2/UploadV2/UploadV2.types.d.ts +56 -0
  63. package/dist/components/InputsV2/UploadV2/index.d.ts +3 -0
  64. package/dist/components/InputsV2/UploadV2/utils.d.ts +32 -0
  65. package/dist/components/KeyValuePair/index.d.ts +1 -0
  66. package/dist/components/Menu/Menu.d.ts +1 -1
  67. package/dist/components/Menu/index.d.ts +1 -0
  68. package/dist/components/Menu/types.d.ts +7 -0
  69. package/dist/components/Menu/utils.d.ts +10 -2
  70. package/dist/components/MenuV2/MenuV2Content.d.ts +1 -0
  71. package/dist/components/MenuV2/menuV2.types.d.ts +5 -0
  72. package/dist/components/MenuV2/menuV2.utils.d.ts +10 -2
  73. package/dist/components/Modal/index.d.ts +1 -0
  74. package/dist/components/ModalV2/ModalV2.d.ts +22 -0
  75. package/dist/components/ModalV2/ModalV2Footer.d.ts +10 -0
  76. package/dist/components/ModalV2/ModalV2Header.d.ts +15 -0
  77. package/dist/components/ModalV2/ModalV2Skeleton.d.ts +4 -0
  78. package/dist/components/ModalV2/index.d.ts +4 -0
  79. package/dist/components/ModalV2/mobileModalV2.d.ts +23 -0
  80. package/dist/components/ModalV2/modalAnimationV2.d.ts +3 -0
  81. package/dist/components/ModalV2/modalV2.dark.tokens.d.ts +3 -0
  82. package/dist/components/ModalV2/modalV2.light.tokens.d.ts +3 -0
  83. package/dist/components/ModalV2/modalV2.tokens.d.ts +5 -0
  84. package/dist/components/ModalV2/modalV2.tokens.types.d.ts +91 -0
  85. package/dist/components/ModalV2/modalV2.types.d.ts +66 -0
  86. package/dist/components/MultiSelect/MultiSelect.d.ts +1 -1
  87. package/dist/components/MultiSelect/MultiSelectMenu.d.ts +1 -1
  88. package/dist/components/MultiSelect/index.d.ts +2 -0
  89. package/dist/components/MultiSelect/types.d.ts +2 -0
  90. package/dist/components/MultiSelectV2/MultiSelectV2.d.ts +1 -1
  91. package/dist/components/MultiSelectV2/MultiSelectV2Menu.d.ts +1 -1
  92. package/dist/components/MultiSelectV2/multiSelectV2.types.d.ts +2 -0
  93. package/dist/components/Popover/index.d.ts +1 -0
  94. package/dist/components/Primitives/Block/Block.d.ts +1 -1
  95. package/dist/components/ProgressBar/index.d.ts +1 -0
  96. package/dist/components/Radio/index.d.ts +2 -0
  97. package/dist/components/Sidebar/SidebarContent.d.ts +9 -1
  98. package/dist/components/Sidebar/index.d.ts +1 -0
  99. package/dist/components/Sidebar/types.d.ts +9 -1
  100. package/dist/components/SidebarV2/SidebarV2Panel.d.ts +10 -2
  101. package/dist/components/SidebarV2/types.d.ts +9 -1
  102. package/dist/components/SingleSelect/SingleSelect.d.ts +1 -1
  103. package/dist/components/SingleSelect/SingleSelectMenu.d.ts +2 -1
  104. package/dist/components/SingleSelect/index.d.ts +1 -0
  105. package/dist/components/SingleSelect/types.d.ts +1 -0
  106. package/dist/components/SingleSelectV2/SingleSelectV2.d.ts +1 -1
  107. package/dist/components/SingleSelectV2/SingleSelectV2Menu.d.ts +1 -1
  108. package/dist/components/SingleSelectV2/singleSelectV2.tokens.types.d.ts +8 -0
  109. package/dist/components/SingleSelectV2/singleSelectV2.types.d.ts +2 -0
  110. package/dist/components/Skeleton/SkeletonCompound.d.ts +24 -33
  111. package/dist/components/Snackbar/Snackbar.d.ts +1 -1
  112. package/dist/components/Snackbar/index.d.ts +2 -0
  113. package/dist/components/Snackbar/snackbar.tokens.d.ts +1 -0
  114. package/dist/components/Snackbar/types.d.ts +2 -0
  115. package/dist/components/StatCard/index.d.ts +1 -0
  116. package/dist/components/Stepper/index.d.ts +1 -0
  117. package/dist/components/Switch/index.d.ts +2 -0
  118. package/dist/components/Tabs/index.d.ts +1 -0
  119. package/dist/components/Tags/index.d.ts +1 -0
  120. package/dist/components/Timeline/Timeline.d.ts +13 -37
  121. package/dist/components/Tooltip/index.d.ts +1 -0
  122. package/dist/components/Topbar/index.d.ts +1 -0
  123. package/dist/components/Upload/index.d.ts +1 -0
  124. package/dist/context/ThemeContext.d.ts +6 -0
  125. package/dist/context/useComponentToken.d.ts +4 -1
  126. package/dist/main.d.ts +6 -0
  127. package/dist/main.js +45436 -42186
  128. package/dist/node-B3rrXW84.js +1023 -0
  129. package/dist/node.d.ts +2 -0
  130. package/dist/node.js +21 -18
  131. package/dist/{tokens.js → token-engine.js} +1 -1
  132. package/lib/components/Accordion/AccordionItem.tsx +2 -6
  133. package/lib/components/Accordion/index.ts +2 -0
  134. package/lib/components/AccordionV2/AccordionV2Item.tsx +1 -1
  135. package/lib/components/AccordionV2/accordionV2.animations.ts +1 -5
  136. package/lib/components/Alert/index.ts +1 -0
  137. package/lib/components/Avatar/index.ts +1 -0
  138. package/lib/components/Breadcrumb/index.ts +1 -0
  139. package/lib/components/Button/index.ts +1 -0
  140. package/lib/components/ButtonGroup/index.ts +1 -0
  141. package/lib/components/Card/index.ts +1 -0
  142. package/lib/components/CardV2/CardV2.tsx +327 -0
  143. package/lib/components/CardV2/CardV2.utils.tsx +77 -0
  144. package/lib/components/CardV2/CardV2Components.tsx +297 -0
  145. package/lib/components/CardV2/CardV2Context.tsx +18 -0
  146. package/lib/components/CardV2/CardV2Skeleton.tsx +40 -0
  147. package/lib/components/CardV2/accessibility/CardV2AccessibilityReport.ts +284 -0
  148. package/lib/components/CardV2/accessibility/index.ts +1 -0
  149. package/lib/components/CardV2/cardV2.dark.tokens.ts +177 -0
  150. package/lib/components/CardV2/cardV2.light.tokens.ts +177 -0
  151. package/lib/components/CardV2/cardV2.tokens.ts +21 -0
  152. package/lib/components/CardV2/cardV2.tokens.types.ts +94 -0
  153. package/lib/components/CardV2/cardV2.types.ts +131 -0
  154. package/lib/components/CardV2/index.ts +13 -0
  155. package/lib/components/Charts/ChartLegend.tsx +25 -5
  156. package/lib/components/Charts/Charts.tsx +10 -0
  157. package/lib/components/Charts/index.ts +10 -0
  158. package/lib/components/Charts/types.tsx +2 -0
  159. package/lib/components/ChatInput/index.tsx +1 -0
  160. package/lib/components/Checkbox/index.ts +1 -0
  161. package/lib/components/CodeEditor/MonacoEditorWrapper.tsx +6 -2
  162. package/lib/components/CodeEditor/index.ts +1 -0
  163. package/lib/components/CodeEditor/types.ts +52 -2
  164. package/lib/components/CodeEditorV2/MonacoEditor/MonacoEditorWrapper.tsx +6 -2
  165. package/lib/components/CodeEditorV2/codeEditorV2.types.ts +44 -5
  166. package/lib/components/DataTable/DataTable.tsx +8 -0
  167. package/lib/components/DataTable/TableBody/index.tsx +47 -11
  168. package/lib/components/DataTable/TableBody/types.ts +7 -1
  169. package/lib/components/DataTable/TableCell/index.tsx +1 -1
  170. package/lib/components/DataTable/hooks/index.ts +2 -0
  171. package/lib/components/DataTable/hooks/useReducedMotion.ts +19 -0
  172. package/lib/components/DataTable/hooks/useRowFlip.ts +170 -0
  173. package/lib/components/DataTable/types.ts +32 -0
  174. package/lib/components/DateRangePicker/CalendarGrid.tsx +39 -6
  175. package/lib/components/DateRangePicker/DateRangePicker.tsx +27 -4
  176. package/lib/components/DateRangePicker/types.ts +6 -1
  177. package/lib/components/DateRangePicker/utils.ts +123 -12
  178. package/lib/components/Directory/Directory.tsx +31 -0
  179. package/lib/components/Directory/NavItem.tsx +177 -86
  180. package/lib/components/Directory/Section.tsx +9 -0
  181. package/lib/components/Directory/VirtualizedDirectory.tsx +670 -0
  182. package/lib/components/Directory/directory.tokens.ts +21 -0
  183. package/lib/components/Directory/types.ts +43 -1
  184. package/lib/components/Directory/utils.ts +81 -1
  185. package/lib/components/Drawer/index.ts +1 -0
  186. package/lib/components/Inputs/DropdownInput/DropdownInput.tsx +6 -2
  187. package/lib/components/Inputs/MultiValueInput/index.ts +1 -0
  188. package/lib/components/Inputs/NumberInput/NumberInput.tsx +6 -2
  189. package/lib/components/Inputs/NumberInput/index.ts +1 -0
  190. package/lib/components/Inputs/OTPInput/index.ts +1 -0
  191. package/lib/components/Inputs/SearchInput/index.ts +1 -0
  192. package/lib/components/Inputs/TextArea/TextArea.tsx +4 -2
  193. package/lib/components/Inputs/TextArea/index.ts +1 -0
  194. package/lib/components/Inputs/TextInput/TextInput.tsx +6 -2
  195. package/lib/components/Inputs/TextInput/index.ts +1 -0
  196. package/lib/components/Inputs/UnitInput/UnitInput.tsx +6 -2
  197. package/lib/components/InputsV2/NumberInputV2/NumberInputV2.tsx +6 -2
  198. package/lib/components/InputsV2/TextAreaV2/TextAreaV2.tsx +2 -1
  199. package/lib/components/InputsV2/TextAreaV2/utils.ts +3 -1
  200. package/lib/components/InputsV2/TextInputV2/TextInputV2.tsx +1 -0
  201. package/lib/components/InputsV2/TextInputV2/utils.ts +6 -8
  202. package/lib/components/InputsV2/UploadV2/UploadContainerV2.tsx +470 -0
  203. package/lib/components/InputsV2/UploadV2/UploadV2.dark.tokens.ts +348 -0
  204. package/lib/components/InputsV2/UploadV2/UploadV2.light.tokens.ts +348 -0
  205. package/lib/components/InputsV2/UploadV2/UploadV2.tokens.ts +20 -0
  206. package/lib/components/InputsV2/UploadV2/UploadV2.tokens.types.ts +117 -0
  207. package/lib/components/InputsV2/UploadV2/UploadV2.tsx +336 -0
  208. package/lib/components/InputsV2/UploadV2/UploadV2.types.ts +67 -0
  209. package/lib/components/InputsV2/UploadV2/index.ts +3 -0
  210. package/lib/components/InputsV2/UploadV2/utils.ts +170 -0
  211. package/lib/components/KeyValuePair/index.ts +1 -0
  212. package/lib/components/Menu/Menu.tsx +18 -2
  213. package/lib/components/Menu/SubMenu.tsx +25 -3
  214. package/lib/components/Menu/index.ts +1 -0
  215. package/lib/components/Menu/types.tsx +14 -0
  216. package/lib/components/Menu/utils.ts +46 -3
  217. package/lib/components/MenuV2/MenuV2.tsx +9 -2
  218. package/lib/components/MenuV2/MenuV2Content.tsx +6 -0
  219. package/lib/components/MenuV2/MenuV2SubMenu.tsx +16 -2
  220. package/lib/components/MenuV2/menuV2.types.ts +11 -0
  221. package/lib/components/MenuV2/menuV2.utils.ts +45 -3
  222. package/lib/components/Modal/index.ts +1 -0
  223. package/lib/components/ModalV2/ModalV2.tsx +269 -0
  224. package/lib/components/ModalV2/ModalV2Footer.tsx +76 -0
  225. package/lib/components/ModalV2/ModalV2Header.tsx +144 -0
  226. package/lib/components/ModalV2/ModalV2Skeleton.tsx +80 -0
  227. package/lib/components/ModalV2/index.ts +4 -0
  228. package/lib/components/ModalV2/mobileModalV2.tsx +411 -0
  229. package/lib/components/ModalV2/modalAnimationV2.tsx +19 -0
  230. package/lib/components/ModalV2/modalV2.dark.tokens.ts +183 -0
  231. package/lib/components/ModalV2/modalV2.light.tokens.ts +183 -0
  232. package/lib/components/ModalV2/modalV2.tokens.ts +21 -0
  233. package/lib/components/ModalV2/modalV2.tokens.types.ts +94 -0
  234. package/lib/components/ModalV2/modalV2.types.ts +80 -0
  235. package/lib/components/MultiSelect/MultiSelect.tsx +4 -1
  236. package/lib/components/MultiSelect/MultiSelectMenu.tsx +8 -0
  237. package/lib/components/MultiSelect/MultiSelectTrigger.tsx +2 -1
  238. package/lib/components/MultiSelect/index.ts +2 -0
  239. package/lib/components/MultiSelect/types.ts +2 -0
  240. package/lib/components/MultiSelectV2/MultiSelectV2.tsx +2 -0
  241. package/lib/components/MultiSelectV2/MultiSelectV2Menu.tsx +8 -0
  242. package/lib/components/MultiSelectV2/MultiSelectV2Trigger.tsx +4 -1
  243. package/lib/components/MultiSelectV2/multiSelectV2.types.ts +2 -0
  244. package/lib/components/Popover/index.ts +1 -0
  245. package/lib/components/Primitives/Block/Block.tsx +1 -1
  246. package/lib/components/ProgressBar/index.ts +1 -0
  247. package/lib/components/Radio/index.ts +2 -0
  248. package/lib/components/Sidebar/Sidebar.tsx +38 -0
  249. package/lib/components/Sidebar/SidebarContent.tsx +25 -1
  250. package/lib/components/Sidebar/index.ts +1 -0
  251. package/lib/components/Sidebar/types.ts +13 -1
  252. package/lib/components/SidebarV2/SidebarV2.tsx +30 -0
  253. package/lib/components/SidebarV2/SidebarV2Panel.tsx +25 -1
  254. package/lib/components/SidebarV2/types.ts +9 -1
  255. package/lib/components/SingleSelect/SingleSelect.tsx +4 -1
  256. package/lib/components/SingleSelect/SingleSelectMenu.tsx +171 -138
  257. package/lib/components/SingleSelect/SingleSelectTrigger.tsx +3 -1
  258. package/lib/components/SingleSelect/index.ts +1 -0
  259. package/lib/components/SingleSelect/types.ts +1 -0
  260. package/lib/components/SingleSelectV2/SingleSelectV2.tsx +2 -0
  261. package/lib/components/SingleSelectV2/SingleSelectV2Menu.tsx +84 -58
  262. package/lib/components/SingleSelectV2/SingleSelectV2Search.tsx +1 -0
  263. package/lib/components/SingleSelectV2/SingleSelectV2Trigger.tsx +3 -1
  264. package/lib/components/SingleSelectV2/singleSelectV2.dark.tokens.ts +8 -0
  265. package/lib/components/SingleSelectV2/singleSelectV2.light.tokens.ts +8 -0
  266. package/lib/components/SingleSelectV2/singleSelectV2.tokens.types.ts +8 -0
  267. package/lib/components/SingleSelectV2/singleSelectV2.types.ts +2 -0
  268. package/lib/components/Skeleton/SkeletonCompound.tsx +45 -31
  269. package/lib/components/Snackbar/Snackbar.tsx +18 -8
  270. package/lib/components/Snackbar/index.ts +2 -0
  271. package/lib/components/Snackbar/snackbar.tokens.ts +6 -0
  272. package/lib/components/Snackbar/types.ts +2 -0
  273. package/lib/components/StatCard/StatCard.tsx +29 -0
  274. package/lib/components/StatCard/index.ts +1 -0
  275. package/lib/components/Stepper/index.ts +1 -0
  276. package/lib/components/Switch/index.ts +2 -0
  277. package/lib/components/Tabs/index.ts +1 -0
  278. package/lib/components/Tags/index.ts +1 -0
  279. package/lib/components/Timeline/Timeline.tsx +9 -1
  280. package/lib/components/Tooltip/index.ts +1 -0
  281. package/lib/components/Topbar/index.ts +1 -0
  282. package/lib/components/Upload/index.ts +1 -0
  283. package/lib/context/ThemeContext.tsx +16 -0
  284. package/lib/context/initComponentTokens.ts +11 -0
  285. package/lib/context/useComponentToken.ts +15 -1
  286. package/lib/hooks/useResponsiveTokens.ts +63 -0
  287. package/lib/main.ts +16 -0
  288. package/lib/node.ts +2 -0
  289. package/package.json +5 -4
  290. package/dist/tokens.d.ts +0 -2
@@ -0,0 +1,470 @@
1
+ import React, { useMemo, useState } from 'react'
2
+ import Block from '../../Primitives/Block/Block'
3
+ import { ButtonV2, ButtonV2Size, ButtonV2Type } from '../../ButtonV2'
4
+ import PrimitiveButton from '../../Primitives/PrimitiveButton/PrimitiveButton'
5
+ import { CaretDownIcon, CaretUpIcon, SwapIcon } from '@phosphor-icons/react'
6
+ import Text from '../../Text/Text'
7
+ import type { UploadV2TokensType } from './UploadV2.tokens.types'
8
+ import {
9
+ TagV2,
10
+ TagV2Color,
11
+ TagV2Size,
12
+ TagV2SubType,
13
+ TagV2Type,
14
+ } from '../../TagV2'
15
+ import { XIcon } from '@phosphor-icons/react'
16
+ import TooltipV2 from '../../TooltipV2/TooltipV2'
17
+ import PopoverV2 from '../../PopoverV2/PopoverV2'
18
+ import { PopoverV2Align, PopoverV2Side } from '../../PopoverV2/popoverV2.types'
19
+ import {
20
+ getFileId,
21
+ getValidationMessage,
22
+ normalizeUploadErrorReason,
23
+ truncateFileNameForTag,
24
+ } from './utils'
25
+ import { UploadDragState, UploadFileV2, UploadState } from './UploadV2.types'
26
+ import {
27
+ ProgressBarV2,
28
+ ProgressBarV2Appearance,
29
+ ProgressBarV2Size,
30
+ ProgressBarV2Variant,
31
+ } from '../../ProgressBarV2'
32
+
33
+ const UploadContainerV2 = ({
34
+ description,
35
+ descriptionId,
36
+ slot,
37
+ disabled,
38
+ onClick,
39
+ tokens,
40
+ files,
41
+ onFileRemove,
42
+ multiple,
43
+ state,
44
+ errorText = '',
45
+ errorId,
46
+ progressBarValue,
47
+ progressBarMaxWidth,
48
+ uploadHeaderText,
49
+ dragState,
50
+ maxSize,
51
+ maxFiles,
52
+ }: {
53
+ description: string
54
+ descriptionId?: string
55
+ slot: React.ReactNode
56
+ disabled: boolean
57
+ onClick: () => void
58
+ tokens: UploadV2TokensType
59
+ files: UploadFileV2[]
60
+ onFileRemove: (fileId: string) => void
61
+ multiple: boolean
62
+ state: UploadState
63
+ errorText: string
64
+ errorId?: string
65
+ progressBarValue: number
66
+ progressBarMaxWidth: string
67
+ uploadHeaderText: string
68
+ dragState: UploadDragState
69
+ maxSize?: number
70
+ maxFiles?: number
71
+ }) => {
72
+ const [isOverflowPopoverOpen, setIsOverflowPopoverOpen] = useState(false)
73
+ const isUploading = state === UploadState.UPLOADING
74
+ const isSuccess = state === UploadState.SUCCESS
75
+ const isInteractionBlocked = isUploading || isSuccess
76
+ const { uploadContainer } = tokens
77
+ const showEmptyDescription = files.length === 0 && !isUploading
78
+ const showSingleFileInfo = files.length > 0 && !multiple && !isUploading
79
+ const showBrowseButton = files.length === 0 && !isUploading
80
+ const showReplaceButton = files.length > 0 && !multiple && !isUploading
81
+ const showMultiFileTags = files.length > 0 && multiple && !isUploading
82
+ const validFileCount = files.filter((file) => file.isValid).length
83
+ const invalidFileCount = files.length - validFileCount
84
+ const showFilledMultiFileCopy = showMultiFileTags
85
+ const headerText = showFilledMultiFileCopy
86
+ ? invalidFileCount > 0
87
+ ? 'Files uploaded'
88
+ : 'Files successfully added'
89
+ : uploadHeaderText
90
+ const filledMultiFileDescription =
91
+ invalidFileCount > 0
92
+ ? `${validFileCount} succeeded, ${invalidFileCount} failed`
93
+ : "We've successfully uploaded the following files"
94
+ const isDragEnter = dragState === UploadDragState.DRAG_ENTER
95
+ const isDragOver = dragState === UploadDragState.DRAG_OVER
96
+ const isDrop = dragState === UploadDragState.DROP
97
+ const isDragActive = isDragEnter || isDragOver || isDrop
98
+ const sortedFiles = useMemo(
99
+ () =>
100
+ [...files].sort((a, b) => {
101
+ if (!a.isValid && b.isValid) return -1
102
+ if (a.isValid && !b.isValid) return 1
103
+ return 0
104
+ }),
105
+ [files]
106
+ )
107
+ const visibleFiles = sortedFiles.slice(0, 4)
108
+ const overflowFiles = sortedFiles.slice(4)
109
+
110
+ const renderFileTag = (uploadFile: UploadFileV2, index: number) => {
111
+ const fileId = getFileId(uploadFile, index)
112
+ const fileColor =
113
+ state === UploadState.SUCCESS
114
+ ? TagV2Color.SUCCESS
115
+ : uploadFile.isValid
116
+ ? TagV2Color.NEUTRAL
117
+ : TagV2Color.ERROR
118
+ const tooltipContent = uploadFile.isValid
119
+ ? uploadFile.file.name
120
+ : `${uploadFile.file.name} - ${getValidationMessage(
121
+ uploadFile.errorReason,
122
+ maxSize,
123
+ maxFiles
124
+ )}`
125
+
126
+ return (
127
+ <TooltipV2 content={tooltipContent} key={fileId}>
128
+ <TagV2
129
+ aria-label={`Remove ${uploadFile.file.name}`}
130
+ rightSlot={{ slot: <XIcon size={14} /> }}
131
+ text={truncateFileNameForTag(uploadFile.file.name)}
132
+ size={TagV2Size.SM}
133
+ type={TagV2Type.SUBTLE}
134
+ subType={TagV2SubType.ROUNDED}
135
+ color={fileColor}
136
+ onClick={(e) => {
137
+ if (disabled || isInteractionBlocked) return
138
+ e.stopPropagation()
139
+ onFileRemove?.(fileId)
140
+ }}
141
+ />
142
+ </TooltipV2>
143
+ )
144
+ }
145
+
146
+ const renderOverflowFileRow = (uploadFile: UploadFileV2, index: number) => {
147
+ const fileId = getFileId(uploadFile, index)
148
+
149
+ return (
150
+ <Block
151
+ key={fileId}
152
+ display="flex"
153
+ alignItems="center"
154
+ justifyContent="space-between"
155
+ gap={uploadContainer.gap}
156
+ width="100%"
157
+ >
158
+ <Text
159
+ fontSize={uploadContainer.header.description.fontSize}
160
+ fontWeight={uploadContainer.header.description.fontWeight}
161
+ color={uploadContainer.header.title.color}
162
+ truncate
163
+ >
164
+ {uploadFile.file.name}
165
+ </Text>
166
+ <Block
167
+ display="flex"
168
+ alignItems="center"
169
+ gap={uploadContainer.gap}
170
+ flexShrink={0}
171
+ >
172
+ {!uploadFile.isValid && (
173
+ <TagV2
174
+ text="Failed"
175
+ size={TagV2Size.SM}
176
+ type={TagV2Type.SUBTLE}
177
+ subType={TagV2SubType.ROUNDED}
178
+ color={TagV2Color.ERROR}
179
+ />
180
+ )}
181
+ <PrimitiveButton
182
+ aria-label={`Remove ${uploadFile.file.name}`}
183
+ onClick={(e) => {
184
+ if (disabled || isInteractionBlocked) return
185
+ e.stopPropagation()
186
+ onFileRemove?.(fileId)
187
+ }}
188
+ display="flex"
189
+ alignItems="center"
190
+ justifyContent="center"
191
+ backgroundColor="transparent"
192
+ border="none"
193
+ padding="0"
194
+ cursor={
195
+ disabled || isInteractionBlocked
196
+ ? 'not-allowed'
197
+ : 'pointer'
198
+ }
199
+ >
200
+ <XIcon size={18} />
201
+ </PrimitiveButton>
202
+ </Block>
203
+ </Block>
204
+ )
205
+ }
206
+
207
+ return (
208
+ <Block
209
+ display="flex"
210
+ flexDirection="column"
211
+ alignItems="center"
212
+ gap={uploadContainer.gap}
213
+ paddingTop={uploadContainer.paddingTop}
214
+ paddingBottom={uploadContainer.paddingBottom}
215
+ paddingLeft={uploadContainer.paddingLeft}
216
+ paddingRight={uploadContainer.paddingRight}
217
+ borderRadius={uploadContainer.borderRadius}
218
+ border={
219
+ isDragActive
220
+ ? uploadContainer.border[dragState]
221
+ : uploadContainer.border[state]
222
+ }
223
+ backgroundColor={
224
+ isDragActive
225
+ ? uploadContainer.backgroundColor[dragState]
226
+ : uploadContainer.backgroundColor[state]
227
+ }
228
+ >
229
+ {slot && !showFilledMultiFileCopy && <Block>{slot}</Block>}
230
+ <Block
231
+ display="flex"
232
+ flexDirection="column"
233
+ alignItems="center"
234
+ gap={uploadContainer.header.gap}
235
+ >
236
+ <Text
237
+ fontSize={uploadContainer.header.title.fontSize}
238
+ fontWeight={uploadContainer.header.title.fontWeight}
239
+ color={uploadContainer.header.title.color}
240
+ textAlign="center"
241
+ >
242
+ {headerText}
243
+ </Text>
244
+ {(showEmptyDescription || showFilledMultiFileCopy) && (
245
+ <Text
246
+ id={showEmptyDescription ? descriptionId : undefined}
247
+ fontSize={uploadContainer.header.description.fontSize}
248
+ fontWeight={
249
+ uploadContainer.header.description.fontWeight
250
+ }
251
+ color={uploadContainer.header.description.color}
252
+ textAlign="center"
253
+ >
254
+ {showFilledMultiFileCopy
255
+ ? filledMultiFileDescription
256
+ : description}
257
+ </Text>
258
+ )}
259
+ {showSingleFileInfo && (
260
+ <Text
261
+ fontSize={uploadContainer.header.description.fontSize}
262
+ fontWeight={
263
+ uploadContainer.header.description.fontWeight
264
+ }
265
+ color={uploadContainer.header.description.color}
266
+ textAlign="center"
267
+ >
268
+ {'Selected file: ' + files[0].file.name}
269
+ </Text>
270
+ )}
271
+ {isUploading && (
272
+ <Block width="100%" maxWidth={progressBarMaxWidth}>
273
+ <Text
274
+ fontSize={
275
+ uploadContainer.header.description.fontSize
276
+ }
277
+ fontWeight={
278
+ uploadContainer.header.description.fontWeight
279
+ }
280
+ color={uploadContainer.header.title.color}
281
+ textAlign="center"
282
+ >
283
+ {'Please wait while uploading'}
284
+ </Text>
285
+ </Block>
286
+ )}
287
+ </Block>
288
+ {isUploading && (
289
+ <Block width="100%" maxWidth={progressBarMaxWidth}>
290
+ <ProgressBarV2
291
+ value={progressBarValue}
292
+ size={ProgressBarV2Size.SM}
293
+ variant={ProgressBarV2Variant.LINEAR}
294
+ appearance={ProgressBarV2Appearance.SOLID}
295
+ showLabel={true}
296
+ />
297
+ </Block>
298
+ )}
299
+ {showBrowseButton && !isInteractionBlocked && (
300
+ <ButtonV2
301
+ buttonType={ButtonV2Type.SECONDARY}
302
+ size={ButtonV2Size.MEDIUM}
303
+ text="Browse Files"
304
+ disabled={disabled}
305
+ onClick={(e) => {
306
+ e.stopPropagation()
307
+ onClick()
308
+ }}
309
+ />
310
+ )}
311
+ {showReplaceButton && !isInteractionBlocked && (
312
+ <ButtonV2
313
+ buttonType={ButtonV2Type.SECONDARY}
314
+ size={ButtonV2Size.MEDIUM}
315
+ text="Replace File"
316
+ disabled={disabled}
317
+ onClick={(e) => {
318
+ e.stopPropagation()
319
+ onClick()
320
+ }}
321
+ leftSlot={{ slot: <SwapIcon size={16} /> }}
322
+ />
323
+ )}
324
+
325
+ {/* for multiple files, show a list of files */}
326
+
327
+ {showMultiFileTags && (
328
+ <Block
329
+ display="flex"
330
+ flexDirection="row"
331
+ alignItems="center"
332
+ justifyContent="center"
333
+ flexWrap="wrap"
334
+ gap="10px"
335
+ width="100%"
336
+ >
337
+ {visibleFiles.map((uploadFile) =>
338
+ renderFileTag(uploadFile, files.indexOf(uploadFile))
339
+ )}
340
+ {overflowFiles.length > 0 && (
341
+ <PopoverV2
342
+ open={isOverflowPopoverOpen}
343
+ onOpenChange={setIsOverflowPopoverOpen}
344
+ trigger={
345
+ <PrimitiveButton
346
+ aria-label={`Show ${overflowFiles.length} more files`}
347
+ onClick={(e) => e.stopPropagation()}
348
+ display="flex"
349
+ backgroundColor="transparent"
350
+ border="none"
351
+ padding="0"
352
+ cursor="pointer"
353
+ width="fit-content"
354
+ >
355
+ <TagV2
356
+ text={`+ ${overflowFiles.length}`}
357
+ size={TagV2Size.SM}
358
+ type={TagV2Type.SUBTLE}
359
+ subType={TagV2SubType.ROUNDED}
360
+ color={TagV2Color.NEUTRAL}
361
+ rightSlot={{
362
+ slot: isOverflowPopoverOpen ? (
363
+ <CaretUpIcon size={16} />
364
+ ) : (
365
+ <CaretDownIcon size={16} />
366
+ ),
367
+ }}
368
+ />
369
+ </PrimitiveButton>
370
+ }
371
+ minWidth={240}
372
+ maxWidth={340}
373
+ maxHeight={280}
374
+ showCloseButton={false}
375
+ asModal={true}
376
+ side={PopoverV2Side.BOTTOM}
377
+ align={PopoverV2Align.CENTER}
378
+ >
379
+ <Block
380
+ display="flex"
381
+ flexDirection="column"
382
+ gap={uploadContainer.gap}
383
+ padding={uploadContainer.gap}
384
+ overflow="auto"
385
+ >
386
+ {overflowFiles.map((uploadFile) =>
387
+ renderOverflowFileRow(
388
+ uploadFile,
389
+ files.indexOf(uploadFile)
390
+ )
391
+ )}
392
+ </Block>
393
+ </PopoverV2>
394
+ )}
395
+ </Block>
396
+ )}
397
+ {state === UploadState.ERROR && !errorText && !multiple && (
398
+ <Text
399
+ id={errorId}
400
+ role="alert"
401
+ aria-live="polite"
402
+ fontSize={uploadContainer.header.errorText.fontSize}
403
+ fontWeight={uploadContainer.header.errorText.fontWeight}
404
+ color={uploadContainer.header.errorText.color}
405
+ >
406
+ {(() => {
407
+ const invalidFiles = files.filter((f) => !f.isValid)
408
+ const hasOversized = invalidFiles.some(
409
+ (f) =>
410
+ normalizeUploadErrorReason(f.errorReason) ===
411
+ 'oversized'
412
+ )
413
+ const hasMaxFiles = invalidFiles.some(
414
+ (f) =>
415
+ normalizeUploadErrorReason(f.errorReason) ===
416
+ 'maxFiles'
417
+ )
418
+ const hasInvalidType = invalidFiles.some(
419
+ (f) =>
420
+ normalizeUploadErrorReason(f.errorReason) ===
421
+ 'invalidType'
422
+ )
423
+ const errors: string[] = []
424
+ if (hasOversized)
425
+ errors.push(
426
+ getValidationMessage(
427
+ 'oversized',
428
+ maxSize,
429
+ maxFiles
430
+ )
431
+ )
432
+ if (hasMaxFiles)
433
+ errors.push(
434
+ getValidationMessage(
435
+ 'maxFiles',
436
+ maxSize,
437
+ maxFiles
438
+ )
439
+ )
440
+ if (hasInvalidType)
441
+ errors.push(
442
+ getValidationMessage(
443
+ 'invalidType',
444
+ maxSize,
445
+ maxFiles
446
+ )
447
+ )
448
+ return errors.length > 0
449
+ ? `${errors.join(', ')}`
450
+ : getValidationMessage(undefined, maxSize, maxFiles)
451
+ })()}
452
+ </Text>
453
+ )}
454
+ {errorText && (
455
+ <Text
456
+ id={errorId}
457
+ role="alert"
458
+ aria-live="polite"
459
+ fontSize={uploadContainer.header.errorText.fontSize}
460
+ fontWeight={uploadContainer.header.errorText.fontWeight}
461
+ color={uploadContainer.header.errorText.color}
462
+ >
463
+ {errorText}
464
+ </Text>
465
+ )}
466
+ </Block>
467
+ )
468
+ }
469
+
470
+ export default UploadContainerV2