@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,72 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { useSnackbar } from 'notistack';
|
|
4
|
+
import { styled } from '../../../../styled';
|
|
5
|
+
import { Button } from '../../../../components';
|
|
6
|
+
import { DefaultSnackProps } from '.';
|
|
7
|
+
|
|
8
|
+
const Wrapper = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: row;
|
|
11
|
+
justify-content: space-evenly;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: 'Feedback/Snacks/Default',
|
|
16
|
+
parameters: {
|
|
17
|
+
docs: {
|
|
18
|
+
inlineStories: false,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
args: {
|
|
22
|
+
type: 'info',
|
|
23
|
+
title: 'Update available',
|
|
24
|
+
message: 'A new software version is available for download.',
|
|
25
|
+
},
|
|
26
|
+
} as Meta<DefaultSnackProps>;
|
|
27
|
+
|
|
28
|
+
export const Default: StoryFn<DefaultSnackProps> = (args) => {
|
|
29
|
+
const { enqueueSnackbar } = useSnackbar();
|
|
30
|
+
|
|
31
|
+
const handleOnClick = () => {
|
|
32
|
+
enqueueSnackbar(args.message, {
|
|
33
|
+
title: args.title,
|
|
34
|
+
type: args.type,
|
|
35
|
+
key: 'software-update',
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Wrapper>
|
|
41
|
+
<Button onClick={handleOnClick} text="show snack" />
|
|
42
|
+
</Wrapper>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const Buttons: StoryFn<DefaultSnackProps> = (args) => {
|
|
47
|
+
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
|
|
48
|
+
|
|
49
|
+
const handleOnClick = () => {
|
|
50
|
+
enqueueSnackbar(args.message, {
|
|
51
|
+
title: args.title,
|
|
52
|
+
type: args.type,
|
|
53
|
+
key: 'software-update',
|
|
54
|
+
button1: <Button text="Update" />,
|
|
55
|
+
button2: (
|
|
56
|
+
<Button
|
|
57
|
+
onClick={() => {
|
|
58
|
+
closeSnackbar('software-update');
|
|
59
|
+
}}
|
|
60
|
+
text="Not now"
|
|
61
|
+
variant="outline"
|
|
62
|
+
/>
|
|
63
|
+
),
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Wrapper>
|
|
69
|
+
<Button onClick={handleOnClick} text="show snack" />
|
|
70
|
+
</Wrapper>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { forwardRef, FC, ReactElement, cloneElement, useCallback } from 'react';
|
|
2
|
+
import { CustomContentProps, useSnackbar } from 'notistack';
|
|
3
|
+
import {
|
|
4
|
+
AiOutlineClose as CloseIcon,
|
|
5
|
+
AiOutlineWarning as WarningIcon,
|
|
6
|
+
AiOutlineInfo as InfoIcon,
|
|
7
|
+
AiOutlineCheck as CheckMarkIcon,
|
|
8
|
+
AiOutlineMeh as ErrorIcon,
|
|
9
|
+
} from 'react-icons/ai';
|
|
10
|
+
|
|
11
|
+
import { Wrapper, ContentContainer, TextContainer, IconContainer, ButtonContainer } from './style';
|
|
12
|
+
import { useTheme } from '../../../../hooks';
|
|
13
|
+
import { ButtonProps, IconButton, Tooltip } from '../../../../components';
|
|
14
|
+
import { AlertVariants } from '../../../../styled';
|
|
15
|
+
|
|
16
|
+
/* IMPORTANT: These props need to be kept in sync with the props defined in helpers/getSnackbarProvider */
|
|
17
|
+
export interface DefaultSnackProps extends CustomContentProps {
|
|
18
|
+
title?: string;
|
|
19
|
+
button1?: FC<ButtonProps>;
|
|
20
|
+
button2?: FC<ButtonProps>;
|
|
21
|
+
type?: AlertVariants;
|
|
22
|
+
icon?: ReactElement;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const DefaultSnack = forwardRef<HTMLDivElement, DefaultSnackProps>(
|
|
26
|
+
({ id, message, title, button1, button2, type = 'info', icon }, ref) => {
|
|
27
|
+
const { closeSnackbar } = useSnackbar();
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
|
|
30
|
+
const getIcon = () => {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'info':
|
|
33
|
+
return <InfoIcon fill={theme.colors.info} size={15} />;
|
|
34
|
+
case 'success':
|
|
35
|
+
return <CheckMarkIcon fill={theme.colors.success} size={15} />;
|
|
36
|
+
case 'warning':
|
|
37
|
+
return <WarningIcon fill={theme.colors.warning} size={15} />;
|
|
38
|
+
case 'error':
|
|
39
|
+
return <ErrorIcon fill={theme.colors.warning} size={15} />;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleDismiss = useCallback(() => {
|
|
44
|
+
closeSnackbar(id);
|
|
45
|
+
}, [id, closeSnackbar]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Wrapper ref={ref}>
|
|
49
|
+
<ContentContainer>
|
|
50
|
+
<IconContainer variant={type}>
|
|
51
|
+
{icon ? cloneElement(icon, { size: 15, fill: theme.colors[type] }) : getIcon()}
|
|
52
|
+
</IconContainer>
|
|
53
|
+
<TextContainer>
|
|
54
|
+
{title && <h3>{title}</h3>}
|
|
55
|
+
<h5>{message}</h5>
|
|
56
|
+
{button1 && (
|
|
57
|
+
<ButtonContainer>
|
|
58
|
+
<>
|
|
59
|
+
{button1}
|
|
60
|
+
{button2 && button2}
|
|
61
|
+
</>
|
|
62
|
+
</ButtonContainer>
|
|
63
|
+
)}
|
|
64
|
+
</TextContainer>
|
|
65
|
+
<div style={{ width: '25px' }}>
|
|
66
|
+
<Tooltip>
|
|
67
|
+
<Tooltip.Trigger asChild>
|
|
68
|
+
<IconButton icon={<CloseIcon />} ariaLabel="Dismiss snack popup" onClick={handleDismiss} />
|
|
69
|
+
</Tooltip.Trigger>
|
|
70
|
+
<Tooltip.Content>Dismiss</Tooltip.Content>
|
|
71
|
+
</Tooltip>
|
|
72
|
+
</div>
|
|
73
|
+
</ContentContainer>
|
|
74
|
+
</Wrapper>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
import { lighten } from 'polished';
|
|
3
|
+
|
|
4
|
+
export const Wrapper = styled.div`
|
|
5
|
+
position: relative;
|
|
6
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
7
|
+
padding: ${({ theme }) =>
|
|
8
|
+
`${theme.spacing['1']} ${theme.spacing[2]} ${theme.spacing['1_5']} ${theme.spacing['1_5']}`};
|
|
9
|
+
box-shadow: ${({ theme }) => theme.elevation[4]};
|
|
10
|
+
border: 0.1rem solid ${({ theme }) => theme.colors.backgroundAlt};
|
|
11
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const ContentContainer = styled.div`
|
|
15
|
+
display: flex;
|
|
16
|
+
width: 100%;
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const TextContainer = styled.div`
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
width: 250px;
|
|
26
|
+
h3 {
|
|
27
|
+
font-weight: 700;
|
|
28
|
+
margin-bottom: ${({ theme }) => theme.spacing[1]};
|
|
29
|
+
}
|
|
30
|
+
margin-right: ${({ theme }) => theme.spacing[1]};
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const IconContainer = styled.div<{
|
|
34
|
+
variant: 'info' | 'warning' | 'success' | 'error';
|
|
35
|
+
}>`
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
padding: ${({ theme }) => theme.spacing['0_5']};
|
|
40
|
+
width: 2.75rem;
|
|
41
|
+
height: 2.75rem;
|
|
42
|
+
border-radius: 50%;
|
|
43
|
+
margin-right: ${({ theme }) => theme.spacing[1]};
|
|
44
|
+
background-color: ${({ variant, theme }): string => lighten(0.3, theme.colors[variant])};
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export const ButtonContainer = styled.div`
|
|
48
|
+
width: 100%;
|
|
49
|
+
margin-top: 1rem;
|
|
50
|
+
display: flex;
|
|
51
|
+
justify-content: space-between;
|
|
52
|
+
|
|
53
|
+
button {
|
|
54
|
+
width: 100%;
|
|
55
|
+
&:first-child {
|
|
56
|
+
margin-right: ${({ theme }) => theme.spacing['0_5']};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { Button } from '../../../';
|
|
4
|
+
import { useSnackbar } from 'notistack';
|
|
5
|
+
import { styled } from '../../../../';
|
|
6
|
+
import { AiFillCheckCircle as CheckMarkIcon } from 'react-icons/ai';
|
|
7
|
+
|
|
8
|
+
const CustomContent = styled.div`
|
|
9
|
+
h4 {
|
|
10
|
+
font-size: 1.2rem;
|
|
11
|
+
}
|
|
12
|
+
p {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
svg {
|
|
16
|
+
margin-right: 0.5rem;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
title: 'Feedback/Snacks/DrawerSnack',
|
|
23
|
+
component: undefined,
|
|
24
|
+
} as Meta;
|
|
25
|
+
|
|
26
|
+
export const Downloads: StoryFn = () => {
|
|
27
|
+
const { enqueueSnackbar } = useSnackbar();
|
|
28
|
+
|
|
29
|
+
const showSnack = () => {
|
|
30
|
+
enqueueSnackbar('Report Complete', {
|
|
31
|
+
autoHideDuration: 20000, // 20s
|
|
32
|
+
anchorOrigin: { horizontal: 'right', vertical: 'bottom' },
|
|
33
|
+
variant: 'drawer',
|
|
34
|
+
children: (
|
|
35
|
+
<CustomContent>
|
|
36
|
+
<h4>Pdf Ready</h4>
|
|
37
|
+
<p>
|
|
38
|
+
<CheckMarkIcon /> Download now
|
|
39
|
+
</p>
|
|
40
|
+
</CustomContent>
|
|
41
|
+
),
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return <Button onClick={() => showSnack()} text="Show snack" />;
|
|
46
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CustomContentProps, useSnackbar } from 'notistack';
|
|
2
|
+
import { useState, forwardRef, PropsWithChildren } from 'react';
|
|
3
|
+
import { styled } from '../../../../styled';
|
|
4
|
+
import { AiOutlineClose as CloseIcon, AiOutlineDown as ArrowDownIcon } from 'react-icons/ai';
|
|
5
|
+
|
|
6
|
+
const Wrapper = styled.div`
|
|
7
|
+
box-shadow: ${({ theme }) => theme.elevation[4]};
|
|
8
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
9
|
+
width: 250px;
|
|
10
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAlt};
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const Container = styled.div<{ expanded: boolean }>`
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
min-height: 0;
|
|
18
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
19
|
+
padding: ${({ theme }) => theme.spacing[1]};
|
|
20
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
21
|
+
|
|
22
|
+
${({ expanded }) => {
|
|
23
|
+
if (expanded) {
|
|
24
|
+
return `
|
|
25
|
+
border-bottom-right-radius: 0;
|
|
26
|
+
border-bottom-left-radius: 0;
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
svg {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
padding: ${({ theme }) => `0 ${theme.spacing['0_5']}`};
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const Content = styled.div<{ expanded: boolean }>`
|
|
37
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
38
|
+
height: ${({ expanded }): string => (expanded ? 'auto' : '0')};
|
|
39
|
+
padding: ${({ expanded, theme }): string => (expanded ? theme.spacing[1] : theme.spacing[0])};
|
|
40
|
+
will-change: height;
|
|
41
|
+
transition: height 0.2s ease-in-out;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
border-radius: ${({ theme }) => `0 0 ${theme.borderRadius.large} ${theme.borderRadius.large}`};
|
|
44
|
+
border-radius-top-left: 0;
|
|
45
|
+
border-radius-top-right: 0;
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
export const DrawerSnack = forwardRef<HTMLDivElement, PropsWithChildren<CustomContentProps>>(
|
|
49
|
+
({ id, message, children }, ref) => {
|
|
50
|
+
const { closeSnackbar } = useSnackbar();
|
|
51
|
+
const [expanded, setExpanded] = useState<boolean>(false);
|
|
52
|
+
|
|
53
|
+
const handleClose = () => {
|
|
54
|
+
closeSnackbar(id);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Wrapper ref={ref} data-testid={id}>
|
|
59
|
+
<Container expanded={expanded}>
|
|
60
|
+
<h4>{message}</h4>
|
|
61
|
+
<div>
|
|
62
|
+
<ArrowDownIcon onClick={() => setExpanded(!expanded)} size={16} />
|
|
63
|
+
<CloseIcon onClick={handleClose} size={16} />
|
|
64
|
+
</div>
|
|
65
|
+
</Container>
|
|
66
|
+
<Content expanded={expanded}>{children}</Content>
|
|
67
|
+
</Wrapper>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { styled } from '../../../../styled';
|
|
3
|
+
import { useTheme } from '../../../../hooks';
|
|
4
|
+
import { FiWifi as WifiIcon, FiWifiOff as WifiOffIcon } from 'react-icons/fi';
|
|
5
|
+
import { AiOutlineClose as CloseIcon } from 'react-icons/ai';
|
|
6
|
+
import { CustomContentProps, useSnackbar } from 'notistack';
|
|
7
|
+
|
|
8
|
+
const Container = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
padding: 1.2rem;
|
|
13
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
14
|
+
width: 300px;
|
|
15
|
+
background-color: white;
|
|
16
|
+
box-shadow: ${({ theme }): string => theme.elevation[4]};
|
|
17
|
+
p {
|
|
18
|
+
font-size: 1.325rem;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const CloseIconContainer = styled.div`
|
|
22
|
+
border-radius: 50%;
|
|
23
|
+
padding: 0.3rem;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
|
|
26
|
+
&:hover {
|
|
27
|
+
background-color: ${({ theme }): string => theme.colors.background};
|
|
28
|
+
svg {
|
|
29
|
+
fill: white;
|
|
30
|
+
stroke: white;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const NetworkDetectorOfflineSnack = forwardRef<HTMLDivElement, CustomContentProps>(({ id, message }, ref) => {
|
|
36
|
+
const { closeSnackbar } = useSnackbar();
|
|
37
|
+
|
|
38
|
+
const handleClose = () => {
|
|
39
|
+
closeSnackbar(id);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Container ref={ref}>
|
|
44
|
+
<WifiOffIcon size={18} style={{ stroke: 'black' }} />
|
|
45
|
+
<p>{message}</p>
|
|
46
|
+
<CloseIconContainer>
|
|
47
|
+
<CloseIcon onClick={handleClose} size={18} style={{ cursor: 'pointer' }} />
|
|
48
|
+
</CloseIconContainer>
|
|
49
|
+
</Container>
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const NetworkDetectorOnlineSnack = forwardRef<HTMLDivElement, CustomContentProps>(({ id, message }, ref) => {
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const { closeSnackbar } = useSnackbar();
|
|
56
|
+
|
|
57
|
+
const handleClose = () => {
|
|
58
|
+
closeSnackbar(id);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Container ref={ref}>
|
|
63
|
+
<WifiIcon size={20} style={{ stroke: theme.colors.success }} />
|
|
64
|
+
<p>{message}</p>
|
|
65
|
+
<CloseIconContainer>
|
|
66
|
+
<CloseIcon onClick={handleClose} size={18} style={{ cursor: 'pointer' }} />
|
|
67
|
+
</CloseIconContainer>
|
|
68
|
+
</Container>
|
|
69
|
+
);
|
|
70
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DefaultSnackProps } from './Default';
|
|
2
|
+
import { DrawerSnackProps } from './Drawer';
|
|
3
|
+
|
|
4
|
+
declare module 'notistack' {
|
|
5
|
+
interface VariantOverrides {
|
|
6
|
+
// disable default variants
|
|
7
|
+
success: false;
|
|
8
|
+
error: false;
|
|
9
|
+
info: false;
|
|
10
|
+
warning: false;
|
|
11
|
+
|
|
12
|
+
default: DefaultSnackProps;
|
|
13
|
+
draw: DrawerSnackProps;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { DefaultSnack } from './Default';
|
|
2
|
+
export type { DefaultSnackProps } from './Default';
|
|
3
|
+
|
|
4
|
+
export { DrawerSnack } from './Drawer';
|
|
5
|
+
|
|
6
|
+
export { NetworkDetectorOfflineSnack, NetworkDetectorOnlineSnack } from './NetworkDetector';
|
|
7
|
+
|
|
8
|
+
export { CookieConsentSnack } from './CookieConsent';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { CheckBox, CheckBoxProps, Button } from '../../../components';
|
|
5
|
+
import { SubmitHandler, useForm, useWatch } from 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
const Wrapper = styled.div`
|
|
8
|
+
padding: 5rem;
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Inputs/Checkbox',
|
|
13
|
+
component: CheckBox,
|
|
14
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
15
|
+
args: {
|
|
16
|
+
name: 'checkbox',
|
|
17
|
+
loading: false,
|
|
18
|
+
defaultValue: false,
|
|
19
|
+
readOnly: false,
|
|
20
|
+
label: 'this is the label',
|
|
21
|
+
labelPosition: 'left',
|
|
22
|
+
disabled: false,
|
|
23
|
+
required: true,
|
|
24
|
+
size: 'medium',
|
|
25
|
+
},
|
|
26
|
+
} as Meta<CheckBoxProps>;
|
|
27
|
+
|
|
28
|
+
export const OnSubmit: StoryFn<CheckBoxProps & { defaultValue: boolean }> = (args) => {
|
|
29
|
+
type FormFields = { checkbox: boolean };
|
|
30
|
+
|
|
31
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
32
|
+
defaultValues: {
|
|
33
|
+
checkbox: args.defaultValue,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const [result, setResult] = React.useState<boolean>(false);
|
|
37
|
+
|
|
38
|
+
const onSubmit: SubmitHandler<FormFields> = (values) => {
|
|
39
|
+
setResult(values[args.name]);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
45
|
+
<CheckBox {...args} control={control} />
|
|
46
|
+
<Button type="submit" text="submit" />
|
|
47
|
+
</form>
|
|
48
|
+
<pre>value: {result ? 'true' : 'false'}</pre>
|
|
49
|
+
<p>NOTE: defaultValue will only be set on initial load. Limitation of react-hook-form.</p>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const OnChange: StoryFn<CheckBoxProps> = (args) => {
|
|
55
|
+
const { control } = useForm();
|
|
56
|
+
const CheckBoxValue = useWatch({ control, name: args.name });
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<CheckBox {...args} control={control} />
|
|
61
|
+
<pre>value: {CheckBoxValue ? 'true' : 'false'}</pre>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { GenericCheckBox } from '.';
|
|
4
|
+
import { Container, CheckboxContainer } from './style';
|
|
5
|
+
|
|
6
|
+
import { defaultInputProps, defaultInputPropsFactory, ControlledInputProps } from '../InputProps';
|
|
7
|
+
import { Label, ErrorMessage, InputWrapper, Description } from '../layout';
|
|
8
|
+
|
|
9
|
+
export interface CheckBoxProps {
|
|
10
|
+
labelPosition?: 'left' | 'right';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ControlledCheckBoxProps = ControlledInputProps & CheckBoxProps;
|
|
14
|
+
|
|
15
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledCheckBoxProps>(defaultInputProps);
|
|
16
|
+
|
|
17
|
+
export const ControlledCheckBox: FC<ControlledCheckBoxProps> = (props) => {
|
|
18
|
+
const {
|
|
19
|
+
name,
|
|
20
|
+
size,
|
|
21
|
+
label,
|
|
22
|
+
loading,
|
|
23
|
+
required,
|
|
24
|
+
readOnly,
|
|
25
|
+
disabled,
|
|
26
|
+
description,
|
|
27
|
+
labelPosition = 'left',
|
|
28
|
+
hint,
|
|
29
|
+
control,
|
|
30
|
+
} = defaultsApplier(props);
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
field,
|
|
34
|
+
fieldState: { error },
|
|
35
|
+
} = useController({
|
|
36
|
+
name,
|
|
37
|
+
control,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (loading) {
|
|
41
|
+
return (
|
|
42
|
+
<InputWrapper>
|
|
43
|
+
<Container>
|
|
44
|
+
{/* CASE: Show label before <CheckBox /> */}
|
|
45
|
+
{labelPosition === 'left' && label && (
|
|
46
|
+
<Label
|
|
47
|
+
error={!!error}
|
|
48
|
+
position={labelPosition}
|
|
49
|
+
size={size}
|
|
50
|
+
text={label}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
required={required}
|
|
53
|
+
hint={hint}
|
|
54
|
+
htmlFor={name}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
<CheckboxContainer className="placeholder" readOnly={readOnly} hasError={!!error} disabled={disabled} />
|
|
58
|
+
{/* CASE: show label after <CheckBox /> */}
|
|
59
|
+
{labelPosition === 'right' && label && (
|
|
60
|
+
<Label
|
|
61
|
+
error={!!error}
|
|
62
|
+
position={labelPosition}
|
|
63
|
+
size={size}
|
|
64
|
+
text={label}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
required={required}
|
|
67
|
+
hint={hint}
|
|
68
|
+
htmlFor={name}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</Container>
|
|
72
|
+
{description && <Description description={description} inputName={name} />}
|
|
73
|
+
</InputWrapper>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<InputWrapper>
|
|
79
|
+
<Container>
|
|
80
|
+
{/* CASE: Show label before <CheckBox /> */}
|
|
81
|
+
{labelPosition === 'left' && label && (
|
|
82
|
+
<Label
|
|
83
|
+
error={!!error}
|
|
84
|
+
position={labelPosition}
|
|
85
|
+
size={size}
|
|
86
|
+
text={label}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
required={required}
|
|
89
|
+
htmlFor={name}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
<GenericCheckBox
|
|
93
|
+
id={name}
|
|
94
|
+
hasError={!!error}
|
|
95
|
+
hasDescription={!!description}
|
|
96
|
+
name={name}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
size={size}
|
|
99
|
+
readOnly={readOnly}
|
|
100
|
+
required={required}
|
|
101
|
+
onChange={field.onChange}
|
|
102
|
+
onBlur={field.onBlur}
|
|
103
|
+
value={field.value}
|
|
104
|
+
ref={field.ref}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
{/* CASE: show label after <CheckBox /> */}
|
|
108
|
+
{labelPosition === 'right' && label && (
|
|
109
|
+
<Label
|
|
110
|
+
error={!!error}
|
|
111
|
+
position={labelPosition}
|
|
112
|
+
text={label}
|
|
113
|
+
disabled={disabled}
|
|
114
|
+
required={required}
|
|
115
|
+
htmlFor={name}
|
|
116
|
+
size={size}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
{error && error.message && <ErrorMessage message={error.message} />}
|
|
120
|
+
</Container>
|
|
121
|
+
{description && <Description description={description} inputName={name} />}
|
|
122
|
+
</InputWrapper>
|
|
123
|
+
);
|
|
124
|
+
};
|