@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,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeatMap, HeatmapProps } from '.';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import { DateTime } from 'luxon';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/Heatmap',
|
|
9
|
+
component: HeatMap,
|
|
10
|
+
} as Meta<HeatmapProps<number>>;
|
|
11
|
+
|
|
12
|
+
const Wrapper = styled.div`
|
|
13
|
+
height: 250px;
|
|
14
|
+
width: 250px;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
interface Data {
|
|
18
|
+
timestamp: string;
|
|
19
|
+
value: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// this represents a month of a player's online status
|
|
23
|
+
const data: Data[] = Array.from({ length: 30 }, (_, i) => ({
|
|
24
|
+
timestamp: DateTime.local().minus({ days: i }).toISODate()!,
|
|
25
|
+
value: Math.random() > 0.5,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
export const Default: StoryFn<HeatmapProps<number>> = () => {
|
|
29
|
+
// Extract the day of the week from the timestamp (0 for Sunday, 6 for Saturday)
|
|
30
|
+
const yAccessor = (d: Data) => DateTime.fromISO(d.timestamp).weekday;
|
|
31
|
+
// Extract the week of the month from the timestamp
|
|
32
|
+
const xAccessor = (d: Data): number => Math.floor(DateTime.fromISO(d.timestamp).day / 7);
|
|
33
|
+
// Convert boolean value to 0 or 1 because the heatmap expects a number
|
|
34
|
+
const zAccessor = (d: Data) => (d.value ? 1 : 0);
|
|
35
|
+
|
|
36
|
+
const tooltipAccessor = (d: Data) => {
|
|
37
|
+
const date = DateTime.fromISO(d.timestamp);
|
|
38
|
+
// format: "Sun, 10 jan: online
|
|
39
|
+
return `${date.weekdayShort}, ${date.day} ${date.monthShort}: ${d.value ? 'online' : 'offline'}`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Wrapper>
|
|
44
|
+
<HeatMap<Data>
|
|
45
|
+
data={data}
|
|
46
|
+
xAccessor={xAccessor}
|
|
47
|
+
yAccessor={yAccessor}
|
|
48
|
+
zAccessor={zAccessor}
|
|
49
|
+
tooltipAccessor={tooltipAccessor}
|
|
50
|
+
variant="month"
|
|
51
|
+
name="online"
|
|
52
|
+
/>
|
|
53
|
+
</Wrapper>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { ParentSize } from '@visx/responsive';
|
|
2
|
+
import { scaleLinear } from '@visx/scale';
|
|
3
|
+
import { Group } from '@visx/group';
|
|
4
|
+
import { AxisTop, AxisLeft } from '@visx/axis';
|
|
5
|
+
import { HeatmapRect } from '@visx/heatmap';
|
|
6
|
+
import { useTooltipInPortal } from '@visx/tooltip';
|
|
7
|
+
import { scaleBand } from '@visx/scale';
|
|
8
|
+
|
|
9
|
+
import { InnerChartProps, Margin } from '../util';
|
|
10
|
+
import { useTheme } from '../../../hooks';
|
|
11
|
+
|
|
12
|
+
interface InnerBin {
|
|
13
|
+
bin: number;
|
|
14
|
+
count: number;
|
|
15
|
+
tooltip: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface OuterBin {
|
|
19
|
+
bin: number;
|
|
20
|
+
bins: InnerBin[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DATE_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
24
|
+
|
|
25
|
+
export interface HeatmapProps<T> {
|
|
26
|
+
name: string;
|
|
27
|
+
data: T[];
|
|
28
|
+
variant?: 'month';
|
|
29
|
+
margin?: Margin;
|
|
30
|
+
xAccessor: (d: T) => number;
|
|
31
|
+
yAccessor: (d: T) => number;
|
|
32
|
+
zAccessor: (d: T) => number;
|
|
33
|
+
tooltipAccessor: (d: T) => string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
37
|
+
export const HeatMap = <T,>({
|
|
38
|
+
data,
|
|
39
|
+
yAccessor,
|
|
40
|
+
xAccessor,
|
|
41
|
+
zAccessor,
|
|
42
|
+
variant,
|
|
43
|
+
tooltipAccessor,
|
|
44
|
+
name,
|
|
45
|
+
margin = defaultMargin,
|
|
46
|
+
}: HeatmapProps<T>) => {
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<ParentSize>
|
|
50
|
+
{(parent) => (
|
|
51
|
+
<Chart<T>
|
|
52
|
+
name={name}
|
|
53
|
+
data={data}
|
|
54
|
+
width={parent.width}
|
|
55
|
+
variant={variant}
|
|
56
|
+
height={parent.height}
|
|
57
|
+
margin={margin}
|
|
58
|
+
yAccessor={yAccessor}
|
|
59
|
+
xAccessor={xAccessor}
|
|
60
|
+
zAccessor={zAccessor}
|
|
61
|
+
tooltipAccessor={tooltipAccessor}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
</ParentSize>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type InnerHeatmapProps<T> = InnerChartProps & HeatmapProps<T>;
|
|
70
|
+
|
|
71
|
+
const Chart = <T,>({
|
|
72
|
+
data,
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
margin = defaultMargin,
|
|
76
|
+
xAccessor,
|
|
77
|
+
yAccessor,
|
|
78
|
+
zAccessor,
|
|
79
|
+
tooltipAccessor,
|
|
80
|
+
}: InnerHeatmapProps<T>) => {
|
|
81
|
+
const theme = useTheme();
|
|
82
|
+
|
|
83
|
+
const { containerRef } = useTooltipInPortal({
|
|
84
|
+
detectBounds: true,
|
|
85
|
+
scroll: true,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const colorMax = Math.max(...data.map(yAccessor));
|
|
89
|
+
|
|
90
|
+
const xScale = scaleBand<number>({
|
|
91
|
+
domain: [0, 1, 2, 3, 4], // 5 weeks in a month
|
|
92
|
+
range: [margin.left, width - margin.right],
|
|
93
|
+
});
|
|
94
|
+
const yScale = scaleBand<number>({
|
|
95
|
+
domain: [0, 1, 2, 3, 4, 5, 6], // 7 days of the week
|
|
96
|
+
range: [margin.top, height - margin.bottom],
|
|
97
|
+
});
|
|
98
|
+
const colorScale = scaleLinear<string>({
|
|
99
|
+
domain: [0, colorMax],
|
|
100
|
+
range: [theme.colors.primary, theme.colors.primary],
|
|
101
|
+
});
|
|
102
|
+
const opacityScale = scaleLinear<number>({
|
|
103
|
+
domain: [0, colorMax],
|
|
104
|
+
range: [0.1, 1],
|
|
105
|
+
});
|
|
106
|
+
const xAxisScale = scaleBand<number>({
|
|
107
|
+
domain: Array.from({ length: 5 }), // Adjust as needed for weeks in the month
|
|
108
|
+
range: [0, width - margin.left - margin.right],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const yAxisScale = scaleBand<string>({
|
|
112
|
+
domain: DATE_LABELS,
|
|
113
|
+
range: [0, height - margin.top - margin.bottom],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const transformedData = transformData(data, xAccessor, yAccessor, zAccessor, tooltipAccessor);
|
|
117
|
+
|
|
118
|
+
return width < 10 ? null : (
|
|
119
|
+
<svg ref={containerRef} width={width} height={height}>
|
|
120
|
+
<AxisTop
|
|
121
|
+
scale={xAxisScale}
|
|
122
|
+
top={margin.top}
|
|
123
|
+
left={margin.left}
|
|
124
|
+
tickLength={4}
|
|
125
|
+
tickStroke={theme.colors.backgroundAccent}
|
|
126
|
+
stroke={theme.colors.backgroundAccent}
|
|
127
|
+
tickLabelProps={() => ({
|
|
128
|
+
y: -7,
|
|
129
|
+
textAnchor: 'middle',
|
|
130
|
+
})}
|
|
131
|
+
/>
|
|
132
|
+
<AxisLeft
|
|
133
|
+
scale={yAxisScale}
|
|
134
|
+
left={margin.left}
|
|
135
|
+
orientation="left"
|
|
136
|
+
hideTicks
|
|
137
|
+
stroke={theme.colors.backgroundAccent}
|
|
138
|
+
tickLabelProps={(_value, index) => ({
|
|
139
|
+
textAnchor: 'end',
|
|
140
|
+
fontSize: theme.fontSize.tiny,
|
|
141
|
+
fill: index % 2 === 1 ? theme.colors.text : 'none', // Show label for even indices,
|
|
142
|
+
dy: '1.25rem',
|
|
143
|
+
})}
|
|
144
|
+
/>
|
|
145
|
+
<Group>
|
|
146
|
+
<HeatmapRect<OuterBin, InnerBin>
|
|
147
|
+
data={transformedData}
|
|
148
|
+
xScale={(d) => xScale(d) ?? 0}
|
|
149
|
+
yScale={(bin) => yScale(bin) ?? 0}
|
|
150
|
+
count={(bin) => bin.count}
|
|
151
|
+
bins={(bin) => bin.bins}
|
|
152
|
+
colorScale={colorScale}
|
|
153
|
+
opacityScale={opacityScale}
|
|
154
|
+
binWidth={xScale.bandwidth()}
|
|
155
|
+
binHeight={yScale.bandwidth()}
|
|
156
|
+
gap={1}
|
|
157
|
+
>
|
|
158
|
+
{(heatmap) =>
|
|
159
|
+
heatmap.map((heatmapBins) =>
|
|
160
|
+
heatmapBins.map((bin) => {
|
|
161
|
+
return (
|
|
162
|
+
<rect
|
|
163
|
+
key={`heatmap-rect-${bin.row}-${bin.column}`}
|
|
164
|
+
width={bin.width}
|
|
165
|
+
height={bin.height}
|
|
166
|
+
x={bin.x}
|
|
167
|
+
y={bin.y}
|
|
168
|
+
fill={bin.color}
|
|
169
|
+
fillOpacity={bin.opacity}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
})
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
</HeatmapRect>
|
|
176
|
+
</Group>
|
|
177
|
+
</svg>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// transforms data to the structure expected by HeatmapRect
|
|
182
|
+
// In our case, each bins will have a count of 1, since the data will already be aggregated
|
|
183
|
+
// example:
|
|
184
|
+
// [
|
|
185
|
+
// {
|
|
186
|
+
// bin: 0,
|
|
187
|
+
// bins: [
|
|
188
|
+
// { bin: 0, count: 0 },
|
|
189
|
+
// { bin: 4, count: 0 },
|
|
190
|
+
// ]
|
|
191
|
+
// },
|
|
192
|
+
// {
|
|
193
|
+
// bin: 1,
|
|
194
|
+
// bins: [
|
|
195
|
+
// { bin: 0, count: 1 },
|
|
196
|
+
// ]
|
|
197
|
+
// },
|
|
198
|
+
function transformData<T>(
|
|
199
|
+
data: T[],
|
|
200
|
+
xAccessor: (d: T) => number,
|
|
201
|
+
yAccessor: (d: T) => number,
|
|
202
|
+
zAccessor: (d: T) => number,
|
|
203
|
+
tooltipAccessor: (d: T) => string
|
|
204
|
+
): OuterBin[] {
|
|
205
|
+
const map = new Map<number, Map<number, { count: number; tooltip: string }>>();
|
|
206
|
+
|
|
207
|
+
data.forEach((d) => {
|
|
208
|
+
const xValue = xAccessor(d);
|
|
209
|
+
const yValue = yAccessor(d);
|
|
210
|
+
const zValue = zAccessor(d);
|
|
211
|
+
const tooltipValue = tooltipAccessor(d);
|
|
212
|
+
|
|
213
|
+
if (!map.has(xValue)) {
|
|
214
|
+
map.set(xValue, new Map<number, { count: number; tooltip: string }>());
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const innerMap = map.get(xValue)!;
|
|
218
|
+
innerMap.set(yValue, { count: zValue, tooltip: tooltipValue });
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Convert to the structure expected by HeatmapRect
|
|
222
|
+
const transformedData: OuterBin[] = Array.from(map, ([bin, innerBins]) => ({
|
|
223
|
+
bin,
|
|
224
|
+
bins: Array.from(innerBins, ([bin, { count, tooltip }]) => ({ bin, count, tooltip })),
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
return transformedData;
|
|
228
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { LineChart, LineChartProps } from '.';
|
|
5
|
+
import { styled } from '../../../styled';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/LineChart',
|
|
9
|
+
component: LineChart,
|
|
10
|
+
args: {
|
|
11
|
+
curveType: 'curveBasis',
|
|
12
|
+
},
|
|
13
|
+
} as Meta<LineChartProps<AppleStock>>;
|
|
14
|
+
|
|
15
|
+
const Wrapper = styled.div`
|
|
16
|
+
height: 500px;
|
|
17
|
+
width: 500px;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const Default: StoryFn<LineChartProps<AppleStock>> = (args) => {
|
|
21
|
+
const getDate = (d: AppleStock) => new Date(d.date);
|
|
22
|
+
const getStockValue = (d: AppleStock) => d.close;
|
|
23
|
+
const getTooltip = (d: AppleStock) => `Close: ${d.close}`;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Wrapper>
|
|
27
|
+
<LineChart<AppleStock>
|
|
28
|
+
name="AppleStock"
|
|
29
|
+
xAccessor={getDate}
|
|
30
|
+
yAccessor={getStockValue}
|
|
31
|
+
tooltipAccessor={getTooltip}
|
|
32
|
+
data={appleStock}
|
|
33
|
+
curveType={args.curveType}
|
|
34
|
+
/>
|
|
35
|
+
</Wrapper>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { bisector, extent, max } from '@visx/vendor/d3-array';
|
|
2
|
+
import * as allCurves from '@visx/curve';
|
|
3
|
+
import { Group } from '@visx/group';
|
|
4
|
+
import { LinePath } from '@visx/shape';
|
|
5
|
+
import { ParentSize } from '@visx/responsive';
|
|
6
|
+
import { scaleTime, scaleLinear } from '@visx/scale';
|
|
7
|
+
import { AxisBottom, AxisLeft } from '@visx/axis';
|
|
8
|
+
import { useTooltip, Tooltip, TooltipWithBounds } from '@visx/tooltip';
|
|
9
|
+
import { timeFormat } from '@visx/vendor/d3-time-format';
|
|
10
|
+
|
|
11
|
+
import { useTheme } from '../../../hooks';
|
|
12
|
+
import { useCallback, useMemo } from 'react';
|
|
13
|
+
import { Margin, ChartProps, InnerChartProps, getDefaultTooltipStyles } from '../util';
|
|
14
|
+
import { localPoint } from '@visx/event';
|
|
15
|
+
import { PointHighlight } from '../PointHighlight';
|
|
16
|
+
|
|
17
|
+
const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
18
|
+
const defaultShowAxisX = true;
|
|
19
|
+
const defaultShowAxisY = true;
|
|
20
|
+
|
|
21
|
+
type CurveType = keyof typeof allCurves;
|
|
22
|
+
// eslint-disable-next-line quotes
|
|
23
|
+
const formatDate = timeFormat("%b %d, '%y");
|
|
24
|
+
|
|
25
|
+
export interface LineChartProps<T> extends ChartProps {
|
|
26
|
+
data: T[];
|
|
27
|
+
xAccessor: (d: T) => Date;
|
|
28
|
+
yAccessor: (d: T) => number;
|
|
29
|
+
tooltipAccessor?: (d: T) => string;
|
|
30
|
+
margin?: Margin;
|
|
31
|
+
curveType?: CurveType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const LineChart = <T,>({
|
|
35
|
+
data,
|
|
36
|
+
xAccessor,
|
|
37
|
+
yAccessor,
|
|
38
|
+
tooltipAccessor,
|
|
39
|
+
margin = defaultMargin,
|
|
40
|
+
name,
|
|
41
|
+
axisYLabel,
|
|
42
|
+
axisXLabel,
|
|
43
|
+
showGrid,
|
|
44
|
+
showAxisX = defaultShowAxisX,
|
|
45
|
+
showAxisY = defaultShowAxisY,
|
|
46
|
+
curveType = 'curveBasis',
|
|
47
|
+
}: LineChartProps<T>) => {
|
|
48
|
+
if (!data || data.length === 0) return null;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ParentSize>
|
|
52
|
+
{(parent) => (
|
|
53
|
+
<Chart<T>
|
|
54
|
+
name={name}
|
|
55
|
+
xAccessor={xAccessor}
|
|
56
|
+
yAccessor={yAccessor}
|
|
57
|
+
tooltipAccessor={tooltipAccessor}
|
|
58
|
+
data={data}
|
|
59
|
+
width={parent.width}
|
|
60
|
+
height={parent.height}
|
|
61
|
+
showGrid={showGrid}
|
|
62
|
+
margin={margin}
|
|
63
|
+
axisYLabel={axisYLabel}
|
|
64
|
+
axisXLabel={axisXLabel}
|
|
65
|
+
showAxisX={showAxisX}
|
|
66
|
+
showAxisY={showAxisY}
|
|
67
|
+
curveType={curveType}
|
|
68
|
+
/>
|
|
69
|
+
)}
|
|
70
|
+
</ParentSize>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
type InnerLineChartProps<T> = InnerChartProps & LineChartProps<T>;
|
|
75
|
+
|
|
76
|
+
const Chart = <T,>({
|
|
77
|
+
width,
|
|
78
|
+
height,
|
|
79
|
+
name,
|
|
80
|
+
curveType = 'curveBasis',
|
|
81
|
+
data,
|
|
82
|
+
xAccessor,
|
|
83
|
+
yAccessor,
|
|
84
|
+
margin = defaultMargin,
|
|
85
|
+
tooltipAccessor,
|
|
86
|
+
showAxisX,
|
|
87
|
+
showAxisY,
|
|
88
|
+
axisYLabel,
|
|
89
|
+
axisXLabel,
|
|
90
|
+
}: InnerLineChartProps<T>) => {
|
|
91
|
+
const theme = useTheme();
|
|
92
|
+
|
|
93
|
+
const bottomAxisHeight = showAxisX ? 25 : 0;
|
|
94
|
+
const leftAxisWidth = showAxisX ? 25 : 0;
|
|
95
|
+
const innerWidth = width - margin.left - margin.right - leftAxisWidth;
|
|
96
|
+
const innerHeight = height - margin.top - margin.bottom - bottomAxisHeight;
|
|
97
|
+
|
|
98
|
+
const { hideTooltip, showTooltip, tooltipData, tooltipLeft = 0, tooltipTop = 0 } = useTooltip<T>();
|
|
99
|
+
|
|
100
|
+
const xScale = useMemo(
|
|
101
|
+
() =>
|
|
102
|
+
scaleTime<number>({
|
|
103
|
+
range: [margin.left, innerWidth],
|
|
104
|
+
domain: extent(data, xAccessor) as [Date, Date],
|
|
105
|
+
}),
|
|
106
|
+
[innerWidth]
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const yScale = useMemo(
|
|
110
|
+
() =>
|
|
111
|
+
scaleLinear<number>({
|
|
112
|
+
range: [innerHeight, margin.bottom],
|
|
113
|
+
domain: [0, max(data, yAccessor) as number],
|
|
114
|
+
}),
|
|
115
|
+
[innerHeight]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const handleTooltip = useCallback(
|
|
119
|
+
(event: React.TouchEvent<SVGElement> | React.MouseEvent<SVGElement>) => {
|
|
120
|
+
const { x } = localPoint(event) || { x: 0 };
|
|
121
|
+
const x0 = xScale.invert(x - margin.left);
|
|
122
|
+
let index = bisector<T, Date>(xAccessor).left(data, x0);
|
|
123
|
+
|
|
124
|
+
// Clamp the index to ensure it's within the range of data points
|
|
125
|
+
index = Math.min(data.length - 1, Math.max(0, index));
|
|
126
|
+
|
|
127
|
+
const d = data[index];
|
|
128
|
+
const tooltipX = xScale(xAccessor(d));
|
|
129
|
+
const tooltipY = yScale(yAccessor(d));
|
|
130
|
+
|
|
131
|
+
showTooltip({
|
|
132
|
+
tooltipData: d,
|
|
133
|
+
tooltipLeft: tooltipX,
|
|
134
|
+
tooltipTop: tooltipY,
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
[yScale, xScale, data, yAccessor, xAccessor, width, height]
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return width === 10 ? null : (
|
|
141
|
+
<>
|
|
142
|
+
<svg width={width} height={height}>
|
|
143
|
+
<rect width={width} height={height} fill={theme.colors.background} rx={14} ry={14} />
|
|
144
|
+
<Group top={margin.top} left={margin.left}>
|
|
145
|
+
<rect
|
|
146
|
+
x={margin.left}
|
|
147
|
+
width={innerWidth - margin.left - margin.right}
|
|
148
|
+
height={innerHeight}
|
|
149
|
+
fill="transparent"
|
|
150
|
+
onTouchStart={handleTooltip}
|
|
151
|
+
onTouchMove={handleTooltip}
|
|
152
|
+
onMouseMove={handleTooltip}
|
|
153
|
+
onMouseLeave={hideTooltip}
|
|
154
|
+
/>
|
|
155
|
+
<LinePath<T>
|
|
156
|
+
curve={allCurves[curveType]}
|
|
157
|
+
data={data}
|
|
158
|
+
x={(d) => xScale(xAccessor(d)) ?? 0}
|
|
159
|
+
y={(d) => yScale(yAccessor(d)) ?? 0}
|
|
160
|
+
stroke={theme.colors.primary}
|
|
161
|
+
strokeWidth={1.2}
|
|
162
|
+
strokeOpacity={0.6}
|
|
163
|
+
shapeRendering="geometricPrecision"
|
|
164
|
+
/>
|
|
165
|
+
</Group>
|
|
166
|
+
{tooltipData && (
|
|
167
|
+
<PointHighlight margin={margin} tooltipTop={tooltipTop} tooltipLeft={tooltipLeft} yMax={innerHeight} />
|
|
168
|
+
)}
|
|
169
|
+
{showAxisY && (
|
|
170
|
+
<AxisLeft
|
|
171
|
+
top={margin.top}
|
|
172
|
+
left={margin.left + margin.left}
|
|
173
|
+
strokeWidth={1}
|
|
174
|
+
hideZero
|
|
175
|
+
stroke={theme.colors.backgroundAlt}
|
|
176
|
+
labelOffset={42}
|
|
177
|
+
tickStroke={theme.colors.backgroundAlt}
|
|
178
|
+
tickLabelProps={{
|
|
179
|
+
fill: theme.colors.text,
|
|
180
|
+
fontSize: theme.fontSize.small,
|
|
181
|
+
textAnchor: 'end',
|
|
182
|
+
}}
|
|
183
|
+
scale={yScale}
|
|
184
|
+
label={axisYLabel}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
{showAxisX && (
|
|
188
|
+
<AxisBottom
|
|
189
|
+
top={innerHeight + margin.top}
|
|
190
|
+
left={margin.left}
|
|
191
|
+
strokeWidth={1}
|
|
192
|
+
stroke={theme.colors.backgroundAlt}
|
|
193
|
+
hideZero
|
|
194
|
+
tickLabelProps={{
|
|
195
|
+
fill: theme.colors.text,
|
|
196
|
+
fontSize: theme.fontSize.small,
|
|
197
|
+
textAnchor: 'middle',
|
|
198
|
+
}}
|
|
199
|
+
labelProps={{
|
|
200
|
+
fill: theme.colors.textAlt,
|
|
201
|
+
}}
|
|
202
|
+
scale={xScale}
|
|
203
|
+
label={axisXLabel}
|
|
204
|
+
/>
|
|
205
|
+
)}
|
|
206
|
+
</svg>
|
|
207
|
+
{tooltipData && (
|
|
208
|
+
<div>
|
|
209
|
+
<TooltipWithBounds
|
|
210
|
+
key={`${name}-tooltip`}
|
|
211
|
+
top={tooltipTop - margin.top}
|
|
212
|
+
left={tooltipLeft + margin.left}
|
|
213
|
+
style={getDefaultTooltipStyles(theme)}
|
|
214
|
+
>
|
|
215
|
+
{tooltipAccessor ? tooltipAccessor(tooltipData) : yAccessor(tooltipData)}
|
|
216
|
+
</TooltipWithBounds>
|
|
217
|
+
<Tooltip
|
|
218
|
+
top={innerHeight + margin.top - 14}
|
|
219
|
+
left={tooltipLeft + margin.left}
|
|
220
|
+
style={{
|
|
221
|
+
...getDefaultTooltipStyles(theme),
|
|
222
|
+
minWidth: 72,
|
|
223
|
+
textAlign: 'center',
|
|
224
|
+
transform: 'translateX(-50%)',
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{formatDate(xAccessor(tooltipData))}
|
|
228
|
+
</Tooltip>
|
|
229
|
+
</div>
|
|
230
|
+
)}
|
|
231
|
+
</>
|
|
232
|
+
);
|
|
233
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { PieChart, PieChartProps } from '.';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/PieChart',
|
|
9
|
+
component: PieChart,
|
|
10
|
+
args: {
|
|
11
|
+
variant: 'pie',
|
|
12
|
+
},
|
|
13
|
+
} as Meta<PieChartProps<LetterFrequency>>;
|
|
14
|
+
|
|
15
|
+
const Wrapper = styled.div`
|
|
16
|
+
height: 50vh;
|
|
17
|
+
width: 100%;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const Default: StoryFn<PieChartProps<LetterFrequency>> = (args) => {
|
|
21
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
22
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
|
|
23
|
+
|
|
24
|
+
const tooltipAccessor = (d: LetterFrequency) => {
|
|
25
|
+
return `Tooltip content for '${getLetter(d)}' with frequency ${getLetterFrequency(d)}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// only show the first 5 letters
|
|
29
|
+
letterFrequency.length = 6;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Wrapper>
|
|
33
|
+
<PieChart<LetterFrequency>
|
|
34
|
+
name="letterFrequency"
|
|
35
|
+
xAccessor={getLetter}
|
|
36
|
+
yAccessor={getLetterFrequency}
|
|
37
|
+
tooltipAccessor={tooltipAccessor}
|
|
38
|
+
data={letterFrequency}
|
|
39
|
+
variant={args.variant}
|
|
40
|
+
/>
|
|
41
|
+
</Wrapper>
|
|
42
|
+
);
|
|
43
|
+
};
|