@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,457 @@
1
+ import { MouseEvent, useCallback, useState, useMemo } from 'react';
2
+
3
+ import { ParentSize } from '@visx/responsive';
4
+ import { Group } from '@visx/group';
5
+ import { Pie } from '@visx/shape';
6
+ import { scaleOrdinal } from '@visx/scale';
7
+ import { useTooltipInPortal, useTooltip } from '@visx/tooltip';
8
+ import { localPoint } from '@visx/event';
9
+ import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
10
+ import { motion } from 'framer-motion';
11
+
12
+ import { useTheme } from '../../../hooks';
13
+ import {
14
+ getChartColors,
15
+ getDefaultTooltipStyles,
16
+ InnerChartProps,
17
+ LegendPosition,
18
+ TooltipConfig,
19
+ ChartProps,
20
+ } from '../util';
21
+ import { styled } from '../../../styled';
22
+ import { EmptyChart } from '../EmptyChart';
23
+
24
+ type LabelPosition = 'inside' | 'outside';
25
+
26
+ const ChartWrapper = styled.div<{ $legendPosition: LegendPosition }>`
27
+ display: flex;
28
+ width: 100%;
29
+ height: 100%;
30
+
31
+ ${({ $legendPosition }) => {
32
+ switch ($legendPosition) {
33
+ case 'top':
34
+ case 'bottom':
35
+ return 'flex-direction: column;';
36
+ case 'left':
37
+ return 'flex-direction: row;';
38
+ case 'right':
39
+ return 'flex-direction: row-reverse;';
40
+ default:
41
+ return '';
42
+ }
43
+ }}
44
+ `;
45
+
46
+ const LegendContainer = styled.div<{ $position: LegendPosition }>`
47
+ display: flex;
48
+ flex-direction: ${({ $position }) => ($position === 'top' || $position === 'bottom' ? 'row' : 'column')};
49
+ flex-wrap: wrap;
50
+ gap: ${({ theme }) => theme.spacing[1]};
51
+ font-size: ${({ theme }) => theme.fontSize.small};
52
+
53
+ ${({ $position }) => {
54
+ switch ($position) {
55
+ case 'top':
56
+ return 'justify-content: center; margin-bottom: 16px;';
57
+ case 'bottom':
58
+ return 'justify-content: center; margin-top: 16px;';
59
+ case 'left':
60
+ return 'margin-right: 16px; justify-content: center;';
61
+ case 'right':
62
+ return 'margin-left: 16px; justify-content: center;';
63
+ default:
64
+ return '';
65
+ }
66
+ }}
67
+ `;
68
+
69
+ const SvgContainer = styled.div`
70
+ flex: 1;
71
+ min-width: 0;
72
+ min-height: 0;
73
+ display: flex;
74
+ `;
75
+
76
+ export interface PieChartProps<T> extends ChartProps {
77
+ data: T[];
78
+ xAccessor: (d: T) => string;
79
+ yAccessor: (d: T) => number;
80
+ /** Tooltip configuration */
81
+ tooltip?: TooltipConfig<T>;
82
+ /** Label accessor - receives data item, percentage, and value. If not provided, shows name if space allows */
83
+ labelAccessor?: (d: T, percentage: number, value: number) => string;
84
+ /** Position labels inside or outside the slices. Default: 'inside' */
85
+ labelPosition?: LabelPosition;
86
+ /** Click handler for pie slices */
87
+ onSliceClick?: (d: T, index: number) => void;
88
+ /** Show legend and its position. Default: 'none' */
89
+ legendPosition?: LegendPosition;
90
+ /** Enable animation on mount and interactions. Default: true */
91
+ animate?: boolean;
92
+ /** Custom colors for slices. If not provided, uses theme colors */
93
+ colors?: string[];
94
+ /** Inner radius as percentage of outer radius (0-1). 0 = pie chart, >0 = donut chart. Example: 0.6 = 60% of outer radius. Default: 0 */
95
+ innerRadius?: number;
96
+ /** Gap between slices in radians. 0 = no gap, 0.02 = small gap, 0.05 = large gap. Default: 0.005 */
97
+ padAngle?: number;
98
+ /** Corner radius in pixels for rounded corners. 0 = sharp corners. Default: 3. Note: With small innerRadius + large padAngle, set to 0 for consistent slice lengths. */
99
+ cornerRadius?: number;
100
+ /** Content to render in the center when innerRadius > 0. Receives total value and data array */
101
+ centerContent?: (total: number, data: T[]) => React.ReactNode;
102
+ }
103
+
104
+ const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
105
+ export const PieChart = <T,>({
106
+ data,
107
+ yAccessor,
108
+ xAccessor,
109
+ tooltip,
110
+ labelAccessor,
111
+ labelPosition = 'inside',
112
+ name,
113
+ margin,
114
+ colors,
115
+ innerRadius = 0,
116
+ padAngle = 0.005,
117
+ cornerRadius = 3,
118
+ onSliceClick,
119
+ legendPosition = 'none',
120
+ animate = true,
121
+ centerContent,
122
+ }: PieChartProps<T>) => {
123
+ const theme = useTheme();
124
+ const chartColors = colors || getChartColors(theme);
125
+
126
+ const adjustedMargin =
127
+ margin || (labelPosition === 'outside' ? { top: 40, right: 40, bottom: 40, left: 40 } : defaultMargin);
128
+ const total = useMemo(() => data.reduce((sum, d) => sum + yAccessor(d), 0), [data, yAccessor]);
129
+ const legendGlyphSize = 15;
130
+
131
+ const ordinalColorScale = useMemo(
132
+ () =>
133
+ scaleOrdinal({
134
+ domain: data.map(xAccessor),
135
+ range: chartColors,
136
+ }),
137
+ [data, xAccessor, chartColors],
138
+ );
139
+
140
+ const renderLegend = () => (
141
+ <LegendContainer $position={legendPosition}>
142
+ <LegendOrdinal scale={ordinalColorScale}>
143
+ {(labels) => (
144
+ <div
145
+ style={{
146
+ display: 'flex',
147
+ flexDirection: legendPosition === 'top' || legendPosition === 'bottom' ? 'row' : 'column',
148
+ flexWrap: 'wrap',
149
+ gap: '8px',
150
+ }}
151
+ >
152
+ {labels.map((label, i) => (
153
+ <LegendItem key={`legend-item-${i}`} margin="0">
154
+ <svg width={legendGlyphSize} height={legendGlyphSize} style={{ marginRight: '4px' }}>
155
+ <rect fill={label.value} width={legendGlyphSize} height={legendGlyphSize} rx={2} />
156
+ </svg>
157
+ <LegendLabel align="left" margin="0">
158
+ {label.text}
159
+ </LegendLabel>
160
+ </LegendItem>
161
+ ))}
162
+ </div>
163
+ )}
164
+ </LegendOrdinal>
165
+ </LegendContainer>
166
+ );
167
+
168
+ return (
169
+ <ChartWrapper $legendPosition={legendPosition}>
170
+ {legendPosition !== 'none' && (legendPosition === 'top' || legendPosition === 'left') && renderLegend()}
171
+
172
+ <SvgContainer>
173
+ <ParentSize>
174
+ {total > 0
175
+ ? (parent) => (
176
+ <Chart<T>
177
+ name={name}
178
+ data={data}
179
+ width={parent.width}
180
+ height={parent.height}
181
+ margin={adjustedMargin}
182
+ yAccessor={yAccessor}
183
+ xAccessor={xAccessor}
184
+ labelAccessor={labelAccessor}
185
+ labelPosition={labelPosition}
186
+ ordinalColorScale={ordinalColorScale}
187
+ total={total}
188
+ onSliceClick={onSliceClick}
189
+ animate={animate}
190
+ innerRadius={innerRadius}
191
+ padAngle={padAngle}
192
+ cornerRadius={cornerRadius}
193
+ centerContent={centerContent}
194
+ tooltip={tooltip}
195
+ />
196
+ )
197
+ : () => <EmptyChart />}
198
+ </ParentSize>
199
+ </SvgContainer>
200
+
201
+ {legendPosition !== 'none' && (legendPosition === 'bottom' || legendPosition === 'right') && renderLegend()}
202
+ </ChartWrapper>
203
+ );
204
+ };
205
+
206
+ type InnerPieChartProps<T> = InnerChartProps &
207
+ Omit<PieChartProps<T>, 'colors' | 'legendPosition'> & {
208
+ ordinalColorScale: ReturnType<typeof scaleOrdinal<string, string>>;
209
+ total: number;
210
+ };
211
+
212
+ const Chart = <T,>({
213
+ width,
214
+ xAccessor,
215
+ yAccessor,
216
+ data,
217
+ name,
218
+ height,
219
+ labelAccessor,
220
+ labelPosition,
221
+ tooltip,
222
+ margin = defaultMargin,
223
+ ordinalColorScale,
224
+ total,
225
+ onSliceClick,
226
+ animate,
227
+ innerRadius = 0,
228
+ padAngle = 0.005,
229
+ cornerRadius = 3,
230
+ centerContent,
231
+ }: InnerPieChartProps<T>) => {
232
+ const theme = useTheme();
233
+ const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
234
+ const { containerRef, TooltipInPortal } = useTooltipInPortal({
235
+ detectBounds: true,
236
+ scroll: true,
237
+ });
238
+
239
+ const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
240
+ const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
241
+
242
+ const innerWidth = width - margin.left - margin.right;
243
+ const innerHeight = height - margin.top - margin.bottom;
244
+ const radius = Math.min(innerWidth, innerHeight) / 2;
245
+ const centerX = innerWidth / 2;
246
+ const centerY = innerHeight / 2;
247
+
248
+ // Calculate inner radius as percentage of outer radius
249
+ const calculatedInnerRadius = radius * innerRadius;
250
+
251
+ // When innerRadius is 0, force cornerRadius to 0 to prevent center artifact
252
+ // (you can't geometrically round a point where all slices converge)
253
+ const actualCornerRadius = innerRadius === 0 ? 0 : cornerRadius;
254
+
255
+ // When innerRadius is 0, remove stroke to prevent white rectangle artifact at center
256
+ // (overlapping stroke borders create a visible square where slices meet)
257
+ const actualStrokeWidth = innerRadius === 0 ? 0 : 2;
258
+
259
+ const pieSortValues = (a: number, b: number) => b - a;
260
+
261
+ const handleMouseOver = useCallback(
262
+ (event: MouseEvent, datum: T, index: number, percentage: number, value: number) => {
263
+ const target = event.target as SVGElement;
264
+ const coords = localPoint(target.ownerSVGElement!, event);
265
+
266
+ setHoveredIndex(index);
267
+
268
+ const defaultTooltip = `${xAccessor(datum)}: ${value.toFixed(2)} (${percentage.toFixed(1)}%)`;
269
+
270
+ showTooltip({
271
+ tooltipLeft: coords?.x,
272
+ tooltipTop: coords?.y,
273
+ tooltipData: tooltip?.accessor ? tooltip.accessor(datum) : defaultTooltip,
274
+ });
275
+ },
276
+ [tooltip?.accessor, xAccessor, showTooltip],
277
+ );
278
+
279
+ const handleMouseLeave = useCallback(() => {
280
+ setHoveredIndex(null);
281
+ hideTooltip();
282
+ }, [hideTooltip]);
283
+
284
+ const handleClick = useCallback(
285
+ (datum: T, index: number) => {
286
+ setSelectedIndex(index === selectedIndex ? null : index);
287
+ if (onSliceClick) {
288
+ onSliceClick(datum, index);
289
+ }
290
+ },
291
+ [onSliceClick, selectedIndex],
292
+ );
293
+
294
+ return width < 10 ? null : (
295
+ <svg ref={containerRef} id={name} width={width} height={height}>
296
+ <Group top={centerY + margin.top} left={centerX + margin.left}>
297
+ <Pie
298
+ data={data}
299
+ outerRadius={radius}
300
+ innerRadius={calculatedInnerRadius}
301
+ cornerRadius={actualCornerRadius}
302
+ padAngle={padAngle}
303
+ pieSortValues={pieSortValues}
304
+ pieValue={yAccessor}
305
+ >
306
+ {(pie) => {
307
+ return pie.arcs.map((arc, index) => {
308
+ const [centroidX, centroidY] = pie.path.centroid(arc);
309
+ const hasSpaceForLabel = arc.endAngle - arc.startAngle >= 0.1;
310
+ const arcPath = pie.path(arc) ?? '';
311
+ const arcFill = ordinalColorScale(xAccessor(arc.data));
312
+ const value = yAccessor(arc.data);
313
+ const percentage = (value / total) * 100;
314
+
315
+ const isHovered = hoveredIndex === index;
316
+ const isSelected = selectedIndex === index;
317
+
318
+ // Calculate expanded position for hover/select effect (only if animate is enabled)
319
+ const angle = (arc.startAngle + arc.endAngle) / 2;
320
+ const expandDistance = animate && (isHovered || isSelected) ? 10 : 0;
321
+ const translateX = Math.cos(angle - Math.PI / 2) * expandDistance;
322
+ const translateY = Math.sin(angle - Math.PI / 2) * expandDistance;
323
+
324
+ // Calculate label position
325
+ let labelX = centroidX;
326
+ let labelY = centroidY;
327
+
328
+ if (labelPosition === 'outside') {
329
+ const labelRadius = radius + 20;
330
+ labelX = Math.cos(angle - Math.PI / 2) * labelRadius;
331
+ labelY = Math.sin(angle - Math.PI / 2) * labelRadius;
332
+ }
333
+
334
+ const labelText = labelAccessor
335
+ ? labelAccessor(arc.data, percentage, value)
336
+ : hasSpaceForLabel
337
+ ? xAccessor(arc.data)
338
+ : '';
339
+
340
+ return (
341
+ <g
342
+ key={`arc-${xAccessor(arc.data)}-${index}`}
343
+ style={{
344
+ transform: `translate(${translateX}px, ${translateY}px)`,
345
+ transition: animate ? 'transform 0.2s ease-out' : 'none',
346
+ }}
347
+ >
348
+ <motion.path
349
+ d={arcPath}
350
+ fill={arcFill}
351
+ stroke={theme.colors.background}
352
+ strokeWidth={actualStrokeWidth}
353
+ onMouseOver={(e) => handleMouseOver(e, arc.data, index, percentage, value)}
354
+ onMouseLeave={handleMouseLeave}
355
+ onClick={() => handleClick(arc.data, index)}
356
+ style={{
357
+ cursor: onSliceClick ? 'pointer' : 'default',
358
+ transition: animate ? 'opacity 0.2s ease-out' : 'none',
359
+ filter: animate && (isHovered || isSelected) ? 'brightness(1.1)' : 'none',
360
+ }}
361
+ initial={animate ? { opacity: 0 } : { opacity: 0.9 }}
362
+ animate={{
363
+ opacity: isHovered || isSelected ? 1 : hoveredIndex !== null ? 0.6 : 0.9,
364
+ }}
365
+ transition={
366
+ animate
367
+ ? {
368
+ opacity: {
369
+ duration: 0.3,
370
+ delay: (arc.startAngle / (Math.PI * 2)) * 0.6,
371
+ ease: 'linear',
372
+ },
373
+ }
374
+ : { duration: 0 }
375
+ }
376
+ />
377
+ {labelText && (
378
+ <motion.text
379
+ x={labelX}
380
+ y={labelY}
381
+ dy=".33em"
382
+ fill={labelPosition === 'outside' ? theme.colors.text : 'white'}
383
+ fontSize={labelPosition === 'outside' ? 12 : 11}
384
+ fontWeight={animate && (isHovered || isSelected) ? 600 : 500}
385
+ textAnchor="middle"
386
+ pointerEvents="none"
387
+ style={{
388
+ transition: animate ? 'font-weight 0.2s ease-out' : 'none',
389
+ }}
390
+ initial={animate ? { opacity: 0 } : { opacity: 1 }}
391
+ animate={{ opacity: 1 }}
392
+ transition={
393
+ animate
394
+ ? {
395
+ duration: 0.3,
396
+ delay: 1.0,
397
+ ease: 'easeOut',
398
+ }
399
+ : { duration: 0 }
400
+ }
401
+ >
402
+ {labelText}
403
+ </motion.text>
404
+ )}
405
+ </g>
406
+ );
407
+ });
408
+ }}
409
+ </Pie>
410
+ {innerRadius > 0 && centerContent && (
411
+ <foreignObject
412
+ x={-calculatedInnerRadius}
413
+ y={-calculatedInnerRadius}
414
+ width={calculatedInnerRadius * 2}
415
+ height={calculatedInnerRadius * 2}
416
+ style={{ pointerEvents: 'none' }}
417
+ >
418
+ <motion.div
419
+ style={{
420
+ width: '100%',
421
+ height: '100%',
422
+ display: 'flex',
423
+ alignItems: 'center',
424
+ justifyContent: 'center',
425
+ textAlign: 'center',
426
+ color: theme.colors.text,
427
+ }}
428
+ initial={animate ? { opacity: 0, scale: 0.8 } : { opacity: 1, scale: 1 }}
429
+ animate={{ opacity: 1, scale: 1 }}
430
+ transition={
431
+ animate
432
+ ? {
433
+ duration: 0.4,
434
+ delay: 1.1,
435
+ ease: 'easeOut',
436
+ }
437
+ : { duration: 0 }
438
+ }
439
+ >
440
+ {centerContent(total, data)}
441
+ </motion.div>
442
+ </foreignObject>
443
+ )}
444
+ </Group>
445
+ {tooltipOpen && tooltipData && (
446
+ <TooltipInPortal
447
+ key={`tooltip-${name}`}
448
+ top={tooltipTop}
449
+ left={tooltipLeft}
450
+ style={getDefaultTooltipStyles(theme)}
451
+ >
452
+ {tooltipData}
453
+ </TooltipInPortal>
454
+ )}
455
+ </svg>
456
+ );
457
+ };
@@ -0,0 +1,49 @@
1
+ import { FC } from 'react';
2
+ import { Margin } from './util';
3
+ import { Group } from '@visx/group';
4
+ import { Line } from '@visx/shape';
5
+ import { useTheme } from '../../hooks';
6
+
7
+ interface PointHighlightProps {
8
+ margin: Margin;
9
+ yMax: number;
10
+ tooltipLeft: number;
11
+ tooltipTop: number;
12
+ }
13
+
14
+ export const PointHighlight: FC<PointHighlightProps> = ({ margin, yMax, tooltipLeft, tooltipTop }) => {
15
+ const theme = useTheme();
16
+
17
+ return (
18
+ <Group left={margin.left} top={margin.top}>
19
+ <Line
20
+ from={{ x: tooltipLeft, y: 0 }}
21
+ to={{ x: tooltipLeft, y: yMax }}
22
+ stroke={theme.colors.backgroundAccent}
23
+ strokeWidth={1}
24
+ pointerEvents="none"
25
+ strokeDasharray="4,1"
26
+ />
27
+ <circle
28
+ cx={tooltipLeft}
29
+ cy={tooltipTop}
30
+ r={4}
31
+ fill="black"
32
+ fillOpacity={0.1}
33
+ stroke="black"
34
+ strokeOpacity={0.1}
35
+ strokeWidth={2}
36
+ pointerEvents="none"
37
+ />
38
+ <circle
39
+ cx={tooltipLeft}
40
+ cy={tooltipTop}
41
+ r={4}
42
+ fill={theme.colors.backgroundAccent}
43
+ stroke="white"
44
+ strokeWidth={2}
45
+ pointerEvents="none"
46
+ />
47
+ </Group>
48
+ );
49
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { Meta, StoryFn } from '@storybook/react';
3
+ import { RadarChart, RadarChartProps } from '.';
4
+ import { styled } from '../../../styled';
5
+ import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
6
+
7
+ export default {
8
+ title: 'Charts/RadarChart',
9
+ component: RadarChart,
10
+ args: {
11
+ levels: 5,
12
+ items: 6,
13
+ animate: true,
14
+ },
15
+ } as Meta<RadarChartProps<LetterFrequency>>;
16
+
17
+ const Wrapper = styled.div`
18
+ height: 400px;
19
+ width: 400px;
20
+ `;
21
+
22
+ export const Default: StoryFn<RadarChartProps<LetterFrequency>> = (args) => {
23
+ const getLetter = (d: LetterFrequency) => d.letter;
24
+ const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency);
25
+ const tooltipAccessor = (d: LetterFrequency) => {
26
+ return `Tooltip content for '${getLetter(d)}' with frequency ${getLetterFrequency(d) * 100}% `;
27
+ };
28
+
29
+ // only show the first few letters
30
+ const data = letterFrequency.slice(0, (args as any).items);
31
+
32
+ return (
33
+ <Wrapper>
34
+ <RadarChart<LetterFrequency>
35
+ name="letterFrequency"
36
+ yAccessor={getLetterFrequency}
37
+ xAccessor={getLetter}
38
+ tooltip={{
39
+ accessor: tooltipAccessor,
40
+ }}
41
+ data={data}
42
+ levels={args.levels}
43
+ animate={args.animate}
44
+ />
45
+ </Wrapper>
46
+ );
47
+ };
@@ -0,0 +1,30 @@
1
+ export const genAngles = (length: number) =>
2
+ [...new Array(length + 1)].map((_, i) => ({
3
+ angle: i * (360 / length) + (length % 2 === 0 ? 0 : 360 / length / 2),
4
+ }));
5
+
6
+ export const genPoints = (length: number, radius: number) => {
7
+ const step = (Math.PI * 2) / length;
8
+ return [...new Array(length)].map((_, i) => ({
9
+ x: radius * Math.sin(i * step),
10
+ y: radius * Math.cos(i * step),
11
+ }));
12
+ };
13
+
14
+ export function genPolygonPoints<T>(dataArray: T[], scale: (n: number) => number, getValue: (d: T) => number) {
15
+ const step = (Math.PI * 2) / dataArray.length;
16
+ const points: { x: number; y: number }[] = new Array(dataArray.length).fill({
17
+ x: 0,
18
+ y: 0,
19
+ });
20
+ const pointString: string = new Array(dataArray.length + 1).fill('').reduce((res, _, i) => {
21
+ if (i > dataArray.length) return res;
22
+ const xVal = scale(getValue(dataArray[i - 1])) * Math.sin(i * step);
23
+ const yVal = scale(getValue(dataArray[i - 1])) * Math.cos(i * step);
24
+ points[i - 1] = { x: xVal, y: yVal };
25
+ res += `${xVal},${yVal} `;
26
+ return res;
27
+ });
28
+
29
+ return { points, pointString };
30
+ }