@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.
- package/.babelrc +7 -0
- package/@types/files.d.ts +23 -0
- package/@types/react-table-config.d.ts +121 -0
- package/Dockerfile.dev +21 -0
- package/package.json +15 -0
- package/public/images/7-days-to-die/logo.png +0 -0
- package/public/images/csmm-icon.png +0 -0
- package/public/images/milk.png +0 -0
- package/public/images/placeholder-01.jpeg +0 -0
- package/public/images/placeholder-02.jpeg +0 -0
- package/public/images/placeholder-03.jpeg +0 -0
- package/public/images/rust/logo.png +0 -0
- package/readme.md +10 -0
- package/src/components/actions/Button/Button.stories.tsx +149 -0
- package/src/components/actions/Button/Button.test.tsx +8 -0
- package/src/components/actions/Button/Button.test.tsx.snap +89 -0
- package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +18 -0
- package/src/components/actions/Button/index.tsx +89 -0
- package/src/components/actions/Button/style.ts +142 -0
- package/src/components/actions/ContextMenu/ContextMenu.stories.tsx +41 -0
- package/src/components/actions/ContextMenu/Group.tsx +34 -0
- package/src/components/actions/ContextMenu/MenuItem.tsx +69 -0
- package/src/components/actions/ContextMenu/index.tsx +216 -0
- package/src/components/actions/Dropdown/Dropdown.stories.tsx +88 -0
- package/src/components/actions/Dropdown/DropdownContext.tsx +21 -0
- package/src/components/actions/Dropdown/DropdownMenu.tsx +70 -0
- package/src/components/actions/Dropdown/DropdownMenuGroup.tsx +37 -0
- package/src/components/actions/Dropdown/DropdownMenuItem.tsx +128 -0
- package/src/components/actions/Dropdown/DropdownTrigger.tsx +87 -0
- package/src/components/actions/Dropdown/index.tsx +22 -0
- package/src/components/actions/Dropdown/useDropdown.tsx +89 -0
- package/src/components/actions/DropdownButton/DropdownButton.stories.tsx +88 -0
- package/src/components/actions/DropdownButton/index.tsx +128 -0
- package/src/components/actions/IconButton/IconButton.stories.tsx +54 -0
- package/src/components/actions/IconButton/IconButton.test.tsx +8 -0
- package/src/components/actions/IconButton/IconButton.test.tsx.snap +46 -0
- package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +18 -0
- package/src/components/actions/IconButton/getIconSize.ts +16 -0
- package/src/components/actions/IconButton/index.tsx +28 -0
- package/src/components/actions/IconButton/style.ts +51 -0
- package/src/components/actions/ToggleButton/ToggleButton.stories.tsx +85 -0
- package/src/components/actions/ToggleButton/ToggleButton.tsx +48 -0
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +107 -0
- package/src/components/actions/ToggleButton/index.tsx +2 -0
- package/src/components/actions/ToggleButton/style.ts +75 -0
- package/src/components/actions/index.ts +16 -0
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +103 -0
- package/src/components/charts/AreaChart/index.tsx +428 -0
- package/src/components/charts/BarChart/BarChart.stories.tsx +55 -0
- package/src/components/charts/BarChart/index.tsx +420 -0
- package/src/components/charts/BrushHandle.tsx +21 -0
- package/src/components/charts/EmptyChart.tsx +45 -0
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +77 -0
- package/src/components/charts/GeoMercator/index.tsx +228 -0
- package/src/components/charts/GeoMercator/iso3166-alpha2-to-alpha3.ts +250 -0
- package/src/components/charts/GeoMercator/world.d.ts +1 -0
- package/src/components/charts/GeoMercator/world.json +99818 -0
- package/src/components/charts/Heatmap/Heatmap.stories.tsx +189 -0
- package/src/components/charts/Heatmap/index.tsx +461 -0
- package/src/components/charts/LineChart/LineChart.stories.tsx +111 -0
- package/src/components/charts/LineChart/index.tsx +353 -0
- package/src/components/charts/PieChart/PieChart.stories.tsx +151 -0
- package/src/components/charts/PieChart/index.tsx +457 -0
- package/src/components/charts/PointHighlight.tsx +49 -0
- package/src/components/charts/RadarChart/RadarChart.stories.tsx +47 -0
- package/src/components/charts/RadarChart/generators.ts +30 -0
- package/src/components/charts/RadarChart/index.tsx +224 -0
- package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +59 -0
- package/src/components/charts/RadialBarChart/index.tsx +231 -0
- package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +43 -0
- package/src/components/charts/RadialLineChart/index.tsx +231 -0
- package/src/components/charts/ZoomControls.tsx +49 -0
- package/src/components/charts/index.tsx +26 -0
- package/src/components/charts/useGradients.tsx +37 -0
- package/src/components/charts/util.ts +78 -0
- package/src/components/data/Avatar/Avatar.stories.tsx +93 -0
- package/src/components/data/Avatar/context.tsx +20 -0
- package/src/components/data/Avatar/index.tsx +136 -0
- package/src/components/data/Avatar/style.ts +124 -0
- package/src/components/data/Avatar/useImageLoadingStatus.tsx +32 -0
- package/src/components/data/Chip/Chip.stories.tsx +67 -0
- package/src/components/data/Chip/Chip.test.tsx +8 -0
- package/src/components/data/Chip/Chip.test.tsx.snap +50 -0
- package/src/components/data/Chip/__snapshots__/Chip.test.tsx.snap +38 -0
- package/src/components/data/Chip/index.tsx +67 -0
- package/src/components/data/Chip/style.ts +49 -0
- package/src/components/data/Console/Console.stories.tsx +51 -0
- package/src/components/data/Console/Console.tsx +125 -0
- package/src/components/data/Console/ConsoleInput/index.tsx +87 -0
- package/src/components/data/Console/ConsoleInput/style.ts +41 -0
- package/src/components/data/Console/ConsoleLine/index.tsx +127 -0
- package/src/components/data/Console/ConsoleLine/style.ts +76 -0
- package/src/components/data/Console/MessageModel.ts +9 -0
- package/src/components/data/Console/constants.ts +6 -0
- package/src/components/data/Console/index.tsx +4 -0
- package/src/components/data/Console/style.ts +31 -0
- package/src/components/data/Console/useConsoleLiveMode.ts +42 -0
- package/src/components/data/CopyId/CopyId.stories.tsx +36 -0
- package/src/components/data/CopyId/index.tsx +107 -0
- package/src/components/data/CountryList/index.tsx +146 -0
- package/src/components/data/DateFormatter/DateFormatter.stories.tsx +26 -0
- package/src/components/data/DateFormatter/index.tsx +15 -0
- package/src/components/data/Drawer/Drawer.stories.tsx +155 -0
- package/src/components/data/Drawer/DrawerBody.tsx +22 -0
- package/src/components/data/Drawer/DrawerContent.tsx +169 -0
- package/src/components/data/Drawer/DrawerContext.tsx +21 -0
- package/src/components/data/Drawer/DrawerFooter.tsx +19 -0
- package/src/components/data/Drawer/DrawerHeading.tsx +50 -0
- package/src/components/data/Drawer/DrawerSkeleton.tsx +29 -0
- package/src/components/data/Drawer/index.tsx +25 -0
- package/src/components/data/Drawer/useDrawer.tsx +66 -0
- package/src/components/data/InfiniteScroll/InfiniteScroll.stories.tsx +33 -0
- package/src/components/data/InfiniteScroll/index.tsx +54 -0
- package/src/components/data/Stats/Sparkline.tsx +48 -0
- package/src/components/data/Stats/Stat.tsx +192 -0
- package/src/components/data/Stats/Stats.stories.tsx +196 -0
- package/src/components/data/Stats/context.tsx +18 -0
- package/src/components/data/Stats/index.tsx +62 -0
- package/src/components/data/Table/Table.stories.tsx +146 -0
- package/src/components/data/Table/index.tsx +492 -0
- package/src/components/data/Table/react-table.d.ts +14 -0
- package/src/components/data/Table/style.ts +97 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +164 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +207 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +90 -0
- package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +70 -0
- package/src/components/data/Table/subcomponents/Filter/field.tsx +127 -0
- package/src/components/data/Table/subcomponents/Filter/index.tsx +228 -0
- package/src/components/data/Table/subcomponents/Filter/style.ts +26 -0
- package/src/components/data/Table/subcomponents/Filter/types.ts +10 -0
- package/src/components/data/Table/subcomponents/Pagination/PagePicker.tsx +109 -0
- package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +37 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +49 -0
- package/src/components/data/index.ts +28 -0
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +77 -0
- package/src/components/dialogs/Dialog/DialogBody.tsx +64 -0
- package/src/components/dialogs/Dialog/DialogContent.tsx +44 -0
- package/src/components/dialogs/Dialog/DialogContext.tsx +21 -0
- package/src/components/dialogs/Dialog/DialogHeading.tsx +56 -0
- package/src/components/dialogs/Dialog/index.tsx +20 -0
- package/src/components/dialogs/Dialog/useDialog.tsx +50 -0
- package/src/components/feedback/Alert/Alert.stories.tsx +75 -0
- package/src/components/feedback/Alert/Alert.test.tsx +8 -0
- package/src/components/feedback/Alert/Alert.test.tsx.snap +146 -0
- package/src/components/feedback/Alert/__snapshots__/Alert.test.tsx.snap +44 -0
- package/src/components/feedback/Alert/index.tsx +120 -0
- package/src/components/feedback/Alert/style.ts +97 -0
- package/src/components/feedback/Badge/Badge.stories.tsx +23 -0
- package/src/components/feedback/Badge/index.tsx +47 -0
- package/src/components/feedback/ErrorFallback/ErrorFallback.stories.tsx +10 -0
- package/src/components/feedback/ErrorFallback/index.tsx +49 -0
- package/src/components/feedback/ErrorPage/ErrorPage.stories.tsx +31 -0
- package/src/components/feedback/ErrorPage/index.tsx +193 -0
- package/src/components/feedback/FormError/FormError.stories.tsx +25 -0
- package/src/components/feedback/FormError/index.tsx +54 -0
- package/src/components/feedback/IconTooltip/IconTooltip.stories.tsx +22 -0
- package/src/components/feedback/IconTooltip/index.tsx +51 -0
- package/src/components/feedback/Loaders/Loaders.stories.tsx +28 -0
- package/src/components/feedback/Loaders/Loading.test.tsx +8 -0
- package/src/components/feedback/Loaders/Loading.test.tsx.snap +141 -0
- package/src/components/feedback/Loaders/Loading.tsx +107 -0
- package/src/components/feedback/Loaders/Spinner.test.tsx +8 -0
- package/src/components/feedback/Loaders/Spinner.test.tsx.snap +18 -0
- package/src/components/feedback/Loaders/Spinner.tsx +74 -0
- package/src/components/feedback/Loaders/__snapshots__/Loading.test.tsx.snap +141 -0
- package/src/components/feedback/Loaders/__snapshots__/Spinner.test.tsx.snap +10 -0
- package/src/components/feedback/Loaders/index.ts +2 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.stories.tsx +21 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx +8 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx.snap +3 -0
- package/src/components/feedback/NetworkDetector/__snapshots__/NetworkDetector.test.tsx.snap +3 -0
- package/src/components/feedback/NetworkDetector/index.tsx +41 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.stories.tsx +13 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +15 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/__snapshots__/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/index.tsx +78 -0
- package/src/components/feedback/Popover/Popover.stories.tsx +33 -0
- package/src/components/feedback/Popover/PopoverContent.tsx +46 -0
- package/src/components/feedback/Popover/PopoverContext.tsx +21 -0
- package/src/components/feedback/Popover/PopoverTrigger.tsx +45 -0
- package/src/components/feedback/Popover/index.tsx +22 -0
- package/src/components/feedback/Popover/usePopover.tsx +87 -0
- package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +38 -0
- package/src/components/feedback/ProgressBar/index.tsx +137 -0
- package/src/components/feedback/Skeleton/Skeleton.stories.tsx +33 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx +8 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx.snap +35 -0
- package/src/components/feedback/Skeleton/__snapshots__/Skeleton.test.tsx.snap +9 -0
- package/src/components/feedback/Skeleton/index.tsx +62 -0
- package/src/components/feedback/Tooltip/Tooltip.stories.tsx +69 -0
- package/src/components/feedback/Tooltip/TooltipContent.tsx +51 -0
- package/src/components/feedback/Tooltip/TooltipContext.tsx +13 -0
- package/src/components/feedback/Tooltip/TooltipTrigger.tsx +39 -0
- package/src/components/feedback/Tooltip/index.tsx +26 -0
- package/src/components/feedback/Tooltip/useTooltip.tsx +82 -0
- package/src/components/feedback/index.ts +37 -0
- package/src/components/feedback/snacks/CookieConsent/index.tsx +125 -0
- package/src/components/feedback/snacks/CookieConsent/style.ts +99 -0
- package/src/components/feedback/snacks/Default/default.stories.tsx +73 -0
- package/src/components/feedback/snacks/Default/index.tsx +78 -0
- package/src/components/feedback/snacks/Default/style.ts +58 -0
- package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +46 -0
- package/src/components/feedback/snacks/Drawer/index.tsx +85 -0
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +73 -0
- package/src/components/feedback/snacks/index.d.ts +15 -0
- package/src/components/feedback/snacks/index.ts +8 -0
- package/src/components/index.ts +9 -0
- package/src/components/inputs/CheckBox/CheckBox.stories.tsx +64 -0
- package/src/components/inputs/CheckBox/Controlled.tsx +123 -0
- package/src/components/inputs/CheckBox/Generic.tsx +42 -0
- package/src/components/inputs/CheckBox/index.tsx +4 -0
- package/src/components/inputs/CheckBox/style.ts +56 -0
- package/src/components/inputs/CodeField/CodeField.stories.tsx +86 -0
- package/src/components/inputs/CodeField/index.tsx +174 -0
- package/src/components/inputs/CodeField/style.ts +50 -0
- package/src/components/inputs/Date/DatePicker/Controlled.tsx +103 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +267 -0
- package/src/components/inputs/Date/DatePicker/Generic.tsx +283 -0
- package/src/components/inputs/Date/DatePicker/formats.tsx +32 -0
- package/src/components/inputs/Date/DatePicker/style.ts +41 -0
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +123 -0
- package/src/components/inputs/Date/DateRangePicker/Controlled.tsx +74 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +37 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Absolute.tsx +98 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Relative.tsx +54 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/index.tsx +49 -0
- package/src/components/inputs/Date/DateRangePicker/Generic.tsx +167 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +254 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/style.ts +40 -0
- package/src/components/inputs/Date/DateRangePicker/style.ts +65 -0
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +150 -0
- package/src/components/inputs/Date/subcomponents/Calendar/style.ts +61 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +170 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/style.ts +50 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/TimePicker.stories.tsx +25 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/index.tsx +40 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/style.ts +34 -0
- package/src/components/inputs/Date/types.ts +14 -0
- package/src/components/inputs/DurationField/Controlled.tsx +69 -0
- package/src/components/inputs/DurationField/Duration.stories.tsx +57 -0
- package/src/components/inputs/DurationField/Generic.tsx +197 -0
- package/src/components/inputs/DurationField/__tests__/Generic.test.tsx +12 -0
- package/src/components/inputs/DurationField/index.tsx +5 -0
- package/src/components/inputs/DurationField/style.ts +42 -0
- package/src/components/inputs/EditableField/EditableField.stories.tsx +65 -0
- package/src/components/inputs/EditableField/index.tsx +135 -0
- package/src/components/inputs/EditableField/style.ts +11 -0
- package/src/components/inputs/FileField/Controlled.tsx +104 -0
- package/src/components/inputs/FileField/FileField.stories.tsx +210 -0
- package/src/components/inputs/FileField/Generic.tsx +133 -0
- package/src/components/inputs/FileField/index.tsx +5 -0
- package/src/components/inputs/FileField/style.ts +34 -0
- package/src/components/inputs/InputProps.ts +59 -0
- package/src/components/inputs/RadioGroup/Controlled.tsx +45 -0
- package/src/components/inputs/RadioGroup/Generic.tsx +34 -0
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +118 -0
- package/src/components/inputs/RadioGroup/RadioItem.tsx +130 -0
- package/src/components/inputs/RadioGroup/context.tsx +20 -0
- package/src/components/inputs/RadioGroup/index.ts +5 -0
- package/src/components/inputs/RadioGroup/style.ts +3 -0
- package/src/components/inputs/Switch/Controlled.tsx +57 -0
- package/src/components/inputs/Switch/Generic.tsx +40 -0
- package/src/components/inputs/Switch/Switch.stories.tsx +89 -0
- package/src/components/inputs/Switch/index.ts +5 -0
- package/src/components/inputs/Switch/style.ts +62 -0
- package/src/components/inputs/TagField/Controlled.tsx +103 -0
- package/src/components/inputs/TagField/Generic.tsx +138 -0
- package/src/components/inputs/TagField/TagField.stories.tsx +68 -0
- package/src/components/inputs/TagField/index.ts +5 -0
- package/src/components/inputs/TagField/style.ts +25 -0
- package/src/components/inputs/TagField/util.ts +34 -0
- package/src/components/inputs/TextAreaField/Controlled.tsx +101 -0
- package/src/components/inputs/TextAreaField/Generic.tsx +58 -0
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +99 -0
- package/src/components/inputs/TextAreaField/index.ts +5 -0
- package/src/components/inputs/TextAreaField/style.ts +28 -0
- package/src/components/inputs/TextField/Controlled.tsx +120 -0
- package/src/components/inputs/TextField/Generic.tsx +138 -0
- package/src/components/inputs/TextField/TextField.stories.tsx +217 -0
- package/src/components/inputs/TextField/index.ts +5 -0
- package/src/components/inputs/TextField/style.ts +103 -0
- package/src/components/inputs/TextField/util.ts +24 -0
- package/src/components/inputs/ValueConfirmationField/ValueConfirmationField.stories.tsx +33 -0
- package/src/components/inputs/ValueConfirmationField/index.tsx +54 -0
- package/src/components/inputs/index.ts +72 -0
- package/src/components/inputs/layout/Description.tsx +33 -0
- package/src/components/inputs/layout/ErrorMessage/ErrorMessage.stories.tsx +28 -0
- package/src/components/inputs/layout/ErrorMessage/index.tsx +63 -0
- package/src/components/inputs/layout/InputWrapper.ts +6 -0
- package/src/components/inputs/layout/Label/index.tsx +71 -0
- package/src/components/inputs/layout/Label/style.ts +50 -0
- package/src/components/inputs/layout/index.ts +8 -0
- package/src/components/inputs/layout/setAriaDescribedBy.ts +3 -0
- package/src/components/inputs/selects/SelectField/Controlled.tsx +127 -0
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +48 -0
- package/src/components/inputs/selects/SelectField/Generic/index.tsx +299 -0
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +252 -0
- package/src/components/inputs/selects/SelectField/index.ts +5 -0
- package/src/components/inputs/selects/SelectField/style.ts +29 -0
- package/src/components/inputs/selects/SelectQueryField/Controlled.tsx +110 -0
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +401 -0
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +280 -0
- package/src/components/inputs/selects/SelectQueryField/index.tsx +5 -0
- package/src/components/inputs/selects/SelectQueryField/style.ts +13 -0
- package/src/components/inputs/selects/SubComponents/Option.tsx +114 -0
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +18 -0
- package/src/components/inputs/selects/SubComponents/index.ts +10 -0
- package/src/components/inputs/selects/SubComponents/style.ts +51 -0
- package/src/components/inputs/selects/data.ts +123 -0
- package/src/components/inputs/selects/index.tsx +49 -0
- package/src/components/inputs/selects/sharedStyle.ts +76 -0
- package/src/components/layout/Container/index.ts +21 -0
- package/src/components/layout/index.ts +1 -0
- package/src/components/navigation/HorizontalNav/HorizontalNav.stories.tsx +29 -0
- package/src/components/navigation/HorizontalNav/index.tsx +13 -0
- package/src/components/navigation/HorizontalNav/style.ts +93 -0
- package/src/components/navigation/IconNav/IconNav.stories.tsx +46 -0
- package/src/components/navigation/IconNav/index.tsx +50 -0
- package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +90 -0
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +104 -0
- package/src/components/navigation/Steppers/SlimStepper/style.ts +85 -0
- package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +88 -0
- package/src/components/navigation/Steppers/Stepper/index.tsx +114 -0
- package/src/components/navigation/Steppers/Stepper/style.ts +106 -0
- package/src/components/navigation/Steppers/context.tsx +2 -0
- package/src/components/navigation/Steppers/provider.tsx +18 -0
- package/src/components/navigation/Steppers/reducer.ts +51 -0
- package/src/components/navigation/Steppers/stepStates.ts +5 -0
- package/src/components/navigation/Steppers/useStepper.ts +34 -0
- package/src/components/navigation/Tabs/Content.tsx +39 -0
- package/src/components/navigation/Tabs/Context.tsx +21 -0
- package/src/components/navigation/Tabs/List.tsx +17 -0
- package/src/components/navigation/Tabs/Tabs.stories.tsx +119 -0
- package/src/components/navigation/Tabs/Trigger.tsx +66 -0
- package/src/components/navigation/Tabs/index.tsx +35 -0
- package/src/components/navigation/Tabs/useTabs.tsx +28 -0
- package/src/components/navigation/index.ts +17 -0
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +81 -0
- package/src/components/other/ActionMenu/index.tsx +62 -0
- package/src/components/other/ActionMenu/style.ts +47 -0
- package/src/components/other/ClipBoard/ClipBoard.stories.tsx +14 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx +8 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx.snap +70 -0
- package/src/components/other/ClipBoard/__snapshots__/ClipBoard.test.tsx.snap +36 -0
- package/src/components/other/ClipBoard/index.tsx +70 -0
- package/src/components/other/CollapseList/CollapseList.stories.tsx +21 -0
- package/src/components/other/CollapseList/index.tsx +110 -0
- package/src/components/other/Collapsible/Collapsible.stories.tsx +19 -0
- package/src/components/other/Collapsible/CollapsibleContent.tsx +29 -0
- package/src/components/other/Collapsible/CollapsibleContext.tsx +17 -0
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +83 -0
- package/src/components/other/Collapsible/index.tsx +21 -0
- package/src/components/other/Company/index.tsx +44 -0
- package/src/components/other/Company/style.ts +58 -0
- package/src/components/other/Empty/Empty.stories.tsx +28 -0
- package/src/components/other/Empty/Empty.test.tsx +10 -0
- package/src/components/other/Empty/Empty.test.tsx.snap +85 -0
- package/src/components/other/Empty/__snapshots__/Empty.test.tsx.snap +21 -0
- package/src/components/other/Empty/index.tsx +85 -0
- package/src/components/other/PermissionsGuard/PermissionsGuard.stories.tsx +55 -0
- package/src/components/other/PermissionsGuard/hasPermissionsHelper.ts +18 -0
- package/src/components/other/PermissionsGuard/index.tsx +27 -0
- package/src/components/other/Plan/Plan.stories.tsx +21 -0
- package/src/components/other/Plan/index.tsx +92 -0
- package/src/components/other/Plan/style.ts +61 -0
- package/src/components/other/Usage/Usage.stories.tsx +21 -0
- package/src/components/other/Usage/Usage.tsx +35 -0
- package/src/components/other/Usage/UsageCard.stories.tsx +31 -0
- package/src/components/other/Usage/UsageCard.tsx +88 -0
- package/src/components/other/index.ts +27 -0
- package/src/components/visual/Card/Card.stories.tsx +22 -0
- package/src/components/visual/Card/CardBody.tsx +11 -0
- package/src/components/visual/Card/CardTitle.tsx +29 -0
- package/src/components/visual/Card/index.tsx +58 -0
- package/src/components/visual/Divider/Divider.stories.tsx +19 -0
- package/src/components/visual/Divider/Divider.test.tsx +8 -0
- package/src/components/visual/Divider/Divider.test.tsx.snap +35 -0
- package/src/components/visual/Divider/__snapshots__/Divider.test.tsx.snap +13 -0
- package/src/components/visual/Divider/index.tsx +88 -0
- package/src/components/visual/Flag/index.tsx +61 -0
- package/src/components/visual/index.ts +8 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/errors.ts +126 -0
- package/src/errors/index.ts +14 -0
- package/src/helpers/camelCaseToSpaces.ts +5 -0
- package/src/helpers/formatNumber.ts +6 -0
- package/src/helpers/getInitials.ts +16 -0
- package/src/helpers/getSnackbarProvider.tsx +57 -0
- package/src/helpers/getTransition.ts +9 -0
- package/src/helpers/index.ts +6 -0
- package/src/helpers/makeData.ts +34 -0
- package/src/helpers/regexprs.ts +9 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useCallbackRef.tsx +17 -0
- package/src/hooks/useDebounce.tsx +22 -0
- package/src/hooks/useFocus.tsx +12 -0
- package/src/hooks/useLocalStorage.tsx +35 -0
- package/src/hooks/useLockScroll.ts +26 -0
- package/src/hooks/useOnScreen.ts +24 -0
- package/src/hooks/useOutsideAlerter.tsx +15 -0
- package/src/hooks/useTableActions.ts +61 -0
- package/src/hooks/useTheme.tsx +7 -0
- package/src/images/company-icon-primary.svg +3 -0
- package/src/images/company-icon-secondary.svg +3 -0
- package/src/images/index.ts +4 -0
- package/src/index.ts +9 -0
- package/src/stories/Colors.mdx +35 -0
- package/src/stories/Introduction.mdx +17 -0
- package/src/stories/Spacing.mdx +25 -0
- package/src/styled/GlobalStyle.ts +209 -0
- package/src/styled/Snackbar.tsx +41 -0
- package/src/styled/animations.ts +36 -0
- package/src/styled/breakpoint.ts +7 -0
- package/src/styled/device.ts +10 -0
- package/src/styled/index.ts +10 -0
- package/src/styled/spacing.ts +38 -0
- package/src/styled/theme.tsx +110 -0
- package/src/styled/types.ts +5 -0
- package/src/styled/zIndex.ts +31 -0
- package/src/test/__mocks__/fileMock.ts +2 -0
- package/src/test/setupTests.ts +3 -0
- package/src/test/snapshotResolver.js +21 -0
- package/src/test/testUtils.tsx +34 -0
- package/src/types/index.ts +1 -0
- package/src/types/json.ts +5 -0
- package/src/views/LoadingPage.tsx +36 -0
- package/src/views/index.ts +1 -0
- package/tsconfig.json +14 -0
- package/vite.config.mts +17 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { MouseEvent, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ParentSize } from '@visx/responsive';
|
|
4
|
+
import { Group } from '@visx/group';
|
|
5
|
+
import { LineRadial } from '@visx/shape';
|
|
6
|
+
import { scaleLinear } from '@visx/scale';
|
|
7
|
+
import { useTooltipInPortal, useTooltip } from '@visx/tooltip';
|
|
8
|
+
import { localPoint } from '@visx/event';
|
|
9
|
+
import { Text } from '@visx/text';
|
|
10
|
+
import { motion } from 'framer-motion';
|
|
11
|
+
|
|
12
|
+
import { getDefaultTooltipStyles, InnerChartProps, TooltipConfig, ChartProps } from '../util';
|
|
13
|
+
import { genAngles, genPoints, genPolygonPoints } from './generators';
|
|
14
|
+
import { useTheme } from '../../../hooks';
|
|
15
|
+
import { EmptyChart } from '../EmptyChart';
|
|
16
|
+
|
|
17
|
+
export interface RadarChartProps<T> extends Exclude<ChartProps, 'grid'> {
|
|
18
|
+
data: T[];
|
|
19
|
+
xAccessor: (d: T) => string;
|
|
20
|
+
yAccessor: (d: T) => number;
|
|
21
|
+
levels?: number;
|
|
22
|
+
/** Tooltip configuration */
|
|
23
|
+
tooltip?: TooltipConfig<T>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const defaultMargin = { top: 40, right: 40, bottom: 40, left: 40 };
|
|
27
|
+
export const RadarChart = <T,>({
|
|
28
|
+
data,
|
|
29
|
+
xAccessor,
|
|
30
|
+
yAccessor,
|
|
31
|
+
name,
|
|
32
|
+
levels = 5,
|
|
33
|
+
margin = defaultMargin,
|
|
34
|
+
animate = true,
|
|
35
|
+
tooltip,
|
|
36
|
+
}: RadarChartProps<T>) => {
|
|
37
|
+
const hasData = data && data.length > 0;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<ParentSize>
|
|
42
|
+
{hasData
|
|
43
|
+
? (parent) => (
|
|
44
|
+
<Chart<T>
|
|
45
|
+
name={name}
|
|
46
|
+
data={data}
|
|
47
|
+
width={parent.width}
|
|
48
|
+
height={parent.height}
|
|
49
|
+
margin={margin}
|
|
50
|
+
xAccessor={xAccessor}
|
|
51
|
+
yAccessor={yAccessor}
|
|
52
|
+
levels={levels}
|
|
53
|
+
tooltip={tooltip}
|
|
54
|
+
animate={animate}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
: () => <EmptyChart />}
|
|
58
|
+
</ParentSize>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type InnerRadarChartProps<T> = InnerChartProps & RadarChartProps<T>;
|
|
64
|
+
|
|
65
|
+
const Chart = <T,>({
|
|
66
|
+
width,
|
|
67
|
+
yAccessor,
|
|
68
|
+
data,
|
|
69
|
+
name,
|
|
70
|
+
levels = 5,
|
|
71
|
+
xAccessor,
|
|
72
|
+
height,
|
|
73
|
+
margin = defaultMargin,
|
|
74
|
+
tooltip,
|
|
75
|
+
animate = true,
|
|
76
|
+
}: InnerRadarChartProps<T>) => {
|
|
77
|
+
const theme = useTheme();
|
|
78
|
+
|
|
79
|
+
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
|
|
80
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
81
|
+
detectBounds: true,
|
|
82
|
+
scroll: true,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const innerWidth = width - margin.left - margin.right;
|
|
86
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
87
|
+
const radius = Math.min(innerWidth, innerHeight) / 2;
|
|
88
|
+
|
|
89
|
+
// Scale dot size based on chart size (5px for ~400px charts, minimum 3px, maximum 8px)
|
|
90
|
+
const dotRadius = Math.max(3, Math.min(8, radius / 40));
|
|
91
|
+
|
|
92
|
+
const radialScale = scaleLinear<number>({
|
|
93
|
+
domain: [360, 0],
|
|
94
|
+
range: [0, Math.PI * 2],
|
|
95
|
+
});
|
|
96
|
+
const yScale = scaleLinear<number>({
|
|
97
|
+
domain: [0, Math.max(...data.map(yAccessor))],
|
|
98
|
+
range: [0, radius],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const handleMouseOver = useCallback(
|
|
102
|
+
(event: MouseEvent, data: T) => {
|
|
103
|
+
const target = event.target as SVGElement;
|
|
104
|
+
const coords = localPoint(target.ownerSVGElement!, event);
|
|
105
|
+
|
|
106
|
+
showTooltip({
|
|
107
|
+
tooltipLeft: coords?.x,
|
|
108
|
+
tooltipTop: coords?.y,
|
|
109
|
+
tooltipData: tooltip?.accessor && tooltip.accessor(data),
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
[data, tooltip?.accessor],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const webs = genAngles(data.length);
|
|
116
|
+
const points = genPoints(data.length, radius);
|
|
117
|
+
const polygonPoints = genPolygonPoints(data, (d) => yScale(d) ?? 0, yAccessor);
|
|
118
|
+
|
|
119
|
+
return width < 10 ? null : (
|
|
120
|
+
<svg ref={containerRef} width={width} height={height}>
|
|
121
|
+
<rect fill={theme.colors.background} width={width} height={height} rx={14} />
|
|
122
|
+
<Group top={height / 2} left={width / 2}>
|
|
123
|
+
{[...new Array(levels)].map((_, i) => (
|
|
124
|
+
<LineRadial
|
|
125
|
+
key={`web-${i}`}
|
|
126
|
+
data={webs}
|
|
127
|
+
angle={(d) => radialScale(d.angle) ?? 0}
|
|
128
|
+
radius={((i + 1) * radius) / levels}
|
|
129
|
+
>
|
|
130
|
+
{({ path }) => {
|
|
131
|
+
const d = path(webs) || '';
|
|
132
|
+
return (
|
|
133
|
+
<motion.path
|
|
134
|
+
d={d}
|
|
135
|
+
fill="none"
|
|
136
|
+
stroke={theme.colors.backgroundAccent}
|
|
137
|
+
strokeWidth={2}
|
|
138
|
+
strokeOpacity={0.8}
|
|
139
|
+
strokeLinecap="round"
|
|
140
|
+
initial={animate ? { pathLength: 0, opacity: 0 } : { pathLength: 1, opacity: 0.8 }}
|
|
141
|
+
animate={{ pathLength: 1, opacity: 0.8 }}
|
|
142
|
+
transition={
|
|
143
|
+
animate
|
|
144
|
+
? {
|
|
145
|
+
duration: 0.6,
|
|
146
|
+
delay: i * 0.1,
|
|
147
|
+
ease: 'easeOut',
|
|
148
|
+
}
|
|
149
|
+
: { duration: 0 }
|
|
150
|
+
}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
}}
|
|
154
|
+
</LineRadial>
|
|
155
|
+
))}
|
|
156
|
+
{[...new Array(data.length)].map((_, i) => (
|
|
157
|
+
<>
|
|
158
|
+
<motion.line
|
|
159
|
+
key={`radar-line-${i}`}
|
|
160
|
+
x1={0}
|
|
161
|
+
y1={0}
|
|
162
|
+
stroke={theme.colors.backgroundAccent}
|
|
163
|
+
initial={animate ? { x2: 0, y2: 0 } : { x2: points[i].x, y2: points[i].y }}
|
|
164
|
+
animate={{ x2: points[i].x, y2: points[i].y }}
|
|
165
|
+
transition={
|
|
166
|
+
animate
|
|
167
|
+
? {
|
|
168
|
+
duration: 0.5,
|
|
169
|
+
delay: i * 0.05,
|
|
170
|
+
ease: 'easeOut',
|
|
171
|
+
}
|
|
172
|
+
: { duration: 0 }
|
|
173
|
+
}
|
|
174
|
+
/>
|
|
175
|
+
<Text
|
|
176
|
+
textAnchor="middle"
|
|
177
|
+
verticalAnchor="middle"
|
|
178
|
+
y={points[i].y}
|
|
179
|
+
x={points[i].x}
|
|
180
|
+
dy={points[i].y / 12}
|
|
181
|
+
dx={points[i].x / 12}
|
|
182
|
+
fill={theme.colors.text}
|
|
183
|
+
>
|
|
184
|
+
{xAccessor(data[i])}
|
|
185
|
+
</Text>
|
|
186
|
+
</>
|
|
187
|
+
))}
|
|
188
|
+
<polygon
|
|
189
|
+
points={polygonPoints.pointString}
|
|
190
|
+
fill={theme.colors.primary}
|
|
191
|
+
fillOpacity={0.5}
|
|
192
|
+
stroke={theme.colors.primary}
|
|
193
|
+
strokeWidth={2}
|
|
194
|
+
/>
|
|
195
|
+
{polygonPoints.points.map((point, i) => (
|
|
196
|
+
<g key={`radar-point-${i}`}>
|
|
197
|
+
{/* Visible dot */}
|
|
198
|
+
<circle cx={point.x} cy={point.y} r={dotRadius} fill={theme.colors.primary} />
|
|
199
|
+
{/* Invisible larger hit area for tooltip */}
|
|
200
|
+
<circle
|
|
201
|
+
cx={point.x}
|
|
202
|
+
cy={point.y}
|
|
203
|
+
r={dotRadius * 3}
|
|
204
|
+
fill="transparent"
|
|
205
|
+
style={{ cursor: 'pointer' }}
|
|
206
|
+
onMouseOut={hideTooltip}
|
|
207
|
+
onMouseOver={(e) => handleMouseOver(e, data[i])}
|
|
208
|
+
/>
|
|
209
|
+
</g>
|
|
210
|
+
))}
|
|
211
|
+
</Group>
|
|
212
|
+
{tooltipOpen && tooltipData && (
|
|
213
|
+
<TooltipInPortal
|
|
214
|
+
key={`tooltip-${name}`}
|
|
215
|
+
top={tooltipTop}
|
|
216
|
+
left={tooltipLeft}
|
|
217
|
+
style={getDefaultTooltipStyles(theme)}
|
|
218
|
+
>
|
|
219
|
+
{tooltipData}
|
|
220
|
+
</TooltipInPortal>
|
|
221
|
+
)}
|
|
222
|
+
</svg>
|
|
223
|
+
);
|
|
224
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { RadialBarChart, RadialBarChartProps } from '.';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/RadialBarChart',
|
|
9
|
+
component: RadialBarChart,
|
|
10
|
+
} as Meta<RadialBarChartProps<LetterFrequency>>;
|
|
11
|
+
|
|
12
|
+
const Wrapper = styled.div`
|
|
13
|
+
height: 500px;
|
|
14
|
+
width: 500px;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const Default: StoryFn<RadialBarChartProps<LetterFrequency>> = () => {
|
|
18
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
19
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
|
|
20
|
+
const alphabeticalSort = (a: LetterFrequency, b: LetterFrequency) => a.letter.localeCompare(b.letter);
|
|
21
|
+
const data = letterFrequency.sort(alphabeticalSort);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Wrapper>
|
|
25
|
+
<RadialBarChart<LetterFrequency>
|
|
26
|
+
name="LetterFrequency"
|
|
27
|
+
xAccessor={getLetter}
|
|
28
|
+
yAccessor={getLetterFrequency}
|
|
29
|
+
data={data}
|
|
30
|
+
tooltip={{
|
|
31
|
+
accessor: (d) => `Tooltip content for '${d.frequency}'`,
|
|
32
|
+
}}
|
|
33
|
+
animate={true}
|
|
34
|
+
/>
|
|
35
|
+
</Wrapper>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const WithoutAnimation: StoryFn<RadialBarChartProps<LetterFrequency>> = () => {
|
|
40
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
41
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
|
|
42
|
+
const alphabeticalSort = (a: LetterFrequency, b: LetterFrequency) => a.letter.localeCompare(b.letter);
|
|
43
|
+
const data = letterFrequency.sort(alphabeticalSort);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Wrapper>
|
|
47
|
+
<RadialBarChart<LetterFrequency>
|
|
48
|
+
name="LetterFrequency"
|
|
49
|
+
xAccessor={getLetter}
|
|
50
|
+
yAccessor={getLetterFrequency}
|
|
51
|
+
data={data}
|
|
52
|
+
tooltip={{
|
|
53
|
+
accessor: (d) => `Tooltip content for '${d.frequency}'`,
|
|
54
|
+
}}
|
|
55
|
+
animate={false}
|
|
56
|
+
/>
|
|
57
|
+
</Wrapper>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { MouseEvent, useCallback } from 'react';
|
|
2
|
+
import { arc } from '@visx/shape';
|
|
3
|
+
import { Group } from '@visx/group';
|
|
4
|
+
import { scaleBand, scaleRadial } from '@visx/scale';
|
|
5
|
+
import { shade } from 'polished';
|
|
6
|
+
import { motion } from 'framer-motion';
|
|
7
|
+
|
|
8
|
+
import { Margin, InnerChartProps, getDefaultTooltipStyles, TooltipConfig } from '../util';
|
|
9
|
+
import { useTheme } from '../../../hooks';
|
|
10
|
+
import { ParentSize } from '@visx/responsive';
|
|
11
|
+
import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
|
|
12
|
+
import localPoint from '@visx/event/lib/localPointGeneric';
|
|
13
|
+
import { useGradients } from '../useGradients';
|
|
14
|
+
import { EmptyChart } from '../EmptyChart';
|
|
15
|
+
|
|
16
|
+
const defaultMargin = { top: 20, right: 20, bottom: 20, left: 20 };
|
|
17
|
+
export interface RadialBarChartProps<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
data: T[];
|
|
20
|
+
margin?: Margin;
|
|
21
|
+
xAccessor: (d: T) => string;
|
|
22
|
+
yAccessor: (d: T) => number;
|
|
23
|
+
tooltip?: TooltipConfig<T>;
|
|
24
|
+
animate?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const RadialBarChart = <T,>({
|
|
28
|
+
xAccessor,
|
|
29
|
+
data,
|
|
30
|
+
margin,
|
|
31
|
+
yAccessor,
|
|
32
|
+
tooltip,
|
|
33
|
+
name,
|
|
34
|
+
animate = true,
|
|
35
|
+
}: RadialBarChartProps<T>) => {
|
|
36
|
+
const hasData = data.length > 0;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<ParentSize>
|
|
41
|
+
{hasData
|
|
42
|
+
? (parent) => (
|
|
43
|
+
<Chart<T>
|
|
44
|
+
name={name}
|
|
45
|
+
data={data}
|
|
46
|
+
width={parent.width}
|
|
47
|
+
height={parent.height}
|
|
48
|
+
margin={margin}
|
|
49
|
+
yAccessor={yAccessor}
|
|
50
|
+
xAccessor={xAccessor}
|
|
51
|
+
tooltip={tooltip}
|
|
52
|
+
animate={animate}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
: () => <EmptyChart />}
|
|
56
|
+
</ParentSize>
|
|
57
|
+
</>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type InnerRadialBarChartProps<T> = InnerChartProps & RadialBarChartProps<T>;
|
|
62
|
+
|
|
63
|
+
const Chart = <T,>({
|
|
64
|
+
name,
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
xAccessor,
|
|
68
|
+
yAccessor,
|
|
69
|
+
tooltip,
|
|
70
|
+
data,
|
|
71
|
+
margin = defaultMargin,
|
|
72
|
+
animate = true,
|
|
73
|
+
}: InnerRadialBarChartProps<T>) => {
|
|
74
|
+
const toDegrees = (x: number) => (x * 180) / Math.PI;
|
|
75
|
+
const theme = useTheme();
|
|
76
|
+
const gradients = useGradients(name);
|
|
77
|
+
|
|
78
|
+
const tooltipAccessor = tooltip?.accessor;
|
|
79
|
+
const showTooltipEnabled = tooltip?.enabled ?? true;
|
|
80
|
+
|
|
81
|
+
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
|
|
82
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
83
|
+
detectBounds: true,
|
|
84
|
+
scroll: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const handleMouseOver = useCallback(
|
|
88
|
+
(event: MouseEvent, data: T) => {
|
|
89
|
+
if (!showTooltipEnabled || !tooltipAccessor) return;
|
|
90
|
+
const target = event.target as SVGElement;
|
|
91
|
+
const coords = localPoint(target.ownerSVGElement!, event);
|
|
92
|
+
showTooltip({
|
|
93
|
+
tooltipLeft: coords?.x,
|
|
94
|
+
tooltipTop: coords?.y,
|
|
95
|
+
tooltipData: tooltipAccessor(data),
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
[data, tooltipAccessor, showTooltipEnabled],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// bounds
|
|
102
|
+
const xMax = width - margin.left - margin.right;
|
|
103
|
+
const yMax = height - margin.top - margin.bottom;
|
|
104
|
+
const radiusMax = Math.min(xMax, yMax) / 2;
|
|
105
|
+
const innerRadius = radiusMax / 3;
|
|
106
|
+
|
|
107
|
+
const centerX = margin.left + xMax / 2;
|
|
108
|
+
const centerY = margin.top + yMax / 2;
|
|
109
|
+
|
|
110
|
+
const xScale = scaleBand<string>({
|
|
111
|
+
range: [0, 2 * Math.PI],
|
|
112
|
+
domain: data.map(xAccessor),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const yScale = scaleRadial<number>({
|
|
116
|
+
range: [innerRadius, radiusMax],
|
|
117
|
+
domain: [0, Math.max(...data.map(yAccessor))],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return width < 10 ? null : (
|
|
121
|
+
<svg ref={containerRef} width={width} height={height}>
|
|
122
|
+
{gradients.background.gradient}
|
|
123
|
+
<rect width={width} height={height} fill="url(#radial-bars-green)" rx={14} />
|
|
124
|
+
<Group top={centerY} left={centerX}>
|
|
125
|
+
{data.map((d, index) => {
|
|
126
|
+
const xVal = xAccessor(d);
|
|
127
|
+
const startAngle = xScale(xVal) ?? 0;
|
|
128
|
+
const midAngle = startAngle + xScale.bandwidth() / 2;
|
|
129
|
+
const endAngle = startAngle + xScale.bandwidth();
|
|
130
|
+
const outerRadius = yScale(yAccessor(d)) ?? 0;
|
|
131
|
+
|
|
132
|
+
const arcGenerator = arc<{
|
|
133
|
+
innerRadius: number;
|
|
134
|
+
outerRadius: number;
|
|
135
|
+
startAngle: number;
|
|
136
|
+
endAngle: number;
|
|
137
|
+
}>({
|
|
138
|
+
cornerRadius: 3,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Generate path data for static path
|
|
142
|
+
const pathData = arcGenerator({
|
|
143
|
+
startAngle,
|
|
144
|
+
endAngle,
|
|
145
|
+
innerRadius,
|
|
146
|
+
outerRadius,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// convert polar coordinates to cartesian for drawing labels
|
|
150
|
+
const textRadius = outerRadius + 4;
|
|
151
|
+
const textX = textRadius * Math.cos(midAngle - Math.PI / 2);
|
|
152
|
+
const textY = textRadius * Math.sin(midAngle - Math.PI / 2);
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<g key={`bar-${xVal}`}>
|
|
156
|
+
<motion.path
|
|
157
|
+
d={pathData ?? undefined}
|
|
158
|
+
fill={shade(0.5, theme.colors.primary)}
|
|
159
|
+
stroke={theme.colors.primary}
|
|
160
|
+
onMouseOver={(e) => handleMouseOver(e, d)}
|
|
161
|
+
onMouseOut={hideTooltip}
|
|
162
|
+
onMouseLeave={hideTooltip}
|
|
163
|
+
style={{ cursor: 'pointer' }}
|
|
164
|
+
initial={
|
|
165
|
+
animate
|
|
166
|
+
? {
|
|
167
|
+
d:
|
|
168
|
+
arcGenerator({
|
|
169
|
+
startAngle,
|
|
170
|
+
endAngle,
|
|
171
|
+
innerRadius,
|
|
172
|
+
outerRadius: innerRadius,
|
|
173
|
+
}) ?? undefined,
|
|
174
|
+
}
|
|
175
|
+
: {
|
|
176
|
+
d: pathData ?? undefined,
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
animate={{
|
|
180
|
+
d: pathData ?? undefined,
|
|
181
|
+
}}
|
|
182
|
+
transition={
|
|
183
|
+
animate
|
|
184
|
+
? {
|
|
185
|
+
duration: 0.2,
|
|
186
|
+
delay: index * 0.1,
|
|
187
|
+
ease: 'easeOut',
|
|
188
|
+
}
|
|
189
|
+
: { duration: 0 }
|
|
190
|
+
}
|
|
191
|
+
/>
|
|
192
|
+
<motion.text
|
|
193
|
+
x={textX}
|
|
194
|
+
y={textY}
|
|
195
|
+
dominantBaseline="end"
|
|
196
|
+
textAnchor="middle"
|
|
197
|
+
fontSize={theme.fontSize.small}
|
|
198
|
+
fontWeight="bold"
|
|
199
|
+
fill={theme.colors.text}
|
|
200
|
+
transform={`rotate(${toDegrees(midAngle)} ${textX} ${textY})`}
|
|
201
|
+
initial={animate ? { opacity: 0 } : { opacity: 1 }}
|
|
202
|
+
animate={{ opacity: 1 }}
|
|
203
|
+
transition={
|
|
204
|
+
animate
|
|
205
|
+
? {
|
|
206
|
+
duration: 0.3,
|
|
207
|
+
delay: index * 0.1 + 0.3,
|
|
208
|
+
ease: 'easeOut',
|
|
209
|
+
}
|
|
210
|
+
: { duration: 0 }
|
|
211
|
+
}
|
|
212
|
+
>
|
|
213
|
+
{xVal}
|
|
214
|
+
</motion.text>
|
|
215
|
+
</g>
|
|
216
|
+
);
|
|
217
|
+
})}
|
|
218
|
+
</Group>
|
|
219
|
+
{tooltipOpen && tooltipData && (
|
|
220
|
+
<TooltipInPortal
|
|
221
|
+
key={`tooltip-${name}`}
|
|
222
|
+
top={tooltipTop}
|
|
223
|
+
left={tooltipLeft}
|
|
224
|
+
style={getDefaultTooltipStyles(theme)}
|
|
225
|
+
>
|
|
226
|
+
{tooltipData}
|
|
227
|
+
</TooltipInPortal>
|
|
228
|
+
)}
|
|
229
|
+
</svg>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import appleStock, { AppleStock } from '@visx/mock-data/lib/mocks/appleStock';
|
|
4
|
+
import { RadialLineChart, RadialLineChartProps } from '.';
|
|
5
|
+
import { styled } from '../../../styled';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/RadialLineChart',
|
|
9
|
+
component: RadialLineChart,
|
|
10
|
+
args: {
|
|
11
|
+
animate: true,
|
|
12
|
+
},
|
|
13
|
+
argTypes: {
|
|
14
|
+
animate: { control: 'boolean' },
|
|
15
|
+
},
|
|
16
|
+
} as Meta<RadialLineChartProps<AppleStock>>;
|
|
17
|
+
|
|
18
|
+
const Wrapper = styled.div`
|
|
19
|
+
height: 500px;
|
|
20
|
+
width: 500px;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export const Default: StoryFn<RadialLineChartProps<AppleStock>> = (args) => {
|
|
24
|
+
const getDate = (d: AppleStock) => new Date(d.date).valueOf();
|
|
25
|
+
const getStockValue = (d: AppleStock) => d.close;
|
|
26
|
+
const tooltipAccessor = (d: AppleStock) => {
|
|
27
|
+
const date = new Date(d.date).toLocaleDateString();
|
|
28
|
+
return `Date: ${date}\nClose: $${d.close.toFixed(2)}`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Wrapper>
|
|
33
|
+
<RadialLineChart<AppleStock>
|
|
34
|
+
{...args}
|
|
35
|
+
name="AppleStock"
|
|
36
|
+
xAccessor={getDate}
|
|
37
|
+
yAccessor={getStockValue}
|
|
38
|
+
data={appleStock}
|
|
39
|
+
tooltip={{ accessor: tooltipAccessor }}
|
|
40
|
+
/>
|
|
41
|
+
</Wrapper>
|
|
42
|
+
);
|
|
43
|
+
};
|