@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,127 @@
|
|
|
1
|
+
import { CSSProperties, FC, ReactElement, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
AiFillWarning as WarningIcon,
|
|
4
|
+
AiFillCloseCircle as ErrorIcon,
|
|
5
|
+
AiFillBug as DebugIcon,
|
|
6
|
+
AiFillInfoCircle as InfoIcon,
|
|
7
|
+
AiFillMacCommand as CommandIcon,
|
|
8
|
+
} from 'react-icons/ai';
|
|
9
|
+
import { Tooltip } from '../../../../components';
|
|
10
|
+
import { BsChevronExpand as EnterIcon } from 'react-icons/bs';
|
|
11
|
+
import {
|
|
12
|
+
Wrapper,
|
|
13
|
+
Container,
|
|
14
|
+
Body,
|
|
15
|
+
Header,
|
|
16
|
+
IconContainer,
|
|
17
|
+
TimestampContainer,
|
|
18
|
+
TextContainer,
|
|
19
|
+
CollapsedContainer,
|
|
20
|
+
ExpandIconContainer,
|
|
21
|
+
} from './style';
|
|
22
|
+
import { Message, MessageType } from '../MessageModel';
|
|
23
|
+
import { GUTTER_SIZE, LIST_PADDING_SIZE } from '../Console';
|
|
24
|
+
|
|
25
|
+
const COLLAPSED_LENGTH = 125;
|
|
26
|
+
|
|
27
|
+
interface ConsoleLineProps {
|
|
28
|
+
message: Message;
|
|
29
|
+
index: number;
|
|
30
|
+
collapsed: boolean;
|
|
31
|
+
style: CSSProperties;
|
|
32
|
+
setRowState: (i: number, height: number, collapsed: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const ConsoleLine: FC<ConsoleLineProps> = ({ message, collapsed, style, index, setRowState }) => {
|
|
36
|
+
const { data, type, timestamp } = message;
|
|
37
|
+
|
|
38
|
+
const canCollapse = useMemo(() => {
|
|
39
|
+
if (!message.data) return false;
|
|
40
|
+
if (message.type === 'command') return true;
|
|
41
|
+
|
|
42
|
+
// TODO: should calculate the max chars per line based on the font constant, font size and textcontent container
|
|
43
|
+
return message.data.length > COLLAPSED_LENGTH;
|
|
44
|
+
}, [index]);
|
|
45
|
+
|
|
46
|
+
const [isCollapsed, setIsCollapsed] = useState<boolean>(collapsed);
|
|
47
|
+
const rowRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (containerRef.current) {
|
|
52
|
+
setRowState(index, containerRef.current.clientHeight, isCollapsed);
|
|
53
|
+
}
|
|
54
|
+
}, [rowRef, isCollapsed]);
|
|
55
|
+
|
|
56
|
+
function defineCollapsableMessageLayout(): ReactElement {
|
|
57
|
+
let header = '';
|
|
58
|
+
let body = '';
|
|
59
|
+
|
|
60
|
+
if (type === 'command') {
|
|
61
|
+
if (message.result == undefined) {
|
|
62
|
+
throw new Error('Command messages should have a return type');
|
|
63
|
+
}
|
|
64
|
+
header = data;
|
|
65
|
+
body = message.result;
|
|
66
|
+
} else {
|
|
67
|
+
// TODO: maybe the header should contain the max on line with ...
|
|
68
|
+
// and the body the entire message?
|
|
69
|
+
header = data.split('\n')[0];
|
|
70
|
+
body = data.split('\n').slice(1).join('\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<CollapsedContainer>
|
|
75
|
+
<Header isCollapsed={isCollapsed} type={type}>
|
|
76
|
+
<p>{header}</p>
|
|
77
|
+
{body && (
|
|
78
|
+
<Tooltip>
|
|
79
|
+
<Tooltip.Trigger asChild>
|
|
80
|
+
<ExpandIconContainer>
|
|
81
|
+
<EnterIcon onClick={() => setIsCollapsed(!isCollapsed)} size={14} />
|
|
82
|
+
</ExpandIconContainer>
|
|
83
|
+
</Tooltip.Trigger>
|
|
84
|
+
<Tooltip.Content>{isCollapsed ? 'show body' : 'collapse body'}</Tooltip.Content>
|
|
85
|
+
</Tooltip>
|
|
86
|
+
)}
|
|
87
|
+
</Header>
|
|
88
|
+
<Body isCollapsed={isCollapsed} type={type}>
|
|
89
|
+
{body}
|
|
90
|
+
</Body>
|
|
91
|
+
</CollapsedContainer>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const setIcon = (messageType: MessageType): ReactElement => {
|
|
96
|
+
switch (messageType) {
|
|
97
|
+
case 'info':
|
|
98
|
+
return <InfoIcon size={14} />;
|
|
99
|
+
case 'warning':
|
|
100
|
+
return <WarningIcon size={14} />;
|
|
101
|
+
case 'debug':
|
|
102
|
+
return <DebugIcon size={14} />;
|
|
103
|
+
case 'error':
|
|
104
|
+
return <ErrorIcon size={14} />;
|
|
105
|
+
case 'command':
|
|
106
|
+
return <CommandIcon size={14} />;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Wrapper
|
|
112
|
+
messageType={type}
|
|
113
|
+
style={{
|
|
114
|
+
...style,
|
|
115
|
+
top: `${(style.top as number) + GUTTER_SIZE + LIST_PADDING_SIZE}px`,
|
|
116
|
+
height: `${(style.height as number) - GUTTER_SIZE}px`,
|
|
117
|
+
}}
|
|
118
|
+
ref={rowRef}
|
|
119
|
+
>
|
|
120
|
+
<Container isCollapsed={isCollapsed} ref={containerRef}>
|
|
121
|
+
<IconContainer messageType={type}>{setIcon(type)}</IconContainer>
|
|
122
|
+
<TimestampContainer>[{timestamp}]</TimestampContainer>
|
|
123
|
+
{canCollapse ? defineCollapsableMessageLayout() : <TextContainer>{data}</TextContainer>}
|
|
124
|
+
</Container>
|
|
125
|
+
</Wrapper>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
import { MessageType } from '../MessageModel';
|
|
3
|
+
|
|
4
|
+
export const Wrapper = styled.div<{
|
|
5
|
+
messageType: MessageType;
|
|
6
|
+
}>`
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
position: relative;
|
|
10
|
+
font-family: 'inconsolata';
|
|
11
|
+
width: 100%;
|
|
12
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
13
|
+
|
|
14
|
+
&:last-child {
|
|
15
|
+
border-bottom: none;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const Container = styled.div<{ isCollapsed: boolean }>`
|
|
20
|
+
max-width: 100%;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: fit-content;
|
|
23
|
+
display: grid;
|
|
24
|
+
align-content: start;
|
|
25
|
+
grid-template-columns: 4rem 18rem 1fr;
|
|
26
|
+
margin: ${({ theme }) => theme.spacing[0]};
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const IconContainer = styled.div<{ messageType: MessageType }>`
|
|
30
|
+
padding-left: ${({ theme }) => theme.spacing['0_75']};
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
svg {
|
|
34
|
+
fill: ${({ theme, messageType }) => {
|
|
35
|
+
if (messageType === 'debug') return theme.colors.error;
|
|
36
|
+
if (messageType === 'command') return theme.colors.primary;
|
|
37
|
+
return theme.colors[messageType];
|
|
38
|
+
}};
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export const TimestampContainer = styled.div`
|
|
43
|
+
font-family: 'inconsolata';
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
export const TextContainer = styled.div`
|
|
47
|
+
font-family: 'inconsolata';
|
|
48
|
+
font-size: ${({ theme }) => theme.fontSize.medium};
|
|
49
|
+
color: ${({ theme }) => theme.colors.text};
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const CollapsedContainer = styled.div`
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
export const Header = styled.div<{ isCollapsed: boolean; type: MessageType }>`
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: row;
|
|
60
|
+
align-items: center;
|
|
61
|
+
p {
|
|
62
|
+
font-family: 'inconsolata';
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
export const Body = styled.pre<{ isCollapsed: boolean; type: MessageType }>`
|
|
67
|
+
display: ${({ isCollapsed }) => (isCollapsed ? 'none' : 'block')};
|
|
68
|
+
font-family: 'inconsolata';
|
|
69
|
+
margin: 0;
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
export const ExpandIconContainer = styled.span`
|
|
73
|
+
position: absolute;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
right: ${({ theme }) => theme.spacing['2']};
|
|
76
|
+
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Wrapper = styled.div`
|
|
4
|
+
height: 100%;
|
|
5
|
+
font-weight: 500;
|
|
6
|
+
border-left: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
7
|
+
border-right: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
8
|
+
position: relative;
|
|
9
|
+
border-top-right-radius: ${({ theme }) => theme.borderRadius.large};
|
|
10
|
+
border-top-left-radius: ${({ theme }) => theme.borderRadius.large};
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const Header = styled.div`
|
|
14
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
15
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
16
|
+
border-top: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
17
|
+
height: 50px;
|
|
18
|
+
display: flex;
|
|
19
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: flex-end;
|
|
22
|
+
padding: 0 ${({ theme }) => theme.spacing[1]};
|
|
23
|
+
border-top-left-radius: 1rem;
|
|
24
|
+
border-top-right-radius: 1rem;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const MessageContainer = styled.div`
|
|
28
|
+
min-height: 550px;
|
|
29
|
+
height: calc(100% - 50px);
|
|
30
|
+
border-radius: 0;
|
|
31
|
+
`;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Message } from './MessageModel';
|
|
3
|
+
|
|
4
|
+
export function useConsoleLiveModeScrolling(messages: Message[]) {
|
|
5
|
+
const [isLiveModeEnabled, setIsLiveModeEnabled] = useState<boolean>(true);
|
|
6
|
+
const [scrollOffset, setScrollOffset] = useState<number>(0);
|
|
7
|
+
|
|
8
|
+
// unfortunately the react-window libraries does not have up to date types
|
|
9
|
+
const consoleMessagesBoxRef = useRef<null | any>(null);
|
|
10
|
+
|
|
11
|
+
// scrolls to the latest message
|
|
12
|
+
const scrollNewMessages = useCallback(() => {
|
|
13
|
+
consoleMessagesBoxRef.current?.scrollToItem(messages.length, 'end');
|
|
14
|
+
}, [messages]);
|
|
15
|
+
|
|
16
|
+
const toggleLiveModeOnConsoleScroll = useCallback(() => {
|
|
17
|
+
if (consoleMessagesBoxRef.current) {
|
|
18
|
+
// in case we are scrolling down, don't do anything.
|
|
19
|
+
if (consoleMessagesBoxRef.current.state.scrollDirection === 'forward') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (consoleMessagesBoxRef.current.state.scrollOffset < scrollOffset) {
|
|
24
|
+
setIsLiveModeEnabled(false);
|
|
25
|
+
}
|
|
26
|
+
setScrollOffset(consoleMessagesBoxRef.current.state.scrollOffset);
|
|
27
|
+
}
|
|
28
|
+
}, [scrollOffset]);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (isLiveModeEnabled) {
|
|
32
|
+
scrollNewMessages();
|
|
33
|
+
}
|
|
34
|
+
}, [messages, isLiveModeEnabled, scrollNewMessages]);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
consoleMessagesBoxRef,
|
|
38
|
+
isLiveModeEnabled,
|
|
39
|
+
setIsLiveModeEnabled,
|
|
40
|
+
toggleLiveModeOnConsoleScroll,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { CopyId, CopyIdProps } from '../../../components';
|
|
5
|
+
|
|
6
|
+
const Wrapper = styled.div`
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
padding: 5rem;
|
|
12
|
+
background: ${({ theme }) => theme.colors.background};
|
|
13
|
+
text-align: left;
|
|
14
|
+
|
|
15
|
+
& > div {
|
|
16
|
+
margin: 1rem;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
title: 'Data/CopyId',
|
|
22
|
+
component: CopyId,
|
|
23
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
24
|
+
args: {
|
|
25
|
+
id: '3141592653589793238462643383279',
|
|
26
|
+
},
|
|
27
|
+
} as Meta<CopyIdProps>;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryFn<CopyIdProps> = (args) => <CopyId {...args} />;
|
|
30
|
+
|
|
31
|
+
export const CustomPlaceholder: StoryObj<CopyIdProps> = {
|
|
32
|
+
args: {
|
|
33
|
+
placeholder: 'custom placeholder',
|
|
34
|
+
id: '3141592653589793238462643383279',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FC, useEffect, useState } from 'react';
|
|
2
|
+
import { Chip } from '../../../components';
|
|
3
|
+
import { AiFillCopy as CopyIcon, AiOutlineCheck as CheckmarkIcon } from 'react-icons/ai';
|
|
4
|
+
|
|
5
|
+
export interface CopyIdProps {
|
|
6
|
+
id?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const CopyId: FC<CopyIdProps> = ({ id, placeholder }) => {
|
|
11
|
+
const [copied, setCopied] = useState<boolean>(false);
|
|
12
|
+
|
|
13
|
+
function handleCopy(text: string) {
|
|
14
|
+
setCopied(true);
|
|
15
|
+
navigator.clipboard.writeText(text);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
/* If it was copied, show a checkmark for 2.5s thn make it possible to copy again */
|
|
20
|
+
if (copied) {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
setCopied(false);
|
|
23
|
+
}, 2500);
|
|
24
|
+
}
|
|
25
|
+
}, [copied]);
|
|
26
|
+
|
|
27
|
+
if (!id) return <></>;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Chip
|
|
31
|
+
icon={copied ? <CheckmarkIcon /> : <CopyIcon />}
|
|
32
|
+
onClick={() => handleCopy(id)}
|
|
33
|
+
variant="outline"
|
|
34
|
+
label={copied ? 'copied' : placeholder ? placeholder : id}
|
|
35
|
+
color="backgroundAccent"
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// TODO: save images locally so when there is no network they are still loaded.
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
import { DateFormatter, DateFormatterProps } from '.';
|
|
5
|
+
import { DateTime } from 'luxon';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Data/DateFormatter',
|
|
9
|
+
component: DateFormatter,
|
|
10
|
+
args: {
|
|
11
|
+
ISODate: DateTime.now().toISO(),
|
|
12
|
+
format: DateTime.DATE_FULL,
|
|
13
|
+
},
|
|
14
|
+
} as Meta<DateFormatterProps>;
|
|
15
|
+
|
|
16
|
+
export const Default: StoryFn<DateFormatterProps> = (args) => (
|
|
17
|
+
<div>
|
|
18
|
+
provides a wrapper component for formatting dates to the standard format used throughout takaro.
|
|
19
|
+
<br />
|
|
20
|
+
The current date is formatted to format <strong>DATE_FULL</strong>
|
|
21
|
+
<br />
|
|
22
|
+
<strong>
|
|
23
|
+
<DateFormatter ISODate={args.ISODate} format={args.format} />
|
|
24
|
+
</strong>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DateTime, DateTimeFormatOptions } from 'luxon';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface DateFormatterProps {
|
|
5
|
+
ISODate: string;
|
|
6
|
+
format?: DateTimeFormatOptions;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const DateFormatter: FC<DateFormatterProps> = ({ ISODate, format }) => {
|
|
10
|
+
return format ? (
|
|
11
|
+
<>{DateTime.fromISO(ISODate).toLocaleString(format)}</>
|
|
12
|
+
) : (
|
|
13
|
+
<>{DateTime.fromISO(ISODate).toLocaleString(DateTime.DATETIME_SHORT)}</>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
|
|
5
|
+
import { Button, TextField, CollapseList, Chip, RadioGroup, Switch, Drawer, DrawerSkeleton } from '../../../components';
|
|
6
|
+
import { styled } from '../../../styled';
|
|
7
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
10
|
+
|
|
11
|
+
const ButtonContainer = styled.div`
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
gap: ${({ theme }) => theme.spacing[2]};
|
|
15
|
+
`;
|
|
16
|
+
const Status = styled.div`
|
|
17
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
title: 'data/Drawer',
|
|
22
|
+
component: Drawer,
|
|
23
|
+
} as Meta;
|
|
24
|
+
|
|
25
|
+
export const Loading: StoryFn = () => {
|
|
26
|
+
return <DrawerSkeleton />;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
interface FormFields {
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
priceType: 'fixed' | 'variable';
|
|
33
|
+
generateLicenseKeys: boolean;
|
|
34
|
+
redirectAfterPurchase: boolean;
|
|
35
|
+
onStoreFront: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const Default: StoryFn = () => {
|
|
39
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
40
|
+
|
|
41
|
+
const validationSchema = useMemo(
|
|
42
|
+
() =>
|
|
43
|
+
z.object({
|
|
44
|
+
name: z.string().nonempty('Name field cannot be empty'),
|
|
45
|
+
description: z.string().min(20, 'description must be at least 20 characters'),
|
|
46
|
+
priceType: z.enum(['fixed', 'variable']),
|
|
47
|
+
}),
|
|
48
|
+
[]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const { handleSubmit, control } = useForm<FormFields>({
|
|
52
|
+
resolver: zodResolver(validationSchema),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const onSubmit: SubmitHandler<FormFields> = async () => {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<Button onClick={() => setOpen(true)} text="Open drawer" />
|
|
62
|
+
<Drawer open={open} onOpenChange={setOpen}>
|
|
63
|
+
<Drawer.Content>
|
|
64
|
+
<Drawer.Heading>Product Details</Drawer.Heading>
|
|
65
|
+
<Drawer.Body>
|
|
66
|
+
<Status>
|
|
67
|
+
Status: <Chip label="active" color="success" variant="outline" />
|
|
68
|
+
</Status>
|
|
69
|
+
<form id="myform" onSubmit={handleSubmit(onSubmit)}>
|
|
70
|
+
<CollapseList>
|
|
71
|
+
<CollapseList.Item title="General">
|
|
72
|
+
<TextField
|
|
73
|
+
label="Name"
|
|
74
|
+
name="name"
|
|
75
|
+
required
|
|
76
|
+
control={control}
|
|
77
|
+
description={
|
|
78
|
+
'Give your product a short and clear name.\n50-60 characters is the recommended length for search engines.'
|
|
79
|
+
}
|
|
80
|
+
/>
|
|
81
|
+
<TextField
|
|
82
|
+
label="Description"
|
|
83
|
+
name="description"
|
|
84
|
+
required
|
|
85
|
+
control={control}
|
|
86
|
+
description="Give your product a short and clear description. 120-160 characters is the recommended length for search engines"
|
|
87
|
+
/>
|
|
88
|
+
</CollapseList.Item>
|
|
89
|
+
<CollapseList.Item title="Pricing">
|
|
90
|
+
<RadioGroup
|
|
91
|
+
control={control}
|
|
92
|
+
label="Selection a price type"
|
|
93
|
+
name="priceType"
|
|
94
|
+
options={[
|
|
95
|
+
{
|
|
96
|
+
label: 'Fixed',
|
|
97
|
+
labelPosition: 'left',
|
|
98
|
+
value: 'fixed',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
label: 'Variable',
|
|
102
|
+
labelPosition: 'left',
|
|
103
|
+
value: 'variable',
|
|
104
|
+
},
|
|
105
|
+
]}
|
|
106
|
+
/>
|
|
107
|
+
</CollapseList.Item>
|
|
108
|
+
</CollapseList>
|
|
109
|
+
<CollapseList.Item title="Settings">
|
|
110
|
+
<Switch
|
|
111
|
+
control={control}
|
|
112
|
+
label="Generate License Keys"
|
|
113
|
+
name="generateLicenseKeys"
|
|
114
|
+
size="tiny"
|
|
115
|
+
description="Issue each sutomer a unique license key after purchase"
|
|
116
|
+
/>
|
|
117
|
+
<Switch
|
|
118
|
+
control={control}
|
|
119
|
+
label="Redirect customers after purchase"
|
|
120
|
+
name="redirectAfterPurchase"
|
|
121
|
+
size="small"
|
|
122
|
+
description="Redirect customers to a custom URL after making a purchase"
|
|
123
|
+
/>
|
|
124
|
+
<Switch
|
|
125
|
+
control={control}
|
|
126
|
+
label="Display product on storefront?"
|
|
127
|
+
name="onStoreFront"
|
|
128
|
+
description="Show this product on your storefront"
|
|
129
|
+
size="small"
|
|
130
|
+
/>
|
|
131
|
+
</CollapseList.Item>
|
|
132
|
+
</form>
|
|
133
|
+
</Drawer.Body>
|
|
134
|
+
<Drawer.Footer>
|
|
135
|
+
<ButtonContainer>
|
|
136
|
+
<Button text="Cancel" onClick={() => setOpen(false)} color="background" />
|
|
137
|
+
<Button fullWidth text="Save changes" type="submit" form="myform" />
|
|
138
|
+
</ButtonContainer>
|
|
139
|
+
</Drawer.Footer>
|
|
140
|
+
</Drawer.Content>
|
|
141
|
+
</Drawer>
|
|
142
|
+
</>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FC, PropsWithChildren, useId, useLayoutEffect } from 'react';
|
|
2
|
+
import { useDrawerContext } from './DrawerContext';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
|
|
5
|
+
const Container = styled.div<{ canDrag: boolean }>`
|
|
6
|
+
position: relative;
|
|
7
|
+
/* Large left padding is for the drawer handle */
|
|
8
|
+
padding: ${({ theme, canDrag }) =>
|
|
9
|
+
`0 ${theme.spacing['2_5']} ${theme.spacing[2]} ${canDrag ? theme.spacing['4'] : theme.spacing['2_5']}`};
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const DrawerBody: FC<PropsWithChildren> = ({ children }) => {
|
|
13
|
+
const { setLabelId, canDrag } = useDrawerContext();
|
|
14
|
+
const id = useId();
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
setLabelId(id);
|
|
18
|
+
return () => setLabelId(undefined);
|
|
19
|
+
}, [id, setLabelId]);
|
|
20
|
+
|
|
21
|
+
return <Container canDrag={canDrag}>{children}</Container>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { forwardRef, HTMLProps, useState } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
import { AnimatePresence, motion, PanInfo } from 'framer-motion';
|
|
4
|
+
import SimpleBar from 'simplebar-react';
|
|
5
|
+
|
|
6
|
+
import { FloatingFocusManager, FloatingPortal, useMergeRefs, FloatingOverlay } from '@floating-ui/react';
|
|
7
|
+
import { useDrawerContext } from './DrawerContext';
|
|
8
|
+
|
|
9
|
+
const Container = styled(motion.div)`
|
|
10
|
+
position: relative;
|
|
11
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
12
|
+
width: 700px;
|
|
13
|
+
height: 100%;
|
|
14
|
+
z-index: ${({ theme }) => theme.zIndex.drawer};
|
|
15
|
+
border-left: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export const HandleContainer = styled.div`
|
|
19
|
+
height: 80vh;
|
|
20
|
+
top: 10vh;
|
|
21
|
+
width: 15px;
|
|
22
|
+
left: 5px;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
position: absolute;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
|
|
28
|
+
/* handle */
|
|
29
|
+
div {
|
|
30
|
+
background-color: ${({ theme }) => theme.colors.backgroundAccent};
|
|
31
|
+
height: 100px;
|
|
32
|
+
width: 0.8rem;
|
|
33
|
+
border-radius: 9999px;
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const DrawerContent = forwardRef<HTMLElement, HTMLProps<HTMLDivElement>>((props, propRef) => {
|
|
38
|
+
const { context, labelId, descriptionId, getFloatingProps, setOpen, canDrag } = useDrawerContext();
|
|
39
|
+
|
|
40
|
+
const ref = useMergeRefs([context.refs.setFloating, propRef]);
|
|
41
|
+
const [dragPosition, setDragPosition] = useState<number>(0);
|
|
42
|
+
|
|
43
|
+
const root = document.getElementById('drawer');
|
|
44
|
+
if (!root) {
|
|
45
|
+
throw new Error('Drawer needs to render in a <div id="drawer"></div>');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const handleDrag = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
|
49
|
+
const newPosition = Math.min(Math.max(info.offset.x / 650, 0), 1);
|
|
50
|
+
setDragPosition(newPosition);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleDragEnd = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
|
54
|
+
// Snap back to position if dragged to the right
|
|
55
|
+
if (info.offset.x > 450) {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
} else if (info.offset.x >= 0) {
|
|
58
|
+
setDragPosition(0);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<FloatingPortal root={root}>
|
|
64
|
+
<AnimatePresence>
|
|
65
|
+
{context.open && (
|
|
66
|
+
<FloatingOverlay
|
|
67
|
+
lockScroll
|
|
68
|
+
style={{
|
|
69
|
+
placeItems: 'end',
|
|
70
|
+
maxHeight: '100vh',
|
|
71
|
+
maxWidth: '100vw',
|
|
72
|
+
overflow: 'hidden!important',
|
|
73
|
+
display: 'grid',
|
|
74
|
+
background: `rgba(0, 0, 0, ${Math.max(0.8 - dragPosition, 0.4)})`,
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<FloatingFocusManager context={context}>
|
|
78
|
+
<Container
|
|
79
|
+
ref={ref}
|
|
80
|
+
aria-labelledby={labelId}
|
|
81
|
+
aria-describedby={descriptionId}
|
|
82
|
+
{...getFloatingProps(props)}
|
|
83
|
+
initial={{ x: '100%' }}
|
|
84
|
+
animate={{
|
|
85
|
+
x: 0,
|
|
86
|
+
}}
|
|
87
|
+
exit={{
|
|
88
|
+
x: '100%',
|
|
89
|
+
}}
|
|
90
|
+
drag={canDrag ? 'x' : false}
|
|
91
|
+
dragConstraints={{ left: 0, right: 0 }}
|
|
92
|
+
onDrag={handleDrag}
|
|
93
|
+
onDragEnd={handleDragEnd}
|
|
94
|
+
dragElastic={{ left: 0, right: 0.4 }}
|
|
95
|
+
layout
|
|
96
|
+
>
|
|
97
|
+
{canDrag && (
|
|
98
|
+
<HandleContainer>
|
|
99
|
+
<div />
|
|
100
|
+
</HandleContainer>
|
|
101
|
+
)}
|
|
102
|
+
<SimpleBar style={{ maxHeight: '92vh' }}>{props.children}</SimpleBar>
|
|
103
|
+
</Container>
|
|
104
|
+
</FloatingFocusManager>
|
|
105
|
+
</FloatingOverlay>
|
|
106
|
+
)}
|
|
107
|
+
</AnimatePresence>
|
|
108
|
+
</FloatingPortal>
|
|
109
|
+
);
|
|
110
|
+
});
|