@takaro/lib-components 0.0.0-next.0da151e

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 (430) hide show
  1. package/.babelrc +7 -0
  2. package/@types/files.d.ts +23 -0
  3. package/@types/react-table-config.d.ts +121 -0
  4. package/Dockerfile.dev +21 -0
  5. package/package.json +15 -0
  6. package/public/images/7-days-to-die/logo.png +0 -0
  7. package/public/images/csmm-icon.png +0 -0
  8. package/public/images/milk.png +0 -0
  9. package/public/images/placeholder-01.jpeg +0 -0
  10. package/public/images/placeholder-02.jpeg +0 -0
  11. package/public/images/placeholder-03.jpeg +0 -0
  12. package/public/images/rust/logo.png +0 -0
  13. package/readme.md +10 -0
  14. package/src/components/actions/Button/Button.stories.tsx +149 -0
  15. package/src/components/actions/Button/Button.test.tsx +8 -0
  16. package/src/components/actions/Button/Button.test.tsx.snap +89 -0
  17. package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +18 -0
  18. package/src/components/actions/Button/index.tsx +89 -0
  19. package/src/components/actions/Button/style.ts +142 -0
  20. package/src/components/actions/ContextMenu/ContextMenu.stories.tsx +41 -0
  21. package/src/components/actions/ContextMenu/Group.tsx +34 -0
  22. package/src/components/actions/ContextMenu/MenuItem.tsx +69 -0
  23. package/src/components/actions/ContextMenu/index.tsx +216 -0
  24. package/src/components/actions/Dropdown/Dropdown.stories.tsx +88 -0
  25. package/src/components/actions/Dropdown/DropdownContext.tsx +21 -0
  26. package/src/components/actions/Dropdown/DropdownMenu.tsx +70 -0
  27. package/src/components/actions/Dropdown/DropdownMenuGroup.tsx +37 -0
  28. package/src/components/actions/Dropdown/DropdownMenuItem.tsx +128 -0
  29. package/src/components/actions/Dropdown/DropdownTrigger.tsx +87 -0
  30. package/src/components/actions/Dropdown/index.tsx +22 -0
  31. package/src/components/actions/Dropdown/useDropdown.tsx +89 -0
  32. package/src/components/actions/DropdownButton/DropdownButton.stories.tsx +88 -0
  33. package/src/components/actions/DropdownButton/index.tsx +128 -0
  34. package/src/components/actions/IconButton/IconButton.stories.tsx +54 -0
  35. package/src/components/actions/IconButton/IconButton.test.tsx +8 -0
  36. package/src/components/actions/IconButton/IconButton.test.tsx.snap +46 -0
  37. package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +18 -0
  38. package/src/components/actions/IconButton/getIconSize.ts +16 -0
  39. package/src/components/actions/IconButton/index.tsx +28 -0
  40. package/src/components/actions/IconButton/style.ts +51 -0
  41. package/src/components/actions/ToggleButton/ToggleButton.stories.tsx +85 -0
  42. package/src/components/actions/ToggleButton/ToggleButton.tsx +48 -0
  43. package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +107 -0
  44. package/src/components/actions/ToggleButton/index.tsx +2 -0
  45. package/src/components/actions/ToggleButton/style.ts +75 -0
  46. package/src/components/actions/index.ts +16 -0
  47. package/src/components/charts/AreaChart/AreaChart.stories.tsx +103 -0
  48. package/src/components/charts/AreaChart/index.tsx +428 -0
  49. package/src/components/charts/BarChart/BarChart.stories.tsx +55 -0
  50. package/src/components/charts/BarChart/index.tsx +420 -0
  51. package/src/components/charts/BrushHandle.tsx +21 -0
  52. package/src/components/charts/EmptyChart.tsx +45 -0
  53. package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +77 -0
  54. package/src/components/charts/GeoMercator/index.tsx +228 -0
  55. package/src/components/charts/GeoMercator/iso3166-alpha2-to-alpha3.ts +250 -0
  56. package/src/components/charts/GeoMercator/world.d.ts +1 -0
  57. package/src/components/charts/GeoMercator/world.json +99818 -0
  58. package/src/components/charts/Heatmap/Heatmap.stories.tsx +189 -0
  59. package/src/components/charts/Heatmap/index.tsx +461 -0
  60. package/src/components/charts/LineChart/LineChart.stories.tsx +111 -0
  61. package/src/components/charts/LineChart/index.tsx +353 -0
  62. package/src/components/charts/PieChart/PieChart.stories.tsx +151 -0
  63. package/src/components/charts/PieChart/index.tsx +457 -0
  64. package/src/components/charts/PointHighlight.tsx +49 -0
  65. package/src/components/charts/RadarChart/RadarChart.stories.tsx +47 -0
  66. package/src/components/charts/RadarChart/generators.ts +30 -0
  67. package/src/components/charts/RadarChart/index.tsx +224 -0
  68. package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +59 -0
  69. package/src/components/charts/RadialBarChart/index.tsx +231 -0
  70. package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +43 -0
  71. package/src/components/charts/RadialLineChart/index.tsx +231 -0
  72. package/src/components/charts/ZoomControls.tsx +49 -0
  73. package/src/components/charts/index.tsx +26 -0
  74. package/src/components/charts/useGradients.tsx +37 -0
  75. package/src/components/charts/util.ts +78 -0
  76. package/src/components/data/Avatar/Avatar.stories.tsx +93 -0
  77. package/src/components/data/Avatar/context.tsx +20 -0
  78. package/src/components/data/Avatar/index.tsx +136 -0
  79. package/src/components/data/Avatar/style.ts +124 -0
  80. package/src/components/data/Avatar/useImageLoadingStatus.tsx +32 -0
  81. package/src/components/data/Chip/Chip.stories.tsx +67 -0
  82. package/src/components/data/Chip/Chip.test.tsx +8 -0
  83. package/src/components/data/Chip/Chip.test.tsx.snap +50 -0
  84. package/src/components/data/Chip/__snapshots__/Chip.test.tsx.snap +38 -0
  85. package/src/components/data/Chip/index.tsx +67 -0
  86. package/src/components/data/Chip/style.ts +49 -0
  87. package/src/components/data/Console/Console.stories.tsx +51 -0
  88. package/src/components/data/Console/Console.tsx +125 -0
  89. package/src/components/data/Console/ConsoleInput/index.tsx +87 -0
  90. package/src/components/data/Console/ConsoleInput/style.ts +41 -0
  91. package/src/components/data/Console/ConsoleLine/index.tsx +127 -0
  92. package/src/components/data/Console/ConsoleLine/style.ts +76 -0
  93. package/src/components/data/Console/MessageModel.ts +9 -0
  94. package/src/components/data/Console/constants.ts +6 -0
  95. package/src/components/data/Console/index.tsx +4 -0
  96. package/src/components/data/Console/style.ts +31 -0
  97. package/src/components/data/Console/useConsoleLiveMode.ts +42 -0
  98. package/src/components/data/CopyId/CopyId.stories.tsx +36 -0
  99. package/src/components/data/CopyId/index.tsx +107 -0
  100. package/src/components/data/CountryList/index.tsx +146 -0
  101. package/src/components/data/DateFormatter/DateFormatter.stories.tsx +26 -0
  102. package/src/components/data/DateFormatter/index.tsx +15 -0
  103. package/src/components/data/Drawer/Drawer.stories.tsx +155 -0
  104. package/src/components/data/Drawer/DrawerBody.tsx +22 -0
  105. package/src/components/data/Drawer/DrawerContent.tsx +169 -0
  106. package/src/components/data/Drawer/DrawerContext.tsx +21 -0
  107. package/src/components/data/Drawer/DrawerFooter.tsx +19 -0
  108. package/src/components/data/Drawer/DrawerHeading.tsx +50 -0
  109. package/src/components/data/Drawer/DrawerSkeleton.tsx +29 -0
  110. package/src/components/data/Drawer/index.tsx +25 -0
  111. package/src/components/data/Drawer/useDrawer.tsx +66 -0
  112. package/src/components/data/InfiniteScroll/InfiniteScroll.stories.tsx +33 -0
  113. package/src/components/data/InfiniteScroll/index.tsx +54 -0
  114. package/src/components/data/Stats/Sparkline.tsx +48 -0
  115. package/src/components/data/Stats/Stat.tsx +192 -0
  116. package/src/components/data/Stats/Stats.stories.tsx +196 -0
  117. package/src/components/data/Stats/context.tsx +18 -0
  118. package/src/components/data/Stats/index.tsx +62 -0
  119. package/src/components/data/Table/Table.stories.tsx +146 -0
  120. package/src/components/data/Table/index.tsx +492 -0
  121. package/src/components/data/Table/react-table.d.ts +14 -0
  122. package/src/components/data/Table/style.ts +97 -0
  123. package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +164 -0
  124. package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +207 -0
  125. package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +90 -0
  126. package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +70 -0
  127. package/src/components/data/Table/subcomponents/Filter/field.tsx +127 -0
  128. package/src/components/data/Table/subcomponents/Filter/index.tsx +228 -0
  129. package/src/components/data/Table/subcomponents/Filter/style.ts +26 -0
  130. package/src/components/data/Table/subcomponents/Filter/types.ts +10 -0
  131. package/src/components/data/Table/subcomponents/Pagination/PagePicker.tsx +109 -0
  132. package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +37 -0
  133. package/src/components/data/Table/subcomponents/Pagination/style.ts +49 -0
  134. package/src/components/data/index.ts +28 -0
  135. package/src/components/dialogs/Dialog/Dialog.stories.tsx +77 -0
  136. package/src/components/dialogs/Dialog/DialogBody.tsx +64 -0
  137. package/src/components/dialogs/Dialog/DialogContent.tsx +44 -0
  138. package/src/components/dialogs/Dialog/DialogContext.tsx +21 -0
  139. package/src/components/dialogs/Dialog/DialogHeading.tsx +56 -0
  140. package/src/components/dialogs/Dialog/index.tsx +20 -0
  141. package/src/components/dialogs/Dialog/useDialog.tsx +50 -0
  142. package/src/components/feedback/Alert/Alert.stories.tsx +75 -0
  143. package/src/components/feedback/Alert/Alert.test.tsx +8 -0
  144. package/src/components/feedback/Alert/Alert.test.tsx.snap +146 -0
  145. package/src/components/feedback/Alert/__snapshots__/Alert.test.tsx.snap +44 -0
  146. package/src/components/feedback/Alert/index.tsx +120 -0
  147. package/src/components/feedback/Alert/style.ts +97 -0
  148. package/src/components/feedback/Badge/Badge.stories.tsx +23 -0
  149. package/src/components/feedback/Badge/index.tsx +47 -0
  150. package/src/components/feedback/ErrorFallback/ErrorFallback.stories.tsx +10 -0
  151. package/src/components/feedback/ErrorFallback/index.tsx +49 -0
  152. package/src/components/feedback/ErrorPage/ErrorPage.stories.tsx +31 -0
  153. package/src/components/feedback/ErrorPage/index.tsx +193 -0
  154. package/src/components/feedback/FormError/FormError.stories.tsx +25 -0
  155. package/src/components/feedback/FormError/index.tsx +54 -0
  156. package/src/components/feedback/IconTooltip/IconTooltip.stories.tsx +22 -0
  157. package/src/components/feedback/IconTooltip/index.tsx +51 -0
  158. package/src/components/feedback/Loaders/Loaders.stories.tsx +28 -0
  159. package/src/components/feedback/Loaders/Loading.test.tsx +8 -0
  160. package/src/components/feedback/Loaders/Loading.test.tsx.snap +141 -0
  161. package/src/components/feedback/Loaders/Loading.tsx +107 -0
  162. package/src/components/feedback/Loaders/Spinner.test.tsx +8 -0
  163. package/src/components/feedback/Loaders/Spinner.test.tsx.snap +18 -0
  164. package/src/components/feedback/Loaders/Spinner.tsx +74 -0
  165. package/src/components/feedback/Loaders/__snapshots__/Loading.test.tsx.snap +141 -0
  166. package/src/components/feedback/Loaders/__snapshots__/Spinner.test.tsx.snap +10 -0
  167. package/src/components/feedback/Loaders/index.ts +2 -0
  168. package/src/components/feedback/NetworkDetector/NetworkDetector.stories.tsx +21 -0
  169. package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx +8 -0
  170. package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx.snap +3 -0
  171. package/src/components/feedback/NetworkDetector/__snapshots__/NetworkDetector.test.tsx.snap +3 -0
  172. package/src/components/feedback/NetworkDetector/index.tsx +41 -0
  173. package/src/components/feedback/NotificationBanner/NotificationBanner.stories.tsx +13 -0
  174. package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +15 -0
  175. package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx.snap +3 -0
  176. package/src/components/feedback/NotificationBanner/__snapshots__/NotificationBanner.test.tsx.snap +3 -0
  177. package/src/components/feedback/NotificationBanner/index.tsx +78 -0
  178. package/src/components/feedback/Popover/Popover.stories.tsx +33 -0
  179. package/src/components/feedback/Popover/PopoverContent.tsx +46 -0
  180. package/src/components/feedback/Popover/PopoverContext.tsx +21 -0
  181. package/src/components/feedback/Popover/PopoverTrigger.tsx +45 -0
  182. package/src/components/feedback/Popover/index.tsx +22 -0
  183. package/src/components/feedback/Popover/usePopover.tsx +87 -0
  184. package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +38 -0
  185. package/src/components/feedback/ProgressBar/index.tsx +137 -0
  186. package/src/components/feedback/Skeleton/Skeleton.stories.tsx +33 -0
  187. package/src/components/feedback/Skeleton/Skeleton.test.tsx +8 -0
  188. package/src/components/feedback/Skeleton/Skeleton.test.tsx.snap +35 -0
  189. package/src/components/feedback/Skeleton/__snapshots__/Skeleton.test.tsx.snap +9 -0
  190. package/src/components/feedback/Skeleton/index.tsx +62 -0
  191. package/src/components/feedback/Tooltip/Tooltip.stories.tsx +69 -0
  192. package/src/components/feedback/Tooltip/TooltipContent.tsx +51 -0
  193. package/src/components/feedback/Tooltip/TooltipContext.tsx +13 -0
  194. package/src/components/feedback/Tooltip/TooltipTrigger.tsx +39 -0
  195. package/src/components/feedback/Tooltip/index.tsx +26 -0
  196. package/src/components/feedback/Tooltip/useTooltip.tsx +82 -0
  197. package/src/components/feedback/index.ts +37 -0
  198. package/src/components/feedback/snacks/CookieConsent/index.tsx +125 -0
  199. package/src/components/feedback/snacks/CookieConsent/style.ts +99 -0
  200. package/src/components/feedback/snacks/Default/default.stories.tsx +73 -0
  201. package/src/components/feedback/snacks/Default/index.tsx +78 -0
  202. package/src/components/feedback/snacks/Default/style.ts +58 -0
  203. package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +46 -0
  204. package/src/components/feedback/snacks/Drawer/index.tsx +85 -0
  205. package/src/components/feedback/snacks/NetworkDetector/index.tsx +73 -0
  206. package/src/components/feedback/snacks/index.d.ts +15 -0
  207. package/src/components/feedback/snacks/index.ts +8 -0
  208. package/src/components/index.ts +9 -0
  209. package/src/components/inputs/CheckBox/CheckBox.stories.tsx +64 -0
  210. package/src/components/inputs/CheckBox/Controlled.tsx +123 -0
  211. package/src/components/inputs/CheckBox/Generic.tsx +42 -0
  212. package/src/components/inputs/CheckBox/index.tsx +4 -0
  213. package/src/components/inputs/CheckBox/style.ts +56 -0
  214. package/src/components/inputs/CodeField/CodeField.stories.tsx +86 -0
  215. package/src/components/inputs/CodeField/index.tsx +174 -0
  216. package/src/components/inputs/CodeField/style.ts +50 -0
  217. package/src/components/inputs/Date/DatePicker/Controlled.tsx +103 -0
  218. package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +267 -0
  219. package/src/components/inputs/Date/DatePicker/Generic.tsx +283 -0
  220. package/src/components/inputs/Date/DatePicker/formats.tsx +32 -0
  221. package/src/components/inputs/Date/DatePicker/style.ts +41 -0
  222. package/src/components/inputs/Date/DateRangePicker/Context.tsx +123 -0
  223. package/src/components/inputs/Date/DateRangePicker/Controlled.tsx +74 -0
  224. package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +37 -0
  225. package/src/components/inputs/Date/DateRangePicker/DateSelector/Absolute.tsx +98 -0
  226. package/src/components/inputs/Date/DateRangePicker/DateSelector/Relative.tsx +54 -0
  227. package/src/components/inputs/Date/DateRangePicker/DateSelector/index.tsx +49 -0
  228. package/src/components/inputs/Date/DateRangePicker/Generic.tsx +167 -0
  229. package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +254 -0
  230. package/src/components/inputs/Date/DateRangePicker/QuickSelect/style.ts +40 -0
  231. package/src/components/inputs/Date/DateRangePicker/style.ts +65 -0
  232. package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +150 -0
  233. package/src/components/inputs/Date/subcomponents/Calendar/style.ts +61 -0
  234. package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +170 -0
  235. package/src/components/inputs/Date/subcomponents/RelativePicker/style.ts +50 -0
  236. package/src/components/inputs/Date/subcomponents/TimePicker/TimePicker.stories.tsx +25 -0
  237. package/src/components/inputs/Date/subcomponents/TimePicker/index.tsx +40 -0
  238. package/src/components/inputs/Date/subcomponents/TimePicker/style.ts +34 -0
  239. package/src/components/inputs/Date/types.ts +14 -0
  240. package/src/components/inputs/DurationField/Controlled.tsx +69 -0
  241. package/src/components/inputs/DurationField/Duration.stories.tsx +57 -0
  242. package/src/components/inputs/DurationField/Generic.tsx +197 -0
  243. package/src/components/inputs/DurationField/__tests__/Generic.test.tsx +12 -0
  244. package/src/components/inputs/DurationField/index.tsx +5 -0
  245. package/src/components/inputs/DurationField/style.ts +42 -0
  246. package/src/components/inputs/EditableField/EditableField.stories.tsx +65 -0
  247. package/src/components/inputs/EditableField/index.tsx +135 -0
  248. package/src/components/inputs/EditableField/style.ts +11 -0
  249. package/src/components/inputs/FileField/Controlled.tsx +104 -0
  250. package/src/components/inputs/FileField/FileField.stories.tsx +210 -0
  251. package/src/components/inputs/FileField/Generic.tsx +133 -0
  252. package/src/components/inputs/FileField/index.tsx +5 -0
  253. package/src/components/inputs/FileField/style.ts +34 -0
  254. package/src/components/inputs/InputProps.ts +59 -0
  255. package/src/components/inputs/RadioGroup/Controlled.tsx +45 -0
  256. package/src/components/inputs/RadioGroup/Generic.tsx +34 -0
  257. package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +118 -0
  258. package/src/components/inputs/RadioGroup/RadioItem.tsx +130 -0
  259. package/src/components/inputs/RadioGroup/context.tsx +20 -0
  260. package/src/components/inputs/RadioGroup/index.ts +5 -0
  261. package/src/components/inputs/RadioGroup/style.ts +3 -0
  262. package/src/components/inputs/Switch/Controlled.tsx +57 -0
  263. package/src/components/inputs/Switch/Generic.tsx +40 -0
  264. package/src/components/inputs/Switch/Switch.stories.tsx +89 -0
  265. package/src/components/inputs/Switch/index.ts +5 -0
  266. package/src/components/inputs/Switch/style.ts +62 -0
  267. package/src/components/inputs/TagField/Controlled.tsx +103 -0
  268. package/src/components/inputs/TagField/Generic.tsx +138 -0
  269. package/src/components/inputs/TagField/TagField.stories.tsx +68 -0
  270. package/src/components/inputs/TagField/index.ts +5 -0
  271. package/src/components/inputs/TagField/style.ts +25 -0
  272. package/src/components/inputs/TagField/util.ts +34 -0
  273. package/src/components/inputs/TextAreaField/Controlled.tsx +101 -0
  274. package/src/components/inputs/TextAreaField/Generic.tsx +58 -0
  275. package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +99 -0
  276. package/src/components/inputs/TextAreaField/index.ts +5 -0
  277. package/src/components/inputs/TextAreaField/style.ts +28 -0
  278. package/src/components/inputs/TextField/Controlled.tsx +120 -0
  279. package/src/components/inputs/TextField/Generic.tsx +138 -0
  280. package/src/components/inputs/TextField/TextField.stories.tsx +217 -0
  281. package/src/components/inputs/TextField/index.ts +5 -0
  282. package/src/components/inputs/TextField/style.ts +103 -0
  283. package/src/components/inputs/TextField/util.ts +24 -0
  284. package/src/components/inputs/ValueConfirmationField/ValueConfirmationField.stories.tsx +33 -0
  285. package/src/components/inputs/ValueConfirmationField/index.tsx +54 -0
  286. package/src/components/inputs/index.ts +72 -0
  287. package/src/components/inputs/layout/Description.tsx +33 -0
  288. package/src/components/inputs/layout/ErrorMessage/ErrorMessage.stories.tsx +28 -0
  289. package/src/components/inputs/layout/ErrorMessage/index.tsx +63 -0
  290. package/src/components/inputs/layout/InputWrapper.ts +6 -0
  291. package/src/components/inputs/layout/Label/index.tsx +71 -0
  292. package/src/components/inputs/layout/Label/style.ts +50 -0
  293. package/src/components/inputs/layout/index.ts +8 -0
  294. package/src/components/inputs/layout/setAriaDescribedBy.ts +3 -0
  295. package/src/components/inputs/selects/SelectField/Controlled.tsx +127 -0
  296. package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +48 -0
  297. package/src/components/inputs/selects/SelectField/Generic/index.tsx +299 -0
  298. package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +252 -0
  299. package/src/components/inputs/selects/SelectField/index.ts +5 -0
  300. package/src/components/inputs/selects/SelectField/style.ts +29 -0
  301. package/src/components/inputs/selects/SelectQueryField/Controlled.tsx +110 -0
  302. package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +401 -0
  303. package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +280 -0
  304. package/src/components/inputs/selects/SelectQueryField/index.tsx +5 -0
  305. package/src/components/inputs/selects/SelectQueryField/style.ts +13 -0
  306. package/src/components/inputs/selects/SubComponents/Option.tsx +114 -0
  307. package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +18 -0
  308. package/src/components/inputs/selects/SubComponents/index.ts +10 -0
  309. package/src/components/inputs/selects/SubComponents/style.ts +51 -0
  310. package/src/components/inputs/selects/data.ts +123 -0
  311. package/src/components/inputs/selects/index.tsx +49 -0
  312. package/src/components/inputs/selects/sharedStyle.ts +76 -0
  313. package/src/components/layout/Container/index.ts +21 -0
  314. package/src/components/layout/index.ts +1 -0
  315. package/src/components/navigation/HorizontalNav/HorizontalNav.stories.tsx +29 -0
  316. package/src/components/navigation/HorizontalNav/index.tsx +13 -0
  317. package/src/components/navigation/HorizontalNav/style.ts +93 -0
  318. package/src/components/navigation/IconNav/IconNav.stories.tsx +46 -0
  319. package/src/components/navigation/IconNav/index.tsx +50 -0
  320. package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +90 -0
  321. package/src/components/navigation/Steppers/SlimStepper/index.tsx +104 -0
  322. package/src/components/navigation/Steppers/SlimStepper/style.ts +85 -0
  323. package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +88 -0
  324. package/src/components/navigation/Steppers/Stepper/index.tsx +114 -0
  325. package/src/components/navigation/Steppers/Stepper/style.ts +106 -0
  326. package/src/components/navigation/Steppers/context.tsx +2 -0
  327. package/src/components/navigation/Steppers/provider.tsx +18 -0
  328. package/src/components/navigation/Steppers/reducer.ts +51 -0
  329. package/src/components/navigation/Steppers/stepStates.ts +5 -0
  330. package/src/components/navigation/Steppers/useStepper.ts +34 -0
  331. package/src/components/navigation/Tabs/Content.tsx +39 -0
  332. package/src/components/navigation/Tabs/Context.tsx +21 -0
  333. package/src/components/navigation/Tabs/List.tsx +17 -0
  334. package/src/components/navigation/Tabs/Tabs.stories.tsx +119 -0
  335. package/src/components/navigation/Tabs/Trigger.tsx +66 -0
  336. package/src/components/navigation/Tabs/index.tsx +35 -0
  337. package/src/components/navigation/Tabs/useTabs.tsx +28 -0
  338. package/src/components/navigation/index.ts +17 -0
  339. package/src/components/other/ActionMenu/ActionMenu.stories.tsx +81 -0
  340. package/src/components/other/ActionMenu/index.tsx +62 -0
  341. package/src/components/other/ActionMenu/style.ts +47 -0
  342. package/src/components/other/ClipBoard/ClipBoard.stories.tsx +14 -0
  343. package/src/components/other/ClipBoard/ClipBoard.test.tsx +8 -0
  344. package/src/components/other/ClipBoard/ClipBoard.test.tsx.snap +70 -0
  345. package/src/components/other/ClipBoard/__snapshots__/ClipBoard.test.tsx.snap +36 -0
  346. package/src/components/other/ClipBoard/index.tsx +70 -0
  347. package/src/components/other/CollapseList/CollapseList.stories.tsx +21 -0
  348. package/src/components/other/CollapseList/index.tsx +110 -0
  349. package/src/components/other/Collapsible/Collapsible.stories.tsx +19 -0
  350. package/src/components/other/Collapsible/CollapsibleContent.tsx +29 -0
  351. package/src/components/other/Collapsible/CollapsibleContext.tsx +17 -0
  352. package/src/components/other/Collapsible/CollapsibleTrigger.tsx +83 -0
  353. package/src/components/other/Collapsible/index.tsx +21 -0
  354. package/src/components/other/Company/index.tsx +44 -0
  355. package/src/components/other/Company/style.ts +58 -0
  356. package/src/components/other/Empty/Empty.stories.tsx +28 -0
  357. package/src/components/other/Empty/Empty.test.tsx +10 -0
  358. package/src/components/other/Empty/Empty.test.tsx.snap +85 -0
  359. package/src/components/other/Empty/__snapshots__/Empty.test.tsx.snap +21 -0
  360. package/src/components/other/Empty/index.tsx +85 -0
  361. package/src/components/other/PermissionsGuard/PermissionsGuard.stories.tsx +55 -0
  362. package/src/components/other/PermissionsGuard/hasPermissionsHelper.ts +18 -0
  363. package/src/components/other/PermissionsGuard/index.tsx +27 -0
  364. package/src/components/other/Plan/Plan.stories.tsx +21 -0
  365. package/src/components/other/Plan/index.tsx +92 -0
  366. package/src/components/other/Plan/style.ts +61 -0
  367. package/src/components/other/Usage/Usage.stories.tsx +21 -0
  368. package/src/components/other/Usage/Usage.tsx +35 -0
  369. package/src/components/other/Usage/UsageCard.stories.tsx +31 -0
  370. package/src/components/other/Usage/UsageCard.tsx +88 -0
  371. package/src/components/other/index.ts +27 -0
  372. package/src/components/visual/Card/Card.stories.tsx +22 -0
  373. package/src/components/visual/Card/CardBody.tsx +11 -0
  374. package/src/components/visual/Card/CardTitle.tsx +29 -0
  375. package/src/components/visual/Card/index.tsx +58 -0
  376. package/src/components/visual/Divider/Divider.stories.tsx +19 -0
  377. package/src/components/visual/Divider/Divider.test.tsx +8 -0
  378. package/src/components/visual/Divider/Divider.test.tsx.snap +35 -0
  379. package/src/components/visual/Divider/__snapshots__/Divider.test.tsx.snap +13 -0
  380. package/src/components/visual/Divider/index.tsx +88 -0
  381. package/src/components/visual/Flag/index.tsx +61 -0
  382. package/src/components/visual/index.ts +8 -0
  383. package/src/errors/base.ts +14 -0
  384. package/src/errors/errors.ts +126 -0
  385. package/src/errors/index.ts +14 -0
  386. package/src/helpers/camelCaseToSpaces.ts +5 -0
  387. package/src/helpers/formatNumber.ts +6 -0
  388. package/src/helpers/getInitials.ts +16 -0
  389. package/src/helpers/getSnackbarProvider.tsx +57 -0
  390. package/src/helpers/getTransition.ts +9 -0
  391. package/src/helpers/index.ts +6 -0
  392. package/src/helpers/makeData.ts +34 -0
  393. package/src/helpers/regexprs.ts +9 -0
  394. package/src/hooks/index.ts +9 -0
  395. package/src/hooks/useCallbackRef.tsx +17 -0
  396. package/src/hooks/useDebounce.tsx +22 -0
  397. package/src/hooks/useFocus.tsx +12 -0
  398. package/src/hooks/useLocalStorage.tsx +35 -0
  399. package/src/hooks/useLockScroll.ts +26 -0
  400. package/src/hooks/useOnScreen.ts +24 -0
  401. package/src/hooks/useOutsideAlerter.tsx +15 -0
  402. package/src/hooks/useTableActions.ts +61 -0
  403. package/src/hooks/useTheme.tsx +7 -0
  404. package/src/images/company-icon-primary.svg +3 -0
  405. package/src/images/company-icon-secondary.svg +3 -0
  406. package/src/images/index.ts +4 -0
  407. package/src/index.ts +9 -0
  408. package/src/stories/Colors.mdx +35 -0
  409. package/src/stories/Introduction.mdx +17 -0
  410. package/src/stories/Spacing.mdx +25 -0
  411. package/src/styled/GlobalStyle.ts +209 -0
  412. package/src/styled/Snackbar.tsx +41 -0
  413. package/src/styled/animations.ts +36 -0
  414. package/src/styled/breakpoint.ts +7 -0
  415. package/src/styled/device.ts +10 -0
  416. package/src/styled/index.ts +10 -0
  417. package/src/styled/spacing.ts +38 -0
  418. package/src/styled/theme.tsx +110 -0
  419. package/src/styled/types.ts +5 -0
  420. package/src/styled/zIndex.ts +31 -0
  421. package/src/test/__mocks__/fileMock.ts +2 -0
  422. package/src/test/setupTests.ts +3 -0
  423. package/src/test/snapshotResolver.js +21 -0
  424. package/src/test/testUtils.tsx +34 -0
  425. package/src/types/index.ts +1 -0
  426. package/src/types/json.ts +5 -0
  427. package/src/views/LoadingPage.tsx +36 -0
  428. package/src/views/index.ts +1 -0
  429. package/tsconfig.json +14 -0
  430. package/vite.config.mts +17 -0
@@ -0,0 +1,189 @@
1
+ import React from 'react';
2
+ import { HeatMap, HeatmapProps } from '.';
3
+ import { Meta, StoryFn } from '@storybook/react';
4
+ import { styled } from '../../../styled';
5
+
6
+ export default {
7
+ title: 'Charts/Heatmap',
8
+ component: HeatMap,
9
+ args: {
10
+ showMonthLabels: true,
11
+ showDayLabels: true,
12
+ },
13
+ argTypes: {
14
+ showMonthLabels: { control: 'boolean' },
15
+ showDayLabels: { control: 'boolean' },
16
+ },
17
+ } as Meta<HeatmapProps<ContributionData>>;
18
+
19
+ const Wrapper = styled.div`
20
+ height: 200px;
21
+ width: 100%;
22
+ `;
23
+
24
+ interface ContributionData {
25
+ date: Date;
26
+ count: number;
27
+ }
28
+
29
+ // Generate realistic contribution data (GitHub-style)
30
+ const generateContributionData = (): ContributionData[] => {
31
+ const data: ContributionData[] = [];
32
+ const endDate = new Date();
33
+ const startDate = new Date();
34
+ startDate.setDate(startDate.getDate() - 364); // 1 year ago
35
+
36
+ // Generate contributions with realistic patterns
37
+ for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
38
+ const dayOfWeek = d.getDay();
39
+ const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
40
+
41
+ // Simulate realistic patterns:
42
+ // - Less activity on weekends
43
+ // - Random spikes in activity
44
+ // - Some periods of no activity
45
+ let count = 0;
46
+
47
+ if (Math.random() > 0.3) {
48
+ if (isWeekend) {
49
+ count = Math.floor(Math.random() * 5);
50
+ } else {
51
+ count = Math.floor(Math.random() * 15);
52
+ }
53
+ if (Math.random() > 0.9) {
54
+ count += Math.floor(Math.random() * 20);
55
+ }
56
+ }
57
+
58
+ data.push({
59
+ date: new Date(d),
60
+ count,
61
+ });
62
+ }
63
+
64
+ return data;
65
+ };
66
+
67
+ export const Default: StoryFn<HeatmapProps<ContributionData>> = (args) => {
68
+ const data = React.useMemo(() => generateContributionData(), []);
69
+
70
+ return (
71
+ <Wrapper>
72
+ <HeatMap<ContributionData>
73
+ name="contributions"
74
+ data={data}
75
+ dateAccessor={(d) => d.date}
76
+ valueAccessor={(d) => d.count}
77
+ showMonthLabels={args.showMonthLabels}
78
+ showDayLabels={args.showDayLabels}
79
+ />
80
+ </Wrapper>
81
+ );
82
+ };
83
+
84
+ export const LastThreeMonths: StoryFn<HeatmapProps<ContributionData>> = (args) => {
85
+ const data = React.useMemo(() => {
86
+ const result: ContributionData[] = [];
87
+ const endDate = new Date();
88
+ const startDate = new Date();
89
+ startDate.setMonth(startDate.getMonth() - 3);
90
+
91
+ for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
92
+ result.push({
93
+ date: new Date(d),
94
+ count: Math.floor(Math.random() * 10),
95
+ });
96
+ }
97
+
98
+ return result;
99
+ }, []);
100
+
101
+ const startDate = new Date();
102
+ startDate.setMonth(startDate.getMonth() - 3);
103
+
104
+ return (
105
+ <Wrapper>
106
+ <HeatMap<ContributionData>
107
+ name="contributions-3months"
108
+ data={data}
109
+ dateAccessor={(d) => d.date}
110
+ valueAccessor={(d) => d.count}
111
+ startDate={startDate}
112
+ endDate={new Date()}
113
+ showMonthLabels={args.showMonthLabels}
114
+ showDayLabels={args.showDayLabels}
115
+ />
116
+ </Wrapper>
117
+ );
118
+ };
119
+
120
+ // Data interface for categorical mode (24h x 7-day)
121
+ interface ActivityData {
122
+ hour: number; // 0-23
123
+ day: number; // 0-6 (Mon-Sun)
124
+ value: number;
125
+ }
126
+
127
+ // Generate realistic 24h x 7-day activity data
128
+ const generate24x7Data = (): ActivityData[] => {
129
+ const data: ActivityData[] = [];
130
+
131
+ for (let day = 0; day < 7; day++) {
132
+ for (let hour = 0; hour < 24; hour++) {
133
+ // Base activity level
134
+ let value = 5;
135
+
136
+ // Peak hours (lunch and evening)
137
+ if (hour >= 11 && hour <= 13) value = 40; // Lunch peak
138
+ if (hour >= 18 && hour <= 21) value = 60; // Evening peak
139
+
140
+ // Night hours (low activity)
141
+ if (hour >= 0 && hour <= 6) value = 2;
142
+
143
+ // Weekend boost
144
+ if (day === 5 || day === 6) value *= 1.5;
145
+
146
+ // Friday evening extra boost
147
+ if (day === 4 && hour >= 18) value *= 1.3;
148
+
149
+ // Add some randomness
150
+ value = Math.floor(value + Math.random() * 20 - 10);
151
+ value = Math.max(0, value); // Ensure non-negative
152
+
153
+ data.push({ hour, day, value });
154
+ }
155
+ }
156
+
157
+ return data;
158
+ };
159
+
160
+ export const WeeklyActivity: StoryFn<HeatmapProps<ActivityData>> = (args) => {
161
+ const data = React.useMemo(() => generate24x7Data(), []);
162
+
163
+ const hourLabels = Array.from({ length: 24 }, (_, i) =>
164
+ i === 0 ? '12am' : i < 12 ? `${i}am` : i === 12 ? '12pm' : `${i - 12}pm`,
165
+ );
166
+
167
+ const dayLabels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
168
+
169
+ return (
170
+ <Wrapper style={{ height: '250px' }}>
171
+ <HeatMap<ActivityData>
172
+ name="weekly-activity"
173
+ data={data}
174
+ xAccessor={(d) => d.hour}
175
+ yAccessor={(d) => d.day}
176
+ valueAccessor={(d) => d.value}
177
+ xCategories={hourLabels}
178
+ yCategories={dayLabels}
179
+ showDayLabels={args.showDayLabels}
180
+ tooltip={{
181
+ accessor: (d) => {
182
+ const activityData = d as ActivityData;
183
+ return `${dayLabels[activityData.day]}, ${hourLabels[activityData.hour]}\n${activityData.value} activities`;
184
+ },
185
+ }}
186
+ />
187
+ </Wrapper>
188
+ );
189
+ };
@@ -0,0 +1,461 @@
1
+ import { ParentSize } from '@visx/responsive';
2
+ import { Group } from '@visx/group';
3
+ import { useTooltip, TooltipWithBounds } from '@visx/tooltip';
4
+ import { localPoint } from '@visx/event';
5
+
6
+ import { InnerChartProps, getDefaultTooltipStyles, ChartProps, TooltipConfig } from '../util';
7
+ import { useTheme } from '../../../hooks';
8
+ import { useMemo, useCallback } from 'react';
9
+ import { EmptyChart } from '../EmptyChart';
10
+
11
+ const DAY_LABELS = ['', 'Mon', '', 'Wed', '', 'Fri', ''] as const;
12
+ const MONTH_LABELS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] as const;
13
+
14
+ interface NormalizedCell<T = any> {
15
+ x: number;
16
+ y: number;
17
+ value: number;
18
+ displayValue: any;
19
+ xLabel?: string;
20
+ yLabel?: string;
21
+ originalData?: T;
22
+ }
23
+
24
+ interface ProcessedData<T = any> {
25
+ cells: NormalizedCell<T>[];
26
+ xLabels: { label: string; index: number }[];
27
+ yLabels: { label: string; index: number }[];
28
+ maxValue: number;
29
+ gridWidth: number;
30
+ gridHeight: number;
31
+ }
32
+
33
+ // Calendar mode props
34
+ type CalendarModeProps<T> = {
35
+ data: T[];
36
+ dateAccessor: (d: T) => Date;
37
+ valueAccessor: (d: T) => number;
38
+ startDate?: Date;
39
+ endDate?: Date;
40
+ showMonthLabels?: boolean;
41
+ xAccessor?: never;
42
+ yAccessor?: never;
43
+ xCategories?: never;
44
+ yCategories?: never;
45
+ };
46
+
47
+ type CategoricalModeProps<T> = {
48
+ data: T[];
49
+ xAccessor: (d: T) => number | string;
50
+ yAccessor: (d: T) => number | string;
51
+ valueAccessor?: (d: T) => number;
52
+ xCategories?: string[];
53
+ yCategories?: string[];
54
+ dateAccessor?: never;
55
+ startDate?: never;
56
+ endDate?: never;
57
+ showMonthLabels?: never;
58
+ };
59
+
60
+ type SharedHeatmapProps<T> = {
61
+ colors?: [string, string, string, string, string];
62
+ showDayLabels?: boolean;
63
+ tooltip?: TooltipConfig<T>;
64
+ };
65
+
66
+ export type HeatmapProps<T> = ChartProps & SharedHeatmapProps<T> & (CalendarModeProps<T> | CategoricalModeProps<T>);
67
+
68
+ const defaultMargin = { top: 30, right: 10, bottom: 10, left: 40 };
69
+
70
+ const getDefaultStartDate = () => {
71
+ const date = new Date();
72
+ date.setDate(date.getDate() - 364); // 52 weeks = 364 days
73
+ // Round to previous Sunday
74
+ date.setDate(date.getDate() - date.getDay());
75
+ return date;
76
+ };
77
+
78
+ const getDefaultEndDate = () => new Date();
79
+
80
+ const processCalendarData = <T,>(
81
+ data: T[],
82
+ dateAccessor: (d: T) => Date,
83
+ valueAccessor: (d: T) => number,
84
+ startDate: Date,
85
+ endDate: Date,
86
+ ): ProcessedData<T> => {
87
+ const dateValueMap = new Map<string, number>();
88
+ const dateDataMap = new Map<string, T>();
89
+ data.forEach((d) => {
90
+ const date = dateAccessor(d);
91
+ const dateStr = date.toISOString().split('T')[0];
92
+ const value = valueAccessor(d);
93
+ dateValueMap.set(dateStr, (dateValueMap.get(dateStr) || 0) + value);
94
+ // Store the first data item for this date for tooltip purposes
95
+ if (!dateDataMap.has(dateStr)) {
96
+ dateDataMap.set(dateStr, d);
97
+ }
98
+ });
99
+
100
+ const cellsData: NormalizedCell<T>[] = [];
101
+ const monthLabelsData: { label: string; index: number }[] = [];
102
+ const currentDate = new Date(startDate);
103
+ let weekIndex = 0;
104
+ let lastMonth = -1;
105
+ let lastDayIndex = 0;
106
+
107
+ while (currentDate <= endDate) {
108
+ const dayIndex = currentDate.getDay(); // 0 (Sunday) to 6 (Saturday)
109
+ const dateStr = currentDate.toISOString().split('T')[0];
110
+ const value = dateValueMap.get(dateStr) || 0;
111
+
112
+ cellsData.push({
113
+ x: weekIndex,
114
+ y: dayIndex,
115
+ value,
116
+ displayValue: new Date(currentDate),
117
+ originalData: dateDataMap.get(dateStr),
118
+ });
119
+
120
+ // Track month changes for labels
121
+ if (dayIndex === 0 && currentDate.getMonth() !== lastMonth) {
122
+ lastMonth = currentDate.getMonth();
123
+ if (weekIndex >= 2 || currentDate.getDate() <= 7) {
124
+ monthLabelsData.push({
125
+ label: MONTH_LABELS[lastMonth],
126
+ index: weekIndex,
127
+ });
128
+ }
129
+ }
130
+
131
+ lastDayIndex = dayIndex;
132
+ currentDate.setDate(currentDate.getDate() + 1);
133
+
134
+ // If we completed a week (Saturday), move to next week column
135
+ if (dayIndex === 6) {
136
+ weekIndex++;
137
+ }
138
+ }
139
+
140
+ const maxValue = Math.max(...cellsData.map((c) => c.value), 1);
141
+
142
+ const dayLabels = DAY_LABELS.map((label, index) => ({ label, index })).filter((l) => l.label);
143
+
144
+ // Only add an extra column if the last day was not Saturday (incomplete week)
145
+ const gridWidth = lastDayIndex === 6 ? weekIndex : weekIndex + 1;
146
+
147
+ return {
148
+ cells: cellsData,
149
+ xLabels: monthLabelsData,
150
+ yLabels: dayLabels,
151
+ maxValue,
152
+ gridWidth,
153
+ gridHeight: 7,
154
+ };
155
+ };
156
+
157
+ const processCategoricalData = <T,>(
158
+ data: T[],
159
+ xAccessor: (d: T) => number | string,
160
+ yAccessor: (d: T) => number | string,
161
+ valueAccessor: (d: T) => number = (d: any) => d.value || 0,
162
+ xCategories?: string[],
163
+ yCategories?: string[],
164
+ ): ProcessedData<T> => {
165
+ const rawXValues = Array.from(new Set(data.map(xAccessor)));
166
+ const rawYValues = Array.from(new Set(data.map(yAccessor)));
167
+
168
+ const useCustomXCategories = xCategories && xCategories.length > 0;
169
+ const useCustomYCategories = yCategories && yCategories.length > 0;
170
+
171
+ // Build value map and data map using RAW data values as keys
172
+ const valueMap = new Map<string, number>();
173
+ const dataMap = new Map<string, T>();
174
+ data.forEach((d) => {
175
+ const x = xAccessor(d);
176
+ const y = yAccessor(d);
177
+ const key = `${x}-${y}`;
178
+ const value = valueAccessor(d);
179
+ valueMap.set(key, (valueMap.get(key) || 0) + value);
180
+ if (!dataMap.has(key)) {
181
+ dataMap.set(key, d);
182
+ }
183
+ });
184
+
185
+ const xValueToLabel = useCustomXCategories
186
+ ? new Map(rawXValues.map((val, _idx) => [val, xCategories![Number(val)] || String(val)]))
187
+ : new Map(rawXValues.map((val) => [val, String(val)]));
188
+
189
+ const yValueToLabel = useCustomYCategories
190
+ ? new Map(rawYValues.map((val, _idx) => [val, yCategories![Number(val)] || String(val)]))
191
+ : new Map(rawYValues.map((val) => [val, String(val)]));
192
+
193
+ const cells: NormalizedCell<T>[] = [];
194
+ const sortedRawYValues = rawYValues.sort((a, b) => {
195
+ const aNum = Number(a);
196
+ const bNum = Number(b);
197
+ if (!isNaN(aNum) && !isNaN(bNum)) return aNum - bNum;
198
+ return String(a).localeCompare(String(b));
199
+ });
200
+ const sortedRawXValues = rawXValues.sort((a, b) => {
201
+ const aNum = Number(a);
202
+ const bNum = Number(b);
203
+ if (!isNaN(aNum) && !isNaN(bNum)) return aNum - bNum;
204
+ return String(a).localeCompare(String(b));
205
+ });
206
+
207
+ sortedRawYValues.forEach((yVal, yIdx) => {
208
+ sortedRawXValues.forEach((xVal, xIdx) => {
209
+ const key = `${xVal}-${yVal}`;
210
+ cells.push({
211
+ x: xIdx,
212
+ y: yIdx,
213
+ value: valueMap.get(key) || 0,
214
+ displayValue: { x: xVal, y: yVal },
215
+ xLabel: xValueToLabel.get(xVal) || String(xVal),
216
+ yLabel: yValueToLabel.get(yVal) || String(yVal),
217
+ originalData: dataMap.get(key),
218
+ });
219
+ });
220
+ });
221
+
222
+ const maxValue = Math.max(...cells.map((c) => c.value), 1);
223
+
224
+ const xLabels = sortedRawXValues.map((val, index) => ({
225
+ label: xValueToLabel.get(val) || String(val),
226
+ index,
227
+ }));
228
+
229
+ const yLabels = sortedRawYValues.map((val, index) => ({
230
+ label: yValueToLabel.get(val) || String(val),
231
+ index,
232
+ }));
233
+
234
+ return {
235
+ cells,
236
+ xLabels,
237
+ yLabels,
238
+ maxValue,
239
+ gridWidth: sortedRawXValues.length,
240
+ gridHeight: sortedRawYValues.length,
241
+ };
242
+ };
243
+
244
+ export const HeatMap = <T,>(props: HeatmapProps<T>) => {
245
+ const { data, name, colors, showDayLabels = true, margin = defaultMargin, animate = true, tooltip } = props;
246
+ const isCategorical = 'xAccessor' in props && props.xAccessor !== undefined;
247
+ const hasData = data && data.length > 0;
248
+
249
+ return (
250
+ <ParentSize>
251
+ {hasData
252
+ ? (parent) => (
253
+ <Chart<T>
254
+ {...props}
255
+ name={name}
256
+ data={data}
257
+ width={parent.width}
258
+ height={parent.height}
259
+ margin={margin}
260
+ tooltip={tooltip}
261
+ colors={colors}
262
+ showDayLabels={showDayLabels}
263
+ animate={animate}
264
+ isCategorical={isCategorical}
265
+ />
266
+ )
267
+ : () => <EmptyChart />}
268
+ </ParentSize>
269
+ );
270
+ };
271
+
272
+ type InnerHeatmapProps<T> = InnerChartProps & HeatmapProps<T> & { isCategorical: boolean };
273
+
274
+ const Chart = <T,>(props: InnerHeatmapProps<T>) => {
275
+ const {
276
+ data,
277
+ width,
278
+ height,
279
+ margin = defaultMargin,
280
+ tooltip,
281
+ name,
282
+ colors,
283
+ showDayLabels = true,
284
+ animate = true,
285
+ isCategorical,
286
+ } = props;
287
+
288
+ const tooltipAccessor = tooltip?.accessor;
289
+ const theme = useTheme();
290
+
291
+ const _animate = animate;
292
+ const { hideTooltip, showTooltip, tooltipData, tooltipLeft = 0, tooltipTop = 0 } = useTooltip<NormalizedCell<T>>();
293
+
294
+ const defaultColors: [string, string, string, string, string] = [
295
+ `${theme.colors.backgroundAccent}33`,
296
+ `${theme.colors.primary}33`,
297
+ `${theme.colors.primary}66`,
298
+ `${theme.colors.primary}99`,
299
+ theme.colors.primary,
300
+ ];
301
+
302
+ const colorScale = colors || defaultColors;
303
+
304
+ const processedData = useMemo(() => {
305
+ if (isCategorical) {
306
+ const catProps = props as InnerHeatmapProps<T> & CategoricalModeProps<T>;
307
+ return processCategoricalData(
308
+ data,
309
+ catProps.xAccessor,
310
+ catProps.yAccessor,
311
+ catProps.valueAccessor,
312
+ catProps.xCategories,
313
+ catProps.yCategories,
314
+ );
315
+ } else {
316
+ const calProps = props as InnerHeatmapProps<T> & CalendarModeProps<T>;
317
+ return processCalendarData(
318
+ data,
319
+ calProps.dateAccessor,
320
+ calProps.valueAccessor,
321
+ calProps.startDate || getDefaultStartDate(),
322
+ calProps.endDate || getDefaultEndDate(),
323
+ );
324
+ }
325
+ }, [data, isCategorical, props]);
326
+
327
+ const dayLabelWidth = showDayLabels ? (isCategorical ? 40 : 30) : 0;
328
+ const showXLabels = isCategorical || (props as any).showMonthLabels !== false;
329
+ const xLabelHeight = showXLabels ? 20 : 0;
330
+
331
+ // Calculate dynamic cell size based on available space
332
+ const availableWidth = width - margin.left - margin.right - dayLabelWidth;
333
+ const availableHeight = height - margin.top - margin.bottom - xLabelHeight;
334
+
335
+ const cellGap = 3;
336
+ const maxCellWidth = Math.max(
337
+ (availableWidth - cellGap * (processedData.gridWidth - 1)) / processedData.gridWidth,
338
+ 0,
339
+ );
340
+ const maxCellHeight = Math.max(
341
+ (availableHeight - cellGap * (processedData.gridHeight - 1)) / processedData.gridHeight,
342
+ 0,
343
+ );
344
+ const cellSize = Math.max(Math.min(maxCellWidth, maxCellHeight, 20), 1);
345
+
346
+ const mapValueToColor = (value: number): string => {
347
+ if (value === 0) return colorScale[0];
348
+ const level = Math.min(4, Math.ceil((value / processedData.maxValue) * 4));
349
+ return colorScale[level];
350
+ };
351
+
352
+ const formatDate = (date: Date): string => {
353
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
354
+ const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
355
+ return `${days[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
356
+ };
357
+
358
+ const handleMouseOver = useCallback(
359
+ (event: React.MouseEvent<SVGRectElement>, cell: NormalizedCell<T>) => {
360
+ const coords = localPoint(event) || { x: 0, y: 0 };
361
+ showTooltip({
362
+ tooltipData: cell,
363
+ tooltipLeft: coords.x,
364
+ tooltipTop: coords.y,
365
+ });
366
+ },
367
+ [showTooltip],
368
+ );
369
+
370
+ return width < 10 ? null : (
371
+ <>
372
+ <svg width={width} height={height}>
373
+ <Group top={margin.top + xLabelHeight} left={margin.left + dayLabelWidth}>
374
+ {/* X-axis labels (month labels for calendar, category labels for categorical) */}
375
+ {showXLabels &&
376
+ processedData.xLabels
377
+ .filter((label) => {
378
+ // For categorical mode with many labels, show every nth label to prevent overlap
379
+ if (isCategorical && processedData.xLabels.length > 12) {
380
+ // Show every 3rd label for better spacing
381
+ return label.index % 3 === 0;
382
+ }
383
+ return true;
384
+ })
385
+ .map((label) => (
386
+ <text
387
+ key={`x-${label.index}`}
388
+ x={label.index * (cellSize + cellGap) + (isCategorical ? cellSize / 2 : 0)}
389
+ y={-8}
390
+ fill={theme.colors.text}
391
+ fontSize={theme.fontSize.tiny}
392
+ fontWeight={500}
393
+ textAnchor={isCategorical ? 'middle' : 'start'}
394
+ >
395
+ {label.label}
396
+ </text>
397
+ ))}
398
+
399
+ {showDayLabels &&
400
+ processedData.yLabels.map((label) => (
401
+ <text
402
+ key={`y-${label.index}`}
403
+ x={-8}
404
+ y={label.index * (cellSize + cellGap) + cellSize / 2}
405
+ fill={theme.colors.textAlt}
406
+ fontSize={theme.fontSize.tiny}
407
+ textAnchor="end"
408
+ alignmentBaseline="middle"
409
+ >
410
+ {label.label}
411
+ </text>
412
+ ))}
413
+
414
+ {processedData.cells.map((cell, i) => (
415
+ <rect
416
+ key={`cell-${i}`}
417
+ x={cell.x * (cellSize + cellGap)}
418
+ y={cell.y * (cellSize + cellGap)}
419
+ width={cellSize}
420
+ height={cellSize}
421
+ rx={2}
422
+ fill={mapValueToColor(cell.value)}
423
+ stroke={theme.colors.backgroundAlt}
424
+ strokeWidth={0.5}
425
+ onMouseOver={(e) => handleMouseOver(e, cell)}
426
+ onMouseLeave={hideTooltip}
427
+ style={{
428
+ cursor: 'pointer',
429
+ transition: 'all 0.1s ease',
430
+ }}
431
+ onMouseEnter={(e) => {
432
+ e.currentTarget.style.stroke = theme.colors.text;
433
+ e.currentTarget.style.strokeWidth = '1.5';
434
+ }}
435
+ onMouseOut={(e) => {
436
+ e.currentTarget.style.stroke = theme.colors.backgroundAlt;
437
+ e.currentTarget.style.strokeWidth = '0.5';
438
+ }}
439
+ />
440
+ ))}
441
+ </Group>
442
+ </svg>
443
+ {tooltipData && (
444
+ <TooltipWithBounds key={name} top={tooltipTop} left={tooltipLeft} style={getDefaultTooltipStyles(theme)}>
445
+ {tooltipAccessor && tooltipData.originalData ? (
446
+ tooltipAccessor(tooltipData.originalData, tooltipData.displayValue, tooltipData.value)
447
+ ) : isCategorical ? (
448
+ <>
449
+ {tooltipData.xLabel} - {tooltipData.yLabel}: {tooltipData.value}
450
+ </>
451
+ ) : (
452
+ <>
453
+ <strong>{tooltipData.value}</strong> contribution{tooltipData.value !== 1 ? 's' : ''} on{' '}
454
+ {formatDate(tooltipData.displayValue as Date)}
455
+ </>
456
+ )}
457
+ </TooltipWithBounds>
458
+ )}
459
+ </>
460
+ );
461
+ };