@brcarddev/frontend-commons 1.0.2

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 (490) hide show
  1. package/README.md +241 -0
  2. package/eslint.config.js +190 -0
  3. package/package.json +161 -0
  4. package/src/components/atoms/AudioPlayer/audio-player.stories.tsx +36 -0
  5. package/src/components/atoms/AudioPlayer/audio-player.test.tsx +20 -0
  6. package/src/components/atoms/AudioPlayer/audio-player.tsx +13 -0
  7. package/src/components/atoms/AudioPlayer/index.ts +1 -0
  8. package/src/components/atoms/Badge/badge.stories.tsx +80 -0
  9. package/src/components/atoms/Badge/badge.test.tsx +59 -0
  10. package/src/components/atoms/Badge/badge.tsx +47 -0
  11. package/src/components/atoms/Badge/index.ts +1 -0
  12. package/src/components/atoms/Box/box.stories.tsx +37 -0
  13. package/src/components/atoms/Box/box.test.tsx +47 -0
  14. package/src/components/atoms/Box/box.tsx +7 -0
  15. package/src/components/atoms/Box/index.ts +1 -0
  16. package/src/components/atoms/Button/button.stories.tsx +108 -0
  17. package/src/components/atoms/Button/button.test.tsx +54 -0
  18. package/src/components/atoms/Button/button.tsx +96 -0
  19. package/src/components/atoms/Button/index.ts +1 -0
  20. package/src/components/atoms/ButtonUpload/button-upload.stories.tsx +137 -0
  21. package/src/components/atoms/ButtonUpload/button-upload.tsx +304 -0
  22. package/src/components/atoms/ButtonUpload/index.ts +1 -0
  23. package/src/components/atoms/Calendar/calendar.stories.tsx +51 -0
  24. package/src/components/atoms/Calendar/calendar.test.tsx +41 -0
  25. package/src/components/atoms/Calendar/calendar.tsx +107 -0
  26. package/src/components/atoms/Calendar/index.ts +1 -0
  27. package/src/components/atoms/CheckIcon/check-icon.stories.tsx +38 -0
  28. package/src/components/atoms/CheckIcon/check-icon.test.tsx +270 -0
  29. package/src/components/atoms/CheckIcon/check-icon.tsx +141 -0
  30. package/src/components/atoms/CheckIcon/index.ts +1 -0
  31. package/src/components/atoms/Checkbox/checkbox.stories.tsx +133 -0
  32. package/src/components/atoms/Checkbox/checkbox.test.tsx +70 -0
  33. package/src/components/atoms/Checkbox/checkbox.tsx +31 -0
  34. package/src/components/atoms/Checkbox/index.ts +1 -0
  35. package/src/components/atoms/Flex/flex.stories.tsx +33 -0
  36. package/src/components/atoms/Flex/flex.test.tsx +47 -0
  37. package/src/components/atoms/Flex/flex.tsx +7 -0
  38. package/src/components/atoms/Flex/index.ts +1 -0
  39. package/src/components/atoms/Grid/grid.stories.tsx +33 -0
  40. package/src/components/atoms/Grid/grid.test.tsx +47 -0
  41. package/src/components/atoms/Grid/grid.tsx +7 -0
  42. package/src/components/atoms/Grid/index.ts +1 -0
  43. package/src/components/atoms/Icon/icon.stories.tsx +169 -0
  44. package/src/components/atoms/Icon/icon.test.tsx +272 -0
  45. package/src/components/atoms/Icon/icon.tsx +119 -0
  46. package/src/components/atoms/Icon/index.ts +1 -0
  47. package/src/components/atoms/Input/index.ts +1 -0
  48. package/src/components/atoms/Input/input.stories.tsx +704 -0
  49. package/src/components/atoms/Input/input.test.tsx +86 -0
  50. package/src/components/atoms/Input/input.tsx +161 -0
  51. package/src/components/atoms/InputMoney/index.ts +2 -0
  52. package/src/components/atoms/InputMoney/input-money.stories.tsx +240 -0
  53. package/src/components/atoms/InputMoney/input-money.test.tsx +98 -0
  54. package/src/components/atoms/InputMoney/input-money.tsx +254 -0
  55. package/src/components/atoms/InputPhone/index.ts +2 -0
  56. package/src/components/atoms/InputPhone/input-phone.stories.tsx +447 -0
  57. package/src/components/atoms/InputPhone/input-phone.test.tsx +148 -0
  58. package/src/components/atoms/InputPhone/input-phone.tsx +267 -0
  59. package/src/components/atoms/InputSearch/index.ts +2 -0
  60. package/src/components/atoms/InputSearch/input-search.stories.tsx +360 -0
  61. package/src/components/atoms/InputSearch/input-search.test.tsx +239 -0
  62. package/src/components/atoms/InputSearch/input-search.tsx +210 -0
  63. package/src/components/atoms/InputUpload/index.ts +1 -0
  64. package/src/components/atoms/InputUpload/input-upload.stories.tsx +229 -0
  65. package/src/components/atoms/InputUpload/input-upload.test.tsx +556 -0
  66. package/src/components/atoms/InputUpload/input-upload.tsx +434 -0
  67. package/src/components/atoms/InputWithButton/index.ts +2 -0
  68. package/src/components/atoms/InputWithButton/input-with-button.stories.tsx +503 -0
  69. package/src/components/atoms/InputWithButton/input-with-button.test.tsx +128 -0
  70. package/src/components/atoms/InputWithButton/input-with-button.tsx +170 -0
  71. package/src/components/atoms/Label/index.ts +1 -0
  72. package/src/components/atoms/Label/label.stories.tsx +90 -0
  73. package/src/components/atoms/Label/label.test.tsx +59 -0
  74. package/src/components/atoms/Label/label.tsx +43 -0
  75. package/src/components/atoms/Progress/index.ts +1 -0
  76. package/src/components/atoms/Progress/progress.stories.tsx +30 -0
  77. package/src/components/atoms/Progress/progress.test.tsx +63 -0
  78. package/src/components/atoms/Progress/progress.tsx +32 -0
  79. package/src/components/atoms/RenderCondition/index.ts +1 -0
  80. package/src/components/atoms/RenderCondition/render-condition.stories.tsx +28 -0
  81. package/src/components/atoms/RenderCondition/render-condition.test.tsx +27 -0
  82. package/src/components/atoms/RenderCondition/render-condition.tsx +9 -0
  83. package/src/components/atoms/RichTextEditor/index.ts +1 -0
  84. package/src/components/atoms/RichTextEditor/rich-text-editor.stories.tsx +214 -0
  85. package/src/components/atoms/RichTextEditor/rich-text-editor.test.tsx +442 -0
  86. package/src/components/atoms/RichTextEditor/rich-text-editor.tsx +202 -0
  87. package/src/components/atoms/Separator/index.ts +1 -0
  88. package/src/components/atoms/Separator/separator.stories.tsx +117 -0
  89. package/src/components/atoms/Separator/separator.test.tsx +50 -0
  90. package/src/components/atoms/Separator/separator.tsx +28 -0
  91. package/src/components/atoms/Skeleton/index.ts +1 -0
  92. package/src/components/atoms/Skeleton/skeleton.stories.tsx +84 -0
  93. package/src/components/atoms/Skeleton/skeleton.test.tsx +39 -0
  94. package/src/components/atoms/Skeleton/skeleton.tsx +14 -0
  95. package/src/components/atoms/Slider/index.ts +1 -0
  96. package/src/components/atoms/Slider/slider.stories.tsx +28 -0
  97. package/src/components/atoms/Slider/slider.test.tsx +90 -0
  98. package/src/components/atoms/Slider/slider.tsx +54 -0
  99. package/src/components/atoms/Sonner/index.ts +1 -0
  100. package/src/components/atoms/Sonner/sonner.css +39 -0
  101. package/src/components/atoms/Sonner/sonner.stories.tsx +261 -0
  102. package/src/components/atoms/Sonner/sonner.test.tsx +24 -0
  103. package/src/components/atoms/Sonner/sonner.tsx +13 -0
  104. package/src/components/atoms/Switch/index.ts +1 -0
  105. package/src/components/atoms/Switch/switch.stories.tsx +128 -0
  106. package/src/components/atoms/Switch/switch.test.tsx +70 -0
  107. package/src/components/atoms/Switch/switch.tsx +61 -0
  108. package/src/components/atoms/Textarea/index.ts +1 -0
  109. package/src/components/atoms/Textarea/textarea.stories.tsx +169 -0
  110. package/src/components/atoms/Textarea/textarea.test.tsx +56 -0
  111. package/src/components/atoms/Textarea/textarea.tsx +26 -0
  112. package/src/components/atoms/Toggle/index.ts +1 -0
  113. package/src/components/atoms/Toggle/toggle.stories.tsx +170 -0
  114. package/src/components/atoms/Toggle/toggle.test.tsx +62 -0
  115. package/src/components/atoms/Toggle/toggle.tsx +47 -0
  116. package/src/components/atoms/Typography/index.ts +1 -0
  117. package/src/components/atoms/Typography/typography.stories.tsx +95 -0
  118. package/src/components/atoms/Typography/typography.test.tsx +66 -0
  119. package/src/components/atoms/Typography/typography.tsx +63 -0
  120. package/src/components/atoms/UploadImageField/index.ts +1 -0
  121. package/src/components/atoms/UploadImageField/upload-image-field.stories.tsx +249 -0
  122. package/src/components/atoms/UploadImageField/upload-image-field.test.tsx +348 -0
  123. package/src/components/atoms/UploadImageField/upload-image-field.tsx +362 -0
  124. package/src/components/atoms/VideoPlayer/index.ts +1 -0
  125. package/src/components/atoms/VideoPlayer/video-player.stories.tsx +37 -0
  126. package/src/components/atoms/VideoPlayer/video-player.test.tsx +20 -0
  127. package/src/components/atoms/VideoPlayer/video-player.tsx +26 -0
  128. package/src/components/atoms/index.ts +31 -0
  129. package/src/components/icons/alert-circle.tsx +22 -0
  130. package/src/components/icons/align-center.tsx +22 -0
  131. package/src/components/icons/align-left.tsx +22 -0
  132. package/src/components/icons/annotation-dots.tsx +16 -0
  133. package/src/components/icons/annotation-question.tsx +15 -0
  134. package/src/components/icons/annotation.tsx +22 -0
  135. package/src/components/icons/announcement-01.tsx +15 -0
  136. package/src/components/icons/announcement-02.tsx +15 -0
  137. package/src/components/icons/apple-logo.tsx +9 -0
  138. package/src/components/icons/arrow-circle-broken-right.tsx +16 -0
  139. package/src/components/icons/arrow-down.tsx +9 -0
  140. package/src/components/icons/arrow-up.tsx +9 -0
  141. package/src/components/icons/at-sign.tsx +21 -0
  142. package/src/components/icons/award-01.tsx +15 -0
  143. package/src/components/icons/award-03.tsx +16 -0
  144. package/src/components/icons/bank-note-01.tsx +15 -0
  145. package/src/components/icons/bar-chart-square-02.tsx +9 -0
  146. package/src/components/icons/bell-01.tsx +9 -0
  147. package/src/components/icons/bell-04.tsx +16 -0
  148. package/src/components/icons/bold-01.tsx +22 -0
  149. package/src/components/icons/book-open-01.tsx +15 -0
  150. package/src/components/icons/brackets-ellipses.tsx +22 -0
  151. package/src/components/icons/briefcase-01.tsx +9 -0
  152. package/src/components/icons/brush-01.tsx +22 -0
  153. package/src/components/icons/building-02.tsx +9 -0
  154. package/src/components/icons/building-06.tsx +9 -0
  155. package/src/components/icons/calendar-minus-02.tsx +15 -0
  156. package/src/components/icons/calendar.tsx +9 -0
  157. package/src/components/icons/certificate-01.tsx +16 -0
  158. package/src/components/icons/chart-breakout-square.tsx +16 -0
  159. package/src/components/icons/check-circle-02.tsx +16 -0
  160. package/src/components/icons/check-circle.tsx +15 -0
  161. package/src/components/icons/check.tsx +21 -0
  162. package/src/components/icons/chevron-down-double.tsx +16 -0
  163. package/src/components/icons/chevron-down.tsx +9 -0
  164. package/src/components/icons/chevron-left-double.tsx +22 -0
  165. package/src/components/icons/chevron-left.tsx +16 -0
  166. package/src/components/icons/chevron-right-double.tsx +22 -0
  167. package/src/components/icons/chevron-right.tsx +16 -0
  168. package/src/components/icons/chevron-up-double.tsx +16 -0
  169. package/src/components/icons/clock-rewind.tsx +15 -0
  170. package/src/components/icons/clock-stopwatch.tsx +15 -0
  171. package/src/components/icons/coins-hand.tsx +15 -0
  172. package/src/components/icons/coins-stacked-01.tsx +15 -0
  173. package/src/components/icons/coins-stacked-02.tsx +15 -0
  174. package/src/components/icons/container.tsx +9 -0
  175. package/src/components/icons/copy-02.tsx +16 -0
  176. package/src/components/icons/copy-04.tsx +21 -0
  177. package/src/components/icons/corner-down-right.tsx +9 -0
  178. package/src/components/icons/countries/br.tsx +20 -0
  179. package/src/components/icons/countries/es.tsx +19 -0
  180. package/src/components/icons/countries/index.ts +3 -0
  181. package/src/components/icons/countries/us.tsx +21 -0
  182. package/src/components/icons/dataflow-03.tsx +15 -0
  183. package/src/components/icons/dotpoints-01.tsx +22 -0
  184. package/src/components/icons/dots-vertical.tsx +35 -0
  185. package/src/components/icons/download-03.tsx +16 -0
  186. package/src/components/icons/download-cloud-02.tsx +15 -0
  187. package/src/components/icons/drag.tsx +14 -0
  188. package/src/components/icons/dropper.tsx +21 -0
  189. package/src/components/icons/edit-01.tsx +15 -0
  190. package/src/components/icons/edit-02.tsx +9 -0
  191. package/src/components/icons/edit-03.tsx +23 -0
  192. package/src/components/icons/eye.tsx +22 -0
  193. package/src/components/icons/face-frown.tsx +15 -0
  194. package/src/components/icons/face-happy.tsx +15 -0
  195. package/src/components/icons/file-06.tsx +15 -0
  196. package/src/components/icons/file-attachment-04.tsx +15 -0
  197. package/src/components/icons/file-download-02.tsx +16 -0
  198. package/src/components/icons/file-plus-02.tsx +16 -0
  199. package/src/components/icons/file-search-01.tsx +22 -0
  200. package/src/components/icons/file-search-03.tsx +15 -0
  201. package/src/components/icons/filter-lines.tsx +21 -0
  202. package/src/components/icons/first-category.tsx +16 -0
  203. package/src/components/icons/first-stage.tsx +19 -0
  204. package/src/components/icons/folder.tsx +15 -0
  205. package/src/components/icons/google.tsx +12 -0
  206. package/src/components/icons/graduation-hat-02.tsx +15 -0
  207. package/src/components/icons/grid-01.tsx +36 -0
  208. package/src/components/icons/help-circle.tsx +16 -0
  209. package/src/components/icons/help-square.tsx +16 -0
  210. package/src/components/icons/home-line.tsx +21 -0
  211. package/src/components/icons/icons.stories.tsx +199 -0
  212. package/src/components/icons/index.ts +140 -0
  213. package/src/components/icons/info-circle.tsx +15 -0
  214. package/src/components/icons/italic-01.tsx +22 -0
  215. package/src/components/icons/last-category.tsx +11 -0
  216. package/src/components/icons/last-stage.tsx +19 -0
  217. package/src/components/icons/layout-alt-04.tsx +9 -0
  218. package/src/components/icons/lightbulb-02.tsx +16 -0
  219. package/src/components/icons/link-01.tsx +16 -0
  220. package/src/components/icons/link-broken-01.tsx +16 -0
  221. package/src/components/icons/linkedin-logo.tsx +17 -0
  222. package/src/components/icons/lock-01.tsx +21 -0
  223. package/src/components/icons/log-out-01.tsx +9 -0
  224. package/src/components/icons/mail-01.tsx +16 -0
  225. package/src/components/icons/marker-pin-02.tsx +10 -0
  226. package/src/components/icons/menu-01.tsx +9 -0
  227. package/src/components/icons/middle-category.tsx +10 -0
  228. package/src/components/icons/middle-stage.tsx +19 -0
  229. package/src/components/icons/ms-outlook.tsx +47 -0
  230. package/src/components/icons/paragraph-spacing.tsx +15 -0
  231. package/src/components/icons/phone-01.tsx +21 -0
  232. package/src/components/icons/pie-chart-02.tsx +22 -0
  233. package/src/components/icons/plus-circle.tsx +15 -0
  234. package/src/components/icons/portal-logo.tsx +76 -0
  235. package/src/components/icons/presentation-chart-02.tsx +14 -0
  236. package/src/components/icons/route.tsx +22 -0
  237. package/src/components/icons/save-01.tsx +15 -0
  238. package/src/components/icons/search-lg.tsx +15 -0
  239. package/src/components/icons/search-sm.tsx +9 -0
  240. package/src/components/icons/send-03.tsx +15 -0
  241. package/src/components/icons/settings-01.tsx +17 -0
  242. package/src/components/icons/settings-03.tsx +14 -0
  243. package/src/components/icons/share-05.tsx +15 -0
  244. package/src/components/icons/share-06.tsx +15 -0
  245. package/src/components/icons/slash-circle-01.tsx +9 -0
  246. package/src/components/icons/star-01.tsx +9 -0
  247. package/src/components/icons/step-icon-active.tsx +11 -0
  248. package/src/components/icons/step-icon-checked.tsx +10 -0
  249. package/src/components/icons/step-icon-default.tsx +11 -0
  250. package/src/components/icons/switch-horizontal-01.tsx +9 -0
  251. package/src/components/icons/table-01.tsx +15 -0
  252. package/src/components/icons/tag-01.tsx +15 -0
  253. package/src/components/icons/tag-03.tsx +15 -0
  254. package/src/components/icons/tool-02.tsx +14 -0
  255. package/src/components/icons/trash-01.tsx +15 -0
  256. package/src/components/icons/underline-01.tsx +22 -0
  257. package/src/components/icons/upload-cloud-02.tsx +15 -0
  258. package/src/components/icons/user-01.tsx +9 -0
  259. package/src/components/icons/user-03.tsx +9 -0
  260. package/src/components/icons/user-check-01.tsx +14 -0
  261. package/src/components/icons/user-circle.tsx +14 -0
  262. package/src/components/icons/user-edit.tsx +16 -0
  263. package/src/components/icons/user-minus-02.tsx +15 -0
  264. package/src/components/icons/user-plus-01.tsx +22 -0
  265. package/src/components/icons/user-plus-02.tsx +15 -0
  266. package/src/components/icons/user-square.tsx +16 -0
  267. package/src/components/icons/users-01.tsx +14 -0
  268. package/src/components/icons/users-plus-01.tsx +21 -0
  269. package/src/components/icons/users-plus.tsx +16 -0
  270. package/src/components/icons/vertical-drag.tsx +21 -0
  271. package/src/components/icons/x-circle.tsx +15 -0
  272. package/src/components/icons/x-close.tsx +9 -0
  273. package/src/components/icons/zap-fast.tsx +16 -0
  274. package/src/components/icons/zap.tsx +9 -0
  275. package/src/components/index.ts +4 -0
  276. package/src/components/molecules/Accordion/accordion.stories.tsx +81 -0
  277. package/src/components/molecules/Accordion/accordion.test.tsx +91 -0
  278. package/src/components/molecules/Accordion/accordion.tsx +65 -0
  279. package/src/components/molecules/Accordion/index.ts +1 -0
  280. package/src/components/molecules/Alert/alert.stories.tsx +75 -0
  281. package/src/components/molecules/Alert/alert.test.tsx +58 -0
  282. package/src/components/molecules/Alert/alert.tsx +67 -0
  283. package/src/components/molecules/Alert/index.ts +1 -0
  284. package/src/components/molecules/AlertDialog/alert-dialog.stories.tsx +55 -0
  285. package/src/components/molecules/AlertDialog/alert-dialog.test.tsx +34 -0
  286. package/src/components/molecules/AlertDialog/alert-dialog.tsx +172 -0
  287. package/src/components/molecules/AlertDialog/index.ts +1 -0
  288. package/src/components/molecules/Avatar/avatar.stories.tsx +98 -0
  289. package/src/components/molecules/Avatar/avatar.test.tsx +55 -0
  290. package/src/components/molecules/Avatar/avatar.tsx +55 -0
  291. package/src/components/molecules/Avatar/index.ts +1 -0
  292. package/src/components/molecules/Breadcrumb/breadcrumb.stories.tsx +125 -0
  293. package/src/components/molecules/Breadcrumb/breadcrumb.test.tsx +118 -0
  294. package/src/components/molecules/Breadcrumb/breadcrumb.tsx +120 -0
  295. package/src/components/molecules/Breadcrumb/index.ts +1 -0
  296. package/src/components/molecules/Card/card.stories.tsx +109 -0
  297. package/src/components/molecules/Card/card.test.tsx +103 -0
  298. package/src/components/molecules/Card/card.tsx +78 -0
  299. package/src/components/molecules/Card/index.ts +1 -0
  300. package/src/components/molecules/Collapsible/collapsible.stories.tsx +28 -0
  301. package/src/components/molecules/Collapsible/collapsible.test.tsx +36 -0
  302. package/src/components/molecules/Collapsible/collapsible.tsx +31 -0
  303. package/src/components/molecules/Collapsible/index.ts +1 -0
  304. package/src/components/molecules/ColorPicker/color-picker.stories.tsx +40 -0
  305. package/src/components/molecules/ColorPicker/color-picker.tsx +106 -0
  306. package/src/components/molecules/ColorPicker/index.ts +1 -0
  307. package/src/components/molecules/ColorScale/color-scale.stories.tsx +31 -0
  308. package/src/components/molecules/ColorScale/color-scale.tsx +74 -0
  309. package/src/components/molecules/ColorScale/index.ts +1 -0
  310. package/src/components/molecules/Command/command.stories.tsx +71 -0
  311. package/src/components/molecules/Command/command.test.tsx +50 -0
  312. package/src/components/molecules/Command/command.tsx +177 -0
  313. package/src/components/molecules/Command/index.ts +1 -0
  314. package/src/components/molecules/ContextMenu/context-menu.stories.tsx +69 -0
  315. package/src/components/molecules/ContextMenu/context-menu.test.tsx +25 -0
  316. package/src/components/molecules/ContextMenu/context-menu.tsx +259 -0
  317. package/src/components/molecules/ContextMenu/index.ts +1 -0
  318. package/src/components/molecules/DatePicker/date-picker.stories.tsx +204 -0
  319. package/src/components/molecules/DatePicker/date-picker.test.tsx +27 -0
  320. package/src/components/molecules/DatePicker/date-picker.tsx +486 -0
  321. package/src/components/molecules/DatePicker/index.ts +1 -0
  322. package/src/components/molecules/Dialog/dialog.stories.tsx +48 -0
  323. package/src/components/molecules/Dialog/dialog.test.tsx +51 -0
  324. package/src/components/molecules/Dialog/dialog.tsx +150 -0
  325. package/src/components/molecules/Dialog/index.ts +1 -0
  326. package/src/components/molecules/Drawer/drawer.stories.tsx +182 -0
  327. package/src/components/molecules/Drawer/drawer.test.tsx +100 -0
  328. package/src/components/molecules/Drawer/drawer.tsx +206 -0
  329. package/src/components/molecules/Drawer/index.ts +1 -0
  330. package/src/components/molecules/Dropdown/dropdown-async.stories.tsx +15 -0
  331. package/src/components/molecules/Dropdown/dropdown.stories.tsx +112 -0
  332. package/src/components/molecules/Dropdown/dropdown.test.tsx +128 -0
  333. package/src/components/molecules/Dropdown/dropdown.tsx +322 -0
  334. package/src/components/molecules/Dropdown/index.ts +1 -0
  335. package/src/components/molecules/DropdownMenu/dropdown-menu.stories.tsx +154 -0
  336. package/src/components/molecules/DropdownMenu/dropdown-menu.test.tsx +163 -0
  337. package/src/components/molecules/DropdownMenu/dropdown-menu.tsx +313 -0
  338. package/src/components/molecules/DropdownMenu/index.ts +1 -0
  339. package/src/components/molecules/HoverCard/hover-card.stories.tsx +48 -0
  340. package/src/components/molecules/HoverCard/hover-card.test.tsx +42 -0
  341. package/src/components/molecules/HoverCard/hover-card.tsx +44 -0
  342. package/src/components/molecules/HoverCard/index.ts +1 -0
  343. package/src/components/molecules/InputOTP/index.ts +1 -0
  344. package/src/components/molecules/InputOTP/input-otp.stories.tsx +52 -0
  345. package/src/components/molecules/InputOTP/input-otp.test.tsx +28 -0
  346. package/src/components/molecules/InputOTP/input-otp.tsx +76 -0
  347. package/src/components/molecules/Menubar/index.ts +1 -0
  348. package/src/components/molecules/Menubar/menubar.stories.tsx +113 -0
  349. package/src/components/molecules/Menubar/menubar.test.tsx +42 -0
  350. package/src/components/molecules/Menubar/menubar.tsx +314 -0
  351. package/src/components/molecules/NavigationMenu/index.ts +1 -0
  352. package/src/components/molecules/NavigationMenu/navigation-menu.stories.tsx +143 -0
  353. package/src/components/molecules/NavigationMenu/navigation-menu.test.tsx +69 -0
  354. package/src/components/molecules/NavigationMenu/navigation-menu.tsx +174 -0
  355. package/src/components/molecules/PDFViewer/index.ts +1 -0
  356. package/src/components/molecules/PDFViewer/pdf-viewer.stories.tsx +34 -0
  357. package/src/components/molecules/PDFViewer/pdf-viewer.test.tsx +26 -0
  358. package/src/components/molecules/PDFViewer/pdf-viewer.tsx +358 -0
  359. package/src/components/molecules/Pagination/index.ts +1 -0
  360. package/src/components/molecules/Pagination/pagination.stories.tsx +193 -0
  361. package/src/components/molecules/Pagination/pagination.test.tsx +448 -0
  362. package/src/components/molecules/Pagination/pagination.tsx +206 -0
  363. package/src/components/molecules/PaginationDotGroup/index.ts +1 -0
  364. package/src/components/molecules/PaginationDotGroup/pagination-dot-group.stories.tsx +211 -0
  365. package/src/components/molecules/PaginationDotGroup/pagination-dot-group.test.tsx +385 -0
  366. package/src/components/molecules/PaginationDotGroup/pagination-dot-group.tsx +119 -0
  367. package/src/components/molecules/Popover/index.ts +1 -0
  368. package/src/components/molecules/Popover/popover-menu.stories.tsx +27 -0
  369. package/src/components/molecules/Popover/popover.test.tsx +50 -0
  370. package/src/components/molecules/Popover/popover.tsx +38 -0
  371. package/src/components/molecules/ProgressSteps/index.ts +1 -0
  372. package/src/components/molecules/ProgressSteps/progress-steps.stories.tsx +36 -0
  373. package/src/components/molecules/ProgressSteps/progress-steps.test.tsx +470 -0
  374. package/src/components/molecules/ProgressSteps/progress-steps.tsx +140 -0
  375. package/src/components/molecules/RadioGroup/index.ts +1 -0
  376. package/src/components/molecules/RadioGroup/radio-group.stories.tsx +42 -0
  377. package/src/components/molecules/RadioGroup/radio-group.test.tsx +22 -0
  378. package/src/components/molecules/RadioGroup/radio-group.tsx +55 -0
  379. package/src/components/molecules/Resizable/index.ts +1 -0
  380. package/src/components/molecules/Resizable/resizable.stories.tsx +52 -0
  381. package/src/components/molecules/Resizable/resizable.test.tsx +22 -0
  382. package/src/components/molecules/Resizable/resizable.tsx +55 -0
  383. package/src/components/molecules/ScrollArea/index.ts +1 -0
  384. package/src/components/molecules/ScrollArea/scroll-area.stories.tsx +93 -0
  385. package/src/components/molecules/ScrollArea/scroll-area.test.tsx +28 -0
  386. package/src/components/molecules/ScrollArea/scroll-area.tsx +57 -0
  387. package/src/components/molecules/Select/index.ts +1 -0
  388. package/src/components/molecules/Select/select.stories.tsx +63 -0
  389. package/src/components/molecules/Select/select.test.tsx +80 -0
  390. package/src/components/molecules/Select/select.tsx +172 -0
  391. package/src/components/molecules/Sheet/index.ts +1 -0
  392. package/src/components/molecules/Sheet/sheet.stories.tsx +141 -0
  393. package/src/components/molecules/Sheet/sheet.test.tsx +70 -0
  394. package/src/components/molecules/Sheet/sheet.tsx +133 -0
  395. package/src/components/molecules/Tabs/index.ts +1 -0
  396. package/src/components/molecules/Tabs/tabs.stories.tsx +222 -0
  397. package/src/components/molecules/Tabs/tabs.test.tsx +113 -0
  398. package/src/components/molecules/Tabs/tabs.tsx +102 -0
  399. package/src/components/molecules/ToggleGroup/index.ts +1 -0
  400. package/src/components/molecules/ToggleGroup/toggle-group.stories.tsx +117 -0
  401. package/src/components/molecules/ToggleGroup/toggle-group.test.tsx +100 -0
  402. package/src/components/molecules/ToggleGroup/toggle-group.tsx +70 -0
  403. package/src/components/molecules/Tooltip/index.ts +1 -0
  404. package/src/components/molecules/Tooltip/tooltip.stories.tsx +133 -0
  405. package/src/components/molecules/Tooltip/tooltip.test.tsx +58 -0
  406. package/src/components/molecules/Tooltip/tooltip.tsx +58 -0
  407. package/src/components/molecules/index.ts +33 -0
  408. package/src/components/organisms/Carousel/carousel.stories.tsx +94 -0
  409. package/src/components/organisms/Carousel/carousel.test.tsx +24 -0
  410. package/src/components/organisms/Carousel/carousel.tsx +383 -0
  411. package/src/components/organisms/Carousel/index.ts +1 -0
  412. package/src/components/organisms/Chart/chart.stories.tsx +102 -0
  413. package/src/components/organisms/Chart/chart.test.tsx +105 -0
  414. package/src/components/organisms/Chart/chart.tsx +294 -0
  415. package/src/components/organisms/Chart/index.ts +1 -0
  416. package/src/components/organisms/FileUpload/FilePreview/file-preview.tsx +55 -0
  417. package/src/components/organisms/FileUpload/FilePreview/index.ts +1 -0
  418. package/src/components/organisms/FileUpload/file-upload.stories.tsx +20 -0
  419. package/src/components/organisms/FileUpload/file-upload.test.tsx +59 -0
  420. package/src/components/organisms/FileUpload/file-upload.tsx +175 -0
  421. package/src/components/organisms/FileUpload/file.d.ts +21 -0
  422. package/src/components/organisms/FileUpload/index.ts +1 -0
  423. package/src/components/organisms/Form/form.stories.tsx +155 -0
  424. package/src/components/organisms/Form/form.test.tsx +49 -0
  425. package/src/components/organisms/Form/form.tsx +133 -0
  426. package/src/components/organisms/Form/index.ts +1 -0
  427. package/src/components/organisms/Sidebar/index.ts +1 -0
  428. package/src/components/organisms/Sidebar/sidebar.stories.tsx +86 -0
  429. package/src/components/organisms/Sidebar/sidebar.test.tsx +101 -0
  430. package/src/components/organisms/Sidebar/sidebar.tsx +666 -0
  431. package/src/components/organisms/Table/index.ts +1 -0
  432. package/src/components/organisms/Table/table.stories.tsx +86 -0
  433. package/src/components/organisms/Table/table.test.tsx +42 -0
  434. package/src/components/organisms/Table/table.tsx +120 -0
  435. package/src/components/organisms/index.ts +6 -0
  436. package/src/constants/brazilian-states.ts +29 -0
  437. package/src/constants/index.ts +1 -0
  438. package/src/hooks/index.ts +10 -0
  439. package/src/hooks/useEditorActiveMarks.ts +63 -0
  440. package/src/hooks/useForm.ts +8 -0
  441. package/src/hooks/useFormContext.ts +7 -0
  442. package/src/hooks/useFormField.ts +41 -0
  443. package/src/hooks/useMobile.ts +61 -0
  444. package/src/hooks/useOnToggle.ts +28 -0
  445. package/src/hooks/usePDFNavigation.ts +41 -0
  446. package/src/hooks/usePDFZoom.ts +35 -0
  447. package/src/hooks/useSidebar.ts +23 -0
  448. package/src/hooks/useToast.tsx +63 -0
  449. package/src/index.css +73 -0
  450. package/src/main.ts +6 -0
  451. package/src/theme.css +388 -0
  452. package/src/utils/api/api.test.ts +64 -0
  453. package/src/utils/api/api.ts +34 -0
  454. package/src/utils/api/index.ts +1 -0
  455. package/src/utils/array/array.test.ts +160 -0
  456. package/src/utils/array/array.ts +43 -0
  457. package/src/utils/array/index.ts +1 -0
  458. package/src/utils/clipboard/clipboard.test.ts +218 -0
  459. package/src/utils/clipboard/clipboard.ts +40 -0
  460. package/src/utils/clipboard/index.ts +1 -0
  461. package/src/utils/cn/cn.test.ts +43 -0
  462. package/src/utils/cn/cn.ts +6 -0
  463. package/src/utils/cn/index.ts +1 -0
  464. package/src/utils/color-utils/color-utils.test.ts +46 -0
  465. package/src/utils/color-utils/color-utils.ts +97 -0
  466. package/src/utils/color-utils/index.ts +1 -0
  467. package/src/utils/countries/countries.ts +69 -0
  468. package/src/utils/countries/index.ts +1 -0
  469. package/src/utils/currency/currency.test.ts +114 -0
  470. package/src/utils/currency/currency.ts +134 -0
  471. package/src/utils/currency/index.ts +1 -0
  472. package/src/utils/date/date.test.ts +167 -0
  473. package/src/utils/date/date.ts +83 -0
  474. package/src/utils/date/index.ts +1 -0
  475. package/src/utils/file/file.ts +45 -0
  476. package/src/utils/file/index.ts +1 -0
  477. package/src/utils/get-initials/get-initials.test.ts +40 -0
  478. package/src/utils/get-initials/get-initials.ts +13 -0
  479. package/src/utils/get-initials/index.ts +1 -0
  480. package/src/utils/index.ts +14 -0
  481. package/src/utils/masks/index.ts +1 -0
  482. package/src/utils/masks/masks.ts +180 -0
  483. package/src/utils/render-highlighted-text/index.ts +1 -0
  484. package/src/utils/render-highlighted-text/render-highlighted-text.tsx +25 -0
  485. package/src/utils/string/index.ts +1 -0
  486. package/src/utils/string/string.test.ts +171 -0
  487. package/src/utils/string/string.ts +155 -0
  488. package/src/utils/video/index.ts +1 -0
  489. package/src/utils/video/video.ts +9 -0
  490. package/src/vite-env.d.ts +3 -0
@@ -0,0 +1,294 @@
1
+ import * as React from 'react';
2
+
3
+ import * as RechartsPrimitive from 'recharts';
4
+
5
+ import { cn } from '@/utils';
6
+
7
+ // Format: { THEME_NAME: CSS_SELECTOR }
8
+ const THEMES = { light: '', dark: '.dark' } as const;
9
+
10
+ export type ChartConfig = {
11
+ [k in string]: {
12
+ label?: React.ReactNode;
13
+ icon?: React.ComponentType;
14
+ } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> });
15
+ };
16
+
17
+ type ChartContextProps = {
18
+ config: ChartConfig;
19
+ };
20
+
21
+ const ChartContext = React.createContext<ChartContextProps | null>(null);
22
+
23
+ function useChart() {
24
+ const context = React.useContext(ChartContext);
25
+
26
+ if (!context) {
27
+ throw new Error('useChart must be used within a <ChartContainer />');
28
+ }
29
+
30
+ return context;
31
+ }
32
+
33
+ function ChartContainer({
34
+ id,
35
+ className,
36
+ children,
37
+ config,
38
+ ...props
39
+ }: React.ComponentProps<'div'> & {
40
+ config: ChartConfig;
41
+ children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];
42
+ }) {
43
+ const uniqueId = React.useId();
44
+ const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`;
45
+
46
+ return (
47
+ <ChartContext.Provider value={{ config }}>
48
+ <div
49
+ data-slot="chart"
50
+ data-chart={chartId}
51
+ className={cn(
52
+ '[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke=\'#ccc\']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke=\'#ccc\']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke=\'#ccc\']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke=\'#fff\']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke=\'#fff\']]:stroke-transparent [&_.recharts-surface]:outline-hidden',
53
+ className
54
+ )}
55
+ {...props}
56
+ >
57
+ <ChartStyle id={chartId} config={config} />
58
+ <RechartsPrimitive.ResponsiveContainer>{children}</RechartsPrimitive.ResponsiveContainer>
59
+ </div>
60
+ </ChartContext.Provider>
61
+ );
62
+ }
63
+
64
+ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
65
+ const colorConfig = Object.entries(config).filter(([ , config ]) => config.theme || config.color);
66
+
67
+ if (!colorConfig.length) {
68
+ return null;
69
+ }
70
+
71
+ return (
72
+ <style
73
+ dangerouslySetInnerHTML={{
74
+ __html: Object.entries(THEMES)
75
+ .map(
76
+ ([ theme, prefix ]) => `
77
+ ${prefix} [data-chart=${id}] {
78
+ ${colorConfig
79
+ .map(([ key, itemConfig ]) => {
80
+ const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] || itemConfig.color;
81
+ return color ? ` --color-${key}: ${color};` : null;
82
+ })
83
+ .join('\n')}
84
+ }
85
+ `
86
+ )
87
+ .join('\n'),
88
+ }}
89
+ />
90
+ );
91
+ };
92
+
93
+ const ChartTooltip = RechartsPrimitive.Tooltip;
94
+
95
+ function ChartTooltipContent({
96
+ active,
97
+ payload,
98
+ className,
99
+ indicator = 'dot',
100
+ hideLabel = false,
101
+ hideIndicator = false,
102
+ label,
103
+ labelFormatter,
104
+ labelClassName,
105
+ formatter,
106
+ color,
107
+ nameKey,
108
+ labelKey,
109
+ }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
110
+ React.ComponentProps<'div'> & {
111
+ hideLabel?: boolean;
112
+ hideIndicator?: boolean;
113
+ indicator?: 'line' | 'dot' | 'dashed';
114
+ nameKey?: string;
115
+ labelKey?: string;
116
+ }) {
117
+ const { config } = useChart();
118
+
119
+ const tooltipLabel = React.useMemo(() => {
120
+ if (hideLabel || !payload?.length) {
121
+ return null;
122
+ }
123
+
124
+ const [ item ] = payload;
125
+ const key = `${labelKey || item?.dataKey || item?.name || 'value'}`;
126
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
127
+ const value =
128
+ !labelKey && typeof label === 'string' ? config[label as keyof typeof config]?.label || label : itemConfig?.label;
129
+
130
+ if (labelFormatter) {
131
+ return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;
132
+ }
133
+
134
+ if (!value) {
135
+ return null;
136
+ }
137
+
138
+ return (
139
+ <div className={cn('font-medium', labelClassName)} data-testid="chart-tooltip">
140
+ {value}
141
+ </div>
142
+ );
143
+ }, [ label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey ]);
144
+
145
+ if (!active || !payload?.length) {
146
+ return null;
147
+ }
148
+
149
+ const nestLabel = payload.length === 1 && indicator !== 'dot';
150
+
151
+ return (
152
+ <div
153
+ className={cn(
154
+ 'border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',
155
+ className
156
+ )}
157
+ >
158
+ {!nestLabel ? tooltipLabel : null}
159
+ <div className="grid gap-1.5">
160
+ {payload.map((item, index) => {
161
+ const key = `${nameKey || item.name || item.dataKey || 'value'}`;
162
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
163
+ const indicatorColor = color || item.payload.fill || item.color;
164
+
165
+ return (
166
+ <div
167
+ key={item.dataKey}
168
+ className={cn(
169
+ '[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',
170
+ indicator === 'dot' && 'items-center'
171
+ )}
172
+ >
173
+ {formatter && item?.value !== undefined && item.name ? (
174
+ formatter(item.value, item.name, item, index, item.payload)
175
+ ) : (
176
+ <>
177
+ {itemConfig?.icon ? (
178
+ <itemConfig.icon />
179
+ ) : (
180
+ !hideIndicator && (
181
+ <div
182
+ className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {
183
+ 'h-2.5 w-2.5': indicator === 'dot',
184
+ 'w-1': indicator === 'line',
185
+ 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',
186
+ 'my-0.5': nestLabel && indicator === 'dashed',
187
+ })}
188
+ style={
189
+ {
190
+ '--color-bg': indicatorColor,
191
+ '--color-border': indicatorColor,
192
+ } as React.CSSProperties
193
+ }
194
+ />
195
+ )
196
+ )}
197
+ <div
198
+ className={cn('flex flex-1 justify-between leading-none', nestLabel ? 'items-end' : 'items-center')}
199
+ >
200
+ <div className="grid gap-1.5">
201
+ {nestLabel ? tooltipLabel : null}
202
+ <span className="text-muted-foreground">{itemConfig?.label || item.name}</span>
203
+ </div>
204
+ {item.value && (
205
+ <span className="text-foreground font-mono font-medium tabular-nums">
206
+ {item.value.toLocaleString()}
207
+ </span>
208
+ )}
209
+ </div>
210
+ </>
211
+ )}
212
+ </div>
213
+ );
214
+ })}
215
+ </div>
216
+ </div>
217
+ );
218
+ }
219
+
220
+ const ChartLegend = RechartsPrimitive.Legend;
221
+
222
+ function ChartLegendContent({
223
+ className,
224
+ hideIcon = false,
225
+ payload,
226
+ verticalAlign = 'bottom',
227
+ nameKey,
228
+ }: React.ComponentProps<'div'> &
229
+ Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
230
+ hideIcon?: boolean;
231
+ nameKey?: string;
232
+ }) {
233
+ const { config } = useChart();
234
+
235
+ if (!payload?.length) {
236
+ return null;
237
+ }
238
+
239
+ return (
240
+ <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>
241
+ {payload.map((item) => {
242
+ const key = `${nameKey || item.dataKey || 'value'}`;
243
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
244
+
245
+ return (
246
+ <div
247
+ key={item.value}
248
+ className={cn('[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3')}
249
+ >
250
+ {itemConfig?.icon && !hideIcon ? (
251
+ <itemConfig.icon />
252
+ ) : (
253
+ <div
254
+ className="h-2 w-2 shrink-0 rounded-[2px]"
255
+ style={{
256
+ backgroundColor: item.color,
257
+ }}
258
+ />
259
+ )}
260
+ {itemConfig?.label}
261
+ </div>
262
+ );
263
+ })}
264
+ </div>
265
+ );
266
+ }
267
+
268
+ // Helper to extract item config from a payload.
269
+ function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
270
+ if (typeof payload !== 'object' || payload === null) {
271
+ return undefined;
272
+ }
273
+
274
+ const payloadPayload =
275
+ 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null
276
+ ? payload.payload
277
+ : undefined;
278
+
279
+ let configLabelKey: string = key;
280
+
281
+ if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {
282
+ configLabelKey = payload[key as keyof typeof payload] as string;
283
+ } else if (
284
+ payloadPayload &&
285
+ key in payloadPayload &&
286
+ typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'
287
+ ) {
288
+ configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
289
+ }
290
+
291
+ return configLabelKey in config ? config[configLabelKey] : config[key as keyof typeof config];
292
+ }
293
+
294
+ export { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent };
@@ -0,0 +1 @@
1
+ export * from './chart';
@@ -0,0 +1,55 @@
1
+ import { X, FileText } from 'lucide-react';
2
+
3
+ import { FileType } from '../file';
4
+
5
+ import {
6
+ AlertDialog,
7
+ AlertDialogContent,
8
+ AlertDialogTrigger,
9
+ AlertDialogClose,
10
+ Box,
11
+ } from '@/components';
12
+
13
+ export type FilePreviewProps = {
14
+ file: FileType;
15
+ };
16
+
17
+ export const FilePreview = ({ file }: FilePreviewProps) => {
18
+ return (
19
+ <AlertDialog>
20
+ <AlertDialogTrigger asChild>
21
+ <button className='p-1 hover:bg-accent rounded-md cursor-pointer'>
22
+ <FileText className='w-4 h-4' />
23
+ </button>
24
+ </AlertDialogTrigger>
25
+ <AlertDialogContent className='fixed w-full max-w-5xl'>
26
+ <AlertDialogClose className='absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground z-50'>
27
+ <X className='h-4 w-4' />
28
+ </AlertDialogClose>
29
+ <Box className='p-6'>
30
+ {file.file.type.startsWith('image/') && file.preview && (
31
+ <img
32
+ src={file.preview}
33
+ alt={file.file.name}
34
+ className='max-w-full max-h-full object-fit'
35
+ />
36
+ )}
37
+ {file.file.type.startsWith('video/') && (
38
+ <video
39
+ src={URL.createObjectURL(file.file)}
40
+ controls
41
+ controlsList='nodownload'
42
+ className='max-w-full max-h-[80vh]'
43
+ />
44
+ )}
45
+ {file.file.type === 'application/pdf' && (
46
+ <iframe
47
+ src={URL.createObjectURL(file.file)}
48
+ className='w-full h-[80vh]'
49
+ />
50
+ )}
51
+ </Box>
52
+ </AlertDialogContent>
53
+ </AlertDialog>
54
+ );
55
+ };
@@ -0,0 +1 @@
1
+ export * from './file-preview';
@@ -0,0 +1,20 @@
1
+ import { FileUpload } from './file-upload';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ const meta: Meta<typeof FileUpload> = {
6
+ title: 'Components/Data Entry/FileUpload',
7
+ component: FileUpload,
8
+ tags: [ 'autodocs' ],
9
+ };
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof FileUpload>;
13
+
14
+ export const Default: Story = {
15
+ args: {
16
+ maxFiles: 3,
17
+ maxSize: 5 * 1024 * 1024,
18
+ onUpload: (files) => console.log('Uploaded files:', files),
19
+ },
20
+ };
@@ -0,0 +1,59 @@
1
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
2
+ import { describe, it, vi, expect } from 'vitest';
3
+
4
+ import { FileUpload } from './file-upload';
5
+
6
+ const mockCreateObjectURL = vi.fn(() => 'mock-url');
7
+ URL.createObjectURL = mockCreateObjectURL;
8
+
9
+ function createFile(name: string, type: string, size = 1024) {
10
+ const blob = new Blob([ 'a'.repeat(size) ], { type });
11
+ return new File([ blob ], name, { type });
12
+ }
13
+
14
+ describe('<FileUpload />', () => {
15
+ it('should render the upload area', () => {
16
+ render(<FileUpload />);
17
+ expect(
18
+ screen.getByText(/drag and drop files here/i)
19
+ ).toBeInTheDocument();
20
+ });
21
+
22
+ it('should trigger onUpload and show file preview', async () => {
23
+ const mockUpload = vi.fn();
24
+ render(<FileUpload onUpload={mockUpload} />);
25
+
26
+ const input = screen.getByTestId('file-upload-input');
27
+ const file = createFile('image.png', 'image/png');
28
+
29
+ fireEvent.change(input, {
30
+ target: { files: [ file ] },
31
+ });
32
+
33
+ await waitFor(() => {
34
+ expect(mockUpload).toHaveBeenCalled();
35
+ expect(screen.getByText('image.png')).toBeInTheDocument();
36
+ });
37
+ });
38
+
39
+ it('should remove a file when remove button is clicked', async () => {
40
+ const file = createFile('remove.pdf', 'application/pdf');
41
+
42
+ render(<FileUpload />);
43
+
44
+ const input = screen.getByTestId('file-upload-input');
45
+ fireEvent.change(input, {
46
+ target: { files: [ file ] },
47
+ });
48
+
49
+ await waitFor(() => {
50
+ expect(screen.getByText('remove.pdf')).toBeInTheDocument();
51
+ });
52
+
53
+ fireEvent.click(screen.getByTestId('remove-file-button'));
54
+
55
+ await waitFor(() => {
56
+ expect(screen.queryByText('remove.pdf')).not.toBeInTheDocument();
57
+ });
58
+ });
59
+ });
@@ -0,0 +1,175 @@
1
+ import { useCallback, useState } from 'react';
2
+
3
+ import {
4
+ Cross2Icon,
5
+ UploadIcon,
6
+ FileIcon,
7
+ ImageIcon,
8
+ VideoIcon,
9
+ CheckCircledIcon,
10
+ } from '@radix-ui/react-icons';
11
+ import { useDropzone } from 'react-dropzone';
12
+
13
+ import { FileType, FileUploadProps } from './file';
14
+ import { FilePreview } from './FilePreview';
15
+
16
+ import { Box, Flex, Typography, Progress } from '@/components';
17
+ import { cn, formatFileSize } from '@/utils';
18
+
19
+ const getFileIcon = (file: File) => {
20
+ if (file.type.startsWith('image/'))
21
+ return <ImageIcon className='w-8 h-8 text-primary' />;
22
+
23
+ if (file.type.startsWith('video/'))
24
+ return <VideoIcon className='w-8 h-8 text-primary' />;
25
+
26
+ if (file.type === 'application/pdf')
27
+ return <FileIcon className='w-8 h-8 text-primary' />;
28
+
29
+ return <FileIcon className='w-8 h-8 text-primary' />;
30
+ };
31
+
32
+ export const FileUpload = ({
33
+ onUpload,
34
+ maxSize = 10 * 1024 * 1024,
35
+ accept = {
36
+ 'image/*': [ '.png', '.jpg', '.jpeg', '.gif' ],
37
+ 'video/*': [ '.mp4', '.webm', '.mov' ],
38
+ 'application/pdf': [ '.pdf' ],
39
+ 'application/msword': [ '.doc', '.txt' ],
40
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': [
41
+ '.docx',
42
+ ],
43
+ },
44
+ maxFiles = 5,
45
+ className,
46
+ dragAndDropLabel = 'Drag and drop files here, or click to select files',
47
+ dragActiveLabel = 'Drop the files here...',
48
+ maxSizeLabel = 'Max file size',
49
+ maxFilesLabel = 'Max files',
50
+ uploadCompleteLabel = 'Upload complete',
51
+ }: FileUploadProps) => {
52
+ const [ files, setFiles ] = useState<FileType[]>([]);
53
+
54
+ const onDrop = useCallback(
55
+ (acceptedFiles: File[]) => {
56
+ const newFiles = acceptedFiles.map((file) => ({
57
+ id: Math.random().toString(36).substring(7),
58
+ file,
59
+ progress: 0,
60
+ preview: file.type.startsWith('image/')
61
+ ? URL.createObjectURL(file)
62
+ : undefined,
63
+ isUploaded: false,
64
+ }));
65
+
66
+ setFiles((prev) => [ ...prev, ...newFiles ].slice(0, maxFiles));
67
+
68
+ newFiles.forEach((file) => {
69
+ let progress = 0;
70
+ const interval = setInterval(() => {
71
+ progress += 10;
72
+ setFiles((prev) =>
73
+ prev.map((f) =>
74
+ (f.id === file.id
75
+ ? { ...f, progress: Math.min(progress, 100) }
76
+ : f)
77
+ )
78
+ );
79
+
80
+ if (progress >= 100) {
81
+ clearInterval(interval);
82
+ setFiles((prev) =>
83
+ prev.map((f) =>
84
+ (f.id === file.id ? { ...f, isUploaded: true } : f)
85
+ )
86
+ );
87
+ }
88
+ }, 200);
89
+ });
90
+
91
+ onUpload?.(newFiles);
92
+ },
93
+ [ maxFiles, onUpload ]
94
+ );
95
+
96
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
97
+ onDrop,
98
+ maxSize,
99
+ accept,
100
+ maxFiles,
101
+ });
102
+
103
+ const removeFile = (id: string) => {
104
+ setFiles((prev) => prev.filter((file) => file.id !== id));
105
+ };
106
+
107
+ return (
108
+ <Box className={cn('w-full', className)}>
109
+ <Box
110
+ {...getRootProps()}
111
+ className={cn(
112
+ 'border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors',
113
+ isDragActive
114
+ ? 'border-primary bg-primary/10'
115
+ : 'border-muted-foreground/25',
116
+ 'hover:border-primary hover:bg-primary/5'
117
+ )}>
118
+ <input {...getInputProps()} data-testid='file-upload-input' />
119
+ <UploadIcon className='w-8 h-8 mx-auto mb-2 text-muted-foreground' />
120
+ <Typography className='text-sm text-muted-foreground'>
121
+ {isDragActive ? dragActiveLabel : dragAndDropLabel}
122
+ </Typography>
123
+ <Typography className='text-xs text-muted-foreground mt-1'>
124
+ {maxSizeLabel}: {formatFileSize(maxSize)} • {maxFilesLabel}:{' '}
125
+ {maxFiles}
126
+ </Typography>
127
+ </Box>
128
+
129
+ {files.length > 0 && (
130
+ <Box className='mt-4 space-y-4'>
131
+ {files.map((file) => (
132
+ <Flex
133
+ key={file.id}
134
+ className='items-center gap-4 p-3 rounded-lg border bg-card'>
135
+ {getFileIcon(file.file)}
136
+
137
+ <Box className='flex-1 min-w-0'>
138
+ <Typography className='text-sm font-medium truncate'>
139
+ {file.file.name}
140
+ </Typography>
141
+ <Typography className='text-xs text-muted-foreground'>
142
+ {formatFileSize(file.file.size)}
143
+ </Typography>
144
+ {!file.isUploaded ? (
145
+ <Progress value={file.progress} className='mt-2' />
146
+ ) : (
147
+ <Flex className='items-center gap-1 mt-2 text-xs text-primary'>
148
+ <CheckCircledIcon className='w-4 h-4' />
149
+ <Typography className='text-xs'>
150
+ {uploadCompleteLabel}
151
+ </Typography>
152
+ </Flex>
153
+ )}
154
+ </Box>
155
+
156
+ <Flex className='items-center gap-2'>
157
+ {(file.file.type.startsWith('image/') ||
158
+ file.file.type.startsWith('video/') ||
159
+ file.file.type === 'application/pdf') && (
160
+ <FilePreview file={file} />
161
+ )}
162
+ <Box
163
+ data-testid='remove-file-button'
164
+ className='p-1 hover:bg-accent rounded-md cursor-pointer'
165
+ onClick={() => removeFile(file.id)}>
166
+ <Cross2Icon className='w-4 h-4' />
167
+ </Box>
168
+ </Flex>
169
+ </Flex>
170
+ ))}
171
+ </Box>
172
+ )}
173
+ </Box>
174
+ );
175
+ };
@@ -0,0 +1,21 @@
1
+ export type FileType = {
2
+ id: string;
3
+ file: File;
4
+ progress: number;
5
+ preview?: string;
6
+ isUploaded?: boolean;
7
+ };
8
+
9
+ export type FileUploadProps = {
10
+ onUpload?: (files: FileType[]) => void;
11
+ maxSize?: number;
12
+ accept?: Record<string, string[]>;
13
+ maxFiles?: number;
14
+ className?: string;
15
+
16
+ dragAndDropLabel?: string;
17
+ dragActiveLabel?: string;
18
+ maxSizeLabel?: string;
19
+ maxFilesLabel?: string;
20
+ uploadCompleteLabel?: string;
21
+ };
@@ -0,0 +1 @@
1
+ export * from './file-upload';