@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,379 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ParentSize } from '@visx/responsive';
|
|
4
|
+
import { GridColumns } from '@visx/grid';
|
|
5
|
+
import { Group } from '@visx/group';
|
|
6
|
+
import { AreaClosed, Bar } from '@visx/shape';
|
|
7
|
+
import { max, extent } from '@visx/vendor/d3-array';
|
|
8
|
+
import { scaleTime, scaleLinear } from '@visx/scale';
|
|
9
|
+
import { AxisBottom, AxisLeft } from '@visx/axis';
|
|
10
|
+
import { curveMonotoneX } from '@visx/curve';
|
|
11
|
+
import { localPoint } from '@visx/event';
|
|
12
|
+
import { useTooltip, Tooltip, TooltipWithBounds } from '@visx/tooltip';
|
|
13
|
+
import { timeFormat } from '@visx/vendor/d3-time-format';
|
|
14
|
+
import { PatternLines } from '@visx/pattern';
|
|
15
|
+
import { Brush } from '@visx/brush';
|
|
16
|
+
import { Bounds } from '@visx/brush/lib/types';
|
|
17
|
+
import { bisector } from '@visx/vendor/d3-array';
|
|
18
|
+
|
|
19
|
+
import { useTheme } from '../../../hooks';
|
|
20
|
+
import { useGradients } from '../useGradients';
|
|
21
|
+
import { Margin, ChartProps, InnerChartProps, getDefaultTooltipStyles } from '../util';
|
|
22
|
+
import { BrushHandle } from '../BrushHandle';
|
|
23
|
+
import { PointHighlight } from '../PointHighlight';
|
|
24
|
+
|
|
25
|
+
export interface AreaChartProps<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
|
+
showBrush?: boolean;
|
|
32
|
+
brushMargin?: Margin;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line quotes
|
|
36
|
+
const formatDate = timeFormat("%b %d, '%y");
|
|
37
|
+
|
|
38
|
+
const defaultMargin = { top: 20, left: 50, bottom: 20, right: 5 };
|
|
39
|
+
const defaultBrushMargin = { top: 10, bottom: 15, left: 50, right: 5 };
|
|
40
|
+
const defaultShowAxisX = true;
|
|
41
|
+
const defaultShowAxisY = true;
|
|
42
|
+
const defaultShowGrid = true;
|
|
43
|
+
|
|
44
|
+
export const AreaChart = <T,>({
|
|
45
|
+
data,
|
|
46
|
+
xAccessor,
|
|
47
|
+
yAccessor,
|
|
48
|
+
tooltipAccessor,
|
|
49
|
+
margin = defaultMargin,
|
|
50
|
+
showGrid = defaultShowGrid,
|
|
51
|
+
showBrush = false,
|
|
52
|
+
brushMargin = defaultBrushMargin,
|
|
53
|
+
name,
|
|
54
|
+
showAxisX = defaultShowAxisX,
|
|
55
|
+
showAxisY = defaultShowAxisY,
|
|
56
|
+
axisXLabel,
|
|
57
|
+
axisYLabel,
|
|
58
|
+
}: AreaChartProps<T>) => {
|
|
59
|
+
// TODO: handle empty data
|
|
60
|
+
if (!data || data.length === 0) return null;
|
|
61
|
+
|
|
62
|
+
// TODO: handle loading state
|
|
63
|
+
return (
|
|
64
|
+
<ParentSize>
|
|
65
|
+
{(parent) => (
|
|
66
|
+
<Chart<T>
|
|
67
|
+
name={name}
|
|
68
|
+
xAccessor={xAccessor}
|
|
69
|
+
yAccessor={yAccessor}
|
|
70
|
+
tooltipAccessor={tooltipAccessor}
|
|
71
|
+
data={data}
|
|
72
|
+
width={parent.width}
|
|
73
|
+
height={parent.height}
|
|
74
|
+
brushMargin={brushMargin}
|
|
75
|
+
showBrush={showBrush}
|
|
76
|
+
showGrid={showGrid}
|
|
77
|
+
margin={margin}
|
|
78
|
+
axisYLabel={axisYLabel}
|
|
79
|
+
axisXLabel={axisXLabel}
|
|
80
|
+
showAxisX={showAxisX}
|
|
81
|
+
showAxisY={showAxisY}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
</ParentSize>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
type InnerAreaChartProps<T> = InnerChartProps & AreaChartProps<T>;
|
|
89
|
+
|
|
90
|
+
const Chart = <T,>({
|
|
91
|
+
data,
|
|
92
|
+
xAccessor,
|
|
93
|
+
yAccessor,
|
|
94
|
+
tooltipAccessor,
|
|
95
|
+
width,
|
|
96
|
+
height,
|
|
97
|
+
margin = defaultMargin,
|
|
98
|
+
showGrid = defaultShowGrid,
|
|
99
|
+
showBrush = false,
|
|
100
|
+
brushMargin = defaultBrushMargin,
|
|
101
|
+
name,
|
|
102
|
+
showAxisX = defaultShowAxisX,
|
|
103
|
+
showAxisY = defaultShowAxisY,
|
|
104
|
+
axisYLabel,
|
|
105
|
+
axisXLabel,
|
|
106
|
+
}: InnerAreaChartProps<T>) => {
|
|
107
|
+
const PATTERN_ID = `${name}-brush_pattern`;
|
|
108
|
+
const theme = useTheme();
|
|
109
|
+
const gradients = useGradients(name);
|
|
110
|
+
|
|
111
|
+
const brushRef = useRef(null);
|
|
112
|
+
const { hideTooltip, showTooltip, tooltipData, tooltipLeft = 0, tooltipTop = 0 } = useTooltip<T>();
|
|
113
|
+
const [filteredData, setFilteredData] = useState<T[]>(data);
|
|
114
|
+
|
|
115
|
+
const tickFormatDate = (val: Date | { valueOf(): number }) => {
|
|
116
|
+
let date: Date;
|
|
117
|
+
|
|
118
|
+
if (val instanceof Date) {
|
|
119
|
+
date = val;
|
|
120
|
+
} else {
|
|
121
|
+
// 'val' is either a number or an object with a 'valueOf()' method.
|
|
122
|
+
date = new Date(val.valueOf());
|
|
123
|
+
}
|
|
124
|
+
return formatDate(date);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const chartSeparation = 15;
|
|
128
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
129
|
+
const topChartBottomMargin = chartSeparation + 10;
|
|
130
|
+
const topChartHeight = showBrush ? 0.8 * innerHeight - topChartBottomMargin : innerHeight;
|
|
131
|
+
const bottomChartHeight = innerHeight - topChartHeight - chartSeparation;
|
|
132
|
+
|
|
133
|
+
// bounds
|
|
134
|
+
const xMax = Math.max(width - margin.left - margin.right, 0);
|
|
135
|
+
const yMax = Math.max(topChartHeight - margin.bottom, 0);
|
|
136
|
+
|
|
137
|
+
const xBrushMax = Math.max(width - brushMargin.left - brushMargin.right, 0);
|
|
138
|
+
const yBrushMax = Math.max(bottomChartHeight - brushMargin.top - brushMargin.bottom, 0);
|
|
139
|
+
|
|
140
|
+
const xScale = useMemo(
|
|
141
|
+
() =>
|
|
142
|
+
scaleTime<number>({
|
|
143
|
+
range: [0, xMax],
|
|
144
|
+
domain: extent(filteredData, xAccessor) as [Date, Date],
|
|
145
|
+
}),
|
|
146
|
+
[xMax, filteredData]
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const yScale = useMemo(
|
|
150
|
+
() =>
|
|
151
|
+
scaleLinear({
|
|
152
|
+
range: [yMax, 0],
|
|
153
|
+
domain: [0, max(filteredData, yAccessor) || 0],
|
|
154
|
+
nice: true,
|
|
155
|
+
}),
|
|
156
|
+
[yMax, filteredData]
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const xBrushScale = useMemo(
|
|
160
|
+
() =>
|
|
161
|
+
scaleTime<number>({
|
|
162
|
+
range: [0, xBrushMax],
|
|
163
|
+
domain: extent(data, xAccessor) as [Date, Date],
|
|
164
|
+
}),
|
|
165
|
+
[xBrushMax]
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const yBrushScale = useMemo(
|
|
169
|
+
() =>
|
|
170
|
+
scaleLinear({
|
|
171
|
+
range: [yBrushMax, 0],
|
|
172
|
+
domain: [0, max(data, yAccessor) || 0],
|
|
173
|
+
nice: true,
|
|
174
|
+
}),
|
|
175
|
+
[yBrushMax]
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const initialBrushPosition = useMemo(
|
|
179
|
+
() => ({
|
|
180
|
+
start: { x: xBrushScale(xAccessor(data[0])) },
|
|
181
|
+
end: { x: xBrushScale(xAccessor(data[data.length - 1])) },
|
|
182
|
+
}),
|
|
183
|
+
[xBrushScale]
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const onBrushChange = (domain: Bounds | null) => {
|
|
187
|
+
if (!domain) return;
|
|
188
|
+
const { x0, x1, y0, y1 } = domain;
|
|
189
|
+
const filtered = data.filter((d) => {
|
|
190
|
+
const x = xAccessor(d).getTime();
|
|
191
|
+
const y = yAccessor(d);
|
|
192
|
+
return x > x0 && x < x1 && y > y0 && y < y1;
|
|
193
|
+
});
|
|
194
|
+
setFilteredData(filtered);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const handleTooltip = useCallback(
|
|
198
|
+
(event: React.TouchEvent<SVGRectElement> | React.MouseEvent<SVGRectElement>) => {
|
|
199
|
+
const { x } = localPoint(event) || { x: 0 };
|
|
200
|
+
const x0 = xScale.invert(x - margin.left);
|
|
201
|
+
let index = bisector<T, Date>(xAccessor).left(filteredData, x0);
|
|
202
|
+
|
|
203
|
+
// Clamp the index to ensure it's within the range of data points
|
|
204
|
+
index = Math.min(filteredData.length - 1, Math.max(0, index));
|
|
205
|
+
|
|
206
|
+
const d = filteredData[index];
|
|
207
|
+
const tooltipX = xScale(xAccessor(d));
|
|
208
|
+
const tooltipY = yScale(yAccessor(d));
|
|
209
|
+
|
|
210
|
+
showTooltip({
|
|
211
|
+
tooltipData: d,
|
|
212
|
+
tooltipLeft: tooltipX,
|
|
213
|
+
tooltipTop: tooltipY,
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
[yScale, xScale, filteredData, yAccessor, xAccessor, width, height]
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (width < 10) return null;
|
|
220
|
+
return (
|
|
221
|
+
<div>
|
|
222
|
+
<svg width={width} height={height}>
|
|
223
|
+
{gradients.chart.gradient}
|
|
224
|
+
{gradients.background.gradient}
|
|
225
|
+
<rect x={0} y={0} width={width} height={height} fill={`url(#${gradients.background.id})`} rx={14} />
|
|
226
|
+
{showGrid && (
|
|
227
|
+
<GridColumns
|
|
228
|
+
top={margin.top}
|
|
229
|
+
left={margin.left}
|
|
230
|
+
scale={xScale}
|
|
231
|
+
height={yMax}
|
|
232
|
+
strokeDasharray="1,5"
|
|
233
|
+
stroke={theme.colors.backgroundAccent}
|
|
234
|
+
strokeOpacity={0.2}
|
|
235
|
+
pointerEvents="none"
|
|
236
|
+
/>
|
|
237
|
+
)}
|
|
238
|
+
<Group id="chart" top={margin.top} left={margin.left}>
|
|
239
|
+
<AreaClosed<T>
|
|
240
|
+
x={(d) => xScale(xAccessor(d)) ?? 0}
|
|
241
|
+
y={(d) => yScale(yAccessor(d)) ?? 0}
|
|
242
|
+
data={filteredData}
|
|
243
|
+
yScale={yScale}
|
|
244
|
+
strokeWidth={1}
|
|
245
|
+
stroke={theme.colors.primary}
|
|
246
|
+
fill={`url(#${gradients.chart.id})`}
|
|
247
|
+
curve={curveMonotoneX}
|
|
248
|
+
/>
|
|
249
|
+
</Group>
|
|
250
|
+
<Bar
|
|
251
|
+
x={margin.left}
|
|
252
|
+
y={margin.top}
|
|
253
|
+
width={xMax}
|
|
254
|
+
height={yMax}
|
|
255
|
+
fill="transparent"
|
|
256
|
+
rx={14}
|
|
257
|
+
onTouchStart={handleTooltip}
|
|
258
|
+
onTouchMove={handleTooltip}
|
|
259
|
+
onMouseMove={handleTooltip}
|
|
260
|
+
onMouseLeave={hideTooltip}
|
|
261
|
+
/>
|
|
262
|
+
{tooltipData && (
|
|
263
|
+
<PointHighlight margin={margin} yMax={yMax} tooltipLeft={tooltipLeft} tooltipTop={tooltipTop} />
|
|
264
|
+
)}
|
|
265
|
+
{/* brush chart */}
|
|
266
|
+
{showBrush && (
|
|
267
|
+
<Group left={margin.left} top={topChartHeight + topChartBottomMargin + margin.top}>
|
|
268
|
+
<AreaClosed<T>
|
|
269
|
+
x={(d) => xBrushScale(xAccessor(d)) ?? 0}
|
|
270
|
+
y={(d) => yBrushScale(yAccessor(d)) ?? 0}
|
|
271
|
+
width={xBrushMax}
|
|
272
|
+
data={data}
|
|
273
|
+
yScale={yBrushScale}
|
|
274
|
+
strokeWidth={1}
|
|
275
|
+
stroke={`url(#${gradients.chart.id})`}
|
|
276
|
+
fill={`url(#${gradients.chart.id})`}
|
|
277
|
+
curve={curveMonotoneX}
|
|
278
|
+
/>
|
|
279
|
+
<PatternLines
|
|
280
|
+
id={PATTERN_ID}
|
|
281
|
+
height={8}
|
|
282
|
+
width={8}
|
|
283
|
+
stroke={theme.colors.backgroundAccent}
|
|
284
|
+
strokeWidth={1}
|
|
285
|
+
orientation={['diagonal']}
|
|
286
|
+
/>
|
|
287
|
+
<Brush
|
|
288
|
+
xScale={xBrushScale}
|
|
289
|
+
yScale={yBrushScale}
|
|
290
|
+
width={xBrushMax}
|
|
291
|
+
height={yBrushMax}
|
|
292
|
+
innerRef={brushRef}
|
|
293
|
+
resizeTriggerAreas={['left', 'right']}
|
|
294
|
+
brushDirection="horizontal"
|
|
295
|
+
initialBrushPosition={initialBrushPosition}
|
|
296
|
+
margin={brushMargin}
|
|
297
|
+
onChange={onBrushChange}
|
|
298
|
+
selectedBoxStyle={{
|
|
299
|
+
fill: `url(#${PATTERN_ID})`,
|
|
300
|
+
stroke: theme.colors.backgroundAccent,
|
|
301
|
+
}}
|
|
302
|
+
useWindowMoveEvents
|
|
303
|
+
handleSize={8}
|
|
304
|
+
renderBrushHandle={(props) => <BrushHandle {...props} />}
|
|
305
|
+
/>
|
|
306
|
+
</Group>
|
|
307
|
+
)}
|
|
308
|
+
{showAxisY && (
|
|
309
|
+
<AxisLeft
|
|
310
|
+
top={margin.top}
|
|
311
|
+
left={margin.left}
|
|
312
|
+
strokeWidth={1}
|
|
313
|
+
hideZero
|
|
314
|
+
numTicks={5}
|
|
315
|
+
stroke={theme.colors.backgroundAlt}
|
|
316
|
+
labelOffset={42}
|
|
317
|
+
tickStroke={theme.colors.backgroundAlt}
|
|
318
|
+
tickLabelProps={{
|
|
319
|
+
fill: theme.colors.text,
|
|
320
|
+
fontSize: theme.fontSize.small,
|
|
321
|
+
textAnchor: 'end',
|
|
322
|
+
}}
|
|
323
|
+
tickFormat={(val) => `${val}`}
|
|
324
|
+
scale={yScale}
|
|
325
|
+
label={axisYLabel}
|
|
326
|
+
/>
|
|
327
|
+
)}
|
|
328
|
+
{showAxisX && (
|
|
329
|
+
<AxisBottom
|
|
330
|
+
top={yMax + margin.top}
|
|
331
|
+
left={margin.left}
|
|
332
|
+
strokeWidth={1}
|
|
333
|
+
stroke={theme.colors.backgroundAlt}
|
|
334
|
+
hideZero
|
|
335
|
+
numTicks={4}
|
|
336
|
+
tickLabelProps={{
|
|
337
|
+
fill: theme.colors.textAlt,
|
|
338
|
+
fontSize: theme.fontSize.small,
|
|
339
|
+
textAnchor: 'end',
|
|
340
|
+
}}
|
|
341
|
+
tickFormat={tickFormatDate}
|
|
342
|
+
labelProps={{
|
|
343
|
+
fill: theme.colors.textAlt,
|
|
344
|
+
fontSize: theme.fontSize.tiny,
|
|
345
|
+
y: 35,
|
|
346
|
+
x: width / 2 - margin.left,
|
|
347
|
+
}}
|
|
348
|
+
scale={xScale}
|
|
349
|
+
label={axisXLabel}
|
|
350
|
+
/>
|
|
351
|
+
)}
|
|
352
|
+
</svg>
|
|
353
|
+
{tooltipData && (
|
|
354
|
+
<div>
|
|
355
|
+
<TooltipWithBounds
|
|
356
|
+
key={`${name}-tooltip`}
|
|
357
|
+
top={tooltipTop - margin.top}
|
|
358
|
+
left={tooltipLeft + margin.left}
|
|
359
|
+
style={getDefaultTooltipStyles(theme)}
|
|
360
|
+
>
|
|
361
|
+
{tooltipAccessor ? tooltipAccessor(tooltipData) : yAccessor(tooltipData)}
|
|
362
|
+
</TooltipWithBounds>
|
|
363
|
+
<Tooltip
|
|
364
|
+
top={yMax + margin.top - 14}
|
|
365
|
+
left={tooltipLeft + margin.left}
|
|
366
|
+
style={{
|
|
367
|
+
...getDefaultTooltipStyles(theme),
|
|
368
|
+
minWidth: 72,
|
|
369
|
+
textAlign: 'center',
|
|
370
|
+
transform: 'translateX(-50%)',
|
|
371
|
+
}}
|
|
372
|
+
>
|
|
373
|
+
{formatDate(xAccessor(tooltipData))}
|
|
374
|
+
</Tooltip>
|
|
375
|
+
</div>
|
|
376
|
+
)}
|
|
377
|
+
</div>
|
|
378
|
+
);
|
|
379
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { BarChart, BarChartProps } from '.';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Charts/BarChart',
|
|
9
|
+
component: BarChart,
|
|
10
|
+
} as Meta<BarChartProps<LetterFrequency>>;
|
|
11
|
+
|
|
12
|
+
const Wrapper = styled.div`
|
|
13
|
+
height: 50vh;
|
|
14
|
+
width: 100%;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const Default: StoryFn<BarChartProps<LetterFrequency>> = () => {
|
|
18
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
19
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Wrapper>
|
|
23
|
+
<BarChart<LetterFrequency>
|
|
24
|
+
name="letterFrequency"
|
|
25
|
+
xAccessor={getLetter}
|
|
26
|
+
yAccessor={getLetterFrequency}
|
|
27
|
+
data={letterFrequency}
|
|
28
|
+
showBrush={true}
|
|
29
|
+
/>
|
|
30
|
+
</Wrapper>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Bar } from '@visx/shape';
|
|
4
|
+
import { Group } from '@visx/group';
|
|
5
|
+
import { GridRows } from '@visx/grid';
|
|
6
|
+
import { scaleBand, scaleLinear } from '@visx/scale';
|
|
7
|
+
import { max } from '@visx/vendor/d3-array';
|
|
8
|
+
import { ParentSize } from '@visx/responsive';
|
|
9
|
+
import { Bounds } from '@visx/brush/lib/types';
|
|
10
|
+
import { AxisBottom, AxisLeft } from '@visx/axis';
|
|
11
|
+
import { Brush } from '@visx/brush';
|
|
12
|
+
import { PatternLines } from '@visx/pattern';
|
|
13
|
+
import { shade } from 'polished';
|
|
14
|
+
|
|
15
|
+
import { useGradients } from '../useGradients';
|
|
16
|
+
import { useTheme } from '../../../hooks';
|
|
17
|
+
import { ChartProps, InnerChartProps, Margin } from '../util';
|
|
18
|
+
import { BrushHandle } from '../BrushHandle';
|
|
19
|
+
|
|
20
|
+
export interface BarChartProps<T> extends ChartProps {
|
|
21
|
+
data: T[];
|
|
22
|
+
xAccessor: (d: T) => string;
|
|
23
|
+
yAccessor: (d: T) => number;
|
|
24
|
+
margin?: Margin;
|
|
25
|
+
showBrush?: boolean;
|
|
26
|
+
brushMargin?: Margin;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const defaultMargin = { top: 20, left: 50, bottom: 20, right: 20 };
|
|
30
|
+
const defaultBrushMargin = { top: 10, bottom: 15, left: 50, right: 20 };
|
|
31
|
+
const defaultShowAxisX = true;
|
|
32
|
+
const defaultShowAxisY = true;
|
|
33
|
+
const defaultShowGrid = true;
|
|
34
|
+
|
|
35
|
+
export const BarChart = <T,>({
|
|
36
|
+
data,
|
|
37
|
+
xAccessor,
|
|
38
|
+
yAccessor,
|
|
39
|
+
margin = defaultMargin,
|
|
40
|
+
showGrid = defaultShowGrid,
|
|
41
|
+
showBrush = false,
|
|
42
|
+
brushMargin = defaultBrushMargin,
|
|
43
|
+
name,
|
|
44
|
+
showAxisX = defaultShowAxisX,
|
|
45
|
+
showAxisY = defaultShowAxisY,
|
|
46
|
+
axisXLabel,
|
|
47
|
+
axisYLabel,
|
|
48
|
+
}: BarChartProps<T>) => {
|
|
49
|
+
// TODO: handle empty data
|
|
50
|
+
if (!data || data.length === 0) return null;
|
|
51
|
+
|
|
52
|
+
// TODO: handle loading state
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<ParentSize>
|
|
57
|
+
{(parent) => (
|
|
58
|
+
<Chart<T>
|
|
59
|
+
name={name}
|
|
60
|
+
xAccessor={xAccessor}
|
|
61
|
+
yAccessor={yAccessor}
|
|
62
|
+
data={data}
|
|
63
|
+
width={parent.width}
|
|
64
|
+
height={parent.height}
|
|
65
|
+
brushMargin={brushMargin}
|
|
66
|
+
showBrush={showBrush}
|
|
67
|
+
showGrid={showGrid}
|
|
68
|
+
margin={margin}
|
|
69
|
+
axisYLabel={axisYLabel}
|
|
70
|
+
axisXLabel={axisXLabel}
|
|
71
|
+
showAxisX={showAxisX}
|
|
72
|
+
showAxisY={showAxisY}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
</ParentSize>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type InnerBarChartProps<T> = InnerChartProps & BarChartProps<T>;
|
|
81
|
+
|
|
82
|
+
const Chart = <T,>({
|
|
83
|
+
data,
|
|
84
|
+
xAccessor,
|
|
85
|
+
yAccessor,
|
|
86
|
+
width,
|
|
87
|
+
height,
|
|
88
|
+
margin = defaultMargin,
|
|
89
|
+
showGrid = defaultShowGrid,
|
|
90
|
+
showBrush = false,
|
|
91
|
+
brushMargin = defaultBrushMargin,
|
|
92
|
+
name,
|
|
93
|
+
showAxisX = defaultShowAxisX,
|
|
94
|
+
showAxisY = defaultShowAxisY,
|
|
95
|
+
axisYLabel,
|
|
96
|
+
axisXLabel,
|
|
97
|
+
}: InnerBarChartProps<T>) => {
|
|
98
|
+
const gradients = useGradients(name);
|
|
99
|
+
const [filteredData, setFilteredData] = useState(data);
|
|
100
|
+
|
|
101
|
+
const brushRef = useRef(null);
|
|
102
|
+
|
|
103
|
+
const axisHeight = 100;
|
|
104
|
+
const axisWidth = 20;
|
|
105
|
+
const theme = useTheme();
|
|
106
|
+
|
|
107
|
+
const PATTERN_ID = `${name}-brush_pattern`;
|
|
108
|
+
|
|
109
|
+
// bounds
|
|
110
|
+
const xMax = width;
|
|
111
|
+
const yMax = height - margin.top - axisHeight; // 100 for axis
|
|
112
|
+
|
|
113
|
+
const chartSeparation = 30;
|
|
114
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
115
|
+
const topChartBottomMargin = chartSeparation + 10;
|
|
116
|
+
const topChartHeight = 0.8 * innerHeight - topChartBottomMargin;
|
|
117
|
+
const bottomChartHeight = innerHeight - topChartHeight - chartSeparation;
|
|
118
|
+
|
|
119
|
+
const xBrushMax = Math.max(width - brushMargin.left - brushMargin.right, 0);
|
|
120
|
+
const yBrushMax = Math.max(bottomChartHeight - brushMargin.top - brushMargin.bottom, 0);
|
|
121
|
+
|
|
122
|
+
const xScale = useMemo(
|
|
123
|
+
() =>
|
|
124
|
+
scaleBand<string>({
|
|
125
|
+
range: [0, xMax],
|
|
126
|
+
round: true,
|
|
127
|
+
domain: filteredData.map(xAccessor),
|
|
128
|
+
padding: 0.4,
|
|
129
|
+
}),
|
|
130
|
+
[xMax, filteredData]
|
|
131
|
+
);
|
|
132
|
+
const yScale = useMemo(
|
|
133
|
+
() =>
|
|
134
|
+
scaleLinear<number>({
|
|
135
|
+
range: [yMax, 0],
|
|
136
|
+
round: true,
|
|
137
|
+
domain: [0, max(filteredData, yAccessor) ?? 0],
|
|
138
|
+
}),
|
|
139
|
+
[yMax, filteredData]
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const xBrushScale = useMemo(
|
|
143
|
+
() =>
|
|
144
|
+
scaleBand<string>({
|
|
145
|
+
range: [0, xBrushMax],
|
|
146
|
+
domain: data.map(xAccessor),
|
|
147
|
+
round: true,
|
|
148
|
+
}),
|
|
149
|
+
[xBrushMax]
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const yBrushScale = useMemo(
|
|
153
|
+
() =>
|
|
154
|
+
scaleLinear({
|
|
155
|
+
range: [yBrushMax, 0],
|
|
156
|
+
domain: [0, Math.max(...data.map(yAccessor))],
|
|
157
|
+
nice: true,
|
|
158
|
+
}),
|
|
159
|
+
[yBrushMax]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const onBrushChange = (domain: Bounds | null) => {
|
|
163
|
+
if (!domain || !domain.xValues) return;
|
|
164
|
+
const { xValues } = domain;
|
|
165
|
+
|
|
166
|
+
const filtered = data.filter((d) => {
|
|
167
|
+
const xValue = xAccessor(d);
|
|
168
|
+
return xValues.includes(xValue);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
setFilteredData(filtered);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<svg width={width} height={height}>
|
|
176
|
+
{gradients.background.gradient}
|
|
177
|
+
{gradients.chart.gradient}
|
|
178
|
+
<rect width={width} height={height} fill={`url(#${gradients.background.id})`} rx={14} />
|
|
179
|
+
{showGrid && (
|
|
180
|
+
<GridRows
|
|
181
|
+
top={margin.top}
|
|
182
|
+
left={margin.left + axisWidth}
|
|
183
|
+
scale={yScale}
|
|
184
|
+
width={xMax}
|
|
185
|
+
height={yMax}
|
|
186
|
+
stroke={theme.colors.backgroundAccent}
|
|
187
|
+
strokeOpacity={1}
|
|
188
|
+
/>
|
|
189
|
+
)}
|
|
190
|
+
<Group top={margin.top}>
|
|
191
|
+
{filteredData.map((d) => {
|
|
192
|
+
const xVal = xAccessor(d);
|
|
193
|
+
const barWidth = xScale.bandwidth();
|
|
194
|
+
const barHeight = yMax - (yScale(yAccessor(d)) ?? 0);
|
|
195
|
+
return (
|
|
196
|
+
<Bar
|
|
197
|
+
key={`bar-${xVal}`}
|
|
198
|
+
x={xScale(xVal)}
|
|
199
|
+
y={yMax - barHeight}
|
|
200
|
+
width={barWidth}
|
|
201
|
+
height={barHeight}
|
|
202
|
+
fill={shade(0.5, theme.colors.primary)}
|
|
203
|
+
stroke={theme.colors.primary}
|
|
204
|
+
/>
|
|
205
|
+
);
|
|
206
|
+
})}
|
|
207
|
+
</Group>
|
|
208
|
+
{showAxisY && (
|
|
209
|
+
<AxisLeft
|
|
210
|
+
top={margin.top}
|
|
211
|
+
left={margin.left}
|
|
212
|
+
tickStroke={theme.colors.textAlt}
|
|
213
|
+
tickLabelProps={{
|
|
214
|
+
fill: theme.colors.textAlt,
|
|
215
|
+
fontSize: theme.fontSize.small,
|
|
216
|
+
textAnchor: 'middle',
|
|
217
|
+
}}
|
|
218
|
+
scale={yScale}
|
|
219
|
+
label={axisYLabel}
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
222
|
+
|
|
223
|
+
{showAxisX && (
|
|
224
|
+
<AxisBottom
|
|
225
|
+
top={yMax + margin.top}
|
|
226
|
+
tickStroke={theme.colors.textAlt}
|
|
227
|
+
tickLabelProps={{
|
|
228
|
+
fill: theme.colors.textAlt,
|
|
229
|
+
fontSize: theme.fontSize.small,
|
|
230
|
+
textAnchor: 'middle',
|
|
231
|
+
}}
|
|
232
|
+
scale={xScale}
|
|
233
|
+
label={axisXLabel}
|
|
234
|
+
/>
|
|
235
|
+
)}
|
|
236
|
+
|
|
237
|
+
{showBrush && (
|
|
238
|
+
<>
|
|
239
|
+
{/* brush chart */}
|
|
240
|
+
<Group left={brushMargin.left} top={topChartHeight + topChartBottomMargin + margin.top}>
|
|
241
|
+
{data.map((d) => {
|
|
242
|
+
const xVal = xAccessor(d);
|
|
243
|
+
const barWidth = xBrushScale.bandwidth();
|
|
244
|
+
const barHeight = yBrushMax - (yBrushScale(yAccessor(d)) ?? 0);
|
|
245
|
+
return (
|
|
246
|
+
<Bar
|
|
247
|
+
key={`bar-${xVal}`}
|
|
248
|
+
x={xBrushScale(xVal)}
|
|
249
|
+
y={yBrushMax - barHeight}
|
|
250
|
+
width={barWidth}
|
|
251
|
+
height={barHeight}
|
|
252
|
+
fill={`url(#${gradients.chart.id})`}
|
|
253
|
+
/>
|
|
254
|
+
);
|
|
255
|
+
})}
|
|
256
|
+
<PatternLines
|
|
257
|
+
id={PATTERN_ID}
|
|
258
|
+
height={8}
|
|
259
|
+
width={8}
|
|
260
|
+
stroke={theme.colors.backgroundAccent}
|
|
261
|
+
strokeWidth={1}
|
|
262
|
+
orientation={['diagonal']}
|
|
263
|
+
/>
|
|
264
|
+
<Brush
|
|
265
|
+
xScale={xBrushScale}
|
|
266
|
+
yScale={yBrushScale}
|
|
267
|
+
width={xBrushMax}
|
|
268
|
+
height={yBrushMax}
|
|
269
|
+
innerRef={brushRef}
|
|
270
|
+
resizeTriggerAreas={['left', 'right']}
|
|
271
|
+
brushDirection="horizontal"
|
|
272
|
+
margin={brushMargin}
|
|
273
|
+
onChange={onBrushChange}
|
|
274
|
+
selectedBoxStyle={{
|
|
275
|
+
fill: `url(#${PATTERN_ID})`,
|
|
276
|
+
stroke: theme.colors.backgroundAccent,
|
|
277
|
+
}}
|
|
278
|
+
useWindowMoveEvents
|
|
279
|
+
handleSize={8}
|
|
280
|
+
renderBrushHandle={(props) => <BrushHandle {...props} />}
|
|
281
|
+
/>
|
|
282
|
+
</Group>
|
|
283
|
+
</>
|
|
284
|
+
)}
|
|
285
|
+
</svg>
|
|
286
|
+
);
|
|
287
|
+
};
|