@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,141 @@
|
|
|
1
|
+
import { ParentSize } from '@visx/responsive';
|
|
2
|
+
import { Group } from '@visx/group';
|
|
3
|
+
import { LineRadial } from '@visx/shape';
|
|
4
|
+
import { scaleTime, scaleLog, NumberLike } from '@visx/scale';
|
|
5
|
+
import { GridAngle, GridRadial } from '@visx/grid';
|
|
6
|
+
import { AxisLeft } from '@visx/axis';
|
|
7
|
+
import { motion } from 'framer-motion';
|
|
8
|
+
import { extent } from '@visx/vendor/d3-array';
|
|
9
|
+
import { curveBasisOpen } from '@visx/curve';
|
|
10
|
+
|
|
11
|
+
import { InnerChartProps, Margin } from '../util';
|
|
12
|
+
import { useTheme } from '../../../hooks';
|
|
13
|
+
import { useGradients } from '../useGradients';
|
|
14
|
+
|
|
15
|
+
const formatTicks = (val: NumberLike) => String(val);
|
|
16
|
+
|
|
17
|
+
export interface RadialLineChartProps<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
data: T[];
|
|
20
|
+
margin?: Margin;
|
|
21
|
+
xAccessor: (d: T) => number;
|
|
22
|
+
yAccessor: (d: T) => number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultMargin = { top: 10, right: 0, bottom: 25, left: 40 };
|
|
26
|
+
export const RadialLineChart = <T,>({
|
|
27
|
+
data,
|
|
28
|
+
yAccessor,
|
|
29
|
+
xAccessor,
|
|
30
|
+
name,
|
|
31
|
+
margin = defaultMargin,
|
|
32
|
+
}: RadialLineChartProps<T>) => {
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<ParentSize>
|
|
36
|
+
{(parent) => (
|
|
37
|
+
<Chart<T>
|
|
38
|
+
name={name}
|
|
39
|
+
data={data}
|
|
40
|
+
width={parent.width}
|
|
41
|
+
height={parent.height}
|
|
42
|
+
margin={margin}
|
|
43
|
+
yAccessor={yAccessor}
|
|
44
|
+
xAccessor={xAccessor}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
</ParentSize>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type InnerRadialLineChartProps<T> = InnerChartProps & RadialLineChartProps<T>;
|
|
53
|
+
|
|
54
|
+
const Chart = <T,>({ width, xAccessor, yAccessor, data, name, height }: InnerRadialLineChartProps<T>) => {
|
|
55
|
+
const theme = useTheme();
|
|
56
|
+
const gradients = useGradients(name);
|
|
57
|
+
|
|
58
|
+
const xScale = scaleTime<number>({
|
|
59
|
+
range: [0, Math.PI * 2],
|
|
60
|
+
domain: extent(data, xAccessor) as [number, number],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const yScale = scaleLog<number>({
|
|
64
|
+
domain: extent(data, yAccessor) as [number, number],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const firstPoint = yAccessor(data[0]);
|
|
68
|
+
const lastPoint = yAccessor(data[data.length - 1]);
|
|
69
|
+
|
|
70
|
+
const angle = (d: T) => xScale(xAccessor(d)) ?? 0;
|
|
71
|
+
const radius = (d: T) => yScale(yAccessor(d)) ?? 0;
|
|
72
|
+
const padding = 15;
|
|
73
|
+
|
|
74
|
+
// Update scale output to match component dimensions
|
|
75
|
+
yScale.range([0, height / 2 - padding]);
|
|
76
|
+
const reverseYScale = yScale.copy().range(yScale.range().reverse());
|
|
77
|
+
|
|
78
|
+
return width < 10 ? null : (
|
|
79
|
+
<svg width={width} height={height}>
|
|
80
|
+
{gradients.chart.gradient}
|
|
81
|
+
<rect width={width} height={height} fill={theme.colors.background} rx={14} />
|
|
82
|
+
<Group top={height / 2} left={width / 2}>
|
|
83
|
+
<GridAngle
|
|
84
|
+
scale={xScale}
|
|
85
|
+
outerRadius={height / 2 - padding}
|
|
86
|
+
stroke={theme.colors.backgroundAccent}
|
|
87
|
+
strokeWidth={1}
|
|
88
|
+
strokeOpacity={0.3}
|
|
89
|
+
strokeDasharray="5,2"
|
|
90
|
+
numTicks={20}
|
|
91
|
+
/>
|
|
92
|
+
<GridRadial
|
|
93
|
+
scale={yScale}
|
|
94
|
+
numTicks={5}
|
|
95
|
+
stroke={theme.colors.backgroundAccent}
|
|
96
|
+
strokeWidth={1}
|
|
97
|
+
fill={theme.colors.backgroundAccent}
|
|
98
|
+
fillOpacity={0.1}
|
|
99
|
+
strokeOpacity={0.2}
|
|
100
|
+
/>
|
|
101
|
+
<AxisLeft
|
|
102
|
+
top={-height / 2 + padding}
|
|
103
|
+
scale={reverseYScale}
|
|
104
|
+
numTicks={5}
|
|
105
|
+
tickStroke="none"
|
|
106
|
+
tickLabelProps={{
|
|
107
|
+
fontSize: 8,
|
|
108
|
+
fill: theme.colors.text,
|
|
109
|
+
fillOpacity: 1,
|
|
110
|
+
textAnchor: 'middle',
|
|
111
|
+
dx: '1em',
|
|
112
|
+
dy: '-0.5em',
|
|
113
|
+
paintOrder: 'stroke',
|
|
114
|
+
}}
|
|
115
|
+
tickFormat={formatTicks}
|
|
116
|
+
hideAxisLine
|
|
117
|
+
/>
|
|
118
|
+
<LineRadial<T> angle={angle} radius={radius} curve={curveBasisOpen}>
|
|
119
|
+
{({ path }) => {
|
|
120
|
+
const d = path(data) || '';
|
|
121
|
+
return (
|
|
122
|
+
<motion.path
|
|
123
|
+
d={d}
|
|
124
|
+
strokeWidth={2}
|
|
125
|
+
strokeOpacity={0.8}
|
|
126
|
+
strokeLinecap="round"
|
|
127
|
+
fill="none"
|
|
128
|
+
stroke={theme.colors.primary}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}}
|
|
132
|
+
</LineRadial>
|
|
133
|
+
{[firstPoint, lastPoint].map((d, i) => {
|
|
134
|
+
const cx = ((xScale(d) ?? 0) * Math.PI) / 180;
|
|
135
|
+
const cy = -(yScale(d) ?? 0);
|
|
136
|
+
return <circle key={`line-cap-${i}`} cx={cx} cy={cy} fill={theme.colors.primary} r={2} />;
|
|
137
|
+
})}
|
|
138
|
+
</Group>
|
|
139
|
+
</svg>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { BarChart } from './BarChart';
|
|
2
|
+
export type { BarChartProps } from './BarChart';
|
|
3
|
+
|
|
4
|
+
export { AreaChart } from './AreaChart';
|
|
5
|
+
export type { AreaChartProps } from './AreaChart';
|
|
6
|
+
|
|
7
|
+
export { HeatMap } from './Heatmap';
|
|
8
|
+
export type { HeatmapProps } from './Heatmap';
|
|
9
|
+
|
|
10
|
+
export { PieChart } from './PieChart';
|
|
11
|
+
export type { PieChartProps } from './PieChart';
|
|
12
|
+
|
|
13
|
+
export { RadarChart } from './RadarChart';
|
|
14
|
+
export type { RadarChartProps } from './RadarChart';
|
|
15
|
+
|
|
16
|
+
export { RadialLineChart } from './RadialLineChart';
|
|
17
|
+
export type { RadialLineChartProps } from './RadialLineChart';
|
|
18
|
+
|
|
19
|
+
export { RadialBarChart } from './RadialBarChart';
|
|
20
|
+
export type { RadialBarChartProps } from './RadialBarChart';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LinearGradient } from '@visx/gradient';
|
|
2
|
+
import { useTheme } from '../../hooks';
|
|
3
|
+
|
|
4
|
+
export const useGradients = (name: string) => {
|
|
5
|
+
const theme = useTheme();
|
|
6
|
+
|
|
7
|
+
// Constructing the gradient IDs
|
|
8
|
+
const BACKGROUND_GRADIENT_ID = `background-gradient-${name}`;
|
|
9
|
+
const AREA_GRADIENT_ID = `area-gradient-${name}`;
|
|
10
|
+
|
|
11
|
+
// Gradient elements
|
|
12
|
+
const backgroundGradient = (
|
|
13
|
+
<LinearGradient id={BACKGROUND_GRADIENT_ID} from={theme.colors.background} to={theme.colors.background} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const areaGradient = (
|
|
17
|
+
<LinearGradient
|
|
18
|
+
id={AREA_GRADIENT_ID}
|
|
19
|
+
from={theme.colors.primary}
|
|
20
|
+
to={theme.colors.primary}
|
|
21
|
+
fromOpacity={0.6}
|
|
22
|
+
toOpacity={0.2}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Returning both gradient elements and their IDs
|
|
27
|
+
return {
|
|
28
|
+
background: {
|
|
29
|
+
gradient: backgroundGradient,
|
|
30
|
+
id: BACKGROUND_GRADIENT_ID,
|
|
31
|
+
},
|
|
32
|
+
chart: {
|
|
33
|
+
gradient: areaGradient,
|
|
34
|
+
id: AREA_GRADIENT_ID,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defaultStyles } from '@visx/tooltip';
|
|
2
|
+
import { ThemeType } from '../../styled';
|
|
3
|
+
|
|
4
|
+
export interface ChartProps {
|
|
5
|
+
/// Unique identifier for the chart
|
|
6
|
+
name: string;
|
|
7
|
+
showGrid?: boolean;
|
|
8
|
+
axisXLabel?: string;
|
|
9
|
+
axisYLabel?: string;
|
|
10
|
+
showAxisX?: boolean;
|
|
11
|
+
showAxisY?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface InnerChartProps extends ChartProps {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Margin {
|
|
20
|
+
top: number;
|
|
21
|
+
right: number;
|
|
22
|
+
bottom: number;
|
|
23
|
+
left: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const getDefaultTooltipStyles = (theme: ThemeType) => ({
|
|
27
|
+
...defaultStyles,
|
|
28
|
+
background: theme.colors.background,
|
|
29
|
+
border: `1px solid ${theme.colors.backgroundAccent}`,
|
|
30
|
+
borderRadius: theme.borderRadius.small,
|
|
31
|
+
color: theme.colors.text,
|
|
32
|
+
fontSize: theme.fontSize.small,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const getChartColors = (theme: ThemeType) => [
|
|
36
|
+
theme.colors.primary, // Primary color: '#664de5' (Vibrant purple)
|
|
37
|
+
'#FFD700', // Gold for a contrasting yet harmonious color
|
|
38
|
+
'#87CEEB', // Sky blue to complement the purple
|
|
39
|
+
'#FF69B4', // Hot pink for a playful, vibrant look
|
|
40
|
+
];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { Avatar, AvatarGroupProps, AvatarProps } from '.';
|
|
5
|
+
import { getInitials } from '../../../helpers';
|
|
6
|
+
|
|
7
|
+
const Wrapper = styled.div`
|
|
8
|
+
display: grid;
|
|
9
|
+
grid-template-columns: auto auto auto auto auto;
|
|
10
|
+
grid-gap: 2rem;
|
|
11
|
+
padding: 5rem;
|
|
12
|
+
background: ${({ theme }) => theme.colors.background};
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const placeholder01 = 'images/placeholder-01.jpeg';
|
|
16
|
+
const placeholder02 = 'images/placeholder-02.jpeg';
|
|
17
|
+
const placeholder03 = 'images/placeholder-03.jpeg';
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: 'Data/Avatar',
|
|
21
|
+
component: Avatar,
|
|
22
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
23
|
+
argTypes: {
|
|
24
|
+
variant: {
|
|
25
|
+
options: ['square', 'rounded', 'circle'],
|
|
26
|
+
control: {
|
|
27
|
+
type: 'radio',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
args: {
|
|
32
|
+
size: 'medium',
|
|
33
|
+
unstackOnHover: false,
|
|
34
|
+
variant: 'circle',
|
|
35
|
+
max: 3,
|
|
36
|
+
},
|
|
37
|
+
} as Meta<AvatarProps & AvatarGroupProps>;
|
|
38
|
+
|
|
39
|
+
export const Default: StoryFn<AvatarProps> = (args) => (
|
|
40
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
41
|
+
<Avatar.Image src={placeholder01} />
|
|
42
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
43
|
+
</Avatar>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export const Fallback: StoryFn = () => (
|
|
47
|
+
<>
|
|
48
|
+
<Avatar size="tiny">
|
|
49
|
+
<Avatar.Image src="/broken" />
|
|
50
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
51
|
+
</Avatar>
|
|
52
|
+
<Avatar size="small">
|
|
53
|
+
<Avatar.Image src="/broken" />
|
|
54
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
55
|
+
</Avatar>
|
|
56
|
+
<Avatar size="medium">
|
|
57
|
+
<Avatar.Image src="/broken" />
|
|
58
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
59
|
+
</Avatar>
|
|
60
|
+
<Avatar size="large">
|
|
61
|
+
<Avatar.Image src="/broken" />
|
|
62
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
63
|
+
</Avatar>
|
|
64
|
+
<Avatar size="huge">
|
|
65
|
+
<Avatar.Image src="/broken" />
|
|
66
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
67
|
+
</Avatar>
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
export const Group: StoryFn<AvatarProps & AvatarGroupProps> = (args) => (
|
|
71
|
+
<Avatar.Group max={args.max} unstackOnHover={args.unstackOnHover}>
|
|
72
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
73
|
+
<Avatar.Image src={placeholder01} />
|
|
74
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
75
|
+
</Avatar>
|
|
76
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
77
|
+
<Avatar.Image src={placeholder02} />
|
|
78
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
79
|
+
</Avatar>
|
|
80
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
81
|
+
<Avatar.Image src={placeholder03} />
|
|
82
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
83
|
+
</Avatar>
|
|
84
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
85
|
+
<Avatar.Image src={placeholder01} />
|
|
86
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
87
|
+
</Avatar>
|
|
88
|
+
<Avatar size={args.size} variant={args.variant}>
|
|
89
|
+
<Avatar.Image src={placeholder02} />
|
|
90
|
+
<Avatar.FallBack>{getInitials('Harry Potter')}</Avatar.FallBack>
|
|
91
|
+
</Avatar>
|
|
92
|
+
</Avatar.Group>
|
|
93
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export type ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
4
|
+
|
|
5
|
+
type AvatarContextValue = {
|
|
6
|
+
imageLoadingStatus: ImageLoadingStatus;
|
|
7
|
+
onImageLoadingStatusChange: (status: ImageLoadingStatus) => void;
|
|
8
|
+
} | null;
|
|
9
|
+
|
|
10
|
+
export const AvatarContext = createContext<AvatarContextValue>(null);
|
|
11
|
+
|
|
12
|
+
export const useAvatarContext = () => {
|
|
13
|
+
const context = useContext(AvatarContext);
|
|
14
|
+
|
|
15
|
+
if (context == null) {
|
|
16
|
+
throw new Error('Avatar components must be wrapped in <Avatar />');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
FC,
|
|
4
|
+
forwardRef,
|
|
5
|
+
ImgHTMLAttributes,
|
|
6
|
+
PropsWithChildren,
|
|
7
|
+
ReactElement,
|
|
8
|
+
useEffect,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { Size } from '../../../styled/types';
|
|
13
|
+
import { Container, GroupContainer } from './style';
|
|
14
|
+
import { AvatarContext, ImageLoadingStatus, useAvatarContext } from './context';
|
|
15
|
+
import { useCallbackRef } from '../../../hooks';
|
|
16
|
+
import { useImageLoadingStatus } from './useImageLoadingStatus';
|
|
17
|
+
import { Skeleton } from '../../../components';
|
|
18
|
+
|
|
19
|
+
// * -------------------------------------------------------------------------------------------------
|
|
20
|
+
// * Avatar Image
|
|
21
|
+
// * -----------------------------------------------------------------------------------------------*/
|
|
22
|
+
|
|
23
|
+
interface AvatarImageProps extends ImgHTMLAttributes<HTMLImageElement> {
|
|
24
|
+
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const AvatarImage = forwardRef<HTMLImageElement, AvatarImageProps>(
|
|
28
|
+
({ onLoadingStatusChange, src, ...imageProps }, ref) => {
|
|
29
|
+
const context = useAvatarContext();
|
|
30
|
+
const imageLoadingStatus = useImageLoadingStatus(src);
|
|
31
|
+
const handleLoadingStatusChange = useCallbackRef((status: ImageLoadingStatus) => {
|
|
32
|
+
onLoadingStatusChange && onLoadingStatusChange(status);
|
|
33
|
+
context.onImageLoadingStatusChange(status);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
if (imageLoadingStatus !== 'idle') {
|
|
38
|
+
handleLoadingStatusChange(imageLoadingStatus);
|
|
39
|
+
}
|
|
40
|
+
}, [imageLoadingStatus, handleLoadingStatusChange]);
|
|
41
|
+
|
|
42
|
+
if (imageLoadingStatus === 'loading') {
|
|
43
|
+
return <Skeleton variant="circular" width="100%" height="100%" />;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return imageLoadingStatus === 'loaded' ? <img {...imageProps} ref={ref} src={src} /> : null;
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// * -------------------------------------------------------------------------------------------------
|
|
51
|
+
// * FallBack
|
|
52
|
+
// * -----------------------------------------------------------------------------------------------*/
|
|
53
|
+
|
|
54
|
+
interface AvatarFallBackProps {
|
|
55
|
+
delayMs?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const AvatarFallBack = forwardRef<HTMLSpanElement, PropsWithChildren<AvatarFallBackProps>>(
|
|
59
|
+
({ children, delayMs = 250 }, ref) => {
|
|
60
|
+
const { imageLoadingStatus } = useAvatarContext();
|
|
61
|
+
const [canRender, setCanRender] = useState(delayMs === undefined);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (delayMs !== undefined) {
|
|
65
|
+
const timerId = window.setTimeout(() => setCanRender(true), delayMs);
|
|
66
|
+
return () => window.clearTimeout(timerId);
|
|
67
|
+
}
|
|
68
|
+
}, [delayMs]);
|
|
69
|
+
|
|
70
|
+
return canRender && imageLoadingStatus !== 'loaded' ? <span ref={ref}>{children}</span> : null;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// * -------------------------------------------------------------------------------------------------
|
|
75
|
+
// * FallBack
|
|
76
|
+
// * -----------------------------------------------------------------------------------------------*/
|
|
77
|
+
|
|
78
|
+
export interface AvatarGroupProps {
|
|
79
|
+
/// Max amount of avatars that should be shown
|
|
80
|
+
max?: number;
|
|
81
|
+
/// Unstack avatar on hover
|
|
82
|
+
unstackOnHover?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const AvatarGroup: FC<PropsWithChildren<AvatarGroupProps>> = ({ max = 3, children, unstackOnHover = false }) => {
|
|
86
|
+
// get size of first child
|
|
87
|
+
const size = (Children.toArray(children)[0] as ReactElement<AvatarProps>).props.size;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<GroupContainer size={size ?? 'medium'} unStackOnHover={unstackOnHover}>
|
|
91
|
+
{Children.toArray(children).slice(0, Math.min(Children.count(children), max))}
|
|
92
|
+
</GroupContainer>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// * -------------------------------------------------------------------------------------------------
|
|
97
|
+
// * Avatar
|
|
98
|
+
// * -----------------------------------------------------------------------------------------------*/
|
|
99
|
+
|
|
100
|
+
interface SubComponentTypes {
|
|
101
|
+
FallBack: typeof AvatarFallBack;
|
|
102
|
+
Image: typeof AvatarImage;
|
|
103
|
+
Group: typeof AvatarGroup;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type AvatarVariant = 'square' | 'rounded' | 'circle';
|
|
107
|
+
|
|
108
|
+
export interface AvatarProps {
|
|
109
|
+
size?: Size;
|
|
110
|
+
variant?: AvatarVariant;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// TODO: skeleton loading
|
|
114
|
+
export const Avatar: FC<PropsWithChildren<AvatarProps>> & SubComponentTypes = ({
|
|
115
|
+
size = 'medium',
|
|
116
|
+
variant,
|
|
117
|
+
children,
|
|
118
|
+
}) => {
|
|
119
|
+
const [imageLoadingStatus, setImageLoadingStatus] = useState<ImageLoadingStatus>('idle');
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<AvatarContext.Provider value={{ imageLoadingStatus, onImageLoadingStatusChange: setImageLoadingStatus }}>
|
|
123
|
+
<Container size={size} variant={variant}>
|
|
124
|
+
{children}
|
|
125
|
+
</Container>
|
|
126
|
+
</AvatarContext.Provider>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
Avatar.FallBack = AvatarFallBack;
|
|
131
|
+
Avatar.Image = AvatarImage;
|
|
132
|
+
Avatar.Group = AvatarGroup;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { AvatarVariant } from '.';
|
|
2
|
+
import { styled, Size } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
export const GroupContainer = styled.div<{ size: Size; unStackOnHover: boolean }>`
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
|
|
9
|
+
&:hover {
|
|
10
|
+
div {
|
|
11
|
+
${({ unStackOnHover }) => (unStackOnHover ? 'margin-left: 0;' : '')}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
div {
|
|
16
|
+
transition: margin-left 0.2s ease-in-out;
|
|
17
|
+
/* mind the negative sign here */
|
|
18
|
+
margin-left: -${({ theme }) => theme.spacing['5']};
|
|
19
|
+
|
|
20
|
+
:first-child {
|
|
21
|
+
margin-left: ${({ theme }) => theme.spacing[0]};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
${({ size, theme }) => {
|
|
25
|
+
switch (size) {
|
|
26
|
+
case 'tiny':
|
|
27
|
+
return `margin-left: -${theme.spacing['0_25']};`;
|
|
28
|
+
case 'small':
|
|
29
|
+
return `margin-left: -${theme.spacing['1']};`;
|
|
30
|
+
case 'medium':
|
|
31
|
+
return `margin-left: -${theme.spacing['3']};`;
|
|
32
|
+
case 'large':
|
|
33
|
+
return `margin-left: -${theme.spacing['8']};`;
|
|
34
|
+
case 'huge':
|
|
35
|
+
return `margin-left: -${theme.spacing['10']};`;
|
|
36
|
+
}
|
|
37
|
+
}}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export const Container = styled.div<{ size: Size; variant?: AvatarVariant }>`
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
color: white;
|
|
46
|
+
font-weight: 700;
|
|
47
|
+
|
|
48
|
+
img {
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 100%;
|
|
51
|
+
${({ theme, variant }) => {
|
|
52
|
+
switch (variant) {
|
|
53
|
+
case 'square':
|
|
54
|
+
return 'border-radius: 0;';
|
|
55
|
+
case 'rounded':
|
|
56
|
+
return `border-radius: ${theme.borderRadius['small']};`;
|
|
57
|
+
default:
|
|
58
|
+
return 'border-radius: 50%;';
|
|
59
|
+
}
|
|
60
|
+
}}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
span {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: center;
|
|
67
|
+
/* 2px is the size of the border */
|
|
68
|
+
width: calc(100% - 2px);
|
|
69
|
+
height: calc(100% - 2px);
|
|
70
|
+
${({ theme, variant }) => {
|
|
71
|
+
switch (variant) {
|
|
72
|
+
case 'square':
|
|
73
|
+
return 'border-radius: 0;';
|
|
74
|
+
case 'rounded':
|
|
75
|
+
return `border-radius: ${theme.borderRadius['small']};`;
|
|
76
|
+
default:
|
|
77
|
+
return 'border-radius: 50%;';
|
|
78
|
+
}
|
|
79
|
+
}}
|
|
80
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
81
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
82
|
+
margin-left: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
${({ size, theme }) => {
|
|
86
|
+
switch (size) {
|
|
87
|
+
case 'tiny':
|
|
88
|
+
return `
|
|
89
|
+
width: 2rem;
|
|
90
|
+
height: 2rem;
|
|
91
|
+
font-size: .8rem;
|
|
92
|
+
line-height: .8rem;
|
|
93
|
+
`;
|
|
94
|
+
case 'small':
|
|
95
|
+
return `
|
|
96
|
+
width: 3.125rem;
|
|
97
|
+
height: 3.125rem;
|
|
98
|
+
font-size: ${theme.fontSize.small};
|
|
99
|
+
line-height: 3.125rem;
|
|
100
|
+
`;
|
|
101
|
+
case 'medium':
|
|
102
|
+
return `
|
|
103
|
+
width: 6rem;
|
|
104
|
+
height: 6rem;
|
|
105
|
+
font-size: 2rem;
|
|
106
|
+
line-height: 2rem;
|
|
107
|
+
`;
|
|
108
|
+
case 'large':
|
|
109
|
+
return `
|
|
110
|
+
width: 12.5rem;
|
|
111
|
+
height: 12.5rem;
|
|
112
|
+
font-size: 2.8rem;
|
|
113
|
+
line-height: 2.8rem;
|
|
114
|
+
`;
|
|
115
|
+
case 'huge':
|
|
116
|
+
return `
|
|
117
|
+
width: 16rem;
|
|
118
|
+
height: 16rem;
|
|
119
|
+
font-size: 3rem;
|
|
120
|
+
line-height: 3rem;
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
}}
|
|
124
|
+
`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { ImageLoadingStatus } from './context';
|
|
3
|
+
|
|
4
|
+
export function useImageLoadingStatus(src?: string) {
|
|
5
|
+
const [loadingStatus, setLoadingStatus] = useState<ImageLoadingStatus>('idle');
|
|
6
|
+
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
|
+
if (!src) {
|
|
9
|
+
setLoadingStatus('error');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let isMounted = true;
|
|
14
|
+
const image = new window.Image();
|
|
15
|
+
|
|
16
|
+
const updateStatus = (status: ImageLoadingStatus) => () => {
|
|
17
|
+
if (!isMounted) return;
|
|
18
|
+
setLoadingStatus(status);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
setLoadingStatus('loading');
|
|
22
|
+
image.onload = updateStatus('loaded');
|
|
23
|
+
image.onerror = updateStatus('error');
|
|
24
|
+
image.src = src;
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
isMounted = false;
|
|
28
|
+
};
|
|
29
|
+
}, [src]);
|
|
30
|
+
|
|
31
|
+
return loadingStatus;
|
|
32
|
+
}
|