@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,234 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
+
import { styled } from '../../../../styled';
|
|
5
|
+
import { Button, DatePicker, DatePickerProps } from '../../../../components';
|
|
6
|
+
import { useForm, SubmitHandler } from 'react-hook-form';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
9
|
+
import { DateTime } from 'luxon';
|
|
10
|
+
|
|
11
|
+
const Wrapper = styled.div`
|
|
12
|
+
display: flex;
|
|
13
|
+
height: 100vh;
|
|
14
|
+
width: 50%;
|
|
15
|
+
margin: 0 auto;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
title: 'Inputs/DatePicker',
|
|
23
|
+
component: DatePicker,
|
|
24
|
+
args: {
|
|
25
|
+
label: 'date',
|
|
26
|
+
name: 'date',
|
|
27
|
+
required: false,
|
|
28
|
+
description: 'This is a description',
|
|
29
|
+
popOverPlacement: 'bottom',
|
|
30
|
+
readOnly: false,
|
|
31
|
+
allowPastDates: true,
|
|
32
|
+
allowFutureDates: true,
|
|
33
|
+
loading: false,
|
|
34
|
+
timePickerOptions: {
|
|
35
|
+
interval: 30,
|
|
36
|
+
},
|
|
37
|
+
relativePickerOptions: {
|
|
38
|
+
showFriendlyName: true,
|
|
39
|
+
timeDirection: 'future',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as Meta<DatePickerProps>;
|
|
43
|
+
|
|
44
|
+
const validationSchema = z.object({
|
|
45
|
+
date: z.string().datetime({ offset: true }),
|
|
46
|
+
});
|
|
47
|
+
type FormFields = { date: string };
|
|
48
|
+
|
|
49
|
+
export const OnDateSubmit: StoryFn<DatePickerProps> = (args) => {
|
|
50
|
+
const [result, setResult] = useState<string>('none');
|
|
51
|
+
|
|
52
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
53
|
+
mode: 'onSubmit',
|
|
54
|
+
resolver: zodResolver(validationSchema),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const onSubmit: SubmitHandler<FormFields> = ({ date }) => {
|
|
58
|
+
setResult(date);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Wrapper>
|
|
63
|
+
Note: for zod to accept the date, an extra option is needed: {'{ offset: true }'}
|
|
64
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
65
|
+
<DatePicker
|
|
66
|
+
mode="absolute"
|
|
67
|
+
control={control}
|
|
68
|
+
label={args.label}
|
|
69
|
+
name={args.name}
|
|
70
|
+
required={args.required}
|
|
71
|
+
loading={args.loading}
|
|
72
|
+
hint={args.hint}
|
|
73
|
+
description={args.description}
|
|
74
|
+
popOverPlacement={args.popOverPlacement}
|
|
75
|
+
allowFutureDates={args.allowFutureDates}
|
|
76
|
+
allowPastDates={args.allowPastDates}
|
|
77
|
+
/>
|
|
78
|
+
<Button type="submit" text="Submit form" />
|
|
79
|
+
</form>
|
|
80
|
+
<p>result: {result}</p>
|
|
81
|
+
</Wrapper>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const CustomDateFilter: StoryFn<DatePickerProps> = (args) => {
|
|
86
|
+
const [result, setResult] = useState<string>('none');
|
|
87
|
+
|
|
88
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
89
|
+
mode: 'onSubmit',
|
|
90
|
+
resolver: zodResolver(validationSchema),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const onSubmit: SubmitHandler<FormFields> = ({ date }) => {
|
|
94
|
+
setResult(date);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Wrapper>
|
|
99
|
+
Note: for zod to accept the date, an extra option is needed: {'{ offset: true }'}
|
|
100
|
+
<strong>Custom datefilter that only allows weekends</strong>
|
|
101
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
102
|
+
<DatePicker
|
|
103
|
+
mode="absolute"
|
|
104
|
+
control={control}
|
|
105
|
+
label={args.label}
|
|
106
|
+
name={args.name}
|
|
107
|
+
required={args.required}
|
|
108
|
+
loading={args.loading}
|
|
109
|
+
hint={args.hint}
|
|
110
|
+
description={args.description}
|
|
111
|
+
popOverPlacement={args.popOverPlacement}
|
|
112
|
+
customDateFilter={(date) => date.weekday == 6 || date.weekday == 7}
|
|
113
|
+
/>
|
|
114
|
+
<Button type="submit" text="Submit form" />
|
|
115
|
+
</form>
|
|
116
|
+
<p>result: {result}</p>
|
|
117
|
+
</Wrapper>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const OnDateAndTimeSubmit: StoryFn<DatePickerProps> = (args) => {
|
|
122
|
+
const [result, setResult] = useState<string>('none');
|
|
123
|
+
|
|
124
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
125
|
+
mode: 'onSubmit',
|
|
126
|
+
resolver: zodResolver(validationSchema),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const onSubmit: SubmitHandler<FormFields> = ({ date }) => {
|
|
130
|
+
setResult(date);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<Wrapper>
|
|
135
|
+
Note: for zod to accept the date, an extra option is needed: {'{ offset: true }'}
|
|
136
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
137
|
+
<DatePicker
|
|
138
|
+
mode="absolute"
|
|
139
|
+
control={control}
|
|
140
|
+
label={args.label}
|
|
141
|
+
name={args.name}
|
|
142
|
+
required={args.required}
|
|
143
|
+
loading={args.loading}
|
|
144
|
+
hint={args.hint}
|
|
145
|
+
format={DateTime.DATETIME_SHORT}
|
|
146
|
+
timePickerOptions={args.timePickerOptions}
|
|
147
|
+
description={args.description}
|
|
148
|
+
popOverPlacement={args.popOverPlacement}
|
|
149
|
+
allowPastDates={args.allowPastDates}
|
|
150
|
+
allowFutureDates={args.allowFutureDates}
|
|
151
|
+
/>
|
|
152
|
+
<Button type="submit" text="Submit form" />
|
|
153
|
+
</form>
|
|
154
|
+
<p>result: {result}</p>
|
|
155
|
+
</Wrapper>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const onTimeSubmit: StoryFn<DatePickerProps> = (args) => {
|
|
160
|
+
const [result, setResult] = useState<string>('none');
|
|
161
|
+
|
|
162
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
163
|
+
mode: 'onSubmit',
|
|
164
|
+
resolver: zodResolver(validationSchema),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const onSubmit: SubmitHandler<FormFields> = ({ date }) => {
|
|
168
|
+
setResult(date);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<Wrapper>
|
|
173
|
+
Note: for zod to accept the date, an extra option is needed: {'{ offset: true }'}
|
|
174
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
175
|
+
<DatePicker
|
|
176
|
+
mode="absolute"
|
|
177
|
+
control={control}
|
|
178
|
+
label={args.label}
|
|
179
|
+
name={args.name}
|
|
180
|
+
required={args.required}
|
|
181
|
+
loading={args.loading}
|
|
182
|
+
hint={args.hint}
|
|
183
|
+
format={DateTime.TIME_SIMPLE}
|
|
184
|
+
timePickerOptions={args.timePickerOptions}
|
|
185
|
+
description={args.description}
|
|
186
|
+
popOverPlacement={args.popOverPlacement}
|
|
187
|
+
allowPastDates={args.allowPastDates}
|
|
188
|
+
allowFutureDates={args.allowFutureDates}
|
|
189
|
+
/>
|
|
190
|
+
<Button type="submit" text="Submit form" />
|
|
191
|
+
</form>
|
|
192
|
+
<p>result: {result}</p>
|
|
193
|
+
</Wrapper>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const RelativeSubmit: StoryFn<DatePickerProps> = (args) => {
|
|
198
|
+
const [result, setResult] = useState<string>('none');
|
|
199
|
+
|
|
200
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
201
|
+
mode: 'onSubmit',
|
|
202
|
+
resolver: zodResolver(validationSchema),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const onSubmit: SubmitHandler<FormFields> = ({ date }) => {
|
|
206
|
+
setResult(date);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<Wrapper>
|
|
211
|
+
Note: for zod to accept the date, an extra option is needed: {'{ offset: true }'}
|
|
212
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
213
|
+
<DatePicker
|
|
214
|
+
mode="relative"
|
|
215
|
+
control={control}
|
|
216
|
+
label={args.label}
|
|
217
|
+
name={args.name}
|
|
218
|
+
required={args.required}
|
|
219
|
+
loading={args.loading}
|
|
220
|
+
hint={args.hint}
|
|
221
|
+
format={DateTime.DATETIME_MED_WITH_SECONDS}
|
|
222
|
+
timePickerOptions={args.timePickerOptions}
|
|
223
|
+
relativePickerOptions={args.relativePickerOptions}
|
|
224
|
+
description={args.description}
|
|
225
|
+
popOverPlacement={args.popOverPlacement}
|
|
226
|
+
allowPastDates={args.allowPastDates}
|
|
227
|
+
allowFutureDates={args.allowFutureDates}
|
|
228
|
+
/>
|
|
229
|
+
<Button type="submit" text="Submit form" />
|
|
230
|
+
</form>
|
|
231
|
+
<p>result: {result}</p>
|
|
232
|
+
</Wrapper>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { FC, useLayoutEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Button, Popover } from '../../../../components';
|
|
3
|
+
import { DateTime, DateTimeFormatOptions } from 'luxon';
|
|
4
|
+
import { dateFormats, timeFormats } from './formats';
|
|
5
|
+
import { GenericInputProps } from '../../InputProps';
|
|
6
|
+
import { ResultContainer, ContentContainer, InnerContainer, ButtonContainer } from './style';
|
|
7
|
+
import { TimePicker } from '../subcomponents/TimePicker';
|
|
8
|
+
import { Calendar } from '../subcomponents/Calendar';
|
|
9
|
+
import { RelativePicker, timeDirection } from '../subcomponents/RelativePicker';
|
|
10
|
+
import { Placement } from '@floating-ui/react';
|
|
11
|
+
|
|
12
|
+
interface TimePickerOptions {
|
|
13
|
+
/// Determines the interval between time options
|
|
14
|
+
/// Default: 30
|
|
15
|
+
interval?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface RelativePickerOptions {
|
|
19
|
+
/// Determines if the relative picker should be able to show filters to the past, future, or pastAndFuture
|
|
20
|
+
// Default: pastAndFuture
|
|
21
|
+
timeDirection?: timeDirection;
|
|
22
|
+
showFriendlyName?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DatePickerProps {
|
|
26
|
+
/// Determines if the date picker is in absolute or relative mode
|
|
27
|
+
/// Absolute mode is a calendar and time picker
|
|
28
|
+
/// Relative mode is a relative picker
|
|
29
|
+
mode: 'relative' | 'absolute';
|
|
30
|
+
|
|
31
|
+
popOverPlacement?: Placement;
|
|
32
|
+
|
|
33
|
+
customDateFilter?: (date: DateTime) => boolean;
|
|
34
|
+
|
|
35
|
+
/// Allow date selection in the past
|
|
36
|
+
allowPastDates?: boolean;
|
|
37
|
+
|
|
38
|
+
/// Allow date selection in the future
|
|
39
|
+
allowFutureDates?: boolean;
|
|
40
|
+
|
|
41
|
+
/// Determines the format of the selected date/time
|
|
42
|
+
format?: DateTimeFormatOptions;
|
|
43
|
+
|
|
44
|
+
/// Options specific for the time picker
|
|
45
|
+
timePickerOptions?: TimePickerOptions;
|
|
46
|
+
|
|
47
|
+
/// Options specific for the relative picker
|
|
48
|
+
relativePickerOptions?: RelativePickerOptions;
|
|
49
|
+
|
|
50
|
+
/// Placeholder text for the input
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type GenericDatePickerProps = GenericInputProps<string, HTMLInputElement> & DatePickerProps;
|
|
55
|
+
|
|
56
|
+
export const GenericDatePicker: FC<GenericDatePickerProps> = ({
|
|
57
|
+
value,
|
|
58
|
+
id,
|
|
59
|
+
readOnly = false,
|
|
60
|
+
hasError,
|
|
61
|
+
onChange,
|
|
62
|
+
name,
|
|
63
|
+
onFocus,
|
|
64
|
+
onBlur,
|
|
65
|
+
timePickerOptions,
|
|
66
|
+
relativePickerOptions = { showFriendlyName: true, timeDirection: 'future' },
|
|
67
|
+
placeholder,
|
|
68
|
+
popOverPlacement = 'bottom',
|
|
69
|
+
format = DateTime.DATE_SHORT,
|
|
70
|
+
allowPastDates = true,
|
|
71
|
+
allowFutureDates = true,
|
|
72
|
+
customDateFilter,
|
|
73
|
+
mode,
|
|
74
|
+
}) => {
|
|
75
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
76
|
+
|
|
77
|
+
// Function to determine if a date is allowed
|
|
78
|
+
const isDateAllowed = (date: DateTime) => {
|
|
79
|
+
const isPastAllowed = allowPastDates ? true : date >= DateTime.local().startOf('day');
|
|
80
|
+
const isFutureAllowed = allowFutureDates ? true : date <= DateTime.local().startOf('day');
|
|
81
|
+
const isCustomFilterPassed = customDateFilter ? customDateFilter(date) : true;
|
|
82
|
+
return isPastAllowed && isFutureAllowed && isCustomFilterPassed;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Function to find the first allowed date
|
|
86
|
+
const findFirstAllowedDate = () => {
|
|
87
|
+
let dateToCheck = DateTime.local().startOf('day');
|
|
88
|
+
while (!isDateAllowed(dateToCheck)) {
|
|
89
|
+
dateToCheck = dateToCheck.plus({ days: 1 });
|
|
90
|
+
}
|
|
91
|
+
return dateToCheck;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Initialize the selectedDateTime with either today's date or the first allowed date
|
|
95
|
+
const initialSelectedDateTime = value
|
|
96
|
+
? DateTime.fromISO(value)
|
|
97
|
+
: isDateAllowed(DateTime.local().startOf('day'))
|
|
98
|
+
? DateTime.local().startOf('day')
|
|
99
|
+
: findFirstAllowedDate();
|
|
100
|
+
|
|
101
|
+
const [selectedDateTime, setSelectedDateTime] = useState<DateTime>(initialSelectedDateTime);
|
|
102
|
+
const [friendlyName, setFriendlyName] = useState<string | undefined>(undefined);
|
|
103
|
+
|
|
104
|
+
const isDateOnly = !timeFormats.includes(format);
|
|
105
|
+
const isTimeOnly = !dateFormats.includes(format);
|
|
106
|
+
const isDateTime = !isDateOnly && !isTimeOnly;
|
|
107
|
+
|
|
108
|
+
const isAbsolute = mode === 'absolute';
|
|
109
|
+
const isRelative = mode === 'relative';
|
|
110
|
+
|
|
111
|
+
const handleOnChange = (dateTime: DateTime) => {
|
|
112
|
+
const dateTimeString = dateTime.toISO();
|
|
113
|
+
if (dateTimeString == null) {
|
|
114
|
+
throw new Error('Could not convert DateTime to ISO');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Create an object that mimics the structure of a React ChangeEvent
|
|
118
|
+
const event = {
|
|
119
|
+
target: { value: dateTimeString, name },
|
|
120
|
+
preventDefault: () => {},
|
|
121
|
+
stopPropagation: () => {},
|
|
122
|
+
} as unknown as React.ChangeEvent<HTMLInputElement>;
|
|
123
|
+
onChange(event);
|
|
124
|
+
setOpen(false);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const renderPlaceholder = () => {
|
|
128
|
+
if (placeholder) {
|
|
129
|
+
return placeholder;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (isTimeOnly) {
|
|
133
|
+
return 'Select a time';
|
|
134
|
+
}
|
|
135
|
+
return 'Select a date';
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const event = useMemo(() => {
|
|
139
|
+
return {
|
|
140
|
+
// value does not matter I think
|
|
141
|
+
target: { value: '' },
|
|
142
|
+
preventDefault: () => {},
|
|
143
|
+
stopPropagation: () => {},
|
|
144
|
+
} as unknown as React.FocusEvent<HTMLInputElement>;
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
useLayoutEffect(() => {
|
|
148
|
+
if (onFocus && onBlur) {
|
|
149
|
+
// consider open to be a focus event
|
|
150
|
+
open ? onFocus(event) : onBlur(event);
|
|
151
|
+
}
|
|
152
|
+
}, [open]);
|
|
153
|
+
|
|
154
|
+
const renderResult = () => {
|
|
155
|
+
if (friendlyName) {
|
|
156
|
+
return (
|
|
157
|
+
<>
|
|
158
|
+
{DateTime.fromISO(value).toLocaleString(format)} <span>({friendlyName})</span>
|
|
159
|
+
</>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (value) {
|
|
163
|
+
return DateTime.fromISO(value).toLocaleString(format);
|
|
164
|
+
}
|
|
165
|
+
return renderPlaceholder();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<Popover placement={popOverPlacement} open={open} onOpenChange={setOpen}>
|
|
170
|
+
<Popover.Trigger asChild>
|
|
171
|
+
<ResultContainer readOnly={readOnly} hasError={hasError} onClick={() => setOpen(!open)}>
|
|
172
|
+
{renderResult()}
|
|
173
|
+
</ResultContainer>
|
|
174
|
+
</Popover.Trigger>
|
|
175
|
+
<Popover.Content>
|
|
176
|
+
<ContentContainer>
|
|
177
|
+
{isAbsolute && (
|
|
178
|
+
<InnerContainer>
|
|
179
|
+
{dateFormats.includes(format) && (
|
|
180
|
+
<Calendar
|
|
181
|
+
id={`calendar-${id}`}
|
|
182
|
+
// should be start of day to not update the time when only selecting a date
|
|
183
|
+
selectedDate={selectedDateTime}
|
|
184
|
+
allowedFutureDates={allowFutureDates}
|
|
185
|
+
allowedPastDates={allowPastDates}
|
|
186
|
+
customDateFilter={customDateFilter}
|
|
187
|
+
onDateClick={(date) => {
|
|
188
|
+
setSelectedDateTime(date);
|
|
189
|
+
relativePickerOptions?.showFriendlyName && setFriendlyName(undefined);
|
|
190
|
+
if (isDateOnly) {
|
|
191
|
+
handleOnChange(date);
|
|
192
|
+
}
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
{timeFormats.includes(format) && (
|
|
197
|
+
<TimePicker
|
|
198
|
+
selectedDate={selectedDateTime}
|
|
199
|
+
interval={timePickerOptions?.interval}
|
|
200
|
+
onChange={(newTime) => {
|
|
201
|
+
setSelectedDateTime(newTime);
|
|
202
|
+
relativePickerOptions?.showFriendlyName && setFriendlyName(undefined);
|
|
203
|
+
|
|
204
|
+
// see notes above
|
|
205
|
+
if (isTimeOnly) {
|
|
206
|
+
handleOnChange(newTime);
|
|
207
|
+
}
|
|
208
|
+
}}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
211
|
+
</InnerContainer>
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
{isRelative && (
|
|
215
|
+
<InnerContainer>
|
|
216
|
+
<RelativePicker
|
|
217
|
+
id={id}
|
|
218
|
+
timeDirection={relativePickerOptions?.timeDirection}
|
|
219
|
+
onChange={(newDate, friendlyName) => {
|
|
220
|
+
relativePickerOptions?.showFriendlyName && setFriendlyName(friendlyName);
|
|
221
|
+
setSelectedDateTime(newDate);
|
|
222
|
+
handleOnChange(newDate);
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
</InnerContainer>
|
|
226
|
+
)}
|
|
227
|
+
|
|
228
|
+
{isAbsolute && isDateTime && (
|
|
229
|
+
<ButtonContainer>
|
|
230
|
+
<Button
|
|
231
|
+
onClick={() => {
|
|
232
|
+
setOpen(false);
|
|
233
|
+
}}
|
|
234
|
+
fullWidth
|
|
235
|
+
variant="default"
|
|
236
|
+
color="secondary"
|
|
237
|
+
text="Cancel"
|
|
238
|
+
/>
|
|
239
|
+
<Button
|
|
240
|
+
fullWidth
|
|
241
|
+
onClick={() => {
|
|
242
|
+
handleOnChange(selectedDateTime!);
|
|
243
|
+
setOpen(false);
|
|
244
|
+
}}
|
|
245
|
+
text="Select"
|
|
246
|
+
/>
|
|
247
|
+
</ButtonContainer>
|
|
248
|
+
)}
|
|
249
|
+
</ContentContainer>
|
|
250
|
+
</Popover.Content>
|
|
251
|
+
</Popover>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
|
|
3
|
+
const DateAndTimeFormats = [
|
|
4
|
+
DateTime.DATETIME_SHORT,
|
|
5
|
+
DateTime.DATETIME_MED,
|
|
6
|
+
DateTime.DATETIME_FULL,
|
|
7
|
+
DateTime.DATETIME_HUGE,
|
|
8
|
+
DateTime.DATETIME_SHORT_WITH_SECONDS,
|
|
9
|
+
DateTime.DATETIME_MED_WITH_SECONDS,
|
|
10
|
+
DateTime.DATETIME_FULL_WITH_SECONDS,
|
|
11
|
+
DateTime.DATETIME_HUGE_WITH_SECONDS,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const timeFormats = [
|
|
15
|
+
DateTime.TIME_SIMPLE,
|
|
16
|
+
DateTime.TIME_WITH_SECONDS,
|
|
17
|
+
DateTime.TIME_WITH_SHORT_OFFSET,
|
|
18
|
+
DateTime.TIME_WITH_LONG_OFFSET,
|
|
19
|
+
DateTime.TIME_24_SIMPLE,
|
|
20
|
+
DateTime.TIME_24_WITH_SECONDS,
|
|
21
|
+
DateTime.TIME_24_WITH_SHORT_OFFSET,
|
|
22
|
+
DateTime.TIME_24_WITH_LONG_OFFSET,
|
|
23
|
+
...DateAndTimeFormats,
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export const dateFormats = [
|
|
27
|
+
DateTime.DATE_SHORT,
|
|
28
|
+
DateTime.DATE_MED,
|
|
29
|
+
DateTime.DATE_FULL,
|
|
30
|
+
DateTime.DATE_HUGE,
|
|
31
|
+
...DateAndTimeFormats,
|
|
32
|
+
];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
width: 100%;
|
|
5
|
+
position: relative;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const ResultContainer = styled.div<{ readOnly: boolean; hasError: boolean }>`
|
|
9
|
+
list-style-type: none;
|
|
10
|
+
overflow-y: auto;
|
|
11
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
12
|
+
outline: 0;
|
|
13
|
+
border: 0.1rem solid ${({ theme }) => theme.colors.secondary};
|
|
14
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
15
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
16
|
+
box-shadow: ${({ theme }) => theme.elevation[4]};
|
|
17
|
+
text-transform: capitalize;
|
|
18
|
+
z-index: ${({ theme }) => theme.zIndex.dropdown};
|
|
19
|
+
cursor: ${({ readOnly }) => (readOnly ? 'not-allowed' : 'pointer')};
|
|
20
|
+
user-select: none;
|
|
21
|
+
|
|
22
|
+
span {
|
|
23
|
+
color: ${({ theme }) => theme.colors.primary};
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const ContentContainer = styled.div`
|
|
28
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
export const InnerContainer = styled.div`
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: row;
|
|
34
|
+
justify-content: space-between;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const ButtonContainer = styled.div`
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: flex-end;
|
|
41
|
+
gap: ${({ theme }) => theme.spacing['1']};
|
|
42
|
+
margin-top: ${({ theme }) => theme.spacing['1']};
|
|
43
|
+
`;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { createContext, Dispatch, useContext } from 'react';
|
|
3
|
+
import { Tense, Unit } from './QuickSelect';
|
|
4
|
+
|
|
5
|
+
export interface DateRangePickerState {
|
|
6
|
+
start: DateTime;
|
|
7
|
+
end: DateTime;
|
|
8
|
+
quickSelect: {
|
|
9
|
+
show: boolean;
|
|
10
|
+
tense: Tense;
|
|
11
|
+
step: number;
|
|
12
|
+
unit: Unit;
|
|
13
|
+
};
|
|
14
|
+
showStartDate: boolean;
|
|
15
|
+
showEndDate: boolean;
|
|
16
|
+
friendlyStartDate?: string;
|
|
17
|
+
friendlyEndDate?: string;
|
|
18
|
+
friendlyRange?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function reducer(state: DateRangePickerState, action: Action): DateRangePickerState {
|
|
22
|
+
switch (action.type) {
|
|
23
|
+
case 'toggle_quick_select_popover':
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
quickSelect: { ...state.quickSelect, show: action.payload.toggleQuickSelect },
|
|
27
|
+
};
|
|
28
|
+
case 'toggle_start_date_popover':
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
friendlyRange: undefined,
|
|
32
|
+
showStartDate: action.payload.toggleStartDate,
|
|
33
|
+
};
|
|
34
|
+
case 'toggle_end_date_popover':
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
friendlyRange: undefined,
|
|
38
|
+
showEndDate: action.payload.toggleEndDate,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
case 'set_absolute_start_date':
|
|
42
|
+
return {
|
|
43
|
+
...state,
|
|
44
|
+
start: action.payload.startDate,
|
|
45
|
+
// If endDate is before new startDate, set endDate to new startDate
|
|
46
|
+
end: state.end < action.payload.startDate ? action.payload.startDate : state.end,
|
|
47
|
+
friendlyStartDate: undefined,
|
|
48
|
+
friendlyRange: undefined,
|
|
49
|
+
};
|
|
50
|
+
case 'set_relative_start_date':
|
|
51
|
+
return {
|
|
52
|
+
...state,
|
|
53
|
+
start: action.payload.startDate,
|
|
54
|
+
friendlyStartDate: action.payload.friendlyStartDate,
|
|
55
|
+
friendlyRange: undefined,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
case 'set_quick_select':
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
quickSelect: { ...state.quickSelect, ...action.payload.quickSelect },
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
case 'set_absolute_end_date':
|
|
65
|
+
return {
|
|
66
|
+
...state,
|
|
67
|
+
end: action.payload.endDate,
|
|
68
|
+
friendlyEndDate: undefined,
|
|
69
|
+
friendlyRange: undefined,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
case 'set_relative_end_date':
|
|
73
|
+
return {
|
|
74
|
+
...state,
|
|
75
|
+
end: action.payload.endDate,
|
|
76
|
+
friendlyEndDate: action.payload.friendlyEndDate,
|
|
77
|
+
friendlyRange: undefined,
|
|
78
|
+
};
|
|
79
|
+
case 'set_range':
|
|
80
|
+
return {
|
|
81
|
+
...state,
|
|
82
|
+
end: action.payload.endDate,
|
|
83
|
+
start: action.payload.startDate,
|
|
84
|
+
friendlyRange: action.payload.friendlyRange,
|
|
85
|
+
friendlyEndDate: undefined,
|
|
86
|
+
friendlyStartDate: undefined,
|
|
87
|
+
quickSelect: { ...state.quickSelect, show: false },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type Action =
|
|
93
|
+
| { type: 'toggle_quick_select_popover'; payload: { toggleQuickSelect: boolean } }
|
|
94
|
+
| { type: 'toggle_start_date_popover'; payload: { toggleStartDate: boolean } }
|
|
95
|
+
| { type: 'toggle_end_date_popover'; payload: { toggleEndDate: boolean } }
|
|
96
|
+
| { type: 'set_quick_select'; payload: { quickSelect: DateRangePickerState['quickSelect'] } }
|
|
97
|
+
| { type: 'set_relative_start_date'; payload: { startDate: DateTime; friendlyStartDate?: string } }
|
|
98
|
+
| { type: 'set_absolute_start_date'; payload: { startDate: DateTime } }
|
|
99
|
+
| { type: 'set_relative_end_date'; payload: { endDate: DateTime; friendlyEndDate?: string } }
|
|
100
|
+
| { type: 'set_absolute_end_date'; payload: { endDate: DateTime } }
|
|
101
|
+
| { type: 'set_range'; payload: { startDate: DateTime; endDate: DateTime; friendlyRange?: string } };
|
|
102
|
+
|
|
103
|
+
export const DateRangePickerContext = createContext<DateRangePickerState | null>(null);
|
|
104
|
+
export const DateRangePickerDispatchContext = createContext<Dispatch<Action> | null>(null);
|
|
105
|
+
|
|
106
|
+
export function useDateRangePickerContext() {
|
|
107
|
+
return useContext(DateRangePickerContext);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function useDateRangePickerDispatchContext() {
|
|
111
|
+
return useContext(DateRangePickerDispatchContext);
|
|
112
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { DateRangePicker, DateRangePickerProps } from '.';
|
|
4
|
+
import { styled } from '../../../../styled';
|
|
5
|
+
|
|
6
|
+
const Wrapper = styled.div`
|
|
7
|
+
height: 100vh;
|
|
8
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Inputs/DateRangePicker',
|
|
13
|
+
component: DateRangePicker,
|
|
14
|
+
args: {
|
|
15
|
+
readOnly: false,
|
|
16
|
+
hasDescription: false,
|
|
17
|
+
hasError: false,
|
|
18
|
+
},
|
|
19
|
+
} as Meta<DateRangePickerProps>;
|
|
20
|
+
|
|
21
|
+
export const Default: StoryFn<DateRangePickerProps> = (args) => {
|
|
22
|
+
return (
|
|
23
|
+
<Wrapper>
|
|
24
|
+
<DateRangePicker
|
|
25
|
+
readOnly={args.readOnly}
|
|
26
|
+
id="date"
|
|
27
|
+
onChange={(start, end) => console.log(start, end)}
|
|
28
|
+
value="2021-01-01"
|
|
29
|
+
/>
|
|
30
|
+
</Wrapper>
|
|
31
|
+
);
|
|
32
|
+
};
|