@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,49 @@
|
|
|
1
|
+
import { FC, cloneElement } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
import { Link, LinkProps } from '@tanstack/react-router';
|
|
4
|
+
import { Tooltip } from '../../../components';
|
|
5
|
+
|
|
6
|
+
const Container = styled.nav`
|
|
7
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
8
|
+
height: 100vh;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
align-items: center;
|
|
12
|
+
border-right: 1px solid ${({ theme }) => theme.colors.background};
|
|
13
|
+
a {
|
|
14
|
+
display: flex;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
align-items: center;
|
|
17
|
+
width: 100%;
|
|
18
|
+
padding: ${({ theme }) => theme.spacing[1]};
|
|
19
|
+
border: 1px solid transparent;
|
|
20
|
+
border-radius: ${({ theme }) => theme.borderRadius.small};
|
|
21
|
+
&:hover {
|
|
22
|
+
background-color: ${({ theme }) => theme.colors.primaryShade};
|
|
23
|
+
border-color: ${({ theme }) => theme.colors.primary};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export interface IconNavProps {
|
|
29
|
+
items: { icon: JSX.Element; link: LinkProps; title: string }[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const IconNav: FC<IconNavProps> = ({ items }) => {
|
|
33
|
+
return (
|
|
34
|
+
<Container>
|
|
35
|
+
{items.map(({ link, icon, title }, index) => (
|
|
36
|
+
<Tooltip placement="right" key={`icon-${title}-${index}`}>
|
|
37
|
+
<Tooltip.Trigger asChild>
|
|
38
|
+
{/*eslint-disable-next-line @typescript-eslint/ban-ts-comment*/}
|
|
39
|
+
{/*@ts-ignore reusable link*/}
|
|
40
|
+
<Link key={`icon-nav-${title}`} {...link}>
|
|
41
|
+
{cloneElement(icon, { size: 24 })}
|
|
42
|
+
</Link>
|
|
43
|
+
</Tooltip.Trigger>
|
|
44
|
+
<Tooltip.Content>{title}</Tooltip.Content>
|
|
45
|
+
</Tooltip>
|
|
46
|
+
))}
|
|
47
|
+
</Container>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
2
|
+
import { styled } from '../../../../styled';
|
|
3
|
+
import { useStepper } from '../context';
|
|
4
|
+
import { Button, SlimStepper, SlimStepperProps } from '../../../../components';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
/** useStepper requires a context provider which is (currently) mounted on the root of the application.
|
|
8
|
+
* <StepperProvider /> requires no parameters.
|
|
9
|
+
*/
|
|
10
|
+
title: 'Navigation/SlimStepper',
|
|
11
|
+
component: SlimStepper,
|
|
12
|
+
} as Meta<SlimStepperProps>;
|
|
13
|
+
|
|
14
|
+
const StepBody = styled.div`
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
text-align: center;
|
|
20
|
+
p,
|
|
21
|
+
button {
|
|
22
|
+
margin-bottom: 1rem;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const Numbers: StoryFn = () => {
|
|
27
|
+
const { incrementCurrentStep, decrementCurrentStep } = useStepper();
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<SlimStepper showTooltip="always">
|
|
31
|
+
<SlimStepper.Steps>
|
|
32
|
+
<SlimStepper.Step id="first" name="step 1">
|
|
33
|
+
<StepBody>
|
|
34
|
+
<p>Step 1</p>
|
|
35
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
36
|
+
</StepBody>
|
|
37
|
+
</SlimStepper.Step>
|
|
38
|
+
<SlimStepper.Step id="second" name="step 2">
|
|
39
|
+
<StepBody>
|
|
40
|
+
<p>Step 2</p>
|
|
41
|
+
<Button onClick={decrementCurrentStep} text="previous step" />
|
|
42
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
43
|
+
</StepBody>
|
|
44
|
+
</SlimStepper.Step>
|
|
45
|
+
<SlimStepper.Step id="third" name="step 3">
|
|
46
|
+
<StepBody>
|
|
47
|
+
<p>Step 3</p>
|
|
48
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
49
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
50
|
+
</StepBody>
|
|
51
|
+
</SlimStepper.Step>
|
|
52
|
+
<SlimStepper.Step id="fourth" name="step 4">
|
|
53
|
+
<StepBody>
|
|
54
|
+
<p>Step 4</p>
|
|
55
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
56
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
57
|
+
</StepBody>
|
|
58
|
+
</SlimStepper.Step>
|
|
59
|
+
<SlimStepper.Step id="fifth" name="step 5">
|
|
60
|
+
<StepBody>
|
|
61
|
+
<p>Step 5</p>
|
|
62
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
63
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
64
|
+
</StepBody>
|
|
65
|
+
</SlimStepper.Step>
|
|
66
|
+
<SlimStepper.Step id="sixth" name="step 6">
|
|
67
|
+
<StepBody>
|
|
68
|
+
<p>Step 6</p>
|
|
69
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
70
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
71
|
+
</StepBody>
|
|
72
|
+
</SlimStepper.Step>
|
|
73
|
+
<SlimStepper.Step id="seventh" name="step 7">
|
|
74
|
+
<StepBody>
|
|
75
|
+
<p>Step 7</p>
|
|
76
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
77
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
78
|
+
</StepBody>
|
|
79
|
+
</SlimStepper.Step>
|
|
80
|
+
<SlimStepper.Step id="eight" name="step 8">
|
|
81
|
+
<StepBody>
|
|
82
|
+
<p>Step 8</p>
|
|
83
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
84
|
+
</StepBody>
|
|
85
|
+
</SlimStepper.Step>
|
|
86
|
+
</SlimStepper.Steps>
|
|
87
|
+
</SlimStepper>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { FC, useEffect, Children, isValidElement, PropsWithChildren } from 'react';
|
|
2
|
+
import { Tooltip } from '../../../../components';
|
|
3
|
+
import { useStepper } from '../context';
|
|
4
|
+
import { Container, StepperBody, StepperHeader, StepperHeaderItem, Dot } from './style';
|
|
5
|
+
import { StepStates } from '../stepStates';
|
|
6
|
+
|
|
7
|
+
/* Dot behavior components */
|
|
8
|
+
// wrapper <StepperSteps/> component around the multiple <step/>
|
|
9
|
+
const StepperSteps: FC<PropsWithChildren<void>> = ({ children }) => {
|
|
10
|
+
const { currentStep, steps, setSteps } = useStepper();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const stepperSteps = Children.toArray(children)
|
|
14
|
+
.filter((step) => isValidElement(step) && typeof step.type !== 'string' && step.type.name === 'StepperStep')
|
|
15
|
+
.map((step) => {
|
|
16
|
+
if (isValidElement(step)) {
|
|
17
|
+
return step.props;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
});
|
|
21
|
+
setSteps(stepperSteps);
|
|
22
|
+
}, [setSteps, currentStep]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
{children &&
|
|
27
|
+
Children.map(
|
|
28
|
+
children,
|
|
29
|
+
(child) => steps.length !== 0 && isValidElement(child) && child.props.id === steps[currentStep].id && child
|
|
30
|
+
)}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Single <step/> subcomponent
|
|
36
|
+
interface StepProps {
|
|
37
|
+
/// used as tooltip content
|
|
38
|
+
name: string;
|
|
39
|
+
id: string;
|
|
40
|
+
}
|
|
41
|
+
const StepperStep: FC<PropsWithChildren<StepProps>> = ({ children }) => {
|
|
42
|
+
return <>{children}</>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export interface SlimStepperProps {
|
|
46
|
+
canStepBack?: boolean; // disable step back via step header
|
|
47
|
+
showTooltip?: 'never' | 'always' | 'hover';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Main <Stepper/> component which contains subcomponents
|
|
51
|
+
export const SlimStepper: FC<PropsWithChildren<SlimStepperProps>> & {
|
|
52
|
+
Step: FC<StepProps>;
|
|
53
|
+
Steps: FC<PropsWithChildren<void>>;
|
|
54
|
+
} = ({ showTooltip = 'hover', canStepBack = true, children }) => {
|
|
55
|
+
const { currentStep, steps, setCurrentStep } = useStepper();
|
|
56
|
+
|
|
57
|
+
function getStepState(index: number, currentStep: number) {
|
|
58
|
+
if (index === currentStep) {
|
|
59
|
+
return StepStates.CURRENT;
|
|
60
|
+
}
|
|
61
|
+
if (currentStep > index) {
|
|
62
|
+
return StepStates.COMPLETE;
|
|
63
|
+
}
|
|
64
|
+
return StepStates.OTHER;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handleClick(index: number, currentStep: number) {
|
|
68
|
+
if (getStepState(index, currentStep) === StepStates.COMPLETE && canStepBack) {
|
|
69
|
+
setCurrentStep(index);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Container>
|
|
75
|
+
<StepperHeader>
|
|
76
|
+
{steps.length &&
|
|
77
|
+
steps.map(({ id, name }: StepProps, index: number) => (
|
|
78
|
+
<StepperHeaderItem
|
|
79
|
+
canStepBack={canStepBack}
|
|
80
|
+
key={id}
|
|
81
|
+
onClick={() => handleClick(index, currentStep)}
|
|
82
|
+
stepState={getStepState(index, currentStep)}
|
|
83
|
+
>
|
|
84
|
+
{StepStates.CURRENT === getStepState(index, currentStep) && showTooltip !== 'never' ? (
|
|
85
|
+
<Tooltip placement="bottom">
|
|
86
|
+
<Tooltip.Trigger asChild>
|
|
87
|
+
<Dot stepState={getStepState(index, currentStep)} />
|
|
88
|
+
</Tooltip.Trigger>
|
|
89
|
+
<Tooltip.Content>{name}</Tooltip.Content>
|
|
90
|
+
</Tooltip>
|
|
91
|
+
) : (
|
|
92
|
+
<Dot stepState={getStepState(index, currentStep)} />
|
|
93
|
+
)}
|
|
94
|
+
</StepperHeaderItem>
|
|
95
|
+
))}
|
|
96
|
+
</StepperHeader>
|
|
97
|
+
<StepperBody>{children}</StepperBody>
|
|
98
|
+
</Container>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Set dot components
|
|
103
|
+
SlimStepper.Step = StepperStep;
|
|
104
|
+
SlimStepper.Steps = StepperSteps;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
import { StepStates } from '../stepStates';
|
|
3
|
+
import { lighten } from 'polished';
|
|
4
|
+
|
|
5
|
+
export const Container = styled.div`
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
padding-top: ${({ theme }) => theme.spacing[1]};
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const StepperHeader = styled.div`
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
width: 35vw;
|
|
15
|
+
height: 0.7rem;
|
|
16
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
17
|
+
margin: auto;
|
|
18
|
+
`;
|
|
19
|
+
export const StepperHeaderItem = styled.div<{
|
|
20
|
+
stepState: StepStates;
|
|
21
|
+
canStepBack: boolean;
|
|
22
|
+
}>`
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
align-items: center;
|
|
27
|
+
flex: 1;
|
|
28
|
+
${({ theme, stepState }) => {
|
|
29
|
+
if (stepState === StepStates.COMPLETE) {
|
|
30
|
+
return `border-right: .6rem solid ${lighten(0.15, theme.colors.primary)}`;
|
|
31
|
+
} else {
|
|
32
|
+
return 'border-right: .6rem solid transparent';
|
|
33
|
+
}
|
|
34
|
+
}};
|
|
35
|
+
|
|
36
|
+
cursor: ${({ stepState, canStepBack }) => (stepState === StepStates.COMPLETE && canStepBack ? 'pointer' : 'inherit')};
|
|
37
|
+
|
|
38
|
+
&:first-child {
|
|
39
|
+
border-top-left-radius: 1rem;
|
|
40
|
+
border-bottom-left-radius: 1rem;
|
|
41
|
+
}
|
|
42
|
+
&:last-child {
|
|
43
|
+
border-top-right-radius: 1rem;
|
|
44
|
+
border-bottom-right-radius: 1rem;
|
|
45
|
+
border-right: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
background-color: ${({ stepState, theme }) =>
|
|
49
|
+
stepState === StepStates.COMPLETE || stepState === StepStates.CURRENT
|
|
50
|
+
? theme.colors.primary
|
|
51
|
+
: theme.colors.backgroundAccent};
|
|
52
|
+
|
|
53
|
+
@media (max-width: 768px) {
|
|
54
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
export const Dot = styled.div<{ stepState: StepStates }>`
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 50%;
|
|
61
|
+
transform: translateY(-50%);
|
|
62
|
+
z-index: 5;
|
|
63
|
+
border-radius: 100%;
|
|
64
|
+
${({ stepState, theme }) => {
|
|
65
|
+
switch (stepState) {
|
|
66
|
+
case StepStates.CURRENT:
|
|
67
|
+
return `
|
|
68
|
+
right: calc(-1.6rem / 2);
|
|
69
|
+
width: 1.6rem;
|
|
70
|
+
height: 1.6rem;
|
|
71
|
+
background-color: ${theme.colors.primary};
|
|
72
|
+
`;
|
|
73
|
+
case StepStates.OTHER:
|
|
74
|
+
return `
|
|
75
|
+
right: calc(-.7rem/2);
|
|
76
|
+
width: .7rem;
|
|
77
|
+
height: .7rem;
|
|
78
|
+
background-color: ${theme.colors.background};
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
}}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
export const StepperBody = styled.div`
|
|
85
|
+
padding: ${({ theme }) => `${theme.spacing[9]} ${theme.spacing['1_5']}`};
|
|
86
|
+
`;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
2
|
+
import { styled } from '../../../../styled';
|
|
3
|
+
import { useStepper } from '../context';
|
|
4
|
+
import { Button, Stepper } from '../../../../components';
|
|
5
|
+
import { AiFillSafetyCertificate as Safety, AiFillBell as Bell } from 'react-icons/ai';
|
|
6
|
+
import { MdLocalShipping as Shipping } from 'react-icons/md';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
/** useStepper requires a context provider which is (currenlty) mounted on the root of the application.
|
|
10
|
+
* <StepperProvider /> requires no parameters.
|
|
11
|
+
*/
|
|
12
|
+
title: 'Navigation/Stepper',
|
|
13
|
+
component: Stepper,
|
|
14
|
+
} as Meta;
|
|
15
|
+
|
|
16
|
+
const StepBody = styled.div`
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
text-align: center;
|
|
22
|
+
|
|
23
|
+
p,
|
|
24
|
+
button {
|
|
25
|
+
margin-bottom: 1rem;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const Numbers: StoryFn = () => {
|
|
30
|
+
const { incrementCurrentStep, decrementCurrentStep } = useStepper();
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Stepper>
|
|
34
|
+
<Stepper.Steps>
|
|
35
|
+
<Stepper.Step id="first" name="step 1">
|
|
36
|
+
<StepBody>
|
|
37
|
+
<p>Step 1</p>
|
|
38
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
39
|
+
</StepBody>
|
|
40
|
+
</Stepper.Step>
|
|
41
|
+
<Stepper.Step id="second" name="step 2">
|
|
42
|
+
<StepBody>
|
|
43
|
+
<p>Step 2</p>
|
|
44
|
+
<Button onClick={decrementCurrentStep} text="previous step" />
|
|
45
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
46
|
+
</StepBody>
|
|
47
|
+
</Stepper.Step>
|
|
48
|
+
<Stepper.Step id="third" name="step 3">
|
|
49
|
+
<StepBody>
|
|
50
|
+
<p>Step 3</p>
|
|
51
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
52
|
+
</StepBody>
|
|
53
|
+
</Stepper.Step>
|
|
54
|
+
</Stepper.Steps>
|
|
55
|
+
</Stepper>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const Icons: StoryFn = () => {
|
|
60
|
+
const { incrementCurrentStep, decrementCurrentStep } = useStepper();
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Stepper>
|
|
64
|
+
<Stepper.Steps>
|
|
65
|
+
<Stepper.Step icon={<Bell size="24" />} id="first" name="Shopping">
|
|
66
|
+
<StepBody>
|
|
67
|
+
<p>Step 1</p>
|
|
68
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
69
|
+
</StepBody>
|
|
70
|
+
</Stepper.Step>
|
|
71
|
+
<Stepper.Step icon={<Shipping size="24" />} id="second" name="Shipping">
|
|
72
|
+
<StepBody>
|
|
73
|
+
<p>Step 2</p>
|
|
74
|
+
<Button onClick={decrementCurrentStep} text="previous step" />
|
|
75
|
+
<Button onClick={incrementCurrentStep} text="Next step" />
|
|
76
|
+
</StepBody>
|
|
77
|
+
</Stepper.Step>
|
|
78
|
+
<Stepper.Step icon={<Safety size="24" />} id="third" name="Payment">
|
|
79
|
+
<StepBody>
|
|
80
|
+
<p>Step 3</p>
|
|
81
|
+
<Button onClick={decrementCurrentStep} text="Previous step" />
|
|
82
|
+
</StepBody>
|
|
83
|
+
</Stepper.Step>
|
|
84
|
+
</Stepper.Steps>
|
|
85
|
+
</Stepper>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { FC, useEffect, Children, isValidElement, ReactElement, PropsWithChildren } from 'react';
|
|
2
|
+
import { useStepper } from '../context';
|
|
3
|
+
import { Container, StepperBody, StepperHeader, StepperHeaderItem, StepCounter, StepName } from './style';
|
|
4
|
+
import { AiOutlineCheck as CheckMark } from 'react-icons/ai';
|
|
5
|
+
import { Spinner } from '../../..';
|
|
6
|
+
import { StepStates } from '../stepStates';
|
|
7
|
+
/* Dot behavior components */
|
|
8
|
+
// wrapper <StepperSteps/> component around the multiple <step/>
|
|
9
|
+
|
|
10
|
+
const StepperSteps: FC<PropsWithChildren<void>> = ({ children }) => {
|
|
11
|
+
const { currentStep, steps, setSteps } = useStepper();
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const stepperSteps = Children.toArray(children)
|
|
15
|
+
.filter((step) => isValidElement(step) && typeof step.type !== 'string' && step.type.name === 'StepperStep')
|
|
16
|
+
.map((step) => {
|
|
17
|
+
if (isValidElement(step)) {
|
|
18
|
+
return step.props;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
});
|
|
22
|
+
setSteps(stepperSteps);
|
|
23
|
+
}, [setSteps, currentStep]);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div>
|
|
27
|
+
{children &&
|
|
28
|
+
Children.map(
|
|
29
|
+
children,
|
|
30
|
+
(child) => steps.length !== 0 && isValidElement(child) && child.props.id === steps[currentStep].id && child
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Single <step/> subcomponent
|
|
37
|
+
interface StepProps {
|
|
38
|
+
name: string;
|
|
39
|
+
id: string;
|
|
40
|
+
icon?: ReactElement;
|
|
41
|
+
}
|
|
42
|
+
export type FCStep = FC<PropsWithChildren<StepProps>>;
|
|
43
|
+
|
|
44
|
+
const StepperStep: FCStep = ({ children }) => {
|
|
45
|
+
return <>{children}</>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export interface StepperProps {
|
|
49
|
+
currentStepIsLoading?: boolean;
|
|
50
|
+
canStepBack?: boolean; // disable step back via step header
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Main <Stepper/> component which contains subcomponents
|
|
54
|
+
export const Stepper: FC<PropsWithChildren<StepperProps>> & {
|
|
55
|
+
Step: FC<StepProps>;
|
|
56
|
+
Steps: FC<PropsWithChildren<void>>;
|
|
57
|
+
} = ({ currentStepIsLoading = false, canStepBack = true, children }) => {
|
|
58
|
+
const { currentStep, steps, setCurrentStep } = useStepper();
|
|
59
|
+
|
|
60
|
+
function getStepState(index: number, currentStep: number) {
|
|
61
|
+
if (index === currentStep) {
|
|
62
|
+
return StepStates.CURRENT;
|
|
63
|
+
}
|
|
64
|
+
if (currentStep > index) {
|
|
65
|
+
return StepStates.COMPLETE;
|
|
66
|
+
}
|
|
67
|
+
return StepStates.OTHER;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function handleClick(index: number, currentStep: number) {
|
|
71
|
+
if (getStepState(index, currentStep) === StepStates.COMPLETE && canStepBack) {
|
|
72
|
+
setCurrentStep(index);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Container>
|
|
78
|
+
<StepperHeader>
|
|
79
|
+
{steps.length &&
|
|
80
|
+
steps.map((step: StepProps, index: number) => (
|
|
81
|
+
<StepperHeaderItem key={step.id} stepState={getStepState(index, currentStep)}>
|
|
82
|
+
<StepCounter
|
|
83
|
+
canStepBack={canStepBack}
|
|
84
|
+
onClick={() => handleClick(index, currentStep)}
|
|
85
|
+
stepState={getStepState(index, currentStep)}
|
|
86
|
+
>
|
|
87
|
+
{currentStep > index ? (
|
|
88
|
+
<CheckMark size={24} />
|
|
89
|
+
) : currentStep === index ? (
|
|
90
|
+
currentStepIsLoading ? (
|
|
91
|
+
<Spinner size="small" />
|
|
92
|
+
) : step.icon ? (
|
|
93
|
+
step.icon
|
|
94
|
+
) : (
|
|
95
|
+
index + 1
|
|
96
|
+
)
|
|
97
|
+
) : step.icon ? (
|
|
98
|
+
step.icon
|
|
99
|
+
) : (
|
|
100
|
+
index + 1
|
|
101
|
+
)}
|
|
102
|
+
</StepCounter>
|
|
103
|
+
<StepName>{step.name}</StepName>
|
|
104
|
+
</StepperHeaderItem>
|
|
105
|
+
))}
|
|
106
|
+
</StepperHeader>
|
|
107
|
+
<StepperBody>{children}</StepperBody>
|
|
108
|
+
</Container>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Set dot components
|
|
113
|
+
Stepper.Step = StepperStep;
|
|
114
|
+
Stepper.Steps = StepperSteps;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
import { StepStates } from '../stepStates';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const StepperHeader = styled.div`
|
|
10
|
+
margin-top: auto;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
14
|
+
`;
|
|
15
|
+
export const StepperHeaderItem = styled.div<{ stepState: StepStates }>`
|
|
16
|
+
position: relative;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
align-items: center;
|
|
20
|
+
flex: 1;
|
|
21
|
+
|
|
22
|
+
&::after {
|
|
23
|
+
position: absolute;
|
|
24
|
+
content: '';
|
|
25
|
+
border-bottom: 2px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
26
|
+
width: 100%;
|
|
27
|
+
top: 22px;
|
|
28
|
+
left: calc(50% + 20px);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&:first-child {
|
|
32
|
+
&::before {
|
|
33
|
+
content: none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&:last-child {
|
|
38
|
+
&::after {
|
|
39
|
+
content: none;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
${({ stepState, theme }): string => {
|
|
44
|
+
return stepState !== StepStates.OTHER
|
|
45
|
+
? `
|
|
46
|
+
&::before {
|
|
47
|
+
position: absolute;
|
|
48
|
+
content: '';
|
|
49
|
+
border-bottom: 2px solid ${theme.colors.primary};
|
|
50
|
+
width: 100%;
|
|
51
|
+
top: 22px;
|
|
52
|
+
left: -50%;
|
|
53
|
+
`
|
|
54
|
+
: '';
|
|
55
|
+
}}
|
|
56
|
+
|
|
57
|
+
@media (max-width: 768px) {
|
|
58
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
export const StepperBody = styled.div`
|
|
63
|
+
padding: ${({ theme }) => `${theme.spacing[7]} ${theme.spacing['1_5']}`};
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
export const StepCounter = styled.div<{
|
|
67
|
+
stepState: StepStates;
|
|
68
|
+
canStepBack: boolean;
|
|
69
|
+
}>`
|
|
70
|
+
position: relative;
|
|
71
|
+
|
|
72
|
+
/* makes sure the before and after lines don't show above the step circles */
|
|
73
|
+
z-index: 1;
|
|
74
|
+
display: flex;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
align-items: center;
|
|
77
|
+
width: 5rem;
|
|
78
|
+
height: 5rem;
|
|
79
|
+
padding: 0.8rem;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
border: 0.1rem solid
|
|
82
|
+
${({ theme, stepState }) => (stepState !== StepStates.OTHER ? theme.colors.primary : theme.colors.backgroundAccent)};
|
|
83
|
+
background-color: ${({ stepState, theme }) =>
|
|
84
|
+
stepState === StepStates.CURRENT ? theme.colors.primaryShade : theme.colors.background};
|
|
85
|
+
transition: all 0.2s ease-in-out;
|
|
86
|
+
margin-bottom: ${({ theme }) => theme.spacing[1]};
|
|
87
|
+
color: ${({ theme, stepState }) => (stepState !== StepStates.OTHER ? theme.colors.white : theme.colors.text)};
|
|
88
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
89
|
+
cursor: ${({ stepState, canStepBack }) => (stepState === StepStates.COMPLETE && canStepBack ? 'pointer' : 'inherit')};
|
|
90
|
+
|
|
91
|
+
svg {
|
|
92
|
+
fill: ${({ theme, stepState }) => {
|
|
93
|
+
switch (stepState) {
|
|
94
|
+
case StepStates.COMPLETE:
|
|
95
|
+
return theme.colors.primary;
|
|
96
|
+
case StepStates.CURRENT:
|
|
97
|
+
return theme.colors.white;
|
|
98
|
+
case StepStates.OTHER:
|
|
99
|
+
return '#ccc';
|
|
100
|
+
}
|
|
101
|
+
}};
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
export const StepName = styled.h4``;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FC, createContext, useContext, useReducer, useCallback, PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
import { reducer, StepperState, stepTypes } from './reducer';
|
|
3
|
+
|
|
4
|
+
const StepperContext = createContext<any>(undefined);
|
|
5
|
+
|
|
6
|
+
interface StepperProviderProps {
|
|
7
|
+
startStep?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const StepperProvider: FC<PropsWithChildren<StepperProviderProps>> = ({ startStep = 0, children }) => {
|
|
11
|
+
const defaultStepperState: StepperState = {
|
|
12
|
+
steps: [],
|
|
13
|
+
currentStep: startStep,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const [state, dispatch] = useReducer(reducer, defaultStepperState);
|
|
17
|
+
|
|
18
|
+
return <StepperContext.Provider value={[state, dispatch]}>{children}</StepperContext.Provider>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useStepper = () => {
|
|
22
|
+
const [state, dispatch] = useContext(StepperContext);
|
|
23
|
+
const { currentStep, steps } = state;
|
|
24
|
+
|
|
25
|
+
if (!StepperContext) {
|
|
26
|
+
throw new Error('useStepper should be used inside StepperProvider');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// callback hooks otherwise we remake these fns on every change.
|
|
30
|
+
const incrementCurrentStep = useCallback(() => dispatch({ type: stepTypes.INCREMENT_CURRENT_STEP }), [dispatch]);
|
|
31
|
+
const decrementCurrentStep = useCallback(() => dispatch({ type: stepTypes.DECREMENT_CURRENT_STEP }), [dispatch]);
|
|
32
|
+
const setSteps = useCallback(
|
|
33
|
+
(steps: ReactNode[]) => dispatch({ type: stepTypes.SET_STEPS, payload: { steps } }),
|
|
34
|
+
[dispatch]
|
|
35
|
+
);
|
|
36
|
+
const setCurrentStep = useCallback(
|
|
37
|
+
(amount: number) => dispatch({ type: stepTypes.SET_CURRENT_STEP, payload: { amount } }),
|
|
38
|
+
[dispatch]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
incrementCurrentStep,
|
|
43
|
+
decrementCurrentStep,
|
|
44
|
+
setSteps,
|
|
45
|
+
setCurrentStep,
|
|
46
|
+
currentStep,
|
|
47
|
+
steps,
|
|
48
|
+
};
|
|
49
|
+
};
|