@takaro/lib-components 0.0.1
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 +76 -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 +170 -0
- package/src/components/actions/Button/Button.test.tsx +7 -0
- package/src/components/actions/Button/Button.test.tsx.snap +89 -0
- package/src/components/actions/Button/index.tsx +99 -0
- package/src/components/actions/Button/style.ts +148 -0
- package/src/components/actions/ContextMenu/ContextMenu.stories.tsx +40 -0
- package/src/components/actions/ContextMenu/Group.tsx +34 -0
- package/src/components/actions/ContextMenu/MenuItem.tsx +66 -0
- package/src/components/actions/ContextMenu/index.tsx +217 -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 +67 -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 +89 -0
- package/src/components/actions/Dropdown/index.tsx +22 -0
- package/src/components/actions/Dropdown/useDropdown.tsx +82 -0
- package/src/components/actions/DropdownButton/DropdownButton.stories.tsx +88 -0
- package/src/components/actions/DropdownButton/index.tsx +113 -0
- package/src/components/actions/IconButton/IconButton.stories.tsx +54 -0
- package/src/components/actions/IconButton/IconButton.test.tsx +7 -0
- package/src/components/actions/IconButton/IconButton.test.tsx.snap +46 -0
- package/src/components/actions/IconButton/index.tsx +40 -0
- package/src/components/actions/IconButton/style.ts +75 -0
- package/src/components/actions/ToggleButton/ToggleButton.stories.tsx +84 -0
- package/src/components/actions/ToggleButton/ToggleButton.tsx +48 -0
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +99 -0
- package/src/components/actions/ToggleButton/index.tsx +2 -0
- package/src/components/actions/ToggleButton/style.ts +76 -0
- package/src/components/actions/index.ts +16 -0
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +104 -0
- package/src/components/charts/AreaChart/index.tsx +379 -0
- package/src/components/charts/BarChart/BarChart.stories.tsx +32 -0
- package/src/components/charts/BarChart/index.tsx +287 -0
- package/src/components/charts/BrushHandle.tsx +21 -0
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +65 -0
- package/src/components/charts/GeoMercator/index.tsx +141 -0
- package/src/components/charts/GeoMercator/world.d.ts +1 -0
- package/src/components/charts/GeoMercator/world.json +99485 -0
- package/src/components/charts/Heatmap/Heatmap.stories.tsx +55 -0
- package/src/components/charts/Heatmap/index.tsx +228 -0
- package/src/components/charts/LineChart/LineChart.stories.tsx +37 -0
- package/src/components/charts/LineChart/index.tsx +233 -0
- package/src/components/charts/PieChart/PieChart.stories.tsx +43 -0
- package/src/components/charts/PieChart/index.tsx +163 -0
- package/src/components/charts/PointHighlight.tsx +49 -0
- package/src/components/charts/RadarChart/RadarChart.stories.tsx +38 -0
- package/src/components/charts/RadarChart/generators.ts +30 -0
- package/src/components/charts/RadarChart/index.tsx +175 -0
- package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +34 -0
- package/src/components/charts/RadialBarChart/index.tsx +165 -0
- package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +26 -0
- package/src/components/charts/RadialLineChart/index.tsx +141 -0
- package/src/components/charts/index.tsx +20 -0
- package/src/components/charts/useGradients.tsx +37 -0
- package/src/components/charts/util.ts +40 -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 +132 -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 +7 -0
- package/src/components/data/Chip/Chip.test.tsx.snap +50 -0
- package/src/components/data/Chip/index.tsx +76 -0
- package/src/components/data/Chip/style.ts +84 -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/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 +38 -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 +144 -0
- package/src/components/data/Drawer/DrawerBody.tsx +22 -0
- package/src/components/data/Drawer/DrawerContent.tsx +110 -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 +49 -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 +52 -0
- package/src/components/data/InfiniteScroll/InfiniteScroll.stories.tsx +33 -0
- package/src/components/data/InfiniteScroll/index.tsx +51 -0
- package/src/components/data/LinkCard/index.tsx +28 -0
- package/src/components/data/Stats/Stat.tsx +99 -0
- package/src/components/data/Stats/Stats.stories.tsx +72 -0
- package/src/components/data/Stats/context.tsx +11 -0
- package/src/components/data/Stats/index.tsx +50 -0
- package/src/components/data/Table/Table.stories.tsx +142 -0
- package/src/components/data/Table/index.tsx +365 -0
- package/src/components/data/Table/react-table.d.ts +11 -0
- package/src/components/data/Table/style.ts +75 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +161 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +207 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +89 -0
- package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +61 -0
- package/src/components/data/Table/subcomponents/Filter/field.tsx +129 -0
- package/src/components/data/Table/subcomponents/Filter/index.tsx +239 -0
- package/src/components/data/Table/subcomponents/Filter/style.ts +26 -0
- package/src/components/data/Table/subcomponents/Pagination/index.tsx +108 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +49 -0
- package/src/components/data/Table/subcomponents/index.ts +4 -0
- package/src/components/data/index.ts +28 -0
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +74 -0
- package/src/components/dialogs/Dialog/DialogBody.tsx +62 -0
- package/src/components/dialogs/Dialog/DialogContent.tsx +46 -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 +77 -0
- package/src/components/feedback/Alert/Alert.test.tsx +7 -0
- package/src/components/feedback/Alert/Alert.test.tsx.snap +146 -0
- package/src/components/feedback/Alert/index.tsx +109 -0
- package/src/components/feedback/Alert/style.ts +87 -0
- package/src/components/feedback/ErrorFallback/ErrorFallback.stories.tsx +10 -0
- package/src/components/feedback/ErrorFallback/index.tsx +48 -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/Loaders/Loaders.stories.tsx +28 -0
- package/src/components/feedback/Loaders/Loading.test.tsx +7 -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 +7 -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/index.ts +2 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.stories.tsx +21 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx +7 -0
- package/src/components/feedback/NetworkDetector/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 +14 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/index.tsx +79 -0
- package/src/components/feedback/Popover/Popover.stories.tsx +33 -0
- package/src/components/feedback/Popover/PopoverContent.tsx +43 -0
- package/src/components/feedback/Popover/PopoverContext.tsx +21 -0
- package/src/components/feedback/Popover/PopoverTrigger.tsx +43 -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 +103 -0
- package/src/components/feedback/QuestionTooltip/QuestionTooltip.stories.tsx +20 -0
- package/src/components/feedback/QuestionTooltip/index.tsx +36 -0
- package/src/components/feedback/Skeleton/Skeleton.stories.tsx +33 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx +7 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx.snap +35 -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 +50 -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 +79 -0
- package/src/components/feedback/index.ts +33 -0
- package/src/components/feedback/snacks/CookieConsent/index.tsx +122 -0
- package/src/components/feedback/snacks/CookieConsent/style.ts +100 -0
- package/src/components/feedback/snacks/Default/default.stories.tsx +72 -0
- package/src/components/feedback/snacks/Default/index.tsx +77 -0
- package/src/components/feedback/snacks/Default/style.ts +59 -0
- package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +46 -0
- package/src/components/feedback/snacks/Drawer/index.tsx +70 -0
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +70 -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 +124 -0
- package/src/components/inputs/CheckBox/Generic.tsx +96 -0
- package/src/components/inputs/CheckBox/index.tsx +4 -0
- package/src/components/inputs/CheckBox/style.ts +113 -0
- package/src/components/inputs/CodeField/CodeField.stories.tsx +87 -0
- package/src/components/inputs/CodeField/index.tsx +173 -0
- package/src/components/inputs/CodeField/style.ts +50 -0
- package/src/components/inputs/Date/DatePicker/Controlled.tsx +101 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +234 -0
- package/src/components/inputs/Date/DatePicker/Generic.tsx +253 -0
- package/src/components/inputs/Date/DatePicker/formats.tsx +32 -0
- package/src/components/inputs/Date/DatePicker/style.ts +43 -0
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +112 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +32 -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/QuickSelect/index.tsx +270 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/style.ts +40 -0
- package/src/components/inputs/Date/DateRangePicker/index.tsx +134 -0
- package/src/components/inputs/Date/DateRangePicker/style.ts +51 -0
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +150 -0
- package/src/components/inputs/Date/subcomponents/Calendar/style.ts +59 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +186 -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 +32 -0
- package/src/components/inputs/DurationField/Controlled.tsx +69 -0
- package/src/components/inputs/DurationField/Duration.stories.tsx +54 -0
- package/src/components/inputs/DurationField/Generic.tsx +200 -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 +211 -0
- package/src/components/inputs/FileField/Generic.tsx +131 -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 +61 -0
- package/src/components/inputs/RadioGroup/Controlled.tsx +46 -0
- package/src/components/inputs/RadioGroup/Generic.tsx +34 -0
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +116 -0
- package/src/components/inputs/RadioGroup/RadioItem.tsx +129 -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/Slider/Controlled.tsx +87 -0
- package/src/components/inputs/Slider/Generic.tsx +73 -0
- package/src/components/inputs/Slider/Slider.stories.tsx +101 -0
- package/src/components/inputs/Slider/handle.tsx +31 -0
- package/src/components/inputs/Slider/index.tsx +5 -0
- package/src/components/inputs/Slider/style.ts +140 -0
- package/src/components/inputs/Switch/Controlled.tsx +58 -0
- package/src/components/inputs/Switch/Generic.tsx +67 -0
- package/src/components/inputs/Switch/Switch.stories.tsx +91 -0
- package/src/components/inputs/Switch/index.ts +5 -0
- package/src/components/inputs/Switch/style.ts +56 -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 +56 -0
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +98 -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 +113 -0
- package/src/components/inputs/TextField/TextField.stories.tsx +196 -0
- package/src/components/inputs/TextField/index.ts +5 -0
- package/src/components/inputs/TextField/style.ts +97 -0
- package/src/components/inputs/TextField/util.ts +19 -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 +67 -0
- package/src/components/inputs/layout/Description.tsx +40 -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 +51 -0
- package/src/components/inputs/layout/index.ts +6 -0
- package/src/components/inputs/selects/SelectField/Controlled.tsx +130 -0
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +45 -0
- package/src/components/inputs/selects/SelectField/Generic/index.tsx +302 -0
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +253 -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 +100 -0
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +300 -0
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +260 -0
- package/src/components/inputs/selects/SelectQueryField/index.tsx +5 -0
- package/src/components/inputs/selects/SelectQueryField/style.ts +14 -0
- package/src/components/inputs/selects/SubComponents/Option.tsx +114 -0
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +16 -0
- package/src/components/inputs/selects/SubComponents/index.ts +10 -0
- package/src/components/inputs/selects/SubComponents/style.ts +39 -0
- package/src/components/inputs/selects/data.ts +123 -0
- package/src/components/inputs/selects/index.tsx +47 -0
- package/src/components/inputs/selects/sharedStyle.ts +78 -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 +45 -0
- package/src/components/navigation/HorizontalNav/index.tsx +40 -0
- package/src/components/navigation/HorizontalNav/style.ts +83 -0
- package/src/components/navigation/IconNav/IconNav.stories.tsx +46 -0
- package/src/components/navigation/IconNav/index.tsx +49 -0
- package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +89 -0
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +104 -0
- package/src/components/navigation/Steppers/SlimStepper/style.ts +86 -0
- package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +87 -0
- package/src/components/navigation/Steppers/Stepper/index.tsx +114 -0
- package/src/components/navigation/Steppers/Stepper/style.ts +105 -0
- package/src/components/navigation/Steppers/context.tsx +49 -0
- package/src/components/navigation/Steppers/reducer.ts +51 -0
- package/src/components/navigation/Steppers/stepStates.ts +5 -0
- package/src/components/navigation/Tabs/Content.tsx +36 -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 +65 -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 +16 -0
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +86 -0
- package/src/components/other/ActionMenu/index.tsx +55 -0
- package/src/components/other/ActionMenu/style.ts +48 -0
- package/src/components/other/ClipBoard/ClipBoard.stories.tsx +14 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx +7 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx.snap +70 -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 +115 -0
- package/src/components/other/Collapsible/Collapsible.stories.tsx +19 -0
- package/src/components/other/Collapsible/CollapsibleContent.tsx +22 -0
- package/src/components/other/Collapsible/CollapsibleContext.tsx +17 -0
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +67 -0
- package/src/components/other/Collapsible/index.tsx +21 -0
- package/src/components/other/Company/index.tsx +45 -0
- package/src/components/other/Company/style.ts +58 -0
- package/src/components/other/Empty/Empty.stories.tsx +24 -0
- package/src/components/other/Empty/Empty.test.tsx +7 -0
- package/src/components/other/Empty/Empty.test.tsx.snap +85 -0
- package/src/components/other/Empty/index.tsx +87 -0
- package/src/components/other/PermissionsGuard/PermissionsGuard.stories.tsx +54 -0
- package/src/components/other/PermissionsGuard/index.tsx +43 -0
- package/src/components/other/index.ts +19 -0
- package/src/components/visual/Card/Card.stories.tsx +19 -0
- package/src/components/visual/Card/index.tsx +49 -0
- package/src/components/visual/Divider/Divider.stories.tsx +19 -0
- package/src/components/visual/Divider/Divider.test.tsx +7 -0
- package/src/components/visual/Divider/Divider.test.tsx.snap +35 -0
- package/src/components/visual/Divider/index.tsx +85 -0
- package/src/components/visual/index.ts +5 -0
- package/src/errors/base.ts +11 -0
- package/src/errors/errors.ts +109 -0
- package/src/errors/index.ts +14 -0
- package/src/helpers/camelCaseToSpaces.ts +5 -0
- package/src/helpers/getInitials.ts +15 -0
- package/src/helpers/getSnackbarProvider.tsx +57 -0
- package/src/helpers/getTransition.ts +9 -0
- package/src/helpers/index.ts +5 -0
- package/src/helpers/makeData.ts +34 -0
- package/src/helpers/regexprs.ts +7 -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 +10 -0
- package/src/hooks/useLocalStorage.tsx +38 -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 +56 -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.stories.mdx +35 -0
- package/src/stories/Elevation.stories.mdx +56 -0
- package/src/stories/Introduction.stories.mdx +17 -0
- package/src/stories/Spacing.stories.mdx +25 -0
- package/src/styled/GlobalStyle.ts +207 -0
- package/src/styled/Snackbar.tsx +42 -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/elevation.ts +20 -0
- package/src/styled/index.ts +11 -0
- package/src/styled/spacing.ts +38 -0
- package/src/styled/theme.ts +87 -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 +31 -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 +19 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { MouseEvent, useCallback } 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 { shade } from 'polished';
|
|
10
|
+
|
|
11
|
+
import { useTheme } from '../../../hooks';
|
|
12
|
+
import { getChartColors, getDefaultTooltipStyles, InnerChartProps, Margin } from '../util';
|
|
13
|
+
|
|
14
|
+
type PieChartVariant = 'pie' | 'donut';
|
|
15
|
+
|
|
16
|
+
export interface PieChartProps<T> {
|
|
17
|
+
name: string;
|
|
18
|
+
data: T[];
|
|
19
|
+
variant: PieChartVariant;
|
|
20
|
+
margin?: Margin;
|
|
21
|
+
xAccessor: (d: T) => string;
|
|
22
|
+
yAccessor: (d: T) => number;
|
|
23
|
+
tooltipAccessor: (d: T) => string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
27
|
+
export const PieChart = <T,>({
|
|
28
|
+
data,
|
|
29
|
+
yAccessor,
|
|
30
|
+
xAccessor,
|
|
31
|
+
tooltipAccessor,
|
|
32
|
+
name,
|
|
33
|
+
margin = defaultMargin,
|
|
34
|
+
variant,
|
|
35
|
+
}: PieChartProps<T>) => {
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<ParentSize>
|
|
39
|
+
{(parent) => (
|
|
40
|
+
<Chart<T>
|
|
41
|
+
name={name}
|
|
42
|
+
data={data}
|
|
43
|
+
width={parent.width}
|
|
44
|
+
height={parent.height}
|
|
45
|
+
margin={margin}
|
|
46
|
+
variant={variant}
|
|
47
|
+
yAccessor={yAccessor}
|
|
48
|
+
xAccessor={xAccessor}
|
|
49
|
+
tooltipAccessor={tooltipAccessor}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
</ParentSize>
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type InnerPieChartProps<T> = InnerChartProps & PieChartProps<T>;
|
|
58
|
+
|
|
59
|
+
const Chart = <T,>({
|
|
60
|
+
width,
|
|
61
|
+
xAccessor,
|
|
62
|
+
yAccessor,
|
|
63
|
+
data,
|
|
64
|
+
name,
|
|
65
|
+
height,
|
|
66
|
+
variant,
|
|
67
|
+
tooltipAccessor,
|
|
68
|
+
margin = defaultMargin,
|
|
69
|
+
}: InnerPieChartProps<T>) => {
|
|
70
|
+
const theme = useTheme();
|
|
71
|
+
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
|
|
72
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
73
|
+
detectBounds: true,
|
|
74
|
+
scroll: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const innerWidth = width - margin.left - margin.right;
|
|
78
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
79
|
+
const radius = Math.min(innerWidth, innerHeight) / 2;
|
|
80
|
+
const centerX = innerWidth / 2;
|
|
81
|
+
const centerY = innerHeight / 2;
|
|
82
|
+
const donutThickness = 50;
|
|
83
|
+
|
|
84
|
+
const getArcColor = scaleOrdinal({
|
|
85
|
+
domain: data.map(xAccessor),
|
|
86
|
+
range: getChartColors(theme),
|
|
87
|
+
});
|
|
88
|
+
const pieSortValues = (a: number, b: number) => b - a;
|
|
89
|
+
|
|
90
|
+
const handleMouseOver = useCallback(
|
|
91
|
+
(event: MouseEvent, data: T) => {
|
|
92
|
+
const target = event.target as SVGElement;
|
|
93
|
+
const coords = localPoint(target.ownerSVGElement!, event);
|
|
94
|
+
|
|
95
|
+
showTooltip({
|
|
96
|
+
tooltipLeft: coords?.x,
|
|
97
|
+
tooltipTop: coords?.y,
|
|
98
|
+
tooltipData: tooltipAccessor(data),
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
[data, tooltipAccessor]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return width < 10 ? null : (
|
|
105
|
+
<svg ref={containerRef} id={name} width={width} height={height}>
|
|
106
|
+
<Group top={centerY + margin.top} left={centerX + margin.left}>
|
|
107
|
+
<Pie
|
|
108
|
+
data={data}
|
|
109
|
+
outerRadius={radius}
|
|
110
|
+
innerRadius={variant === 'donut' ? radius - donutThickness : 0}
|
|
111
|
+
cornerRadius={3}
|
|
112
|
+
padAngle={0.02}
|
|
113
|
+
pieSortValues={pieSortValues}
|
|
114
|
+
pieValue={yAccessor}
|
|
115
|
+
>
|
|
116
|
+
{(pie) => {
|
|
117
|
+
return pie.arcs.map((arc, index) => {
|
|
118
|
+
const [centroidX, centroidY] = pie.path.centroid(arc);
|
|
119
|
+
const hasSpaceForLabel = arc.endAngle - arc.startAngle >= 0.1;
|
|
120
|
+
const arcPath = pie.path(arc) ?? '';
|
|
121
|
+
const arcFill = getArcColor(xAccessor(arc.data));
|
|
122
|
+
return (
|
|
123
|
+
<g key={`arc-${arc.data}-${index}`}>
|
|
124
|
+
<path
|
|
125
|
+
d={arcPath}
|
|
126
|
+
fill={shade(0.5, arcFill)}
|
|
127
|
+
stroke={arcFill}
|
|
128
|
+
strokeWidth={1}
|
|
129
|
+
onMouseOut={hideTooltip}
|
|
130
|
+
onMouseOver={(e) => handleMouseOver(e, arc.data)}
|
|
131
|
+
/>
|
|
132
|
+
{hasSpaceForLabel && (
|
|
133
|
+
<text
|
|
134
|
+
x={centroidX}
|
|
135
|
+
y={centroidY}
|
|
136
|
+
dy=".33em"
|
|
137
|
+
fill="white"
|
|
138
|
+
fontSize={9}
|
|
139
|
+
textAnchor="middle"
|
|
140
|
+
pointerEvents="none"
|
|
141
|
+
>
|
|
142
|
+
{xAccessor(arc.data)}
|
|
143
|
+
</text>
|
|
144
|
+
)}
|
|
145
|
+
</g>
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
}}
|
|
149
|
+
</Pie>
|
|
150
|
+
</Group>
|
|
151
|
+
{tooltipOpen && tooltipData && (
|
|
152
|
+
<TooltipInPortal
|
|
153
|
+
key={`tooltip-${name}`}
|
|
154
|
+
top={tooltipTop}
|
|
155
|
+
left={tooltipLeft}
|
|
156
|
+
style={getDefaultTooltipStyles(theme)}
|
|
157
|
+
>
|
|
158
|
+
{tooltipData}
|
|
159
|
+
</TooltipInPortal>
|
|
160
|
+
)}
|
|
161
|
+
</svg>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
@@ -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: margin.top }}
|
|
21
|
+
to={{ x: tooltipLeft, y: yMax + margin.top }}
|
|
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,38 @@
|
|
|
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
|
+
} as Meta<RadarChartProps<LetterFrequency>>;
|
|
11
|
+
|
|
12
|
+
const Wrapper = styled.div`
|
|
13
|
+
height: 50vh;
|
|
14
|
+
width: 100%;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const Default: StoryFn<RadarChartProps<LetterFrequency>> = () => {
|
|
18
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
19
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency);
|
|
20
|
+
const tooltipAccessor = (d: LetterFrequency) => {
|
|
21
|
+
return `Tooltip content for '${getLetter(d)}' with frequency ${getLetterFrequency(d) * 100}% `;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// only show the first few letters
|
|
25
|
+
const data = letterFrequency.slice(2, 9);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Wrapper>
|
|
29
|
+
<RadarChart<LetterFrequency>
|
|
30
|
+
name="letterFrequency"
|
|
31
|
+
yAccessor={getLetterFrequency}
|
|
32
|
+
xAccessor={getLetter}
|
|
33
|
+
tooltipAccessor={tooltipAccessor}
|
|
34
|
+
data={data}
|
|
35
|
+
/>
|
|
36
|
+
</Wrapper>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { MouseEvent, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ParentSize } from '@visx/responsive';
|
|
4
|
+
import { Group } from '@visx/group';
|
|
5
|
+
import { Line, LineRadial } from '@visx/shape';
|
|
6
|
+
import { scaleLinear } from '@visx/scale';
|
|
7
|
+
import { useTooltipInPortal, useTooltip } from '@visx/tooltip';
|
|
8
|
+
import { Point } from '@visx/point';
|
|
9
|
+
import { localPoint } from '@visx/event';
|
|
10
|
+
import { Text } from '@visx/text';
|
|
11
|
+
|
|
12
|
+
import { getDefaultTooltipStyles, InnerChartProps, Margin } from '../util';
|
|
13
|
+
import { genAngles, genPoints, genPolygonPoints } from './generators';
|
|
14
|
+
import { useTheme } from '../../../hooks';
|
|
15
|
+
|
|
16
|
+
export interface RadarChartProps<T> {
|
|
17
|
+
name: string;
|
|
18
|
+
data: T[];
|
|
19
|
+
margin?: Margin;
|
|
20
|
+
xAccessor: (d: T) => string;
|
|
21
|
+
yAccessor: (d: T) => number;
|
|
22
|
+
tooltipAccessor: (d: T) => string;
|
|
23
|
+
levels?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
27
|
+
export const RadarChart = <T,>({
|
|
28
|
+
data,
|
|
29
|
+
xAccessor,
|
|
30
|
+
yAccessor,
|
|
31
|
+
tooltipAccessor,
|
|
32
|
+
name,
|
|
33
|
+
levels = 5,
|
|
34
|
+
margin = defaultMargin,
|
|
35
|
+
}: RadarChartProps<T>) => {
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<ParentSize>
|
|
39
|
+
{(parent) => (
|
|
40
|
+
<Chart<T>
|
|
41
|
+
name={name}
|
|
42
|
+
data={data}
|
|
43
|
+
width={parent.width}
|
|
44
|
+
height={parent.height}
|
|
45
|
+
margin={margin}
|
|
46
|
+
xAccessor={xAccessor}
|
|
47
|
+
yAccessor={yAccessor}
|
|
48
|
+
levels={levels}
|
|
49
|
+
tooltipAccessor={tooltipAccessor}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
</ParentSize>
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type InnerRadarChartProps<T> = InnerChartProps & RadarChartProps<T>;
|
|
58
|
+
|
|
59
|
+
const Chart = <T,>({
|
|
60
|
+
width,
|
|
61
|
+
yAccessor,
|
|
62
|
+
data,
|
|
63
|
+
name,
|
|
64
|
+
levels = 5,
|
|
65
|
+
xAccessor,
|
|
66
|
+
height,
|
|
67
|
+
margin = defaultMargin,
|
|
68
|
+
tooltipAccessor,
|
|
69
|
+
}: InnerRadarChartProps<T>) => {
|
|
70
|
+
const theme = useTheme();
|
|
71
|
+
|
|
72
|
+
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
|
|
73
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
74
|
+
detectBounds: true,
|
|
75
|
+
scroll: true,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const innerWidth = width - margin.left - margin.right;
|
|
79
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
80
|
+
const radius = Math.min(innerWidth, innerHeight) / 2;
|
|
81
|
+
|
|
82
|
+
const radialScale = scaleLinear<number>({
|
|
83
|
+
domain: [360, 0],
|
|
84
|
+
range: [0, Math.PI * 2],
|
|
85
|
+
});
|
|
86
|
+
const yScale = scaleLinear<number>({
|
|
87
|
+
domain: [0, Math.max(...data.map(yAccessor))],
|
|
88
|
+
range: [0, radius],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const handleMouseOver = useCallback(
|
|
92
|
+
(event: MouseEvent, data: T) => {
|
|
93
|
+
const target = event.target as SVGElement;
|
|
94
|
+
const coords = localPoint(target.ownerSVGElement!, event);
|
|
95
|
+
|
|
96
|
+
showTooltip({
|
|
97
|
+
tooltipLeft: coords?.x,
|
|
98
|
+
tooltipTop: coords?.y,
|
|
99
|
+
tooltipData: tooltipAccessor(data),
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
[data, tooltipAccessor]
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const webs = genAngles(data.length);
|
|
106
|
+
const points = genPoints(data.length, radius);
|
|
107
|
+
const polygonPoints = genPolygonPoints(data, (d) => yScale(d) ?? 0, yAccessor);
|
|
108
|
+
const zeroPoint = new Point({ x: 0, y: 0 });
|
|
109
|
+
|
|
110
|
+
return width < 10 ? null : (
|
|
111
|
+
<svg ref={containerRef} width={width} height={height}>
|
|
112
|
+
<rect fill={theme.colors.background} width={width} height={height} rx={14} />
|
|
113
|
+
<Group top={height / 2 - margin.top} left={width / 2}>
|
|
114
|
+
{[...new Array(levels)].map((_, i) => (
|
|
115
|
+
<LineRadial
|
|
116
|
+
key={`web-${i}`}
|
|
117
|
+
data={webs}
|
|
118
|
+
angle={(d) => radialScale(d.angle) ?? 0}
|
|
119
|
+
radius={((i + 1) * radius) / levels}
|
|
120
|
+
fill="none"
|
|
121
|
+
stroke={theme.colors.backgroundAccent}
|
|
122
|
+
strokeWidth={2}
|
|
123
|
+
strokeOpacity={0.8}
|
|
124
|
+
strokeLinecap="round"
|
|
125
|
+
/>
|
|
126
|
+
))}
|
|
127
|
+
{[...new Array(data.length)].map((_, i) => (
|
|
128
|
+
<>
|
|
129
|
+
<Line key={`radar-line-${i}`} from={zeroPoint} to={points[i]} stroke={theme.colors.backgroundAccent} />
|
|
130
|
+
<Text
|
|
131
|
+
textAnchor="middle"
|
|
132
|
+
verticalAnchor="middle"
|
|
133
|
+
y={points[i].y}
|
|
134
|
+
x={points[i].x}
|
|
135
|
+
dy={points[i].y / 12}
|
|
136
|
+
dx={points[i].x / 12}
|
|
137
|
+
fill={theme.colors.text}
|
|
138
|
+
>
|
|
139
|
+
{xAccessor(data[i])}
|
|
140
|
+
</Text>
|
|
141
|
+
</>
|
|
142
|
+
))}
|
|
143
|
+
<polygon
|
|
144
|
+
points={polygonPoints.pointString}
|
|
145
|
+
fill={theme.colors.primary}
|
|
146
|
+
fillOpacity={0.3}
|
|
147
|
+
stroke={theme.colors.primary}
|
|
148
|
+
strokeWidth={2}
|
|
149
|
+
/>
|
|
150
|
+
{polygonPoints.points.map((point, i) => (
|
|
151
|
+
<circle
|
|
152
|
+
key={`radar-point-${i}`}
|
|
153
|
+
cx={point.x}
|
|
154
|
+
cy={point.y}
|
|
155
|
+
onMouseOut={hideTooltip}
|
|
156
|
+
onMouseOver={(e) => handleMouseOver(e, data[i])}
|
|
157
|
+
r={5}
|
|
158
|
+
style={{ cursor: 'pointer' }}
|
|
159
|
+
fill={theme.colors.primary}
|
|
160
|
+
/>
|
|
161
|
+
))}
|
|
162
|
+
</Group>
|
|
163
|
+
{tooltipOpen && tooltipData && (
|
|
164
|
+
<TooltipInPortal
|
|
165
|
+
key={`tooltip-${name}`}
|
|
166
|
+
top={tooltipTop}
|
|
167
|
+
left={tooltipLeft}
|
|
168
|
+
style={getDefaultTooltipStyles(theme)}
|
|
169
|
+
>
|
|
170
|
+
{tooltipData}
|
|
171
|
+
</TooltipInPortal>
|
|
172
|
+
)}
|
|
173
|
+
</svg>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
tooltipAccessor={(d) => `Tooltip content for '${d.frequency}'`}
|
|
31
|
+
/>
|
|
32
|
+
</Wrapper>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
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 { Text } from '@visx/text';
|
|
6
|
+
import { shade } from 'polished';
|
|
7
|
+
|
|
8
|
+
import { Margin, InnerChartProps, getDefaultTooltipStyles } 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
|
+
|
|
15
|
+
export const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
16
|
+
export interface RadialBarChartProps<T> {
|
|
17
|
+
name: string;
|
|
18
|
+
data: T[];
|
|
19
|
+
margin?: Margin;
|
|
20
|
+
xAccessor: (d: T) => string;
|
|
21
|
+
yAccessor: (d: T) => number;
|
|
22
|
+
tooltipAccessor: (d: T) => string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const RadialBarChart = <T,>({
|
|
26
|
+
xAccessor,
|
|
27
|
+
data,
|
|
28
|
+
margin,
|
|
29
|
+
yAccessor,
|
|
30
|
+
tooltipAccessor,
|
|
31
|
+
name,
|
|
32
|
+
}: RadialBarChartProps<T>) => {
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<ParentSize>
|
|
36
|
+
{(parent) => (
|
|
37
|
+
<Chart<T>
|
|
38
|
+
name={name}
|
|
39
|
+
data={data}
|
|
40
|
+
width={parent.width}
|
|
41
|
+
height={parent.height}
|
|
42
|
+
margin={margin}
|
|
43
|
+
yAccessor={yAccessor}
|
|
44
|
+
xAccessor={xAccessor}
|
|
45
|
+
tooltipAccessor={tooltipAccessor}
|
|
46
|
+
/>
|
|
47
|
+
)}
|
|
48
|
+
</ParentSize>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type InnerRadialBarChartProps<T> = InnerChartProps & RadialBarChartProps<T>;
|
|
54
|
+
|
|
55
|
+
const Chart = <T,>({
|
|
56
|
+
name,
|
|
57
|
+
width,
|
|
58
|
+
height,
|
|
59
|
+
xAccessor,
|
|
60
|
+
yAccessor,
|
|
61
|
+
tooltipAccessor,
|
|
62
|
+
data,
|
|
63
|
+
margin = defaultMargin,
|
|
64
|
+
}: InnerRadialBarChartProps<T>) => {
|
|
65
|
+
const toDegrees = (x: number) => (x * 180) / Math.PI;
|
|
66
|
+
const theme = useTheme();
|
|
67
|
+
const gradients = useGradients(name);
|
|
68
|
+
|
|
69
|
+
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, hideTooltip, showTooltip } = useTooltip<string>();
|
|
70
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
71
|
+
detectBounds: true,
|
|
72
|
+
scroll: true,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const handleMouseOver = useCallback(
|
|
76
|
+
(event: MouseEvent, data: T) => {
|
|
77
|
+
const target = event.target as SVGElement;
|
|
78
|
+
const coords = localPoint(target.ownerSVGElement!, event);
|
|
79
|
+
showTooltip({
|
|
80
|
+
tooltipLeft: coords?.x,
|
|
81
|
+
tooltipTop: coords?.y,
|
|
82
|
+
tooltipData: tooltipAccessor(data),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
[data, tooltipAccessor]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// bounds
|
|
89
|
+
const xMax = width - margin.left - margin.right;
|
|
90
|
+
const yMax = height - margin.top - margin.bottom;
|
|
91
|
+
const radiusMax = Math.min(xMax, yMax) / 2;
|
|
92
|
+
const innerRadius = radiusMax / 3;
|
|
93
|
+
|
|
94
|
+
const xScale = scaleBand<string>({
|
|
95
|
+
range: [0, 2 * Math.PI],
|
|
96
|
+
domain: data.map(xAccessor),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const yScale = scaleRadial<number>({
|
|
100
|
+
range: [innerRadius, radiusMax],
|
|
101
|
+
domain: [0, Math.max(...data.map(yAccessor))],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return width < 10 ? null : (
|
|
105
|
+
<svg ref={containerRef} width={width} height={height}>
|
|
106
|
+
{gradients.background.gradient}
|
|
107
|
+
<rect width={width} height={height} fill="url(#radial-bars-green)" rx={14} />
|
|
108
|
+
<Group top={yMax / 2 + margin.top} left={xMax / 2 + margin.left}>
|
|
109
|
+
{data.map((d) => {
|
|
110
|
+
const xVal = xAccessor(d);
|
|
111
|
+
const startAngle = xScale(xVal) ?? 0;
|
|
112
|
+
const midAngle = startAngle + xScale.bandwidth() / 2;
|
|
113
|
+
const endAngle = startAngle + xScale.bandwidth();
|
|
114
|
+
const outerRadius = yScale(yAccessor(d)) ?? 0;
|
|
115
|
+
|
|
116
|
+
// convert polar coordinates to cartesian for drawing labels
|
|
117
|
+
const textRadius = outerRadius + 4;
|
|
118
|
+
const textX = textRadius * Math.cos(midAngle - Math.PI / 2);
|
|
119
|
+
const textY = textRadius * Math.sin(midAngle - Math.PI / 2);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<Arc
|
|
124
|
+
key={`bar-${xVal}`}
|
|
125
|
+
cornerRadius={3}
|
|
126
|
+
startAngle={startAngle}
|
|
127
|
+
endAngle={endAngle}
|
|
128
|
+
outerRadius={outerRadius}
|
|
129
|
+
innerRadius={innerRadius}
|
|
130
|
+
fill={shade(0.5, theme.colors.primary)}
|
|
131
|
+
stroke={theme.colors.primary}
|
|
132
|
+
onMouseOver={(e) => handleMouseOver(e, d)}
|
|
133
|
+
onMouseOut={hideTooltip}
|
|
134
|
+
onMouseLeave={hideTooltip}
|
|
135
|
+
style={{ cursor: 'pointer' }}
|
|
136
|
+
/>
|
|
137
|
+
<Text
|
|
138
|
+
x={textX}
|
|
139
|
+
y={textY}
|
|
140
|
+
dominantBaseline="end"
|
|
141
|
+
textAnchor="middle"
|
|
142
|
+
fontSize={theme.fontSize.small}
|
|
143
|
+
fontWeight="bold"
|
|
144
|
+
fill={theme.colors.text}
|
|
145
|
+
angle={toDegrees(midAngle)}
|
|
146
|
+
>
|
|
147
|
+
{xVal}
|
|
148
|
+
</Text>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
})}
|
|
152
|
+
</Group>
|
|
153
|
+
{tooltipOpen && tooltipData && (
|
|
154
|
+
<TooltipInPortal
|
|
155
|
+
key={`tooltip-${name}`}
|
|
156
|
+
top={tooltipTop}
|
|
157
|
+
left={tooltipLeft}
|
|
158
|
+
style={getDefaultTooltipStyles(theme)}
|
|
159
|
+
>
|
|
160
|
+
{tooltipData}
|
|
161
|
+
</TooltipInPortal>
|
|
162
|
+
)}
|
|
163
|
+
</svg>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
} as Meta<RadialLineChartProps<AppleStock>>;
|
|
11
|
+
|
|
12
|
+
const Wrapper = styled.div`
|
|
13
|
+
height: 500px;
|
|
14
|
+
width: 500px;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const Default: StoryFn<RadialLineChartProps<AppleStock>> = () => {
|
|
18
|
+
const getDate = (d: AppleStock) => new Date(d.date).valueOf();
|
|
19
|
+
const getStockValue = (d: AppleStock) => d.close;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Wrapper>
|
|
23
|
+
<RadialLineChart<AppleStock> name="AppleStock" xAccessor={getDate} yAccessor={getStockValue} data={appleStock} />
|
|
24
|
+
</Wrapper>
|
|
25
|
+
);
|
|
26
|
+
};
|