@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,98 @@
|
|
|
1
|
+
import { FC, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Calendar } from '../../subcomponents/Calendar';
|
|
3
|
+
import { TimePicker } from '../../subcomponents/TimePicker';
|
|
4
|
+
import { useDateRangePickerContext, useDateRangePickerDispatchContext } from '../Context';
|
|
5
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
import { DateTime } from 'luxon';
|
|
9
|
+
import { TextField, Divider } from '../../../../../components';
|
|
10
|
+
import { styled } from '../../../../../styled';
|
|
11
|
+
|
|
12
|
+
const Container = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const StyledForm = styled.form<{ hasError: boolean }>`
|
|
18
|
+
margin-top: ${({ theme }) => theme.spacing['0_5']};
|
|
19
|
+
padding-bottom: ${({ theme, hasError }) => (hasError ? theme.spacing['2_5'] : 0)};
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
interface AbsoluteProps {
|
|
23
|
+
isStart: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Absolute: FC<AbsoluteProps> = ({ isStart }) => {
|
|
27
|
+
const dispatch = useDateRangePickerDispatchContext();
|
|
28
|
+
const state = useDateRangePickerContext();
|
|
29
|
+
|
|
30
|
+
if (!dispatch || !state) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'useDateRangePickerDispatchContext and useDateRangePickerContext must be used within a DateRangePickerProvider'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface IFormInputs {
|
|
37
|
+
date: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const validationSchema = useMemo(() => {
|
|
41
|
+
return z.object({
|
|
42
|
+
date: z.string().refine(
|
|
43
|
+
(dateStr: string) => {
|
|
44
|
+
const dateTime = DateTime.fromFormat(dateStr, 'MMM d, yyyy @ HH:mm:ss.SSS', { locale: 'en' });
|
|
45
|
+
return dateTime.isValid;
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
message: 'Invalid date format, it should be "MMM D, YYYY @ HH:mm:ss.SSS"',
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
});
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const { control, handleSubmit, setValue, formState, clearErrors } = useForm<IFormInputs>({
|
|
55
|
+
mode: 'onChange',
|
|
56
|
+
resolver: zodResolver(validationSchema),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
clearErrors('date');
|
|
61
|
+
setValue(
|
|
62
|
+
'date',
|
|
63
|
+
isStart ? state.start.toFormat('MMM d, yyyy @ HH:mm:ss.SSS') : state.end.toFormat('MMM d, yyyy @ HH:mm:ss.SSS')
|
|
64
|
+
);
|
|
65
|
+
}, [isStart ? state.start : state.end]);
|
|
66
|
+
|
|
67
|
+
const onSubmit: SubmitHandler<IFormInputs> = ({ date }) => {
|
|
68
|
+
const dateTime = DateTime.fromFormat(date, 'MMM d, yyyy @ HH:mm:ss.SSS', { locale: 'en' });
|
|
69
|
+
if (isStart) dispatch({ type: 'set_absolute_start_date', payload: { startDate: dateTime } });
|
|
70
|
+
else dispatch({ type: 'set_absolute_end_date', payload: { endDate: dateTime } });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
<Container>
|
|
76
|
+
<Calendar
|
|
77
|
+
onDateClick={(date) => {
|
|
78
|
+
if (isStart) dispatch({ type: 'set_absolute_start_date', payload: { startDate: date } });
|
|
79
|
+
else dispatch({ type: 'set_absolute_end_date', payload: { endDate: date } });
|
|
80
|
+
}}
|
|
81
|
+
id={isStart ? 'start' : 'end'}
|
|
82
|
+
selectedDate={isStart ? state.start : state.end}
|
|
83
|
+
/>
|
|
84
|
+
<TimePicker
|
|
85
|
+
selectedDate={isStart ? state.start : state.end}
|
|
86
|
+
onChange={(date) => {
|
|
87
|
+
if (isStart) dispatch({ type: 'set_absolute_start_date', payload: { startDate: date } });
|
|
88
|
+
else dispatch({ type: 'set_absolute_end_date', payload: { endDate: date } });
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
</Container>
|
|
92
|
+
<Divider fullWidth />
|
|
93
|
+
<StyledForm hasError={formState.errors.date?.message ? true : false} onChange={handleSubmit(onSubmit)}>
|
|
94
|
+
<TextField prefix={isStart ? 'Start date' : 'End date'} control={control} name="date" type="text" />
|
|
95
|
+
</StyledForm>
|
|
96
|
+
</>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Divider } from '../../../../../components';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { useDateRangePickerContext, useDateRangePickerDispatchContext } from '../Context';
|
|
5
|
+
import { RelativePicker } from '../../subcomponents/RelativePicker';
|
|
6
|
+
import { GenericTextField } from '../../../TextField';
|
|
7
|
+
|
|
8
|
+
interface RelativeProps {
|
|
9
|
+
isStart: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Relative: FC<RelativeProps> = ({ isStart }) => {
|
|
13
|
+
const dispatch = useDateRangePickerDispatchContext();
|
|
14
|
+
const state = useDateRangePickerContext();
|
|
15
|
+
|
|
16
|
+
if (!dispatch || !state) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'useDateRangePickerDispatchContext and useDateRangePickerContext must be used within a DateRangePickerProvider'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const handleOnChange = (selectedDate: DateTime, friendlyName?: string) => {
|
|
23
|
+
if (selectedDate) {
|
|
24
|
+
if (isStart)
|
|
25
|
+
dispatch({
|
|
26
|
+
type: 'set_relative_start_date',
|
|
27
|
+
payload: { startDate: selectedDate, friendlyStartDate: friendlyName },
|
|
28
|
+
});
|
|
29
|
+
else
|
|
30
|
+
dispatch({ type: 'set_relative_end_date', payload: { endDate: selectedDate, friendlyEndDate: friendlyName } });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<RelativePicker id={`${isStart ? 'start' : 'end'}`} onChange={handleOnChange} />
|
|
37
|
+
<Divider fullWidth />
|
|
38
|
+
<GenericTextField
|
|
39
|
+
hasDescription={false}
|
|
40
|
+
hasError={false}
|
|
41
|
+
name={`date-preview-${isStart}`}
|
|
42
|
+
id={`date-preview-${isStart}`}
|
|
43
|
+
onChange={() => {}}
|
|
44
|
+
readOnly={true}
|
|
45
|
+
prefix={isStart ? 'Start date' : 'End date'}
|
|
46
|
+
value={
|
|
47
|
+
isStart
|
|
48
|
+
? state.start.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')
|
|
49
|
+
: state.end.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')
|
|
50
|
+
}
|
|
51
|
+
/>
|
|
52
|
+
</>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Tabs } from '../../../../../components';
|
|
3
|
+
import { useDateRangePickerDispatchContext, useDateRangePickerContext } from '../Context';
|
|
4
|
+
import { styled } from '../../../../../styled';
|
|
5
|
+
import { Absolute } from './Absolute';
|
|
6
|
+
import { Relative } from './Relative';
|
|
7
|
+
|
|
8
|
+
const Wrapper = styled.div`
|
|
9
|
+
width: 400px;
|
|
10
|
+
padding: ${({ theme }) => `${theme.spacing[1]} ${theme.spacing[1]} 0 ${theme.spacing[1]}`};
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
interface DateSelectorProps {
|
|
18
|
+
isStart: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DateSelector: FC<DateSelectorProps> = ({ isStart }) => {
|
|
22
|
+
const dispatch = useDateRangePickerDispatchContext();
|
|
23
|
+
const state = useDateRangePickerContext();
|
|
24
|
+
|
|
25
|
+
if (!dispatch || !state) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'useDateRangePickerDispatchContext and useDateRangePickerContext must be used within a DateRangePickerProvider'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Tabs defaultValue="relative">
|
|
33
|
+
<Tabs.List>
|
|
34
|
+
<Tabs.Trigger value="absolute">Absolute</Tabs.Trigger>
|
|
35
|
+
<Tabs.Trigger value="relative">Relative</Tabs.Trigger>
|
|
36
|
+
</Tabs.List>
|
|
37
|
+
<Tabs.Content value="absolute">
|
|
38
|
+
<Wrapper>
|
|
39
|
+
<Absolute isStart={isStart} />
|
|
40
|
+
</Wrapper>
|
|
41
|
+
</Tabs.Content>
|
|
42
|
+
<Tabs.Content value="relative">
|
|
43
|
+
<Wrapper>
|
|
44
|
+
<Relative isStart={isStart} />
|
|
45
|
+
</Wrapper>
|
|
46
|
+
</Tabs.Content>
|
|
47
|
+
</Tabs>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Button, Divider, SelectField, TextField } from '../../../../../components';
|
|
2
|
+
import { FC, useMemo } from 'react';
|
|
3
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
6
|
+
import { useDateRangePickerDispatchContext, useDateRangePickerContext } from '../Context';
|
|
7
|
+
import { DateTime, DateTimeUnit } from 'luxon';
|
|
8
|
+
import { Container, StyledForm, InputsContainer, CommonlyUsedGrid } from './style';
|
|
9
|
+
|
|
10
|
+
export enum Tense {
|
|
11
|
+
Last = 'Last',
|
|
12
|
+
Next = 'Next',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum Unit {
|
|
16
|
+
Seconds = 'Seconds',
|
|
17
|
+
Minutes = 'Minutes',
|
|
18
|
+
Hours = 'Hours',
|
|
19
|
+
Days = 'Days',
|
|
20
|
+
Weeks = 'Weeks',
|
|
21
|
+
Months = 'Months',
|
|
22
|
+
Years = 'Years',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface FormInputs {
|
|
26
|
+
tense: string;
|
|
27
|
+
step: number;
|
|
28
|
+
unit: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface QuickSelectProps {
|
|
32
|
+
id: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const QuickSelect: FC<QuickSelectProps> = ({ id }) => {
|
|
36
|
+
const state = useDateRangePickerContext();
|
|
37
|
+
const dispatch = useDateRangePickerDispatchContext();
|
|
38
|
+
|
|
39
|
+
if (!dispatch) {
|
|
40
|
+
throw new Error('useDateRangePickerDispatchContext must be used within a DateRangePickerProvider');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const validationSchema = useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
z.object({
|
|
46
|
+
tense: z.nativeEnum(Tense),
|
|
47
|
+
step: z.number().positive(),
|
|
48
|
+
unit: z.nativeEnum(Unit),
|
|
49
|
+
}),
|
|
50
|
+
[]
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const { control, handleSubmit } = useForm<FormInputs>({
|
|
54
|
+
mode: 'onSubmit',
|
|
55
|
+
resolver: zodResolver(validationSchema),
|
|
56
|
+
defaultValues: {
|
|
57
|
+
step: state?.quickSelect.step,
|
|
58
|
+
tense: state?.quickSelect.tense,
|
|
59
|
+
unit: state?.quickSelect.unit,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const onSubmit: SubmitHandler<FormInputs> = ({ tense, step, unit }) => {
|
|
64
|
+
const baseDate =
|
|
65
|
+
tense === Tense.Last ? DateTime.local() : DateTime.local().startOf(unit.toLowerCase() as DateTimeUnit);
|
|
66
|
+
const action = tense === Tense.Last ? 'minus' : 'plus';
|
|
67
|
+
const range = { [unit.toLowerCase()]: step };
|
|
68
|
+
const otherDate = baseDate[action](range);
|
|
69
|
+
|
|
70
|
+
const startDate = tense === Tense.Last ? otherDate : baseDate;
|
|
71
|
+
const endDate = tense === Tense.Last ? baseDate : otherDate;
|
|
72
|
+
const friendlyRangeName = `${tense} ${step} ${unit.toLowerCase()}`;
|
|
73
|
+
|
|
74
|
+
dispatch({
|
|
75
|
+
type: 'set_quick_select',
|
|
76
|
+
payload: {
|
|
77
|
+
quickSelect: {
|
|
78
|
+
show: false,
|
|
79
|
+
tense: tense as Tense,
|
|
80
|
+
step,
|
|
81
|
+
unit: unit as Unit,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
dispatch({
|
|
87
|
+
type: 'set_range',
|
|
88
|
+
payload: {
|
|
89
|
+
startDate,
|
|
90
|
+
endDate,
|
|
91
|
+
friendlyRange: friendlyRangeName,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Container>
|
|
98
|
+
<h4>Quick select</h4>
|
|
99
|
+
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
|
100
|
+
<InputsContainer>
|
|
101
|
+
<SelectField
|
|
102
|
+
inPortal
|
|
103
|
+
control={control}
|
|
104
|
+
name="tense"
|
|
105
|
+
render={(selectedItems) => (
|
|
106
|
+
<div>
|
|
107
|
+
{selectedItems.length > 0 ? Object.values(Tense).find((v) => v === selectedItems[0].value) : Tense.Last}
|
|
108
|
+
</div>
|
|
109
|
+
)}
|
|
110
|
+
>
|
|
111
|
+
<SelectField.OptionGroup>
|
|
112
|
+
{Object.values(Tense).map((val: string) => (
|
|
113
|
+
<SelectField.Option key={`${val}-${id}`} value={val} label={val}>
|
|
114
|
+
<span>{val}</span>
|
|
115
|
+
</SelectField.Option>
|
|
116
|
+
))}
|
|
117
|
+
</SelectField.OptionGroup>
|
|
118
|
+
</SelectField>
|
|
119
|
+
|
|
120
|
+
<TextField control={control} type="number" name="step" />
|
|
121
|
+
|
|
122
|
+
<SelectField
|
|
123
|
+
inPortal
|
|
124
|
+
control={control}
|
|
125
|
+
name="unit"
|
|
126
|
+
render={(selectedItems) => (
|
|
127
|
+
<div>
|
|
128
|
+
{selectedItems.length > 0
|
|
129
|
+
? Object.values(Unit).find((v) => v === selectedItems[0].value)
|
|
130
|
+
: Unit.Minutes}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
<SelectField.OptionGroup>
|
|
135
|
+
{Object.values(Unit).map((val: string) => (
|
|
136
|
+
<SelectField.Option key={`${val}-${id}`} value={val} label={val}>
|
|
137
|
+
<span>{val}</span>
|
|
138
|
+
</SelectField.Option>
|
|
139
|
+
))}
|
|
140
|
+
</SelectField.OptionGroup>
|
|
141
|
+
</SelectField>
|
|
142
|
+
</InputsContainer>
|
|
143
|
+
<Button type="submit" text="Apply" />
|
|
144
|
+
</StyledForm>
|
|
145
|
+
|
|
146
|
+
<Divider fullWidth />
|
|
147
|
+
<h4>Commonly used</h4>
|
|
148
|
+
<CommonlyUsedGrid>
|
|
149
|
+
<li
|
|
150
|
+
onClick={() =>
|
|
151
|
+
dispatch({
|
|
152
|
+
type: 'set_range',
|
|
153
|
+
payload: {
|
|
154
|
+
startDate: DateTime.local().startOf('day'),
|
|
155
|
+
endDate: DateTime.local().endOf('day'),
|
|
156
|
+
friendlyRange: 'Today',
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
Today
|
|
162
|
+
</li>
|
|
163
|
+
|
|
164
|
+
<li
|
|
165
|
+
onClick={() => {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: 'set_range',
|
|
168
|
+
payload: {
|
|
169
|
+
startDate: DateTime.local().startOf('week'),
|
|
170
|
+
endDate: DateTime.local().endOf('week'),
|
|
171
|
+
friendlyRange: 'This week',
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
This week
|
|
177
|
+
</li>
|
|
178
|
+
<li
|
|
179
|
+
onClick={() => {
|
|
180
|
+
dispatch({
|
|
181
|
+
type: 'set_range',
|
|
182
|
+
payload: {
|
|
183
|
+
startDate: DateTime.local().minus({ minutes: 15 }),
|
|
184
|
+
endDate: DateTime.local(),
|
|
185
|
+
friendlyRange: 'Last 15 minutes',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
Last 15 minutes
|
|
191
|
+
</li>
|
|
192
|
+
|
|
193
|
+
<li
|
|
194
|
+
onClick={() => {
|
|
195
|
+
dispatch({
|
|
196
|
+
type: 'set_range',
|
|
197
|
+
payload: {
|
|
198
|
+
startDate: DateTime.local().minus({ minutes: 30 }),
|
|
199
|
+
endDate: DateTime.local(),
|
|
200
|
+
friendlyRange: 'Last 30 minutes',
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
Last 30 minutes
|
|
206
|
+
</li>
|
|
207
|
+
|
|
208
|
+
<li
|
|
209
|
+
onClick={() => {
|
|
210
|
+
dispatch({
|
|
211
|
+
type: 'set_range',
|
|
212
|
+
payload: {
|
|
213
|
+
startDate: DateTime.local().minus({ hours: 1 }),
|
|
214
|
+
endDate: DateTime.local(),
|
|
215
|
+
friendlyRange: 'Last hour',
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
Last 1 hour
|
|
221
|
+
</li>
|
|
222
|
+
|
|
223
|
+
<li
|
|
224
|
+
onClick={() => {
|
|
225
|
+
dispatch({
|
|
226
|
+
type: 'set_range',
|
|
227
|
+
payload: {
|
|
228
|
+
startDate: DateTime.local().minus({ hours: 24 }),
|
|
229
|
+
endDate: DateTime.local(),
|
|
230
|
+
friendlyRange: 'Last 24 hours',
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
Last 24 hours
|
|
236
|
+
</li>
|
|
237
|
+
|
|
238
|
+
<li
|
|
239
|
+
onClick={() => {
|
|
240
|
+
dispatch({
|
|
241
|
+
type: 'set_range',
|
|
242
|
+
payload: {
|
|
243
|
+
startDate: DateTime.local().minus({ days: 7 }),
|
|
244
|
+
endDate: DateTime.local(),
|
|
245
|
+
friendlyRange: 'Last 7 days',
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
Last 7 days
|
|
251
|
+
</li>
|
|
252
|
+
|
|
253
|
+
<li
|
|
254
|
+
onClick={() => {
|
|
255
|
+
dispatch({
|
|
256
|
+
type: 'set_range',
|
|
257
|
+
payload: {
|
|
258
|
+
startDate: DateTime.local().minus({ days: 30 }),
|
|
259
|
+
endDate: DateTime.local(),
|
|
260
|
+
friendlyRange: 'Last 30 days',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}}
|
|
264
|
+
>
|
|
265
|
+
Last 30 days
|
|
266
|
+
</li>
|
|
267
|
+
</CommonlyUsedGrid>
|
|
268
|
+
</Container>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { styled } from '../../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
padding: ${({ theme }) => theme.spacing[2]};
|
|
5
|
+
min-width: 400px;
|
|
6
|
+
h4 {
|
|
7
|
+
margin-bottom: ${({ theme }) => theme.spacing['1']};
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const CommonlyUsedGrid = styled.ul`
|
|
12
|
+
display: grid;
|
|
13
|
+
grid-auto-flow: column;
|
|
14
|
+
grid-template-rows: repeat(5, 1fr);
|
|
15
|
+
grid-template-columns: repeat(2, 1fr);
|
|
16
|
+
gap: ${({ theme }) => `${theme.spacing['0_5']} ${theme.spacing[1]}`};
|
|
17
|
+
padding: 0 ${({ theme }) => theme.spacing[1]};
|
|
18
|
+
|
|
19
|
+
li {
|
|
20
|
+
text-align: left;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const StyledForm = styled.form`
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export const InputsContainer = styled.div`
|
|
31
|
+
width: 100%;
|
|
32
|
+
display: grid;
|
|
33
|
+
grid-template-columns: 0.5fr 0.5fr 1fr;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
36
|
+
div {
|
|
37
|
+
width: 100%;
|
|
38
|
+
margin-bottom: 0;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { FC, useEffect, useReducer, useState } from 'react';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import {
|
|
4
|
+
AiOutlineCalendar as CalendarIcon,
|
|
5
|
+
AiOutlineDown as DownIcon,
|
|
6
|
+
AiOutlineArrowRight as ArrowRightIcon,
|
|
7
|
+
} from 'react-icons/ai';
|
|
8
|
+
import { Popover } from '../../../../components';
|
|
9
|
+
import { QuickSelect, Tense, Unit } from './QuickSelect';
|
|
10
|
+
import { Container, QuickSelectContainer, ItemContainer } from './style';
|
|
11
|
+
import { DateSelector } from './DateSelector';
|
|
12
|
+
import { DateRangePickerDispatchContext, DateRangePickerContext, reducer } from './Context';
|
|
13
|
+
|
|
14
|
+
export interface DateRangePickerProps {
|
|
15
|
+
defaultValue?: { start: DateTime; end: DateTime };
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
id: string;
|
|
18
|
+
onChange: (start: DateTime, end: DateTime) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DateRangePicker: FC<DateRangePickerProps> = ({
|
|
22
|
+
readOnly = false,
|
|
23
|
+
id,
|
|
24
|
+
onChange,
|
|
25
|
+
defaultValue = {
|
|
26
|
+
start: DateTime.local().startOf('day'),
|
|
27
|
+
end: DateTime.local().endOf('day'),
|
|
28
|
+
},
|
|
29
|
+
}) => {
|
|
30
|
+
const [state, dispatch] = useReducer(reducer, {
|
|
31
|
+
quickSelect: {
|
|
32
|
+
show: false,
|
|
33
|
+
tense: Tense.Last,
|
|
34
|
+
step: 15,
|
|
35
|
+
unit: Unit.Minutes,
|
|
36
|
+
},
|
|
37
|
+
showStartDate: false,
|
|
38
|
+
showEndDate: false,
|
|
39
|
+
start: defaultValue.start,
|
|
40
|
+
end: defaultValue.end,
|
|
41
|
+
friendlyRange: undefined,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const [hasError, setHasError] = useState<boolean>(false);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (state.start > state.end) {
|
|
48
|
+
setHasError(true);
|
|
49
|
+
} else {
|
|
50
|
+
setHasError(false);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
onChange(state.start, state.end);
|
|
54
|
+
}, [state.start, state.end]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<DateRangePickerContext.Provider value={state}>
|
|
58
|
+
<DateRangePickerDispatchContext.Provider value={dispatch}>
|
|
59
|
+
<Container hasError={hasError} isOpen={state.quickSelect.show || state.showStartDate || state.showEndDate}>
|
|
60
|
+
<Popover
|
|
61
|
+
open={state.quickSelect.show}
|
|
62
|
+
onOpenChange={(open) =>
|
|
63
|
+
dispatch({ type: 'toggle_quick_select_popover', payload: { toggleQuickSelect: open } })
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
<Popover.Trigger asChild>
|
|
67
|
+
<QuickSelectContainer
|
|
68
|
+
readOnly={readOnly}
|
|
69
|
+
onClick={() =>
|
|
70
|
+
dispatch({
|
|
71
|
+
type: 'toggle_quick_select_popover',
|
|
72
|
+
payload: { toggleQuickSelect: !state.quickSelect.show },
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
>
|
|
76
|
+
<CalendarIcon size={18} />
|
|
77
|
+
<DownIcon size={18} />
|
|
78
|
+
</QuickSelectContainer>
|
|
79
|
+
</Popover.Trigger>
|
|
80
|
+
<Popover.Content>
|
|
81
|
+
<QuickSelect id={`quick-select-${id}`} />
|
|
82
|
+
</Popover.Content>
|
|
83
|
+
</Popover>
|
|
84
|
+
<Popover
|
|
85
|
+
open={state.showStartDate}
|
|
86
|
+
onOpenChange={(open) => dispatch({ type: 'toggle_start_date_popover', payload: { toggleStartDate: open } })}
|
|
87
|
+
>
|
|
88
|
+
<Popover.Trigger asChild>
|
|
89
|
+
<ItemContainer
|
|
90
|
+
readOnly={readOnly}
|
|
91
|
+
onClick={() => {
|
|
92
|
+
dispatch({ type: 'toggle_start_date_popover', payload: { toggleStartDate: !state.showStartDate } });
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{state.friendlyStartDate ??
|
|
96
|
+
state.friendlyRange ??
|
|
97
|
+
// e.g. Aug 2, 2023 @ 00:00:00.000
|
|
98
|
+
state.start.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')}
|
|
99
|
+
</ItemContainer>
|
|
100
|
+
</Popover.Trigger>
|
|
101
|
+
<Popover.Content>
|
|
102
|
+
<DateSelector isStart />
|
|
103
|
+
</Popover.Content>
|
|
104
|
+
</Popover>
|
|
105
|
+
{!state.friendlyRange && (
|
|
106
|
+
<>
|
|
107
|
+
<ArrowRightIcon size={18} style={{ marginLeft: '10px', marginRight: '10px' }} />
|
|
108
|
+
<Popover
|
|
109
|
+
open={state.showEndDate}
|
|
110
|
+
onOpenChange={(open) => {
|
|
111
|
+
dispatch({ type: 'toggle_end_date_popover', payload: { toggleEndDate: open } });
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<Popover.Trigger asChild>
|
|
115
|
+
<ItemContainer
|
|
116
|
+
readOnly={readOnly}
|
|
117
|
+
onClick={() => {
|
|
118
|
+
dispatch({ type: 'toggle_end_date_popover', payload: { toggleEndDate: !state.showEndDate } });
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{state.friendlyEndDate ?? state.end.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')}
|
|
122
|
+
</ItemContainer>
|
|
123
|
+
</Popover.Trigger>
|
|
124
|
+
<Popover.Content>
|
|
125
|
+
<DateSelector isStart={false} />
|
|
126
|
+
</Popover.Content>
|
|
127
|
+
</Popover>
|
|
128
|
+
</>
|
|
129
|
+
)}
|
|
130
|
+
</Container>
|
|
131
|
+
</DateRangePickerDispatchContext.Provider>
|
|
132
|
+
</DateRangePickerContext.Provider>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div<{
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
hasError: boolean;
|
|
6
|
+
}>`
|
|
7
|
+
width: 100%;
|
|
8
|
+
position: relative;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: row;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justyfy-content: flex-start;
|
|
13
|
+
text-align: left;
|
|
14
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
15
|
+
width: fit-content;
|
|
16
|
+
font-family: inherit;
|
|
17
|
+
outline: 0;
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
text-transform: capitalize;
|
|
20
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
21
|
+
border: 0.1rem solid
|
|
22
|
+
${({ theme, isOpen, hasError }) => {
|
|
23
|
+
if (hasError) return theme.colors.error;
|
|
24
|
+
return isOpen ? theme.colors.primary : theme.colors.backgroundAccent;
|
|
25
|
+
}};
|
|
26
|
+
|
|
27
|
+
&:focus {
|
|
28
|
+
border-color: ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
flex-shrink: 0;
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const ItemContainer = styled.div<{ readOnly: boolean }>`
|
|
35
|
+
cursor: ${({ readOnly }) => (readOnly ? 'default' : 'pointer')};
|
|
36
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']}`};
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const QuickSelectContainer = styled.div<{ readOnly: boolean }>`
|
|
40
|
+
border-radius: ${({ theme }) => `${theme.borderRadius.medium} 0 0 ${theme.borderRadius.medium};`};
|
|
41
|
+
height: 100%;
|
|
42
|
+
cursor: ${({ readOnly }) => (readOnly ? 'default' : 'pointer')};
|
|
43
|
+
gap: ${({ theme }) => theme.spacing['0_25']};
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
padding: ${({ theme }) => `0 ${theme.spacing['0_75']}`};
|
|
48
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
49
|
+
border-right: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
50
|
+
flex-shrink: 0;
|
|
51
|
+
`;
|