@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,200 @@
|
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { SelectField, TextField } from '..';
|
|
3
|
+
import { useForm, SubmitHandler, useFieldArray } from 'react-hook-form';
|
|
4
|
+
import { AiOutlineDelete as RemoveIcon, AiOutlinePlus as AddIcon } from 'react-icons/ai';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { useState, forwardRef, useEffect } from 'react';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
import { DurationContainer, FieldContainer, InnerContent, ButtonContainer } from './style';
|
|
9
|
+
import { Button, IconButton, Popover, Tooltip } from '../../../components';
|
|
10
|
+
import { Duration } from 'luxon';
|
|
11
|
+
import { GenericInputPropsFunctionHandlers } from '../InputProps';
|
|
12
|
+
import { AiOutlineClose as ResetIcon, AiOutlineDown as ArrowIcon } from 'react-icons/ai';
|
|
13
|
+
|
|
14
|
+
const durationObjectToUnitAndValue = (millis: number): { unit: LuxonUnit; value: number }[] => {
|
|
15
|
+
// fallback, otherwise there is is no option to set a new duration.
|
|
16
|
+
if (millis === 0) {
|
|
17
|
+
return [{ unit: 'milliseconds', value: 0 }];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const obj = Duration.fromMillis(millis).rescale().toObject();
|
|
21
|
+
return Object.entries(obj).map(([unit, value]) => {
|
|
22
|
+
return { unit: unit as LuxonUnit, value: value || 0 };
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface DurationProps {
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
canClear?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type LuxonUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
|
|
32
|
+
const luxonUnits = ['milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'] as const;
|
|
33
|
+
|
|
34
|
+
const validationSchema = z.object({
|
|
35
|
+
durations: z.array(
|
|
36
|
+
z.object({
|
|
37
|
+
value: z.number().positive(),
|
|
38
|
+
unit: z.enum(luxonUnits), // Use updated units array
|
|
39
|
+
})
|
|
40
|
+
),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export type GenericDurationFieldProps = DurationProps & GenericInputPropsFunctionHandlers<number, HTMLDivElement>;
|
|
44
|
+
export const GenericDurationField = forwardRef<HTMLDivElement, GenericDurationFieldProps>(
|
|
45
|
+
(
|
|
46
|
+
{
|
|
47
|
+
onChange,
|
|
48
|
+
hasError,
|
|
49
|
+
value,
|
|
50
|
+
name,
|
|
51
|
+
disabled = false,
|
|
52
|
+
readOnly = false,
|
|
53
|
+
canClear = false,
|
|
54
|
+
placeholder = 'Select a duration',
|
|
55
|
+
onBlur,
|
|
56
|
+
onFocus,
|
|
57
|
+
},
|
|
58
|
+
ref
|
|
59
|
+
) => {
|
|
60
|
+
const { control, handleSubmit, setValue } = useForm<z.infer<typeof validationSchema>>({
|
|
61
|
+
mode: 'onSubmit',
|
|
62
|
+
resolver: zodResolver(validationSchema),
|
|
63
|
+
defaultValues: {
|
|
64
|
+
durations: value || value === 0 ? durationObjectToUnitAndValue(value) : [],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const { fields, remove: removeField, append: addField } = useFieldArray({ control, name: 'durations' });
|
|
69
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (open && value == undefined && fields.length === 0) {
|
|
73
|
+
addField({ value: 0, unit: 'seconds' });
|
|
74
|
+
}
|
|
75
|
+
}, [open]);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (value || value == 0) {
|
|
79
|
+
setValue('durations', durationObjectToUnitAndValue(value));
|
|
80
|
+
}
|
|
81
|
+
}, [value]);
|
|
82
|
+
|
|
83
|
+
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = ({ durations }) => {
|
|
84
|
+
const totalDuration = durations.reduce((accumulator, { value, unit }) => {
|
|
85
|
+
const duration = Duration.fromObject({ [unit]: value });
|
|
86
|
+
return accumulator.plus(duration);
|
|
87
|
+
}, Duration.fromMillis(0));
|
|
88
|
+
onChange(totalDuration.toMillis());
|
|
89
|
+
setOpen(false);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleReset = (e: MouseEvent) => {
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
onChange(undefined as unknown as number);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const formId = `${name}-form`;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
101
|
+
<Popover.Trigger asChild>
|
|
102
|
+
<DurationContainer
|
|
103
|
+
disabled={disabled}
|
|
104
|
+
readOnly={readOnly}
|
|
105
|
+
aria-disabled={disabled}
|
|
106
|
+
aria-readonly={readOnly}
|
|
107
|
+
ref={ref}
|
|
108
|
+
hasError={hasError}
|
|
109
|
+
aria-labelledby={name}
|
|
110
|
+
onFocus={onFocus}
|
|
111
|
+
onBlur={onBlur}
|
|
112
|
+
onClick={() => !readOnly && !disabled && setOpen(!open)}
|
|
113
|
+
>
|
|
114
|
+
{value ? Duration.fromMillis(value).rescale().toHuman({ listStyle: 'long' }) : placeholder}
|
|
115
|
+
|
|
116
|
+
{canClear && !readOnly && !disabled && value && !open ? (
|
|
117
|
+
<IconButton icon={<ResetIcon />} ariaLabel="Reset duration" onClick={handleReset} />
|
|
118
|
+
) : (
|
|
119
|
+
<ArrowIcon size={16} />
|
|
120
|
+
)}
|
|
121
|
+
</DurationContainer>
|
|
122
|
+
</Popover.Trigger>
|
|
123
|
+
<Popover.Content>
|
|
124
|
+
<InnerContent>
|
|
125
|
+
<form id={formId}>
|
|
126
|
+
<h2>Select a duration</h2>
|
|
127
|
+
{fields.map((field, index) => (
|
|
128
|
+
<FieldContainer
|
|
129
|
+
hasMultipleFields={fields.length > 1}
|
|
130
|
+
key={`${name}-${field.id}-${index}`}
|
|
131
|
+
id={field.id}
|
|
132
|
+
>
|
|
133
|
+
<TextField
|
|
134
|
+
key={`${name}-${index}-value`}
|
|
135
|
+
name={`durations.${index}.value`}
|
|
136
|
+
control={control}
|
|
137
|
+
type="number"
|
|
138
|
+
/>
|
|
139
|
+
<SelectField
|
|
140
|
+
key={`${name}-${index}-unit`}
|
|
141
|
+
inPortal
|
|
142
|
+
control={control}
|
|
143
|
+
name={`durations.${index}.unit`}
|
|
144
|
+
multiple={false}
|
|
145
|
+
render={(selectedItems) => {
|
|
146
|
+
if (selectedItems.length === 0) {
|
|
147
|
+
return <div>Select...</div>;
|
|
148
|
+
}
|
|
149
|
+
return <div>{selectedItems[0].label}</div>;
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<SelectField.OptionGroup key={`${name}-${index}-option-group`}>
|
|
153
|
+
{luxonUnits.map((unit) => (
|
|
154
|
+
<SelectField.Option key={`${name}-${index}-option-${unit}`} value={unit} label={unit}>
|
|
155
|
+
{unit}
|
|
156
|
+
</SelectField.Option>
|
|
157
|
+
))}
|
|
158
|
+
</SelectField.OptionGroup>
|
|
159
|
+
</SelectField>
|
|
160
|
+
{fields.length !== 1 && (
|
|
161
|
+
<Tooltip key={`${name}-${index}-remove-field`}>
|
|
162
|
+
<Tooltip.Trigger>
|
|
163
|
+
<IconButton ariaLabel="Remove field" icon={<RemoveIcon />} onClick={() => removeField(index)} />
|
|
164
|
+
</Tooltip.Trigger>
|
|
165
|
+
<Tooltip.Content>Remove field</Tooltip.Content>
|
|
166
|
+
</Tooltip>
|
|
167
|
+
)}
|
|
168
|
+
{index === fields.length - 1 && fields.length < luxonUnits.length && (
|
|
169
|
+
<Tooltip key={`${name}-${index}-add-field`}>
|
|
170
|
+
<Tooltip.Trigger>
|
|
171
|
+
<IconButton
|
|
172
|
+
icon={<AddIcon />}
|
|
173
|
+
ariaLabel="Add field"
|
|
174
|
+
onClick={() => addField({ value: 0, unit: 'seconds' })}
|
|
175
|
+
/>
|
|
176
|
+
</Tooltip.Trigger>
|
|
177
|
+
<Tooltip.Content>Add field</Tooltip.Content>
|
|
178
|
+
</Tooltip>
|
|
179
|
+
)}
|
|
180
|
+
</FieldContainer>
|
|
181
|
+
))}
|
|
182
|
+
<ButtonContainer>
|
|
183
|
+
<Button
|
|
184
|
+
form={formId}
|
|
185
|
+
type="submit"
|
|
186
|
+
fullWidth
|
|
187
|
+
text="Apply"
|
|
188
|
+
onClick={(e) => {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
handleSubmit(onSubmit)();
|
|
191
|
+
}}
|
|
192
|
+
/>
|
|
193
|
+
</ButtonContainer>
|
|
194
|
+
</form>
|
|
195
|
+
</InnerContent>
|
|
196
|
+
</Popover.Content>
|
|
197
|
+
</Popover>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div``;
|
|
4
|
+
|
|
5
|
+
export const DurationContainer = styled.div<{ hasError: boolean; disabled: boolean; readOnly: boolean }>`
|
|
6
|
+
position: relative;
|
|
7
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
8
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
9
|
+
width: 100%;
|
|
10
|
+
border: 1px solid ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.backgroundAccent)};
|
|
11
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
gap: ${({ theme }) => theme.spacing['0_5']};
|
|
16
|
+
cursor: ${({ disabled, readOnly }) => (disabled || readOnly ? 'default' : 'pointer')};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const InnerContent = styled.div`
|
|
20
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
21
|
+
|
|
22
|
+
h2 {
|
|
23
|
+
margin-bottom: ${({ theme }) => theme.spacing['1']};
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const FieldContainer = styled.div<{ hasMultipleFields: boolean }>`
|
|
28
|
+
display: grid;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: ${({ theme }) => theme.spacing['0_75']};
|
|
31
|
+
grid-template-columns: 120px 200px 30px ${({ hasMultipleFields }) => (hasMultipleFields ? '30px' : '0px')};
|
|
32
|
+
margin-bottom: ${({ theme }) => theme.spacing['1']};
|
|
33
|
+
|
|
34
|
+
div {
|
|
35
|
+
margin-bottom: 0;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const ButtonContainer = styled.div`
|
|
40
|
+
display: flex;
|
|
41
|
+
justify-content: flex-end;
|
|
42
|
+
`;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
import { EditableFieldProps, EditableField } from '.';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Inputs/EditableField',
|
|
9
|
+
component: EditableField,
|
|
10
|
+
args: {
|
|
11
|
+
disabled: false,
|
|
12
|
+
isEditing: false,
|
|
13
|
+
value: 'I am the text, double click me',
|
|
14
|
+
required: true,
|
|
15
|
+
label: 'label',
|
|
16
|
+
validationSchema: z
|
|
17
|
+
.string()
|
|
18
|
+
.refine((value) => !value.includes('/'), { message: 'The field must not contain slashes.' }),
|
|
19
|
+
},
|
|
20
|
+
} as Meta<EditableFieldProps>;
|
|
21
|
+
|
|
22
|
+
const Container = styled.div`
|
|
23
|
+
width: 50%;
|
|
24
|
+
input {
|
|
25
|
+
width: 100%;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryFn<EditableFieldProps> = (args) => {
|
|
30
|
+
const [value, setValue] = React.useState(args.value);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Container>
|
|
34
|
+
<EditableField
|
|
35
|
+
name="editableField"
|
|
36
|
+
isEditing={args.isEditing}
|
|
37
|
+
disabled={args.disabled}
|
|
38
|
+
required={args.required}
|
|
39
|
+
value={args.value}
|
|
40
|
+
validationSchema={args.validationSchema}
|
|
41
|
+
onEdited={(value) => setValue(value)}
|
|
42
|
+
/>
|
|
43
|
+
<div>The value: {value}</div>
|
|
44
|
+
</Container>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const RemoteEditEnable: StoryFn<EditableFieldProps> = (args) => {
|
|
49
|
+
const [editing, setEditing] = React.useState<boolean>(false);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Container>
|
|
53
|
+
This tests if we can change the state to editing from outside the component
|
|
54
|
+
<EditableField
|
|
55
|
+
name="editableField"
|
|
56
|
+
isEditing={editing}
|
|
57
|
+
disabled={args.disabled}
|
|
58
|
+
required={args.required}
|
|
59
|
+
value={args.value}
|
|
60
|
+
/>
|
|
61
|
+
<button onClick={() => setEditing(!editing)}>toggle editing state</button>
|
|
62
|
+
<span>current state: {editing ? 'true' : 'false'}</span>
|
|
63
|
+
</Container>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { FC, KeyboardEvent, MouseEvent, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { ErrorMessage } from '../layout';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { Container } from './style';
|
|
5
|
+
|
|
6
|
+
export interface EditableFieldProps {
|
|
7
|
+
isEditing?: boolean;
|
|
8
|
+
editingChange?: (editing: boolean) => unknown;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
|
|
11
|
+
// fires when the input value is changed
|
|
12
|
+
onEdited?: (value: string) => unknown;
|
|
13
|
+
|
|
14
|
+
validationSchema?: z.ZodSchema;
|
|
15
|
+
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
name: string;
|
|
19
|
+
loading?: boolean;
|
|
20
|
+
|
|
21
|
+
// defaultval
|
|
22
|
+
value?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const EditableField: FC<EditableFieldProps> = ({
|
|
26
|
+
isEditing = false,
|
|
27
|
+
required = false,
|
|
28
|
+
value = '',
|
|
29
|
+
name,
|
|
30
|
+
disabled = false,
|
|
31
|
+
onEdited,
|
|
32
|
+
validationSchema,
|
|
33
|
+
editingChange = () => {},
|
|
34
|
+
loading = false,
|
|
35
|
+
}) => {
|
|
36
|
+
const [editing, setEditing] = useState(isEditing);
|
|
37
|
+
const [inputValue, setInputValue] = useState<string>(value);
|
|
38
|
+
const [spanValue, setSpanValue] = useState<string>(value);
|
|
39
|
+
const [error, setError] = useState<string | undefined>(undefined);
|
|
40
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (inputRef && inputRef.current && editing === true) {
|
|
44
|
+
inputRef.current.focus();
|
|
45
|
+
inputRef.current.select();
|
|
46
|
+
}
|
|
47
|
+
}, [editing, inputRef]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!editing && inputValue != spanValue && onEdited && !error) {
|
|
51
|
+
onEdited(inputValue);
|
|
52
|
+
setSpanValue(inputValue);
|
|
53
|
+
}
|
|
54
|
+
editingChange(editing);
|
|
55
|
+
}, [editing]);
|
|
56
|
+
|
|
57
|
+
// change editing state when new isEditing prop is passed
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (isEditing !== editing) {
|
|
60
|
+
setEditing(isEditing);
|
|
61
|
+
}
|
|
62
|
+
}, [isEditing]);
|
|
63
|
+
|
|
64
|
+
// handle focus change
|
|
65
|
+
const handleKeyDown = ({ key }: KeyboardEvent) => {
|
|
66
|
+
const keys = ['Escape', 'Tab', 'Enter'];
|
|
67
|
+
|
|
68
|
+
if (required && inputRef.current?.value == '') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (keys.indexOf(key) > -1 && inputRef.current && !disabled && !error) {
|
|
73
|
+
setEditing(false);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const handleOnBlur = () => {
|
|
78
|
+
if (required && inputRef.current?.value == '') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setEditing(false);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleOnClick = ({ detail }: MouseEvent<HTMLDivElement>) => {
|
|
85
|
+
// double click
|
|
86
|
+
if (detail == 2 && !disabled) {
|
|
87
|
+
setEditing(true);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
92
|
+
const newValue = e.currentTarget.value;
|
|
93
|
+
setInputValue(newValue);
|
|
94
|
+
validateInput(newValue);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const validateInput = (value: string) => {
|
|
98
|
+
if (!validationSchema) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const validationResult = validationSchema.safeParse(value);
|
|
103
|
+
if (!validationResult.success) {
|
|
104
|
+
setError(validationResult.error.errors[0].message);
|
|
105
|
+
} else {
|
|
106
|
+
setError(undefined);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (loading) {
|
|
111
|
+
return <div>loading</div>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Container>
|
|
116
|
+
{editing ? (
|
|
117
|
+
<div onBlur={handleOnBlur} onKeyDown={(e) => handleKeyDown(e)}>
|
|
118
|
+
<input
|
|
119
|
+
type="text"
|
|
120
|
+
ref={inputRef}
|
|
121
|
+
name={name}
|
|
122
|
+
value={inputValue}
|
|
123
|
+
aria-required={required}
|
|
124
|
+
onChange={handleChange}
|
|
125
|
+
/>
|
|
126
|
+
{error && <ErrorMessage message={error} />}
|
|
127
|
+
</div>
|
|
128
|
+
) : (
|
|
129
|
+
<div onClick={handleOnClick}>
|
|
130
|
+
<span>{spanValue}</span>
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</Container>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
position: relative;
|
|
5
|
+
width: 100%;
|
|
6
|
+
input {
|
|
7
|
+
width: 100%;
|
|
8
|
+
border: 0.1rem solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
9
|
+
padding: ${({ theme }) => `${theme.spacing['0_1']} ${theme.spacing['0_5']}`};
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
4
|
+
import { FileFieldProps, GenericFileField } from '.';
|
|
5
|
+
import { Container, InputContainer } from './style';
|
|
6
|
+
import { Label, ErrorMessage, InputWrapper, Description } from '../layout';
|
|
7
|
+
|
|
8
|
+
export type ControlledFileFieldProps = ControlledInputProps & FileFieldProps;
|
|
9
|
+
|
|
10
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledFileFieldProps>(defaultInputProps);
|
|
11
|
+
|
|
12
|
+
export const ControlledFileField: FC<ControlledFileFieldProps> = (props) => {
|
|
13
|
+
const {
|
|
14
|
+
description,
|
|
15
|
+
loading,
|
|
16
|
+
label,
|
|
17
|
+
hint,
|
|
18
|
+
disabled,
|
|
19
|
+
required,
|
|
20
|
+
name,
|
|
21
|
+
size,
|
|
22
|
+
readOnly,
|
|
23
|
+
multiple = false,
|
|
24
|
+
placeholder,
|
|
25
|
+
control,
|
|
26
|
+
} = defaultsApplier(props);
|
|
27
|
+
|
|
28
|
+
const { field, fieldState } = useController({
|
|
29
|
+
name,
|
|
30
|
+
control,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const [showError, setShowError] = useState<boolean>(false);
|
|
34
|
+
|
|
35
|
+
const handleOnFocus = () => {
|
|
36
|
+
setShowError(true);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleOnBlur = () => {
|
|
40
|
+
field.onBlur();
|
|
41
|
+
setShowError(false);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (loading) {
|
|
45
|
+
return (
|
|
46
|
+
<InputWrapper>
|
|
47
|
+
<Container>
|
|
48
|
+
{label && (
|
|
49
|
+
<Label
|
|
50
|
+
required={required}
|
|
51
|
+
htmlFor={name}
|
|
52
|
+
error={!!fieldState.error}
|
|
53
|
+
size={size}
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
text={label}
|
|
56
|
+
position="top"
|
|
57
|
+
/>
|
|
58
|
+
)}
|
|
59
|
+
<InputContainer className="placeholder" />
|
|
60
|
+
</Container>
|
|
61
|
+
</InputWrapper>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<InputWrapper>
|
|
67
|
+
<Container>
|
|
68
|
+
{label && (
|
|
69
|
+
<Label
|
|
70
|
+
required={required}
|
|
71
|
+
hint={hint}
|
|
72
|
+
htmlFor={name}
|
|
73
|
+
error={!!fieldState.error}
|
|
74
|
+
size={size}
|
|
75
|
+
text={label}
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
position="top"
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
<GenericFileField
|
|
81
|
+
hasError={!!fieldState.error}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
name={name}
|
|
84
|
+
id={name}
|
|
85
|
+
required={required}
|
|
86
|
+
size={size}
|
|
87
|
+
multiple={multiple}
|
|
88
|
+
readOnly={readOnly}
|
|
89
|
+
onChange={field.onChange}
|
|
90
|
+
onFocus={handleOnFocus}
|
|
91
|
+
onBlur={handleOnBlur}
|
|
92
|
+
placeholder={placeholder}
|
|
93
|
+
value={field.value}
|
|
94
|
+
ref={field.ref}
|
|
95
|
+
hasDescription={!!description}
|
|
96
|
+
/>
|
|
97
|
+
{fieldState.error && fieldState.error.message && showError && (
|
|
98
|
+
<ErrorMessage message={fieldState.error.message} />
|
|
99
|
+
)}
|
|
100
|
+
</Container>
|
|
101
|
+
{description && <Description description={description} inputName={name} />}
|
|
102
|
+
</InputWrapper>
|
|
103
|
+
);
|
|
104
|
+
};
|