@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,148 @@
|
|
|
1
|
+
import { styled, Color, Size, AlertVariants } from '../../../styled';
|
|
2
|
+
import { shade } from 'polished';
|
|
3
|
+
|
|
4
|
+
export type ButtonColor = Color | AlertVariants | 'background' | 'white';
|
|
5
|
+
|
|
6
|
+
export const Default = styled.button<{
|
|
7
|
+
size: Size;
|
|
8
|
+
color: ButtonColor;
|
|
9
|
+
icon: boolean;
|
|
10
|
+
iconPosition: 'left' | 'right';
|
|
11
|
+
fullWidth: boolean;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
}>`
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
width: ${({ fullWidth }) => (fullWidth ? '100%' : 'fit-content')};
|
|
18
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
19
|
+
background-size: 200% auto;
|
|
20
|
+
cursor: ${({ isLoading }) => (isLoading ? 'default' : 'pointer')};
|
|
21
|
+
line-height: 1.9rem;
|
|
22
|
+
letter-spacing: 0;
|
|
23
|
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
|
24
|
+
border: 1px solid ${({ theme, color }) => theme.colors[color]};
|
|
25
|
+
background: ${({ theme, color }) => shade(0.5, theme.colors[color])};
|
|
26
|
+
|
|
27
|
+
&:focus {
|
|
28
|
+
outline: 0;
|
|
29
|
+
}
|
|
30
|
+
&:hover {
|
|
31
|
+
background-position: right center;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
span {
|
|
35
|
+
font-size: 1.25rem;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
color: ${({ theme, color }) => {
|
|
38
|
+
switch (color) {
|
|
39
|
+
case 'white':
|
|
40
|
+
return theme.colors.primary;
|
|
41
|
+
case 'background':
|
|
42
|
+
return theme.colors.text;
|
|
43
|
+
default:
|
|
44
|
+
return 'white';
|
|
45
|
+
}
|
|
46
|
+
}};
|
|
47
|
+
|
|
48
|
+
margin-left: ${({ icon, isLoading, iconPosition }): string =>
|
|
49
|
+
iconPosition === 'left' && (icon || isLoading) ? '10px' : '0px'};
|
|
50
|
+
margin-right: ${({ icon, isLoading, iconPosition }): string =>
|
|
51
|
+
iconPosition === 'right' && (icon || isLoading) ? '10px' : '0px'};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:disabled {
|
|
55
|
+
cursor: default;
|
|
56
|
+
background: ${({ theme }) => theme.colors.disabled};
|
|
57
|
+
border-color: ${({ theme }) => theme.colors.disabled};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
svg {
|
|
61
|
+
display: ${({ icon, isLoading }): string => (icon || isLoading ? 'block' : 'none')};
|
|
62
|
+
cursor: ${({ disabled }) => (disabled ? 'default' : 'pointer')};
|
|
63
|
+
fill: ${({ theme, color }) => {
|
|
64
|
+
switch (color) {
|
|
65
|
+
case 'white':
|
|
66
|
+
return theme.colors.primary;
|
|
67
|
+
case 'background':
|
|
68
|
+
return theme.colors.text;
|
|
69
|
+
default:
|
|
70
|
+
return 'white';
|
|
71
|
+
}
|
|
72
|
+
}};
|
|
73
|
+
stroke: white;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
${({ size, theme }) => {
|
|
77
|
+
switch (size) {
|
|
78
|
+
case 'tiny':
|
|
79
|
+
return `
|
|
80
|
+
padding: ${theme.spacing['0_25']} ${theme.spacing['0_75']};
|
|
81
|
+
`;
|
|
82
|
+
case 'small':
|
|
83
|
+
return `
|
|
84
|
+
padding: ${theme.spacing['0_5']} ${theme.spacing['1']}
|
|
85
|
+
`;
|
|
86
|
+
case 'medium':
|
|
87
|
+
return `
|
|
88
|
+
padding: ${theme.spacing['0_75']} ${theme.spacing['1_5']}
|
|
89
|
+
`;
|
|
90
|
+
case 'large':
|
|
91
|
+
return `
|
|
92
|
+
padding: ${theme.spacing['1']} ${theme.spacing['2']}
|
|
93
|
+
`;
|
|
94
|
+
case 'huge':
|
|
95
|
+
return `
|
|
96
|
+
span {
|
|
97
|
+
font-size: 105%;
|
|
98
|
+
}
|
|
99
|
+
padding: ${theme.spacing[1]} ${theme.spacing[2]}
|
|
100
|
+
`;
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
export const Outline = styled(Default)<{ color: ButtonColor }>`
|
|
106
|
+
background: transparent;
|
|
107
|
+
border: 0.1rem solid ${({ theme, color }): string => theme.colors[color]};
|
|
108
|
+
span {
|
|
109
|
+
color: ${({ theme, color }): string => theme.colors[color]};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&:hover {
|
|
113
|
+
background-position: right center;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&:disabled {
|
|
117
|
+
background: none;
|
|
118
|
+
border-color: ${({ theme }): string => theme.colors.text};
|
|
119
|
+
span {
|
|
120
|
+
color: ${({ theme }): string => theme.colors.text};
|
|
121
|
+
}
|
|
122
|
+
svg {
|
|
123
|
+
fill: ${({ theme }): string => theme.colors.backgroundAlt};
|
|
124
|
+
stroke: ${({ theme }): string => theme.colors.backgroundAlt};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
svg {
|
|
129
|
+
fill: ${({ theme, color }): string => theme.colors[color]};
|
|
130
|
+
stroke: ${({ theme, color }): string => theme.colors[color]};
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
export const Clear = styled(Outline)`
|
|
135
|
+
background: transparent;
|
|
136
|
+
box-shadow: none;
|
|
137
|
+
border: none;
|
|
138
|
+
span {
|
|
139
|
+
color: ${({ theme, color }): string => theme.colors[color]};
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
export const White = styled(Clear)`
|
|
144
|
+
background: ${({ theme }): string => theme.colors.white};
|
|
145
|
+
&:disabled {
|
|
146
|
+
background-color: white;
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { ContextMenu, ContextMenuProps } from '.';
|
|
5
|
+
|
|
6
|
+
const Container = styled.div`
|
|
7
|
+
border: 1px solid orange;
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Actions/ContextMenu',
|
|
12
|
+
component: ContextMenu,
|
|
13
|
+
} as Meta<ContextMenuProps>;
|
|
14
|
+
|
|
15
|
+
export const Document: StoryFn<ContextMenuProps> = () => {
|
|
16
|
+
return (
|
|
17
|
+
<Container>
|
|
18
|
+
The context menu does not receive a targetRef prop, so it is triggered on the entire document.
|
|
19
|
+
<ContextMenu>
|
|
20
|
+
<ContextMenu.Item label="Item 1" />
|
|
21
|
+
<ContextMenu.Item label="Item 2" />
|
|
22
|
+
<ContextMenu.Item label="Item 3" />
|
|
23
|
+
</ContextMenu>
|
|
24
|
+
</Container>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Target: StoryFn<ContextMenuProps> = () => {
|
|
29
|
+
const targetRef = React.useRef<HTMLDivElement>(null);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Container ref={targetRef}>
|
|
33
|
+
<ContextMenu targetRef={targetRef}>
|
|
34
|
+
<ContextMenu.Item label="Item 1" />
|
|
35
|
+
<ContextMenu.Item label="Item 2" />
|
|
36
|
+
<ContextMenu.Item label="Item 3" />
|
|
37
|
+
</ContextMenu>
|
|
38
|
+
</Container>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
const Container = styled.div<{ divider: boolean; hasChildren: boolean }>`
|
|
5
|
+
border-bottom: ${({ divider, theme, hasChildren }) =>
|
|
6
|
+
divider && hasChildren && `1px solid ${theme.colors.secondary}`};
|
|
7
|
+
padding-left: 0;
|
|
8
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
9
|
+
& > span {
|
|
10
|
+
opacity: 0.5;
|
|
11
|
+
padding-left: ${({ theme }) => theme.spacing[1]};
|
|
12
|
+
font-weight: 600;
|
|
13
|
+
font-size: ${({ theme }) => theme.fontSize.tiny};
|
|
14
|
+
}
|
|
15
|
+
&:last-child {
|
|
16
|
+
border-bottom: none;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
interface DropdownGroupProps {
|
|
21
|
+
label?: string;
|
|
22
|
+
divider?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ContextMenuGroup: FC<PropsWithChildren<DropdownGroupProps>> = ({ label, divider = false, children }) => {
|
|
26
|
+
const showDivider = divider || label ? true : false;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Container role="group" divider={showDivider} hasChildren={Array.isArray(children) ? children.length !== 0 : true}>
|
|
30
|
+
{label && <span role="presentation">{label}</span>}
|
|
31
|
+
{children}
|
|
32
|
+
</Container>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
const Container = styled.button`
|
|
5
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
6
|
+
color: ${({ theme }) => theme.colors.text};
|
|
7
|
+
width: 100%;
|
|
8
|
+
text-align: left;
|
|
9
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
10
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
11
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']} ${theme.spacing['1_5']}`};
|
|
12
|
+
|
|
13
|
+
&:first-child {
|
|
14
|
+
border-top-left-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
15
|
+
border-top-right-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&:last-child {
|
|
19
|
+
border-bottom-left-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
20
|
+
border-bottom-right-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
display: grid;
|
|
24
|
+
grid-template-columns: auto 50px auto;
|
|
25
|
+
align-items: center;
|
|
26
|
+
|
|
27
|
+
&:hover {
|
|
28
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&:disabled {
|
|
32
|
+
opacity: 0.5;
|
|
33
|
+
cursor: not-allowed;
|
|
34
|
+
|
|
35
|
+
&:hover {
|
|
36
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export interface MenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
42
|
+
label: string;
|
|
43
|
+
shortcut?: string;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(({ label, shortcut, disabled, ...props }, ref) => {
|
|
48
|
+
const containerRef = useRef<HTMLButtonElement>(null);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (containerRef.current) {
|
|
52
|
+
const labelSpan = containerRef.current.children[0] as HTMLSpanElement;
|
|
53
|
+
const shortcutSpan = containerRef.current.children[1] as HTMLSpanElement;
|
|
54
|
+
const totalWidth = labelSpan.offsetWidth + shortcutSpan.offsetWidth + 60;
|
|
55
|
+
containerRef.current.style.minWidth = `${totalWidth}px`;
|
|
56
|
+
}
|
|
57
|
+
}, [label, shortcut]);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Container {...props} ref={ref} role="menuitem" disabled={disabled}>
|
|
61
|
+
<span>{label}</span>
|
|
62
|
+
<span></span>
|
|
63
|
+
<span style={{ textAlign: 'right' }}>{shortcut}</span>
|
|
64
|
+
</Container>
|
|
65
|
+
);
|
|
66
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
forwardRef,
|
|
5
|
+
isValidElement,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
HTMLProps,
|
|
10
|
+
RefObject,
|
|
11
|
+
ReactElement,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import {
|
|
14
|
+
useFloating,
|
|
15
|
+
autoUpdate,
|
|
16
|
+
flip,
|
|
17
|
+
offset,
|
|
18
|
+
shift,
|
|
19
|
+
useRole,
|
|
20
|
+
useDismiss,
|
|
21
|
+
useInteractions,
|
|
22
|
+
useListNavigation,
|
|
23
|
+
useTypeahead,
|
|
24
|
+
FloatingPortal,
|
|
25
|
+
FloatingFocusManager,
|
|
26
|
+
} from '@floating-ui/react';
|
|
27
|
+
import { MenuItem, MenuItemProps } from './MenuItem';
|
|
28
|
+
import { ContextMenuGroup } from './Group';
|
|
29
|
+
|
|
30
|
+
import { styled } from '../../../styled';
|
|
31
|
+
|
|
32
|
+
const Container = styled.div`
|
|
33
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
34
|
+
box-shadow: ${({ theme }) => theme.elevation[2]};
|
|
35
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
36
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
37
|
+
&:focus-visible {
|
|
38
|
+
outline: none;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export interface ContextMenuProps extends HTMLProps<HTMLButtonElement> {
|
|
43
|
+
label?: string;
|
|
44
|
+
nested?: boolean;
|
|
45
|
+
targetRef?: RefObject<HTMLElement>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type ContextMenuComponent = {
|
|
49
|
+
(props: ContextMenuProps, ref: React.Ref<HTMLButtonElement>): JSX.Element;
|
|
50
|
+
Item: typeof MenuItem;
|
|
51
|
+
Group: typeof ContextMenuGroup;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const ContextMenu = forwardRef<HTMLButtonElement, ContextMenuProps>(({ children, targetRef }, _ref) => {
|
|
55
|
+
const [activeIndex, setActiveIndex] = useState<number | null>(null);
|
|
56
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
57
|
+
|
|
58
|
+
const listItemsRef = useRef<Array<HTMLButtonElement | null>>([]);
|
|
59
|
+
const listContentRef = useRef(
|
|
60
|
+
Children.map(children, (child) => (isValidElement(child) ? child.props.label : null)) as Array<string | null>
|
|
61
|
+
);
|
|
62
|
+
const allowMouseUpCloseRef = useRef(false);
|
|
63
|
+
|
|
64
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
65
|
+
open: isOpen,
|
|
66
|
+
onOpenChange: setIsOpen,
|
|
67
|
+
middleware: [
|
|
68
|
+
offset({ mainAxis: 5, alignmentAxis: 4 }),
|
|
69
|
+
flip({
|
|
70
|
+
fallbackPlacements: ['left-start'],
|
|
71
|
+
}),
|
|
72
|
+
shift({ padding: 10 }),
|
|
73
|
+
],
|
|
74
|
+
placement: 'right-start',
|
|
75
|
+
strategy: 'fixed',
|
|
76
|
+
whileElementsMounted: autoUpdate,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const role = useRole(context, { role: 'menu' });
|
|
80
|
+
const dismiss = useDismiss(context);
|
|
81
|
+
const listNavigation = useListNavigation(context, {
|
|
82
|
+
listRef: listItemsRef,
|
|
83
|
+
onNavigate: setActiveIndex,
|
|
84
|
+
activeIndex,
|
|
85
|
+
});
|
|
86
|
+
const typeahead = useTypeahead(context, {
|
|
87
|
+
enabled: isOpen,
|
|
88
|
+
listRef: listContentRef,
|
|
89
|
+
onMatch: setActiveIndex,
|
|
90
|
+
activeIndex,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const { getFloatingProps, getItemProps } = useInteractions([role, dismiss, listNavigation, typeahead]);
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
let timeout: number;
|
|
97
|
+
|
|
98
|
+
function onContextMenu(e: MouseEvent) {
|
|
99
|
+
if (targetRef?.current && targetRef?.current.contains(e.target as Node)) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
refs.setPositionReference({
|
|
102
|
+
getBoundingClientRect() {
|
|
103
|
+
return {
|
|
104
|
+
width: 0,
|
|
105
|
+
height: 0,
|
|
106
|
+
x: e.clientX,
|
|
107
|
+
y: e.clientY,
|
|
108
|
+
top: e.clientY,
|
|
109
|
+
right: e.clientX,
|
|
110
|
+
bottom: e.clientY,
|
|
111
|
+
left: e.clientX,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
setIsOpen(true);
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
|
|
119
|
+
allowMouseUpCloseRef.current = false;
|
|
120
|
+
timeout = window.setTimeout(() => {
|
|
121
|
+
allowMouseUpCloseRef.current = true;
|
|
122
|
+
}, 300);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function onMouseUp() {
|
|
127
|
+
if (allowMouseUpCloseRef.current) {
|
|
128
|
+
setIsOpen(false);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (targetRef?.current) {
|
|
133
|
+
targetRef.current.addEventListener('contextmenu', onContextMenu);
|
|
134
|
+
targetRef.current.addEventListener('mouseup', onMouseUp);
|
|
135
|
+
} else {
|
|
136
|
+
document.addEventListener('contextmenu', onContextMenu);
|
|
137
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
if (targetRef?.current) {
|
|
142
|
+
targetRef.current.removeEventListener('contextmenu', onContextMenu);
|
|
143
|
+
targetRef.current.removeEventListener('mouseup', onMouseUp);
|
|
144
|
+
} else {
|
|
145
|
+
document.removeEventListener('contextmenu', onContextMenu);
|
|
146
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
147
|
+
}
|
|
148
|
+
clearTimeout(timeout);
|
|
149
|
+
};
|
|
150
|
+
}, [refs]);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<FloatingPortal>
|
|
154
|
+
{isOpen && (
|
|
155
|
+
<FloatingFocusManager context={context} initialFocus={refs.floating}>
|
|
156
|
+
<Container className="ContextMenu" ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}>
|
|
157
|
+
{Children.map(children, (child, index) => {
|
|
158
|
+
if (isValidElement(child)) {
|
|
159
|
+
// If child is a Group, iterate over its children
|
|
160
|
+
if (child.type === ContextMenu.Group) {
|
|
161
|
+
const newGroupChildren = Children.map(
|
|
162
|
+
child.props.children,
|
|
163
|
+
(groupChild: ReactElement<MenuItemProps>, groupIndex) => {
|
|
164
|
+
if (isValidElement(groupChild)) {
|
|
165
|
+
return cloneElement(
|
|
166
|
+
groupChild,
|
|
167
|
+
getItemProps({
|
|
168
|
+
tabIndex: activeIndex === index ? 0 : -1,
|
|
169
|
+
ref(node: HTMLButtonElement) {
|
|
170
|
+
listItemsRef.current[groupIndex] = node;
|
|
171
|
+
},
|
|
172
|
+
onClick(e: React.MouseEvent<HTMLButtonElement>) {
|
|
173
|
+
groupChild.props.onClick?.(e);
|
|
174
|
+
setIsOpen(false);
|
|
175
|
+
},
|
|
176
|
+
onMouseUp(e: React.MouseEvent<HTMLButtonElement>) {
|
|
177
|
+
groupChild.props.onClick?.(e);
|
|
178
|
+
setIsOpen(false);
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return groupChild;
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
return <ContextMenu.Group {...child.props}>{newGroupChildren}</ContextMenu.Group>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// If child is not a Group, handle it as before
|
|
190
|
+
return cloneElement(
|
|
191
|
+
child,
|
|
192
|
+
getItemProps({
|
|
193
|
+
tabIndex: activeIndex === index ? 0 : -1,
|
|
194
|
+
ref(node: HTMLButtonElement) {
|
|
195
|
+
listItemsRef.current[index] = node;
|
|
196
|
+
},
|
|
197
|
+
onClick(e) {
|
|
198
|
+
child.props.onClick?.(e);
|
|
199
|
+
setIsOpen(false);
|
|
200
|
+
},
|
|
201
|
+
onMouseUp(e) {
|
|
202
|
+
child.props.onClick?.(e);
|
|
203
|
+
setIsOpen(false);
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
})}
|
|
209
|
+
</Container>
|
|
210
|
+
</FloatingFocusManager>
|
|
211
|
+
)}
|
|
212
|
+
</FloatingPortal>
|
|
213
|
+
);
|
|
214
|
+
}) as unknown as ContextMenuComponent;
|
|
215
|
+
|
|
216
|
+
ContextMenu.Item = MenuItem;
|
|
217
|
+
ContextMenu.Group = ContextMenuGroup;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { IconButton } from '../../../components';
|
|
4
|
+
import { Dropdown } from '.';
|
|
5
|
+
import { DropdownMenu } from './DropdownMenu';
|
|
6
|
+
import {
|
|
7
|
+
AiOutlineMenu as MenuIcon,
|
|
8
|
+
AiOutlineEdit as EditIcon,
|
|
9
|
+
AiOutlineSortAscending as SortAscendingIcon,
|
|
10
|
+
AiOutlineSortDescending as SortDescendingIcon,
|
|
11
|
+
AiOutlineFilter as FilterIcon,
|
|
12
|
+
AiOutlineGroup as GroupIcon,
|
|
13
|
+
AiOutlineEyeInvisible as HideIcon,
|
|
14
|
+
AiOutlineDelete as DeleteIcon,
|
|
15
|
+
} from 'react-icons/ai';
|
|
16
|
+
import { styled } from '../../../styled';
|
|
17
|
+
|
|
18
|
+
const Wrapper = styled.div`
|
|
19
|
+
display: flex;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
title: 'Actions/Dropdown',
|
|
25
|
+
component: Dropdown,
|
|
26
|
+
} as Meta;
|
|
27
|
+
|
|
28
|
+
export const Default: StoryFn = () => {
|
|
29
|
+
return (
|
|
30
|
+
<Wrapper>
|
|
31
|
+
<Dropdown>
|
|
32
|
+
<Dropdown.Trigger asChild>
|
|
33
|
+
<IconButton icon={<MenuIcon />} ariaLabel="click me" />
|
|
34
|
+
</Dropdown.Trigger>
|
|
35
|
+
<Dropdown.Menu>
|
|
36
|
+
<DropdownMenu.Group label="Sorting">
|
|
37
|
+
<Dropdown.Menu.Item label="Sort ascending (first...last)" onClick={() => {}} icon={<SortAscendingIcon />} />
|
|
38
|
+
<Dropdown.Menu.Item
|
|
39
|
+
label="Sort descending (last...first)"
|
|
40
|
+
onClick={() => {}}
|
|
41
|
+
icon={<SortDescendingIcon />}
|
|
42
|
+
/>
|
|
43
|
+
</DropdownMenu.Group>
|
|
44
|
+
|
|
45
|
+
<DropdownMenu.Group label="Editing">
|
|
46
|
+
<Dropdown.Menu.Item iconPosition="right" label="Edit values..." onClick={() => {}} icon={<EditIcon />} />
|
|
47
|
+
<Dropdown.Menu.Item
|
|
48
|
+
iconPosition="right"
|
|
49
|
+
label="Filter by values"
|
|
50
|
+
onClick={() => {}}
|
|
51
|
+
icon={<FilterIcon />}
|
|
52
|
+
/>
|
|
53
|
+
<Dropdown.Menu.Item iconPosition="right" label="Group by values" onClick={() => {}} icon={<GroupIcon />} />
|
|
54
|
+
</DropdownMenu.Group>
|
|
55
|
+
|
|
56
|
+
<DropdownMenu.Group>
|
|
57
|
+
<Dropdown.Menu.Item label="Hide field" onClick={() => {}} icon={<HideIcon />} disabled />
|
|
58
|
+
<Dropdown.Menu.Item label="Delete field" onClick={() => {}} icon={<DeleteIcon />} />
|
|
59
|
+
</DropdownMenu.Group>
|
|
60
|
+
</Dropdown.Menu>
|
|
61
|
+
</Dropdown>
|
|
62
|
+
</Wrapper>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const ToolTipOnTrigger = () => {
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
Because <strong>Dropdown.trigger</strong> adds properties to the child element, The IconButton cannot be wrapped
|
|
70
|
+
in a tooltip. Tooltip props should be passed as props to the <strong>Dropdown.trigger</strong> element.
|
|
71
|
+
<Dropdown>
|
|
72
|
+
<Dropdown.Trigger
|
|
73
|
+
asChild
|
|
74
|
+
tooltipOptions={{
|
|
75
|
+
content: 'This is the tooltip',
|
|
76
|
+
placement: 'top',
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<IconButton icon={<MenuIcon />} ariaLabel="click me" />
|
|
80
|
+
</Dropdown.Trigger>
|
|
81
|
+
<Dropdown.Menu>
|
|
82
|
+
<Dropdown.Menu.Item label="Sort ascending (first...last)" onClick={() => {}} icon={<SortAscendingIcon />} />
|
|
83
|
+
<Dropdown.Menu.Item label="Sort descending (last...first)" onClick={() => {}} icon={<SortDescendingIcon />} />
|
|
84
|
+
</Dropdown.Menu>
|
|
85
|
+
</Dropdown>
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useContext, createContext, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { useDropdown } from './useDropdown';
|
|
3
|
+
|
|
4
|
+
type ContextType =
|
|
5
|
+
| (ReturnType<typeof useDropdown> & {
|
|
6
|
+
setLabelId: Dispatch<SetStateAction<string | undefined>>;
|
|
7
|
+
setDescriptionId: Dispatch<SetStateAction<string | undefined>>;
|
|
8
|
+
})
|
|
9
|
+
| null;
|
|
10
|
+
|
|
11
|
+
export const DropdownContext = createContext<ContextType>(null);
|
|
12
|
+
|
|
13
|
+
export const useDropdownContext = () => {
|
|
14
|
+
const context = useContext(DropdownContext);
|
|
15
|
+
|
|
16
|
+
if (context == null) {
|
|
17
|
+
throw new Error('Dropdown components must be wrapped in <Dropdown />');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return context;
|
|
21
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { forwardRef, HTMLProps, Ref } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useMergeRefs,
|
|
4
|
+
FloatingPortal,
|
|
5
|
+
FloatingFocusManager,
|
|
6
|
+
FloatingList,
|
|
7
|
+
useTransitionStyles,
|
|
8
|
+
} from '@floating-ui/react';
|
|
9
|
+
import { useDropdownContext } from './DropdownContext';
|
|
10
|
+
import { DropdownMenuItem } from './DropdownMenuItem';
|
|
11
|
+
import { DropdownMenuGroup } from './DropdownMenuGroup';
|
|
12
|
+
import { styled } from '../../../styled';
|
|
13
|
+
|
|
14
|
+
const Container = styled.div`
|
|
15
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
16
|
+
border: 0.1rem solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
17
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
18
|
+
padding: ${({ theme }) => theme.spacing['0_5']};
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
type DropdownMenuComponent = {
|
|
22
|
+
(props: HTMLProps<HTMLDivElement>, ref: Ref<HTMLButtonElement>): JSX.Element;
|
|
23
|
+
Item: typeof DropdownMenuItem;
|
|
24
|
+
Group: typeof DropdownMenuGroup;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const DropdownMenu = forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(({ children, ...props }, propRef) => {
|
|
28
|
+
const { context, floatingStyles, elementsRef, labelsRef, getFloatingProps, descriptionId, labelId } =
|
|
29
|
+
useDropdownContext();
|
|
30
|
+
|
|
31
|
+
const ref = useMergeRefs([context.refs.setFloating, propRef]);
|
|
32
|
+
|
|
33
|
+
const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
|
|
34
|
+
duration: {
|
|
35
|
+
open: 0,
|
|
36
|
+
close: 100,
|
|
37
|
+
},
|
|
38
|
+
initial: () => ({
|
|
39
|
+
opacity: 0,
|
|
40
|
+
open: { opacity: 1 },
|
|
41
|
+
close: { opacity: 0 },
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<FloatingPortal>
|
|
47
|
+
{isMounted && (
|
|
48
|
+
<FloatingFocusManager context={context} modal={false}>
|
|
49
|
+
<Container
|
|
50
|
+
ref={ref}
|
|
51
|
+
style={{ ...transitionStyles, ...floatingStyles }}
|
|
52
|
+
aria-labelledby={labelId}
|
|
53
|
+
aria-describedby={descriptionId}
|
|
54
|
+
{...getFloatingProps(props)}
|
|
55
|
+
>
|
|
56
|
+
<FloatingList elementsRef={elementsRef} labelsRef={labelsRef}>
|
|
57
|
+
{children}
|
|
58
|
+
</FloatingList>
|
|
59
|
+
</Container>
|
|
60
|
+
</FloatingFocusManager>
|
|
61
|
+
)}
|
|
62
|
+
</FloatingPortal>
|
|
63
|
+
);
|
|
64
|
+
}) as unknown as DropdownMenuComponent;
|
|
65
|
+
|
|
66
|
+
DropdownMenu.Item = DropdownMenuItem;
|
|
67
|
+
DropdownMenu.Group = DropdownMenuGroup;
|