@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,211 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Alert, FileField, FileFieldProps } from '../../../components';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
5
|
+
import { useForm, SubmitHandler } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
|
|
9
|
+
const Wrapper = styled.div`
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
height: 100vh;
|
|
13
|
+
width: 50%;
|
|
14
|
+
margin: 0 auto;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: 'Inputs/FileField',
|
|
21
|
+
component: FileField,
|
|
22
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
23
|
+
args: {
|
|
24
|
+
label: 'Profile Image',
|
|
25
|
+
loading: false,
|
|
26
|
+
description: 'This is a description',
|
|
27
|
+
},
|
|
28
|
+
} as Meta<FileFieldProps>;
|
|
29
|
+
|
|
30
|
+
export const onSubmit: StoryFn<FileFieldProps> = (args) => {
|
|
31
|
+
type FormFields = {
|
|
32
|
+
profileImage: FileList;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const MAX_FILE_SIZE = 500000; // 5MB
|
|
36
|
+
const ACCEPTED_IMAGE_TYPES = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
|
37
|
+
const [value, setValue] = useState<string | null>(null);
|
|
38
|
+
|
|
39
|
+
const validationSchema = z.object({
|
|
40
|
+
profileImage: z
|
|
41
|
+
.any()
|
|
42
|
+
.refine((files) => files?.length == 1, 'Image is required.')
|
|
43
|
+
.refine((files) => files?.[0]?.size <= MAX_FILE_SIZE, 'Max file size is 5MB.')
|
|
44
|
+
.refine(
|
|
45
|
+
(files) => ACCEPTED_IMAGE_TYPES.includes(files?.[0]?.type),
|
|
46
|
+
'Only .jpg, .jpeg, .png and .webp files are accepted.'
|
|
47
|
+
),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
51
|
+
resolver: zodResolver(validationSchema),
|
|
52
|
+
});
|
|
53
|
+
const onSubmit: SubmitHandler<FormFields> = ({ profileImage }) => {
|
|
54
|
+
setValue(profileImage[0].name);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<Alert
|
|
60
|
+
variant="warning"
|
|
61
|
+
text="Although the upload could be limited to a single file, the returned type will always be a FileList."
|
|
62
|
+
/>
|
|
63
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
64
|
+
<FileField
|
|
65
|
+
name="profileImage"
|
|
66
|
+
hint={args.hint}
|
|
67
|
+
label={args.label}
|
|
68
|
+
loading={args.loading}
|
|
69
|
+
description={args.description}
|
|
70
|
+
disabled={args.disabled}
|
|
71
|
+
required={args.required}
|
|
72
|
+
readOnly={args.readOnly}
|
|
73
|
+
placeholder={args.placeholder}
|
|
74
|
+
multiple={false}
|
|
75
|
+
control={control}
|
|
76
|
+
/>
|
|
77
|
+
<button type="submit">Submit</button>
|
|
78
|
+
</form>
|
|
79
|
+
<p>uploaded filename: {value}</p>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const MultipleImages: StoryFn<FileFieldProps> = (args) => {
|
|
85
|
+
type FormFields = {
|
|
86
|
+
profileImages: FileList;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const MAX_FILE_SIZE = 500000; // 5MB
|
|
90
|
+
const ACCEPTED_IMAGE_TYPES = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
|
91
|
+
const MAX_FILES = 2;
|
|
92
|
+
const [fileNames, setFileNames] = useState<string[] | null>(null);
|
|
93
|
+
|
|
94
|
+
const validationSchema = z.object({
|
|
95
|
+
profileImages: z
|
|
96
|
+
.any()
|
|
97
|
+
.refine(
|
|
98
|
+
(obj) => {
|
|
99
|
+
// Check if obj is a FileList
|
|
100
|
+
return obj instanceof FileList;
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
message: 'You must select at least one file.',
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
.refine(
|
|
107
|
+
(fileList: FileList) => {
|
|
108
|
+
// Check the number of files
|
|
109
|
+
return fileList.length > 0 && fileList.length <= MAX_FILES;
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
message: `You must select between 1 and ${MAX_FILES} files.`,
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
.refine(
|
|
116
|
+
(fileList: FileList) => {
|
|
117
|
+
// Check each file's size
|
|
118
|
+
return Array.from(fileList).every((file) => file.size <= MAX_FILE_SIZE);
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
message: 'Each file must be no larger than 5MB.',
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
.refine(
|
|
125
|
+
(fileList: FileList) => {
|
|
126
|
+
// Check each file's type
|
|
127
|
+
return Array.from(fileList).every((file) => ACCEPTED_IMAGE_TYPES.includes(file.type));
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
message: 'Only .jpg, .jpeg, .png, and .webp files are accepted.',
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
136
|
+
resolver: zodResolver(validationSchema),
|
|
137
|
+
});
|
|
138
|
+
const onSubmit: SubmitHandler<FormFields> = ({ profileImages }) => {
|
|
139
|
+
setFileNames(Array.from(profileImages).map((file) => file.name));
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
145
|
+
<FileField
|
|
146
|
+
name="profileImages"
|
|
147
|
+
hint={args.hint}
|
|
148
|
+
label="Profile images"
|
|
149
|
+
loading={args.loading}
|
|
150
|
+
description={args.description}
|
|
151
|
+
disabled={args.disabled}
|
|
152
|
+
required={args.required}
|
|
153
|
+
readOnly={args.readOnly}
|
|
154
|
+
placeholder={args.placeholder}
|
|
155
|
+
multiple={true}
|
|
156
|
+
control={control}
|
|
157
|
+
/>
|
|
158
|
+
<button type="submit">Submit</button>
|
|
159
|
+
</form>
|
|
160
|
+
<p>uploaded filenames: {fileNames}</p>
|
|
161
|
+
</>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const JsonValidationExample: StoryFn<FileFieldProps> = (args) => {
|
|
166
|
+
type FormFields = {
|
|
167
|
+
configFile: FileList;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const MAX_FILE_SIZE = 500000; // 5MB
|
|
171
|
+
const ACCEPTED_IMAGE_TYPES = ['application/json'];
|
|
172
|
+
const [file, setFile] = useState<File | null>(null);
|
|
173
|
+
|
|
174
|
+
const validationSchema = z.object({
|
|
175
|
+
configFile: z
|
|
176
|
+
.any()
|
|
177
|
+
// Unfortunately we cannot try and parse the file since refine does not allow async functions
|
|
178
|
+
.refine((files) => files?.length == 1, 'File is required.')
|
|
179
|
+
.refine((files) => files?.[0]?.size <= MAX_FILE_SIZE, 'Max file size is 5MB.')
|
|
180
|
+
.refine((files) => ACCEPTED_IMAGE_TYPES.includes(files?.[0]?.type), 'Only json files are accepted.'),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
184
|
+
resolver: zodResolver(validationSchema),
|
|
185
|
+
});
|
|
186
|
+
const onSubmit: SubmitHandler<FormFields> = ({ configFile }) => {
|
|
187
|
+
setFile(configFile[0]);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<>
|
|
192
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
193
|
+
<FileField
|
|
194
|
+
name="configFile"
|
|
195
|
+
hint={args.hint}
|
|
196
|
+
label="Config file"
|
|
197
|
+
loading={args.loading}
|
|
198
|
+
description={args.description}
|
|
199
|
+
disabled={args.disabled}
|
|
200
|
+
required={args.required}
|
|
201
|
+
readOnly={args.readOnly}
|
|
202
|
+
placeholder={args.placeholder}
|
|
203
|
+
multiple={false}
|
|
204
|
+
control={control}
|
|
205
|
+
/>
|
|
206
|
+
<button type="submit">Submit</button>
|
|
207
|
+
</form>
|
|
208
|
+
{file && <p>uploaded filename: {file.name}</p>}
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { forwardRef, useCallback, useRef } from 'react';
|
|
2
|
+
import { InputContainer, ContentContainer } from './style';
|
|
3
|
+
import { Size } from '../../../styled';
|
|
4
|
+
import { defaultInputProps, defaultInputPropsFactory, GenericInputProps } from '../InputProps';
|
|
5
|
+
import { setAriaDescribedBy } from '../layout';
|
|
6
|
+
import { IconButton, Tooltip } from '../../../components';
|
|
7
|
+
import { AiOutlineDelete as ClearIcon, AiOutlineUpload as UploadIcon } from 'react-icons/ai';
|
|
8
|
+
|
|
9
|
+
function getFileNames(files: FileList) {
|
|
10
|
+
return Array.from(files)
|
|
11
|
+
.map((file) => file.name)
|
|
12
|
+
.join(', ');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface FileFieldProps {
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
size?: Size;
|
|
18
|
+
// TODO: Add multiple file selection
|
|
19
|
+
multiple?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type GenericFileFieldProps = GenericInputProps<string, HTMLInputElement> & FileFieldProps;
|
|
23
|
+
|
|
24
|
+
const defaultsApplier = defaultInputPropsFactory<GenericFileFieldProps>(defaultInputProps);
|
|
25
|
+
|
|
26
|
+
export const GenericFileField = forwardRef<HTMLInputElement, GenericFileFieldProps>((props, ref) => {
|
|
27
|
+
// TODO: clean up this incorrect type cast mess
|
|
28
|
+
const value = props.value as unknown as FileList;
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
onChange,
|
|
32
|
+
onBlur = () => {},
|
|
33
|
+
onFocus = () => {},
|
|
34
|
+
name,
|
|
35
|
+
disabled,
|
|
36
|
+
required,
|
|
37
|
+
readOnly,
|
|
38
|
+
hasError,
|
|
39
|
+
multiple = false,
|
|
40
|
+
placeholder = 'Choose file...',
|
|
41
|
+
id,
|
|
42
|
+
hasDescription,
|
|
43
|
+
} = defaultsApplier(props);
|
|
44
|
+
|
|
45
|
+
value as unknown as FileList;
|
|
46
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
47
|
+
|
|
48
|
+
const handleClear = useCallback(() => {
|
|
49
|
+
if (inputRef.current) {
|
|
50
|
+
inputRef.current.value = '';
|
|
51
|
+
// Manually trigger the onChange handler
|
|
52
|
+
if (onChange) {
|
|
53
|
+
const fakeEvent = {
|
|
54
|
+
currentTarget: {
|
|
55
|
+
files: new DataTransfer().files,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
onChange(fakeEvent);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, [inputRef, multiple]);
|
|
64
|
+
|
|
65
|
+
const handleFileChange = useCallback(
|
|
66
|
+
(e: any) => {
|
|
67
|
+
onChange(e.currentTarget.files);
|
|
68
|
+
},
|
|
69
|
+
[onChange, multiple]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<InputContainer>
|
|
74
|
+
<input
|
|
75
|
+
type="file"
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
style={{ position: 'absolute', pointerEvents: 'none', opacity: 0, margin: 0 }}
|
|
78
|
+
id={`${id}-hidden-file-field`}
|
|
79
|
+
multiple={multiple}
|
|
80
|
+
tabIndex={-1}
|
|
81
|
+
onChange={handleFileChange}
|
|
82
|
+
ref={inputRef}
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
<ContentContainer
|
|
86
|
+
role="button"
|
|
87
|
+
aria-required={required}
|
|
88
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
89
|
+
hasError={hasError}
|
|
90
|
+
tabIndex={readOnly || disabled ? -1 : 0}
|
|
91
|
+
ref={ref}
|
|
92
|
+
onFocus={onFocus}
|
|
93
|
+
onBlur={onBlur}
|
|
94
|
+
onClick={() => inputRef.current?.click()}
|
|
95
|
+
>
|
|
96
|
+
<span>{value && value.length > 0 ? getFileNames(value) : placeholder}</span>
|
|
97
|
+
{value && value.length > 0 ? (
|
|
98
|
+
<Tooltip>
|
|
99
|
+
<Tooltip.Trigger asChild>
|
|
100
|
+
<IconButton
|
|
101
|
+
icon={<ClearIcon />}
|
|
102
|
+
ariaLabel="Remove files"
|
|
103
|
+
onClick={(e) => {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
e.stopPropagation();
|
|
106
|
+
handleClear();
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
109
|
+
</Tooltip.Trigger>
|
|
110
|
+
<Tooltip.Content>{`Remove file${value.length > 1 ? 's' : ''}`}</Tooltip.Content>
|
|
111
|
+
</Tooltip>
|
|
112
|
+
) : (
|
|
113
|
+
<Tooltip>
|
|
114
|
+
<Tooltip.Trigger asChild>
|
|
115
|
+
<IconButton
|
|
116
|
+
icon={<UploadIcon />}
|
|
117
|
+
ariaLabel="Upload files"
|
|
118
|
+
onClick={(e) => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
inputRef.current?.click();
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
</Tooltip.Trigger>
|
|
125
|
+
<Tooltip.Content>Upload file</Tooltip.Content>
|
|
126
|
+
</Tooltip>
|
|
127
|
+
)}
|
|
128
|
+
</ContentContainer>
|
|
129
|
+
</InputContainer>
|
|
130
|
+
);
|
|
131
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
width: 100%;
|
|
5
|
+
position: relative;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const InputContainer = styled.div``;
|
|
9
|
+
|
|
10
|
+
export const ContentContainer = styled.div<{ hasError: boolean }>`
|
|
11
|
+
width: 100%;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
|
|
17
|
+
border: 1px solid ${({ theme, hasError }): string => (hasError ? theme.colors.error : theme.colors.backgroundAccent)};
|
|
18
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']} ${theme.spacing[1]}`};
|
|
19
|
+
border-width: 0.1rem;
|
|
20
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
21
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
22
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
23
|
+
color: ${({ theme }) => theme.colors.textAlt};
|
|
24
|
+
|
|
25
|
+
&:focus {
|
|
26
|
+
border: 1px solid ${({ theme, hasError }): string => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
span {
|
|
30
|
+
text-overflow: ellipsis;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ChangeEventHandler, FocusEventHandler } from 'react';
|
|
2
|
+
import { Control, FieldValues } from 'react-hook-form';
|
|
3
|
+
import { Size } from '../../styled';
|
|
4
|
+
|
|
5
|
+
// Props that available on all fields (but no default value)
|
|
6
|
+
interface InputProps extends DefaultInputProps {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Props for generic input props
|
|
11
|
+
export interface GenericInputProps<V, T> extends InputProps {
|
|
12
|
+
value: V;
|
|
13
|
+
// Although name could be used as a unique field identifier, name is not retrievable in JsonSchemaForm/FieldTemplate
|
|
14
|
+
id: string;
|
|
15
|
+
hasDescription: boolean;
|
|
16
|
+
hasError: boolean;
|
|
17
|
+
onChange: ChangeEventHandler<T>;
|
|
18
|
+
onBlur?: FocusEventHandler<T>;
|
|
19
|
+
onFocus?: FocusEventHandler<T>;
|
|
20
|
+
}
|
|
21
|
+
export interface GenericInputPropsFunctionHandlers<V, D> extends InputProps {
|
|
22
|
+
value: V;
|
|
23
|
+
id: string;
|
|
24
|
+
hasError: boolean;
|
|
25
|
+
hasDescription: boolean;
|
|
26
|
+
onChange: (val: V) => void;
|
|
27
|
+
onBlur?: FocusEventHandler<D>;
|
|
28
|
+
onFocus?: FocusEventHandler<D>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ControlledInputProps extends InputProps {
|
|
32
|
+
control: Control<FieldValues> | Control<any>;
|
|
33
|
+
label?: string;
|
|
34
|
+
loading?: boolean;
|
|
35
|
+
hint?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// All input components have a set of props in common which all should have the same default values.
|
|
40
|
+
interface DefaultInputProps {
|
|
41
|
+
required?: boolean;
|
|
42
|
+
readOnly?: boolean;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
size?: Size;
|
|
45
|
+
hasMargin?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Required<T> = {
|
|
49
|
+
[P in keyof T]-?: T[P];
|
|
50
|
+
};
|
|
51
|
+
export const defaultInputProps: Required<DefaultInputProps> = {
|
|
52
|
+
required: false,
|
|
53
|
+
readOnly: false,
|
|
54
|
+
disabled: false,
|
|
55
|
+
size: 'medium',
|
|
56
|
+
hasMargin: true,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export function defaultInputPropsFactory<T extends InputProps>(defaultValues: Required<DefaultInputProps>) {
|
|
60
|
+
return (values: T) => Object.assign({} as Required<DefaultInputProps> & T, defaultValues, values);
|
|
61
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
4
|
+
|
|
5
|
+
import { Container } from './style';
|
|
6
|
+
import { RadioItem } from './RadioItem';
|
|
7
|
+
import { InputWrapper, ErrorMessage, Description } from '../layout';
|
|
8
|
+
import { GenericRadioGroup, RadioGroupSubComponents } from './Generic';
|
|
9
|
+
|
|
10
|
+
export type ControlledRadioGroupProps = PropsWithChildren<ControlledInputProps>;
|
|
11
|
+
|
|
12
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledRadioGroupProps>(defaultInputProps);
|
|
13
|
+
|
|
14
|
+
export const ControlledRadioGroup: FC<ControlledRadioGroupProps> & RadioGroupSubComponents = (props) => {
|
|
15
|
+
const { name, control, description, children, disabled, readOnly, required, hasMargin } = defaultsApplier(props);
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
field,
|
|
19
|
+
fieldState: { error },
|
|
20
|
+
} = useController({ name, control });
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<InputWrapper>
|
|
24
|
+
<Container>
|
|
25
|
+
<GenericRadioGroup
|
|
26
|
+
id={name}
|
|
27
|
+
name={name}
|
|
28
|
+
onChange={field.onChange}
|
|
29
|
+
value={field.value}
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
readOnly={readOnly}
|
|
32
|
+
hasError={!!error}
|
|
33
|
+
required={required}
|
|
34
|
+
hasDescription={!!description}
|
|
35
|
+
hasMargin={hasMargin}
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</GenericRadioGroup>
|
|
39
|
+
{error && error.message && <ErrorMessage message={error.message} />}
|
|
40
|
+
</Container>
|
|
41
|
+
{description && <Description description={description} inputName={name} />}
|
|
42
|
+
</InputWrapper>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
ControlledRadioGroup.Item = RadioItem;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ChangeEvent, FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { defaultInputProps, defaultInputPropsFactory, GenericInputProps } from '../InputProps';
|
|
3
|
+
import { RadioItem } from './RadioItem';
|
|
4
|
+
import { Container } from './style';
|
|
5
|
+
import { setAriaDescribedBy } from '../layout';
|
|
6
|
+
import { RadioGroupContext } from './context';
|
|
7
|
+
|
|
8
|
+
export interface RadioGroupSubComponents {
|
|
9
|
+
Item: typeof RadioItem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type RadioGroupProps = PropsWithChildren<GenericInputProps<string, HTMLInputElement>>;
|
|
13
|
+
const defaultsApplier = defaultInputPropsFactory<RadioGroupProps>(defaultInputProps);
|
|
14
|
+
|
|
15
|
+
export const GenericRadioGroup: FC<RadioGroupProps> & RadioGroupSubComponents = (props) => {
|
|
16
|
+
const { readOnly, value, name, onChange, hasDescription, disabled, children } = defaultsApplier(props);
|
|
17
|
+
|
|
18
|
+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
19
|
+
if (readOnly || disabled) return;
|
|
20
|
+
onChange(e);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Container role="radiogroup" aria-describedby={setAriaDescribedBy(name, hasDescription)}>
|
|
25
|
+
<RadioGroupContext.Provider
|
|
26
|
+
value={{ name, selectedValue: value, setSelectedValue: handleChange, readOnly, disabled }}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</RadioGroupContext.Provider>
|
|
30
|
+
</Container>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
GenericRadioGroup.Item = RadioItem;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
import { Button, RadioGroup, RadioGroupProps } from '../../../components';
|
|
5
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
import { GenericRadioGroup } from './Generic';
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{ value: 'm', label: 'male' },
|
|
12
|
+
{ value: 'f', label: 'female' },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: 'Inputs/RadioGroup',
|
|
17
|
+
component: RadioGroup,
|
|
18
|
+
args: {
|
|
19
|
+
readOnly: false,
|
|
20
|
+
disabled: false,
|
|
21
|
+
loading: false,
|
|
22
|
+
hint: 'this is the hint',
|
|
23
|
+
label: 'Enter your gender',
|
|
24
|
+
description: 'this is the description',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
} as Meta<RadioGroupProps>;
|
|
28
|
+
|
|
29
|
+
export const OnSubmit: StoryFn<RadioGroupProps> = (args) => {
|
|
30
|
+
type FormFields = {
|
|
31
|
+
gender: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const [result, setResult] = useState<string>('');
|
|
35
|
+
|
|
36
|
+
const validationSchema = useMemo(
|
|
37
|
+
() =>
|
|
38
|
+
z.object({
|
|
39
|
+
gender: z.enum(['m', 'f']),
|
|
40
|
+
}),
|
|
41
|
+
[]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
45
|
+
resolver: zodResolver(validationSchema),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const onSubmit: SubmitHandler<FormFields> = async ({ gender }) => {
|
|
49
|
+
setResult(gender);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
55
|
+
<RadioGroup
|
|
56
|
+
control={control}
|
|
57
|
+
loading={args.loading}
|
|
58
|
+
readOnly={args.readOnly}
|
|
59
|
+
label={args.label}
|
|
60
|
+
name="gender"
|
|
61
|
+
hint={args.hint}
|
|
62
|
+
disabled={args.disabled}
|
|
63
|
+
required={args.required}
|
|
64
|
+
description={args.description}
|
|
65
|
+
>
|
|
66
|
+
{options.map(({ value, label }) => (
|
|
67
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginBottom: '1rem' }}>
|
|
68
|
+
<RadioGroup.Item value={value} id={value} />
|
|
69
|
+
<label htmlFor={value} style={{ cursor: !args.disabled && !args.readOnly ? 'pointer' : 'default' }}>
|
|
70
|
+
{label}
|
|
71
|
+
</label>
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
74
|
+
</RadioGroup>
|
|
75
|
+
<Button text="submit" type="submit" />
|
|
76
|
+
</form>
|
|
77
|
+
<div>Result: {result}</div>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const Generic: StoryFn<RadioGroupProps> = (args) => {
|
|
83
|
+
const id = 'gender';
|
|
84
|
+
const [value, setValue] = useState<string>('m');
|
|
85
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
86
|
+
setValue(e.target.value);
|
|
87
|
+
};
|
|
88
|
+
return (
|
|
89
|
+
<div>
|
|
90
|
+
<GenericRadioGroup
|
|
91
|
+
id={id}
|
|
92
|
+
readOnly={args.readOnly}
|
|
93
|
+
name="gender"
|
|
94
|
+
required={args.required}
|
|
95
|
+
disabled={args.disabled}
|
|
96
|
+
hasDescription={!!args.description}
|
|
97
|
+
hasError={false}
|
|
98
|
+
value={value}
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
onChange={handleOnChange}
|
|
102
|
+
>
|
|
103
|
+
{options.map(({ value, label }) => (
|
|
104
|
+
<div
|
|
105
|
+
key={`${id}-${value}`}
|
|
106
|
+
style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginBottom: '1rem' }}
|
|
107
|
+
>
|
|
108
|
+
<GenericRadioGroup.Item value={value} id={value} />
|
|
109
|
+
<label htmlFor={value}>{label}</label>
|
|
110
|
+
</div>
|
|
111
|
+
))}
|
|
112
|
+
</GenericRadioGroup>
|
|
113
|
+
<>{value}</>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|