@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,239 @@
|
|
|
1
|
+
import { useForm, useFieldArray, SubmitHandler } from 'react-hook-form';
|
|
2
|
+
import { Table } from '@tanstack/react-table';
|
|
3
|
+
import { Button, IconButton, Popover, Tooltip } from '../../../../../components';
|
|
4
|
+
import { AiOutlineFilter as FilterIcon, AiOutlineClose as RemoveIcon } from 'react-icons/ai';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { ButtonContainer, Container, FilterActions, FilterContainer } from './style';
|
|
9
|
+
import { FilterRow } from './field';
|
|
10
|
+
|
|
11
|
+
export enum Operators {
|
|
12
|
+
is = 'is',
|
|
13
|
+
contains = 'contains',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum FilterInputType {
|
|
17
|
+
string = 'string',
|
|
18
|
+
uuid = 'uuid',
|
|
19
|
+
datetime = 'datetime',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IFormInputs {
|
|
23
|
+
filters: {
|
|
24
|
+
column: string;
|
|
25
|
+
operator: string;
|
|
26
|
+
value: string;
|
|
27
|
+
type: FilterInputType;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface FilterProps<DataType extends object> {
|
|
32
|
+
table: Table<DataType>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function Filter<DataType extends object>({ table }: FilterProps<DataType>) {
|
|
36
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
37
|
+
|
|
38
|
+
// Only get the columnIds on initial table render
|
|
39
|
+
const columnIds = useMemo(() => {
|
|
40
|
+
const ids = table
|
|
41
|
+
.getAllColumns()
|
|
42
|
+
.filter((column) => {
|
|
43
|
+
return column.getCanFilter();
|
|
44
|
+
})
|
|
45
|
+
.map((column) => column.id);
|
|
46
|
+
|
|
47
|
+
return ids;
|
|
48
|
+
}, [table.getAllColumns()]);
|
|
49
|
+
|
|
50
|
+
const basedShape = z.object({
|
|
51
|
+
column: z.string().refine((value) => columnIds.includes(value), {
|
|
52
|
+
message: 'Please select a valid column.',
|
|
53
|
+
}),
|
|
54
|
+
operator: z.nativeEnum(Operators, {
|
|
55
|
+
errorMap: () => {
|
|
56
|
+
return {
|
|
57
|
+
message: 'Condition is required.',
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const validationSchema = useMemo(() => {
|
|
64
|
+
return z.object({
|
|
65
|
+
filters: z.array(
|
|
66
|
+
z
|
|
67
|
+
.discriminatedUnion('type', [
|
|
68
|
+
z.object({
|
|
69
|
+
type: z.literal(FilterInputType.string),
|
|
70
|
+
value: z.string().nonempty({
|
|
71
|
+
message: 'Value is required.',
|
|
72
|
+
}),
|
|
73
|
+
}),
|
|
74
|
+
z.object({
|
|
75
|
+
type: z.literal(FilterInputType.uuid),
|
|
76
|
+
value: z.string().uuid().nonempty({
|
|
77
|
+
message: 'Value is required.',
|
|
78
|
+
}),
|
|
79
|
+
}),
|
|
80
|
+
z.object({
|
|
81
|
+
type: z.literal(FilterInputType.datetime),
|
|
82
|
+
value: z.string().datetime().nonempty({
|
|
83
|
+
message: 'Value is required.',
|
|
84
|
+
}),
|
|
85
|
+
}),
|
|
86
|
+
])
|
|
87
|
+
.and(basedShape)
|
|
88
|
+
),
|
|
89
|
+
});
|
|
90
|
+
}, [columnIds]);
|
|
91
|
+
|
|
92
|
+
// these are the filters that are already applied to the table
|
|
93
|
+
const defaultColumnFilters = table
|
|
94
|
+
.getState()
|
|
95
|
+
.columnFilters.filter((filter) => Object.keys(filter).length)
|
|
96
|
+
.map(({ id, value }) => {
|
|
97
|
+
return {
|
|
98
|
+
column: id,
|
|
99
|
+
operator: Operators.is,
|
|
100
|
+
value: [...(value as string[])],
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// these are the global filters (search in api) that are already applied to the table
|
|
105
|
+
const defaultGlobalFilters = table
|
|
106
|
+
.getState()
|
|
107
|
+
.globalFilter.filter((filter: { value: string; id: string }) => Object.keys(filter).length)
|
|
108
|
+
.map(({ value, id }: { value: string[]; id: string }) => {
|
|
109
|
+
return {
|
|
110
|
+
column: id,
|
|
111
|
+
operator: Operators.contains,
|
|
112
|
+
value: [...value],
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const { control, handleSubmit, setValue } = useForm<IFormInputs>({
|
|
117
|
+
mode: 'onSubmit',
|
|
118
|
+
|
|
119
|
+
resolver: zodResolver(validationSchema),
|
|
120
|
+
defaultValues: {
|
|
121
|
+
filters: [...defaultColumnFilters, ...defaultGlobalFilters],
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const { append, fields, remove } = useFieldArray({ name: 'filters', control });
|
|
126
|
+
|
|
127
|
+
const handleClearFilters = useCallback(() => {
|
|
128
|
+
table.resetColumnFilters();
|
|
129
|
+
table.resetGlobalFilter();
|
|
130
|
+
remove();
|
|
131
|
+
append({
|
|
132
|
+
column: '',
|
|
133
|
+
operator: '',
|
|
134
|
+
value: '',
|
|
135
|
+
type: FilterInputType.string,
|
|
136
|
+
});
|
|
137
|
+
}, [remove]);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (fields.length === 0) {
|
|
141
|
+
append({
|
|
142
|
+
column: '',
|
|
143
|
+
operator: '',
|
|
144
|
+
value: '',
|
|
145
|
+
type: FilterInputType.string,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, [fields]);
|
|
149
|
+
|
|
150
|
+
// filters contains both column filters and global filters
|
|
151
|
+
const onSubmit: SubmitHandler<IFormInputs> = ({ filters }) => {
|
|
152
|
+
const columnFilters: Record<string, string[]> = {};
|
|
153
|
+
const globalFilters: Record<string, string[]> = {};
|
|
154
|
+
|
|
155
|
+
filters.forEach((filter) => {
|
|
156
|
+
const target = filter.operator === 'is' ? columnFilters : globalFilters;
|
|
157
|
+
if (!target[filter.column]) {
|
|
158
|
+
target[filter.column] = [];
|
|
159
|
+
}
|
|
160
|
+
target[filter.column].push(filter.value);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const columnFiltersArray = Object.entries(columnFilters).map(([id, values]) => ({ id, value: values }));
|
|
164
|
+
const globalFiltersArray = Object.entries(globalFilters).map(([id, values]) => ({ id, value: values }));
|
|
165
|
+
|
|
166
|
+
table.setColumnFilters(columnFiltersArray);
|
|
167
|
+
table.setGlobalFilter(globalFiltersArray);
|
|
168
|
+
setOpen(false);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// const filterCount = table.getState().columnFilters.length + table.getState().globalFilter.length;
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<Popover open={open} onOpenChange={setOpen} placement="bottom-end">
|
|
175
|
+
<Popover.Trigger asChild>
|
|
176
|
+
<IconButton icon={<FilterIcon />} onClick={() => setOpen(!open)} size="large" ariaLabel="filter" />
|
|
177
|
+
</Popover.Trigger>
|
|
178
|
+
<Popover.Content>
|
|
179
|
+
<Container>
|
|
180
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
181
|
+
{fields.map((field, index) => {
|
|
182
|
+
return (
|
|
183
|
+
<FilterContainer key={field.id} hasMultipleFields={fields.length > 1}>
|
|
184
|
+
{fields.length > 1 && (
|
|
185
|
+
<Tooltip key={`remove-${field.id}`}>
|
|
186
|
+
<Tooltip.Trigger asChild>
|
|
187
|
+
<IconButton
|
|
188
|
+
size="tiny"
|
|
189
|
+
icon={<RemoveIcon />}
|
|
190
|
+
ariaLabel="remove filter"
|
|
191
|
+
onClick={() => {
|
|
192
|
+
remove(index);
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
</Tooltip.Trigger>
|
|
196
|
+
<Tooltip.Content>Remove filter</Tooltip.Content>
|
|
197
|
+
</Tooltip>
|
|
198
|
+
)}
|
|
199
|
+
<FilterRow
|
|
200
|
+
index={index}
|
|
201
|
+
id={field.id}
|
|
202
|
+
columnIds={columnIds}
|
|
203
|
+
control={control}
|
|
204
|
+
setValue={setValue}
|
|
205
|
+
getColumn={table.getColumn}
|
|
206
|
+
/>
|
|
207
|
+
</FilterContainer>
|
|
208
|
+
);
|
|
209
|
+
})}
|
|
210
|
+
<ButtonContainer justifyContent={fields.length > 0 ? 'space-between' : 'flex-end'}>
|
|
211
|
+
{fields.length > 0 && (
|
|
212
|
+
<Button type="button" variant="clear" text="Clear filters" onClick={handleClearFilters} />
|
|
213
|
+
)}
|
|
214
|
+
<FilterActions>
|
|
215
|
+
<Button
|
|
216
|
+
onClick={() =>
|
|
217
|
+
append({
|
|
218
|
+
column: '',
|
|
219
|
+
operator: '',
|
|
220
|
+
value: '',
|
|
221
|
+
type: FilterInputType.string,
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
variant="clear"
|
|
225
|
+
text="Add filter"
|
|
226
|
+
/>
|
|
227
|
+
<Button type="submit" text="Apply filters" />
|
|
228
|
+
</FilterActions>
|
|
229
|
+
</ButtonContainer>
|
|
230
|
+
</form>
|
|
231
|
+
{/* dropdown with all columns */}
|
|
232
|
+
{/* dropdown with all operators */}
|
|
233
|
+
{/* input for value */}
|
|
234
|
+
{/* when all fields are valid, considered a filter */}
|
|
235
|
+
</Container>
|
|
236
|
+
</Popover.Content>
|
|
237
|
+
</Popover>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { styled } from '../../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
padding: ${({ theme }) => theme.spacing['1_5']};
|
|
5
|
+
`;
|
|
6
|
+
|
|
7
|
+
export const FilterContainer = styled.div<{ hasMultipleFields: boolean }>`
|
|
8
|
+
display: grid;
|
|
9
|
+
grid-template-columns: ${({ hasMultipleFields }) => (hasMultipleFields ? '20px 1fr 1fr 1fr' : '1fr 1fr 1fr')};
|
|
10
|
+
gap: ${({ theme }) => theme.spacing['1_5']};
|
|
11
|
+
align-items: center;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const ButtonContainer = styled.div<{ justifyContent: string }>`
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
justify-content: ${({ justifyContent }) => justifyContent};
|
|
18
|
+
gap: ${({ theme }) => theme.spacing['1_5']};
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const FilterActions = styled.div`
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: row;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
gap: ${({ theme }) => theme.spacing['1_5']};
|
|
26
|
+
`;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { FC, useMemo } from 'react';
|
|
2
|
+
import { Button, IconButton } from '../../../../../components';
|
|
3
|
+
import { PaginationContainer } from './style';
|
|
4
|
+
import {
|
|
5
|
+
FaAngleRight as NextIcon,
|
|
6
|
+
FaAnglesRight as LastIcon,
|
|
7
|
+
FaChevronLeft as PreviousIcon,
|
|
8
|
+
FaAnglesLeft as FirstIcon,
|
|
9
|
+
} from 'react-icons/fa6';
|
|
10
|
+
|
|
11
|
+
const range = (start: number, end: number) => {
|
|
12
|
+
return Array.from({ length: end - start }, (_, index) => index + start);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getPageWindow = (pageCount: number, windowSize: number, currentPage: number): { start: number; end: number } => {
|
|
16
|
+
const ceiling = Math.ceil(windowSize / 2);
|
|
17
|
+
const floor = Math.floor(windowSize / 2);
|
|
18
|
+
|
|
19
|
+
if (pageCount < windowSize) {
|
|
20
|
+
return { start: 1, end: pageCount + 1 };
|
|
21
|
+
} else if (currentPage >= 1 && currentPage <= ceiling) {
|
|
22
|
+
return { start: 1, end: windowSize + 1 };
|
|
23
|
+
} else if (currentPage + floor >= pageCount) {
|
|
24
|
+
return { start: pageCount - windowSize + 1, end: pageCount + 1 };
|
|
25
|
+
} else {
|
|
26
|
+
return { start: currentPage - ceiling + 1, end: currentPage + floor + 1 };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface PaginationProps {
|
|
31
|
+
setPageIndex: (index: number) => void;
|
|
32
|
+
pageIndex: number;
|
|
33
|
+
hasPrevious: boolean;
|
|
34
|
+
previousPage: () => void;
|
|
35
|
+
nextPage: () => void;
|
|
36
|
+
hasNext: boolean;
|
|
37
|
+
pageCount: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Pagination: FC<PaginationProps> = ({
|
|
41
|
+
setPageIndex,
|
|
42
|
+
hasPrevious,
|
|
43
|
+
pageIndex,
|
|
44
|
+
hasNext,
|
|
45
|
+
pageCount,
|
|
46
|
+
previousPage,
|
|
47
|
+
nextPage,
|
|
48
|
+
}) => {
|
|
49
|
+
const windowSize = 5;
|
|
50
|
+
const pageWindow = getPageWindow(pageCount, windowSize, pageIndex + 1);
|
|
51
|
+
const pages = range(pageWindow.start, pageWindow.end);
|
|
52
|
+
|
|
53
|
+
const showButtons = useMemo(() => {
|
|
54
|
+
return pageCount > 1;
|
|
55
|
+
}, [pageCount]);
|
|
56
|
+
|
|
57
|
+
const showJumps = useMemo(() => {
|
|
58
|
+
return showButtons && pageCount > windowSize;
|
|
59
|
+
}, [showButtons, pageCount, windowSize]);
|
|
60
|
+
|
|
61
|
+
const handlePreviousPageClick = () => {
|
|
62
|
+
previousPage();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<PaginationContainer border={false}>
|
|
67
|
+
{showJumps && (
|
|
68
|
+
<IconButton
|
|
69
|
+
size="tiny"
|
|
70
|
+
onClick={() => setPageIndex(0)}
|
|
71
|
+
icon={<FirstIcon />}
|
|
72
|
+
disabled={!hasPrevious}
|
|
73
|
+
ariaLabel="First page"
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
{showButtons && (
|
|
77
|
+
<IconButton
|
|
78
|
+
size="tiny"
|
|
79
|
+
onClick={handlePreviousPageClick}
|
|
80
|
+
icon={<PreviousIcon />}
|
|
81
|
+
disabled={!hasPrevious}
|
|
82
|
+
ariaLabel="Previous page"
|
|
83
|
+
/>
|
|
84
|
+
)}
|
|
85
|
+
{showButtons &&
|
|
86
|
+
pages.map((i) => (
|
|
87
|
+
<Button
|
|
88
|
+
variant="outline"
|
|
89
|
+
onClick={() => setPageIndex(i - 1)}
|
|
90
|
+
className={i === pageIndex + 1 ? 'active' : ''}
|
|
91
|
+
text={`${i}`}
|
|
92
|
+
/>
|
|
93
|
+
))}
|
|
94
|
+
{showButtons && (
|
|
95
|
+
<IconButton size="tiny" icon={<NextIcon />} onClick={nextPage} disabled={!hasNext} ariaLabel="next page" />
|
|
96
|
+
)}
|
|
97
|
+
{showJumps && (
|
|
98
|
+
<IconButton
|
|
99
|
+
size="tiny"
|
|
100
|
+
icon={<LastIcon />}
|
|
101
|
+
onClick={() => setPageIndex(pageCount - 1)}
|
|
102
|
+
disabled={!hasNext}
|
|
103
|
+
ariaLabel="Last page"
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
</PaginationContainer>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { styled } from '../../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const PaginationContainer = styled.div<{ border?: boolean }>`
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: flex-end;
|
|
6
|
+
|
|
7
|
+
span {
|
|
8
|
+
color: ${({ theme }) => theme.colors.text};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
button {
|
|
12
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
13
|
+
padding: ${({ theme }) => `${theme.spacing['0_5']} ${theme.spacing[1]}`};
|
|
14
|
+
font-weight: 400;
|
|
15
|
+
border-color: ${({ theme }) => theme.colors.textAlt};
|
|
16
|
+
border-right: 0;
|
|
17
|
+
border-radius: ${({ theme }) => theme.borderRadius.small};
|
|
18
|
+
|
|
19
|
+
margin-left: ${({ theme }) => theme.spacing['0_25']};
|
|
20
|
+
margin-right: ${({ theme }) => theme.spacing['0_25']};
|
|
21
|
+
&:first-child {
|
|
22
|
+
margin-left: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&:last-child {
|
|
26
|
+
margin-right: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.active {
|
|
30
|
+
border: 1px solid ${({ theme }) => theme.colors.primary};
|
|
31
|
+
span {
|
|
32
|
+
color: ${({ theme }) => theme.colors.text};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
${({ border }) => !border && 'border: 0;'}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
button:first-of-type {
|
|
40
|
+
border-radius: 0.25rem 0 0 0.25rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
button:last-of-type {
|
|
44
|
+
border-right: ${({ theme }) => `solid 1px ${theme.colors.textAlt}`};
|
|
45
|
+
border-radius: 0 0.25rem 0.25rem 0;
|
|
46
|
+
|
|
47
|
+
${({ border }) => !border && 'border: 0;'}
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Avatar } from './Avatar';
|
|
2
|
+
export type { AvatarProps } from './Avatar';
|
|
3
|
+
|
|
4
|
+
export { Chip } from './Chip';
|
|
5
|
+
export type { ChipProps } from './Chip';
|
|
6
|
+
|
|
7
|
+
export { Table } from './Table';
|
|
8
|
+
export type { TableProps } from './Table';
|
|
9
|
+
|
|
10
|
+
export { Console } from './Console';
|
|
11
|
+
export type { ConsoleProps, Message } from './Console';
|
|
12
|
+
|
|
13
|
+
export { InfiniteScroll } from './InfiniteScroll';
|
|
14
|
+
export type { InfiniteScrollProps } from './InfiniteScroll';
|
|
15
|
+
|
|
16
|
+
export { Drawer, DrawerSkeleton } from './Drawer';
|
|
17
|
+
|
|
18
|
+
export { Stats } from './Stats';
|
|
19
|
+
export type { StatsProps } from './Stats/';
|
|
20
|
+
|
|
21
|
+
export { LinkCard } from './LinkCard';
|
|
22
|
+
export type { LinkCardProps } from './LinkCard';
|
|
23
|
+
|
|
24
|
+
export { DateFormatter } from './DateFormatter';
|
|
25
|
+
export type { DateFormatterProps } from './DateFormatter';
|
|
26
|
+
|
|
27
|
+
export { CopyId } from './CopyId';
|
|
28
|
+
export type { CopyIdProps } from './CopyId';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
4
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
import { Dialog } from '.';
|
|
7
|
+
import { Button, TextField } from '../../../components';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Dialogs/Default',
|
|
11
|
+
component: Dialog,
|
|
12
|
+
} as Meta;
|
|
13
|
+
|
|
14
|
+
export const Default: StoryFn = () => {
|
|
15
|
+
interface IFormInputs {
|
|
16
|
+
moduleName: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
20
|
+
const [data, setData] = useState<IFormInputs>();
|
|
21
|
+
const { control, handleSubmit } = useForm<IFormInputs>();
|
|
22
|
+
|
|
23
|
+
const onSubmit: SubmitHandler<IFormInputs> = (data) => {
|
|
24
|
+
setData(data);
|
|
25
|
+
setOpen(false);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<Button onClick={() => setOpen(true)} text="Open dialog" />
|
|
31
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
32
|
+
<Dialog.Content>
|
|
33
|
+
<Dialog.Heading>New Module</Dialog.Heading>
|
|
34
|
+
<Dialog.Body>
|
|
35
|
+
<h2>Create module</h2>
|
|
36
|
+
<p>Modules are what makes Takaro great.</p>
|
|
37
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
38
|
+
<TextField label="Module name" name="moduleName" placeholder="cute kittens" control={control} />
|
|
39
|
+
<Button text="Create module" type="submit" fullWidth />
|
|
40
|
+
</form>
|
|
41
|
+
</Dialog.Body>
|
|
42
|
+
</Dialog.Content>
|
|
43
|
+
</Dialog>
|
|
44
|
+
<pre>result: {data?.moduleName}</pre>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const SingleActionDialog: StoryFn = () => {
|
|
50
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
51
|
+
|
|
52
|
+
const handleAction = () => {
|
|
53
|
+
setOpen(false);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<Button onClick={() => setOpen(true)} text="Open dialog" />
|
|
59
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
60
|
+
<Dialog.Content>
|
|
61
|
+
<Dialog.Heading>New Module</Dialog.Heading>
|
|
62
|
+
<Dialog.Body size="small">
|
|
63
|
+
<h2>Go back to dashboard!</h2>
|
|
64
|
+
<p>
|
|
65
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
|
|
66
|
+
dolore magna aliqua.
|
|
67
|
+
</p>
|
|
68
|
+
<Button onClick={handleAction} size="large" fullWidth text="Go back to dashboard" />
|
|
69
|
+
</Dialog.Body>
|
|
70
|
+
</Dialog.Content>
|
|
71
|
+
</Dialog>
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { forwardRef, PropsWithChildren, useId, useLayoutEffect } from 'react';
|
|
2
|
+
import { useDialogContext } from './DialogContext';
|
|
3
|
+
import { Size, styled } from '../../../styled';
|
|
4
|
+
|
|
5
|
+
const Container = styled.div<{ size: Size }>`
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-flow: column nowrap;
|
|
8
|
+
align-items: center;
|
|
9
|
+
width: 100%;
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
padding: ${({ theme }) => theme.spacing[4]};
|
|
12
|
+
|
|
13
|
+
& > p {
|
|
14
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
${({ size, theme }) => {
|
|
18
|
+
switch (size) {
|
|
19
|
+
case 'tiny':
|
|
20
|
+
case 'small':
|
|
21
|
+
return `
|
|
22
|
+
max-width: 450px;
|
|
23
|
+
padding: ${theme.spacing[2]};
|
|
24
|
+
`;
|
|
25
|
+
case 'medium':
|
|
26
|
+
return `
|
|
27
|
+
max-width: 500px;
|
|
28
|
+
padding: ${theme.spacing[3]};
|
|
29
|
+
`;
|
|
30
|
+
case 'large':
|
|
31
|
+
case 'huge':
|
|
32
|
+
return `
|
|
33
|
+
max-width: 600px;
|
|
34
|
+
padding: ${theme.spacing[4]};
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
}};
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export interface DialogBodyProps {
|
|
41
|
+
size?: Size;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const DialogBody = forwardRef<HTMLParagraphElement, PropsWithChildren<DialogBodyProps>>(
|
|
45
|
+
({ children, size = 'medium', ...props }, ref) => {
|
|
46
|
+
const { setDescriptionId } = useDialogContext();
|
|
47
|
+
const id = useId();
|
|
48
|
+
|
|
49
|
+
// Only sets `aria-describedby` on the Dialog root element
|
|
50
|
+
// if this component is mounted inside it.
|
|
51
|
+
useLayoutEffect(() => {
|
|
52
|
+
setDescriptionId(id);
|
|
53
|
+
return () => setDescriptionId(undefined);
|
|
54
|
+
}, [id, setDescriptionId]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Container {...props} ref={ref} id={id} size={size}>
|
|
58
|
+
{children}
|
|
59
|
+
</Container>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
import { FloatingFocusManager, FloatingOverlay, FloatingPortal, useMergeRefs } from '@floating-ui/react';
|
|
3
|
+
import { Card } from '../../../components';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import { useDialogContext } from './DialogContext';
|
|
6
|
+
|
|
7
|
+
const StyledFloatingOverlay = styled(FloatingOverlay)`
|
|
8
|
+
background: rgba(0, 0, 0, 0.8);
|
|
9
|
+
display: grid;
|
|
10
|
+
place-items: center;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const CardBody = styled.div`
|
|
14
|
+
min-width: 300px;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const DialogContent = forwardRef<HTMLDivElement, React.HTMLProps<HTMLDivElement>>((props, propRef) => {
|
|
18
|
+
const { context: floatingContext, ...context } = useDialogContext();
|
|
19
|
+
const ref = useMergeRefs([context.refs.setFloating, propRef]);
|
|
20
|
+
|
|
21
|
+
const root = document.getElementById('dialog');
|
|
22
|
+
if (!root) {
|
|
23
|
+
throw new Error('Dialog need to render in a <div id="dialog"></div>');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<FloatingPortal root={root}>
|
|
28
|
+
{context.open && (
|
|
29
|
+
<StyledFloatingOverlay lockScroll>
|
|
30
|
+
<FloatingFocusManager context={floatingContext}>
|
|
31
|
+
<Card
|
|
32
|
+
ref={ref}
|
|
33
|
+
aria-labelledby={context.labelId}
|
|
34
|
+
aria-describedby={context.descriptionId}
|
|
35
|
+
{...context.getFloatingProps({
|
|
36
|
+
...props,
|
|
37
|
+
})}
|
|
38
|
+
>
|
|
39
|
+
<CardBody>{props.children}</CardBody>
|
|
40
|
+
</Card>
|
|
41
|
+
</FloatingFocusManager>
|
|
42
|
+
</StyledFloatingOverlay>
|
|
43
|
+
)}
|
|
44
|
+
</FloatingPortal>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useContext, createContext } from 'react';
|
|
2
|
+
import { useDialog } from './useDialog';
|
|
3
|
+
|
|
4
|
+
type ContextType =
|
|
5
|
+
| (ReturnType<typeof useDialog> & {
|
|
6
|
+
setLabelId: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
7
|
+
setDescriptionId: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
8
|
+
})
|
|
9
|
+
| null;
|
|
10
|
+
|
|
11
|
+
export const DialogContext = createContext<ContextType>(null);
|
|
12
|
+
|
|
13
|
+
export const useDialogContext = () => {
|
|
14
|
+
const context = useContext(DialogContext);
|
|
15
|
+
|
|
16
|
+
if (context == null) {
|
|
17
|
+
throw new Error('Dialog components must be wrapped in <Dialog />');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return context;
|
|
21
|
+
};
|