@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,67 @@
|
|
|
1
|
+
import { forwardRef, useRef } from 'react';
|
|
2
|
+
import { getTransition } from '../../../helpers';
|
|
3
|
+
import { Dot, ContentContainer } from './style';
|
|
4
|
+
import { defaultInputProps, defaultInputPropsFactory, GenericInputProps } from '../InputProps';
|
|
5
|
+
import { setAriaDescribedBy } from '../layout';
|
|
6
|
+
|
|
7
|
+
export type GenericSwitchProps = GenericInputProps<boolean, HTMLInputElement>;
|
|
8
|
+
|
|
9
|
+
const defaultsApplier = defaultInputPropsFactory<GenericSwitchProps>(defaultInputProps);
|
|
10
|
+
|
|
11
|
+
export const GenericSwitch = forwardRef<HTMLButtonElement, GenericSwitchProps>((props, ref) => {
|
|
12
|
+
const {
|
|
13
|
+
readOnly,
|
|
14
|
+
onChange,
|
|
15
|
+
value: isChecked = false,
|
|
16
|
+
id,
|
|
17
|
+
hasDescription,
|
|
18
|
+
name,
|
|
19
|
+
disabled,
|
|
20
|
+
hasError,
|
|
21
|
+
} = defaultsApplier(props);
|
|
22
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
23
|
+
|
|
24
|
+
function handleOnClick(): void {
|
|
25
|
+
if (readOnly || disabled) return;
|
|
26
|
+
inputRef.current?.click();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
<input
|
|
32
|
+
type="checkbox"
|
|
33
|
+
aria-hidden="true"
|
|
34
|
+
style={{ position: 'absolute', pointerEvents: 'none', opacity: 0, margin: 0 }}
|
|
35
|
+
checked={isChecked}
|
|
36
|
+
tabIndex={-1}
|
|
37
|
+
id={`${id}-hidden-input`}
|
|
38
|
+
value="on"
|
|
39
|
+
onChange={(e) => onChange(e)}
|
|
40
|
+
ref={inputRef}
|
|
41
|
+
/>
|
|
42
|
+
<ContentContainer
|
|
43
|
+
role="switch"
|
|
44
|
+
id={id}
|
|
45
|
+
isChecked={isChecked}
|
|
46
|
+
disabled={disabled}
|
|
47
|
+
readOnly={readOnly}
|
|
48
|
+
onClick={handleOnClick}
|
|
49
|
+
ref={ref}
|
|
50
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
51
|
+
aria-checked={isChecked}
|
|
52
|
+
hasError={hasError}
|
|
53
|
+
tabIndex={readOnly || disabled ? -1 : 0}
|
|
54
|
+
type="button"
|
|
55
|
+
>
|
|
56
|
+
<Dot
|
|
57
|
+
initial={{ right: isChecked ? '2px' : '25px' }}
|
|
58
|
+
animate={{ right: isChecked ? '2px' : '25px' }}
|
|
59
|
+
$readOnly={readOnly}
|
|
60
|
+
$isChecked={isChecked}
|
|
61
|
+
layout
|
|
62
|
+
transition={getTransition()}
|
|
63
|
+
/>
|
|
64
|
+
</ContentContainer>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import {} from '.';
|
|
5
|
+
import { Switch, SwitchProps, Button } from '../../../components';
|
|
6
|
+
import { useForm, SubmitHandler, useWatch } from 'react-hook-form';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
|
|
9
|
+
const Wrapper = styled.div`
|
|
10
|
+
padding: 5rem;
|
|
11
|
+
background: ${({ theme }) => theme.colors.background};
|
|
12
|
+
|
|
13
|
+
& > div {
|
|
14
|
+
margin: 0 auto;
|
|
15
|
+
padding: 0.2rem 1rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
form {
|
|
19
|
+
width: 100%;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
title: 'Inputs/Switch',
|
|
25
|
+
component: Switch,
|
|
26
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
27
|
+
args: {
|
|
28
|
+
label: 'Do you have a car?',
|
|
29
|
+
loading: false,
|
|
30
|
+
name: 'hasCar',
|
|
31
|
+
description: 'This is a description',
|
|
32
|
+
readOnly: false,
|
|
33
|
+
required: true,
|
|
34
|
+
disabled: false,
|
|
35
|
+
},
|
|
36
|
+
} as Meta<SwitchProps>;
|
|
37
|
+
|
|
38
|
+
type FormFields = {
|
|
39
|
+
hasCar: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const onSubmit: StoryFn<SwitchProps> = (args) => {
|
|
43
|
+
const [value, setValue] = useState<boolean>();
|
|
44
|
+
const { control, handleSubmit } = useForm<FormFields>();
|
|
45
|
+
|
|
46
|
+
const onSubmit: SubmitHandler<FormFields> = ({ hasCar }) => {
|
|
47
|
+
setValue(hasCar);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
53
|
+
<Switch
|
|
54
|
+
name={args.name}
|
|
55
|
+
label={args.label}
|
|
56
|
+
control={control}
|
|
57
|
+
description={args.description}
|
|
58
|
+
hint={args.hint}
|
|
59
|
+
loading={args.loading}
|
|
60
|
+
disabled={args.disabled}
|
|
61
|
+
required={args.required}
|
|
62
|
+
readOnly={args.readOnly}
|
|
63
|
+
/>
|
|
64
|
+
<Button type="submit" text="submit" />
|
|
65
|
+
</form>
|
|
66
|
+
submitted value: {value ? 'true' : 'false'}
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const OnChange: StoryFn<SwitchProps> = (args) => {
|
|
72
|
+
const { control } = useForm({ mode: 'onChange' });
|
|
73
|
+
const switchValue = useWatch({ control, name: args.name });
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<Switch
|
|
78
|
+
control={control}
|
|
79
|
+
name={args.name}
|
|
80
|
+
label={args.label}
|
|
81
|
+
description={args.description}
|
|
82
|
+
hint={args.hint}
|
|
83
|
+
loading={args.loading}
|
|
84
|
+
disabled={args.disabled}
|
|
85
|
+
required={args.required}
|
|
86
|
+
readOnly={args.readOnly}
|
|
87
|
+
/>
|
|
88
|
+
<pre>value: {switchValue ? 'true' : 'false'}</pre>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
import { motion } from 'framer-motion';
|
|
3
|
+
import { shade } from 'polished';
|
|
4
|
+
|
|
5
|
+
export const Container = styled.div`
|
|
6
|
+
position: relative;
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
text-align: left;
|
|
10
|
+
margin-bottom: ${({ theme }) => theme.spacing['0_5']};
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const ContentContainer = styled.button<{ isChecked: boolean; hasError: boolean; readOnly: boolean }>`
|
|
14
|
+
position: relative;
|
|
15
|
+
width: 4.2rem;
|
|
16
|
+
height: 2.5rem;
|
|
17
|
+
display: block;
|
|
18
|
+
cursor: ${({ readOnly }) => (readOnly ? 'default' : 'pointer')};
|
|
19
|
+
border-radius: 9999px;
|
|
20
|
+
border: 0.1rem solid ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
21
|
+
margin: ${({ theme }) => theme.spacing[0]};
|
|
22
|
+
background-color: ${({ theme, isChecked, hasError }) => {
|
|
23
|
+
if (isChecked && hasError) {
|
|
24
|
+
return theme.colors.error;
|
|
25
|
+
}
|
|
26
|
+
return isChecked ? theme.colors.primaryShade : shade(0.5, theme.colors.background);
|
|
27
|
+
}};
|
|
28
|
+
|
|
29
|
+
&:focus {
|
|
30
|
+
border: 0.1rem solid ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:disabled {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export const Dot = styled(motion.span)<{
|
|
39
|
+
$isChecked: boolean;
|
|
40
|
+
$readOnly: boolean;
|
|
41
|
+
}>`
|
|
42
|
+
will-change: right;
|
|
43
|
+
position: absolute;
|
|
44
|
+
margin-top: -0.45rem;
|
|
45
|
+
top: calc(50% - 0.62rem);
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
width: 2.1rem;
|
|
48
|
+
height: 2.1rem;
|
|
49
|
+
background-color: ${({ theme, $readOnly, $isChecked }) => {
|
|
50
|
+
let color = $isChecked ? theme.colors.white : theme.colors.white;
|
|
51
|
+
if ($readOnly) {
|
|
52
|
+
color = theme.colors.backgroundAccent;
|
|
53
|
+
}
|
|
54
|
+
return color;
|
|
55
|
+
}};
|
|
56
|
+
`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { TagFieldProps, GenericTagField } from '.';
|
|
4
|
+
import { Container, TagsContainer } from './style';
|
|
5
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
6
|
+
import { InputWrapper, Description, ErrorMessage, Label } from '../layout';
|
|
7
|
+
|
|
8
|
+
export type ControlledTagFieldProps = TagFieldProps & ControlledInputProps;
|
|
9
|
+
|
|
10
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledTagFieldProps>(defaultInputProps);
|
|
11
|
+
|
|
12
|
+
export const ControlledTagField: FC<ControlledTagFieldProps> = (props) => {
|
|
13
|
+
const {
|
|
14
|
+
loading,
|
|
15
|
+
label,
|
|
16
|
+
hint,
|
|
17
|
+
disabled,
|
|
18
|
+
required,
|
|
19
|
+
description,
|
|
20
|
+
placeholder,
|
|
21
|
+
name,
|
|
22
|
+
size,
|
|
23
|
+
readOnly,
|
|
24
|
+
control,
|
|
25
|
+
allowDuplicates,
|
|
26
|
+
} = defaultsApplier(props);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
field,
|
|
30
|
+
fieldState: { error },
|
|
31
|
+
} = useController({
|
|
32
|
+
name,
|
|
33
|
+
control,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const [showError, setShowError] = useState<boolean>(false);
|
|
37
|
+
|
|
38
|
+
const handleOnBlur = () => {
|
|
39
|
+
field.onBlur();
|
|
40
|
+
setShowError(false);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleOnFocus = () => {};
|
|
44
|
+
|
|
45
|
+
if (loading) {
|
|
46
|
+
return (
|
|
47
|
+
<Container>
|
|
48
|
+
{label && (
|
|
49
|
+
<Label
|
|
50
|
+
required={required}
|
|
51
|
+
htmlFor={name}
|
|
52
|
+
error={!!error}
|
|
53
|
+
size={size}
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
text={label}
|
|
56
|
+
position="top"
|
|
57
|
+
/>
|
|
58
|
+
)}
|
|
59
|
+
<TagsContainer className="placeholder" />
|
|
60
|
+
</Container>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<InputWrapper>
|
|
66
|
+
<Container>
|
|
67
|
+
{label && (
|
|
68
|
+
<Label
|
|
69
|
+
text={label}
|
|
70
|
+
htmlFor={name}
|
|
71
|
+
error={false}
|
|
72
|
+
disabled={disabled}
|
|
73
|
+
required={required}
|
|
74
|
+
position="top"
|
|
75
|
+
size="medium"
|
|
76
|
+
hint={hint}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
|
|
80
|
+
<GenericTagField
|
|
81
|
+
readOnly={readOnly}
|
|
82
|
+
size={size}
|
|
83
|
+
name={name}
|
|
84
|
+
id={name}
|
|
85
|
+
ref={field.ref}
|
|
86
|
+
onBlur={handleOnBlur}
|
|
87
|
+
onFocus={handleOnFocus}
|
|
88
|
+
onChange={(values) => {
|
|
89
|
+
field.onChange(values);
|
|
90
|
+
}}
|
|
91
|
+
placeholder={placeholder}
|
|
92
|
+
allowDuplicates={allowDuplicates}
|
|
93
|
+
hasError={!!error}
|
|
94
|
+
hasDescription={!!description}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
value={field.value as string[]}
|
|
97
|
+
/>
|
|
98
|
+
{error && error.message && showError && <ErrorMessage message={error.message} />}
|
|
99
|
+
</Container>
|
|
100
|
+
{description && <Description description={description} inputName={name} />}
|
|
101
|
+
</InputWrapper>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { forwardRef, KeyboardEvent, ClipboardEvent, useState, useEffect } from 'react';
|
|
2
|
+
import { GenericInputPropsFunctionHandlers } from '../InputProps';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import { TagsContainer, Tag } from './style';
|
|
5
|
+
import { splitPaste, useDidUpdateEffect } from './util';
|
|
6
|
+
import { setAriaDescribedBy } from '../layout';
|
|
7
|
+
|
|
8
|
+
const defaultSeparators = ['Enter'];
|
|
9
|
+
|
|
10
|
+
export interface TagFieldProps {
|
|
11
|
+
onRemoved?: (tag: string) => void;
|
|
12
|
+
tagValidationSchema?: ZodType<{ tags: string[] }, any, any>;
|
|
13
|
+
separators?: string[];
|
|
14
|
+
disableBackspaceRemove?: boolean;
|
|
15
|
+
// When using backspace, the item itself is removed and the value is shown in the inputfield
|
|
16
|
+
isEditOnRemove?: boolean;
|
|
17
|
+
allowDuplicates?: boolean;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
onKeyUp?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// these are props that should only be available on the generic version.
|
|
23
|
+
export type GenericTagFieldProps = TagFieldProps & GenericInputPropsFunctionHandlers<string[], HTMLInputElement>;
|
|
24
|
+
|
|
25
|
+
export const GenericTagField = forwardRef<HTMLDivElement, GenericTagFieldProps>(
|
|
26
|
+
(
|
|
27
|
+
{
|
|
28
|
+
onRemoved,
|
|
29
|
+
separators = [],
|
|
30
|
+
name,
|
|
31
|
+
readOnly,
|
|
32
|
+
placeholder,
|
|
33
|
+
// TODO: tagValidationSchema,
|
|
34
|
+
disableBackspaceRemove,
|
|
35
|
+
value = [],
|
|
36
|
+
onKeyUp,
|
|
37
|
+
allowDuplicates = false,
|
|
38
|
+
isEditOnRemove,
|
|
39
|
+
disabled = false,
|
|
40
|
+
onBlur = () => {},
|
|
41
|
+
onFocus = () => {},
|
|
42
|
+
onChange,
|
|
43
|
+
required,
|
|
44
|
+
hasDescription,
|
|
45
|
+
},
|
|
46
|
+
ref
|
|
47
|
+
) => {
|
|
48
|
+
const combinedSeparators = [...defaultSeparators, ...separators];
|
|
49
|
+
const [tags, setTags] = useState<string[]>(Array.isArray(value) ? value : []);
|
|
50
|
+
|
|
51
|
+
useDidUpdateEffect(() => {
|
|
52
|
+
onChange(tags);
|
|
53
|
+
}, [tags]);
|
|
54
|
+
|
|
55
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
const text = e.currentTarget.value;
|
|
58
|
+
|
|
59
|
+
// handle tag removing
|
|
60
|
+
if (!text && !disableBackspaceRemove && tags.length && e.key === 'Backspace') {
|
|
61
|
+
e.currentTarget.value = isEditOnRemove ? `${tags.at(-1)} ` : '';
|
|
62
|
+
setTags([...tags.slice(0, -1)]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// handle new tag confirmation
|
|
66
|
+
if (text && combinedSeparators.includes(e.key)) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
|
|
69
|
+
// TODO: check tag validation logic
|
|
70
|
+
// if (tagValidationSchema && tagValidationSchema.parse(tags)) return;
|
|
71
|
+
|
|
72
|
+
if (tags.includes(text) && !allowDuplicates) {
|
|
73
|
+
// should not add duplicate tags
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setTags([...tags, text]);
|
|
78
|
+
|
|
79
|
+
// clear input field
|
|
80
|
+
e.currentTarget.value = '';
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
// remove duplicates from tag list when allowDuplicates is set to false
|
|
86
|
+
if (!allowDuplicates) {
|
|
87
|
+
setTags([...new Set(tags)]);
|
|
88
|
+
}
|
|
89
|
+
}, [allowDuplicates]);
|
|
90
|
+
|
|
91
|
+
const onTagDelete = (text: string) => {
|
|
92
|
+
setTags(tags.filter((tag) => tag !== text));
|
|
93
|
+
onRemoved && onRemoved(text);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleOnPaste = (event: ClipboardEvent<HTMLInputElement>) => {
|
|
97
|
+
const pasteText = event.clipboardData.getData('text');
|
|
98
|
+
if (pasteText.length < 1) return;
|
|
99
|
+
|
|
100
|
+
const pasteTags = splitPaste({
|
|
101
|
+
text: pasteText,
|
|
102
|
+
tags,
|
|
103
|
+
separators: combinedSeparators,
|
|
104
|
+
});
|
|
105
|
+
setTags([...tags, ...pasteTags]);
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<TagsContainer aria-labelledby={name} ref={ref}>
|
|
111
|
+
{tags.map((tag) => (
|
|
112
|
+
<Tag
|
|
113
|
+
key={tag}
|
|
114
|
+
label={tag}
|
|
115
|
+
onDelete={() => onTagDelete(tag)}
|
|
116
|
+
disabled={disabled}
|
|
117
|
+
readOnly={readOnly}
|
|
118
|
+
color="secondary"
|
|
119
|
+
/>
|
|
120
|
+
))}
|
|
121
|
+
<input
|
|
122
|
+
type="text"
|
|
123
|
+
name={name}
|
|
124
|
+
placeholder={placeholder}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
onKeyDown={handleKeyDown}
|
|
127
|
+
onKeyUp={onKeyUp}
|
|
128
|
+
readOnly={readOnly}
|
|
129
|
+
onBlur={onBlur}
|
|
130
|
+
onPaste={handleOnPaste}
|
|
131
|
+
onFocus={onFocus}
|
|
132
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
133
|
+
aria-required={required}
|
|
134
|
+
/>
|
|
135
|
+
</TagsContainer>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { Button, TagField, TagFieldProps } from '../../../components';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { SubmitHandler, useForm, useWatch } from 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Inputs/TagField',
|
|
9
|
+
component: TagField,
|
|
10
|
+
args: {
|
|
11
|
+
label: 'Fruits',
|
|
12
|
+
placeholder: 'Press ENTER to save a value',
|
|
13
|
+
required: true,
|
|
14
|
+
disabled: false,
|
|
15
|
+
isEditOnRemove: true,
|
|
16
|
+
readOnly: false,
|
|
17
|
+
separators: [','],
|
|
18
|
+
description: 'Very basic description. But atleast it is here and can be improved in the future.',
|
|
19
|
+
name: 'fruits',
|
|
20
|
+
hint: '',
|
|
21
|
+
onBlur: () => {},
|
|
22
|
+
},
|
|
23
|
+
} as Meta<TagFieldProps>;
|
|
24
|
+
|
|
25
|
+
interface FormInputs {
|
|
26
|
+
tags: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const OnSubmit: StoryFn<TagFieldProps> = (args) => {
|
|
30
|
+
const [result, setResult] = useState<string[]>([]);
|
|
31
|
+
const { control, handleSubmit } = useForm<FormInputs>({
|
|
32
|
+
defaultValues: {
|
|
33
|
+
tags: ['jari'],
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const beforeAddValidationSchema = z.object({
|
|
38
|
+
tags: z.array(z.string()),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const onSubmit: SubmitHandler<FormInputs> = ({ tags }) => {
|
|
42
|
+
setResult(() => [...tags]);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div style={{ marginBottom: '32px' }}>
|
|
47
|
+
<h1>Add Fruits</h1>
|
|
48
|
+
<pre>paste tester: apple,banana,jeroen</pre>
|
|
49
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
50
|
+
<TagField {...args} tagValidationSchema={beforeAddValidationSchema} control={control} name="tags" />
|
|
51
|
+
<Button type="submit" text="Submit" />
|
|
52
|
+
</form>
|
|
53
|
+
<pre>result: {result.join(', ')}</pre>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const OnChange: StoryFn<TagFieldProps> = (args) => {
|
|
59
|
+
const { control } = useForm({ mode: 'onChange' });
|
|
60
|
+
const TagFieldValues = useWatch({ control, name: args.name });
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<TagField {...args} control={control} />
|
|
65
|
+
<pre>{TagFieldValues}</pre>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Chip } from '../../data/Chip';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.div``;
|
|
5
|
+
|
|
6
|
+
export const TagsContainer = styled.div`
|
|
7
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
8
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']} ${theme.spacing['0_5']} 0 ${theme.spacing['0_5']}`};
|
|
9
|
+
width: 100%;
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-wrap: wrap;
|
|
12
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
13
|
+
margin-bottom: ${({ theme }) => theme.spacing['0_75']};
|
|
14
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
15
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
16
|
+
|
|
17
|
+
input {
|
|
18
|
+
display: inline;
|
|
19
|
+
width: 100%;
|
|
20
|
+
padding-top: 0;
|
|
21
|
+
border-radius: 0;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const Tag = styled(Chip)``;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useDidUpdateEffect(fn: () => unknown, inputs: unknown[]) {
|
|
4
|
+
const didMountRef = useRef(false);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (didMountRef.current) fn();
|
|
8
|
+
else didMountRef.current = true;
|
|
9
|
+
}, inputs);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type splitPasteParamType = {
|
|
13
|
+
tags: Array<string>;
|
|
14
|
+
text: string;
|
|
15
|
+
separators: Array<string>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function splitPaste({ tags, text, separators }: splitPasteParamType) {
|
|
19
|
+
const dirtyTags: string[] = separators.reduce((accumulator: string[], separator) => {
|
|
20
|
+
const splitText = text.split(separator);
|
|
21
|
+
if (splitText.length > accumulator.length) accumulator = splitText;
|
|
22
|
+
return accumulator;
|
|
23
|
+
}, []);
|
|
24
|
+
const cleanTags = dirtyTags.map((tag) => tag.trim());
|
|
25
|
+
|
|
26
|
+
const cleanDuplicateTags = cleanTags.reduce((accumulator: string[], tag) => {
|
|
27
|
+
if (!tags.includes(tag)) {
|
|
28
|
+
accumulator.push(tag);
|
|
29
|
+
}
|
|
30
|
+
return accumulator;
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
return cleanDuplicateTags;
|
|
34
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { TextAreaFieldProps, GenericTextAreaField } from '.';
|
|
3
|
+
import { ControlledInputProps, defaultInputPropsFactory, defaultInputProps } from '../InputProps';
|
|
4
|
+
import { Container, TextAreaContainer } from './style';
|
|
5
|
+
import { useController } from 'react-hook-form';
|
|
6
|
+
import { InputWrapper, Description, Label, ErrorMessage } from '../layout';
|
|
7
|
+
|
|
8
|
+
export type ControlledTextAreaFieldProps = TextAreaFieldProps & ControlledInputProps;
|
|
9
|
+
|
|
10
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledTextAreaFieldProps>(defaultInputProps);
|
|
11
|
+
|
|
12
|
+
export const ControlledTextAreaField: FC<ControlledTextAreaFieldProps> = (props) => {
|
|
13
|
+
const {
|
|
14
|
+
loading,
|
|
15
|
+
label,
|
|
16
|
+
hint,
|
|
17
|
+
disabled,
|
|
18
|
+
required,
|
|
19
|
+
description,
|
|
20
|
+
placeholder,
|
|
21
|
+
control,
|
|
22
|
+
name,
|
|
23
|
+
rows = 5,
|
|
24
|
+
size,
|
|
25
|
+
readOnly,
|
|
26
|
+
} = defaultsApplier(props);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
field,
|
|
30
|
+
fieldState: { error },
|
|
31
|
+
} = useController({
|
|
32
|
+
name,
|
|
33
|
+
control,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const [showError, setShowError] = useState<boolean>(false);
|
|
37
|
+
|
|
38
|
+
const handleOnBlur = () => {
|
|
39
|
+
field.onBlur();
|
|
40
|
+
setShowError(false);
|
|
41
|
+
};
|
|
42
|
+
const handleOnFocus = () => {
|
|
43
|
+
setShowError(true);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (loading) {
|
|
47
|
+
return (
|
|
48
|
+
<Container>
|
|
49
|
+
{label && (
|
|
50
|
+
<Label
|
|
51
|
+
required={required}
|
|
52
|
+
htmlFor={name}
|
|
53
|
+
error={!!error}
|
|
54
|
+
size={size}
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
text={label}
|
|
57
|
+
position="top"
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
<TextAreaContainer className="placeholder" />
|
|
61
|
+
</Container>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<InputWrapper>
|
|
67
|
+
<Container>
|
|
68
|
+
{label && (
|
|
69
|
+
<Label
|
|
70
|
+
required={required}
|
|
71
|
+
htmlFor={name}
|
|
72
|
+
error={!!error}
|
|
73
|
+
size={size}
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
text={label}
|
|
76
|
+
hint={hint}
|
|
77
|
+
position="top"
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
<GenericTextAreaField
|
|
81
|
+
name={name}
|
|
82
|
+
id={name}
|
|
83
|
+
required={required}
|
|
84
|
+
readOnly={readOnly}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
rows={rows}
|
|
87
|
+
placeholder={placeholder}
|
|
88
|
+
value={field.value}
|
|
89
|
+
onBlur={handleOnBlur}
|
|
90
|
+
onChange={field.onChange}
|
|
91
|
+
onFocus={handleOnFocus}
|
|
92
|
+
hasError={!!error}
|
|
93
|
+
hasDescription={!!description}
|
|
94
|
+
ref={field.ref}
|
|
95
|
+
/>
|
|
96
|
+
{error && error.message && showError && <ErrorMessage message={error.message} />}
|
|
97
|
+
</Container>
|
|
98
|
+
{description && <Description description={description} inputName={name} />}
|
|
99
|
+
</InputWrapper>
|
|
100
|
+
);
|
|
101
|
+
};
|