@takaro/lib-components 0.0.0-next.0da151e
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 +15 -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 +149 -0
- package/src/components/actions/Button/Button.test.tsx +8 -0
- package/src/components/actions/Button/Button.test.tsx.snap +89 -0
- package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +18 -0
- package/src/components/actions/Button/index.tsx +89 -0
- package/src/components/actions/Button/style.ts +142 -0
- package/src/components/actions/ContextMenu/ContextMenu.stories.tsx +41 -0
- package/src/components/actions/ContextMenu/Group.tsx +34 -0
- package/src/components/actions/ContextMenu/MenuItem.tsx +69 -0
- package/src/components/actions/ContextMenu/index.tsx +216 -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 +70 -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 +87 -0
- package/src/components/actions/Dropdown/index.tsx +22 -0
- package/src/components/actions/Dropdown/useDropdown.tsx +89 -0
- package/src/components/actions/DropdownButton/DropdownButton.stories.tsx +88 -0
- package/src/components/actions/DropdownButton/index.tsx +128 -0
- package/src/components/actions/IconButton/IconButton.stories.tsx +54 -0
- package/src/components/actions/IconButton/IconButton.test.tsx +8 -0
- package/src/components/actions/IconButton/IconButton.test.tsx.snap +46 -0
- package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +18 -0
- package/src/components/actions/IconButton/getIconSize.ts +16 -0
- package/src/components/actions/IconButton/index.tsx +28 -0
- package/src/components/actions/IconButton/style.ts +51 -0
- package/src/components/actions/ToggleButton/ToggleButton.stories.tsx +85 -0
- package/src/components/actions/ToggleButton/ToggleButton.tsx +48 -0
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +107 -0
- package/src/components/actions/ToggleButton/index.tsx +2 -0
- package/src/components/actions/ToggleButton/style.ts +75 -0
- package/src/components/actions/index.ts +16 -0
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +103 -0
- package/src/components/charts/AreaChart/index.tsx +428 -0
- package/src/components/charts/BarChart/BarChart.stories.tsx +55 -0
- package/src/components/charts/BarChart/index.tsx +420 -0
- package/src/components/charts/BrushHandle.tsx +21 -0
- package/src/components/charts/EmptyChart.tsx +45 -0
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +77 -0
- package/src/components/charts/GeoMercator/index.tsx +228 -0
- package/src/components/charts/GeoMercator/iso3166-alpha2-to-alpha3.ts +250 -0
- package/src/components/charts/GeoMercator/world.d.ts +1 -0
- package/src/components/charts/GeoMercator/world.json +99818 -0
- package/src/components/charts/Heatmap/Heatmap.stories.tsx +189 -0
- package/src/components/charts/Heatmap/index.tsx +461 -0
- package/src/components/charts/LineChart/LineChart.stories.tsx +111 -0
- package/src/components/charts/LineChart/index.tsx +353 -0
- package/src/components/charts/PieChart/PieChart.stories.tsx +151 -0
- package/src/components/charts/PieChart/index.tsx +457 -0
- package/src/components/charts/PointHighlight.tsx +49 -0
- package/src/components/charts/RadarChart/RadarChart.stories.tsx +47 -0
- package/src/components/charts/RadarChart/generators.ts +30 -0
- package/src/components/charts/RadarChart/index.tsx +224 -0
- package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +59 -0
- package/src/components/charts/RadialBarChart/index.tsx +231 -0
- package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +43 -0
- package/src/components/charts/RadialLineChart/index.tsx +231 -0
- package/src/components/charts/ZoomControls.tsx +49 -0
- package/src/components/charts/index.tsx +26 -0
- package/src/components/charts/useGradients.tsx +37 -0
- package/src/components/charts/util.ts +78 -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 +136 -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 +8 -0
- package/src/components/data/Chip/Chip.test.tsx.snap +50 -0
- package/src/components/data/Chip/__snapshots__/Chip.test.tsx.snap +38 -0
- package/src/components/data/Chip/index.tsx +67 -0
- package/src/components/data/Chip/style.ts +49 -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/constants.ts +6 -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 +107 -0
- package/src/components/data/CountryList/index.tsx +146 -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 +155 -0
- package/src/components/data/Drawer/DrawerBody.tsx +22 -0
- package/src/components/data/Drawer/DrawerContent.tsx +169 -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 +50 -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 +66 -0
- package/src/components/data/InfiniteScroll/InfiniteScroll.stories.tsx +33 -0
- package/src/components/data/InfiniteScroll/index.tsx +54 -0
- package/src/components/data/Stats/Sparkline.tsx +48 -0
- package/src/components/data/Stats/Stat.tsx +192 -0
- package/src/components/data/Stats/Stats.stories.tsx +196 -0
- package/src/components/data/Stats/context.tsx +18 -0
- package/src/components/data/Stats/index.tsx +62 -0
- package/src/components/data/Table/Table.stories.tsx +146 -0
- package/src/components/data/Table/index.tsx +492 -0
- package/src/components/data/Table/react-table.d.ts +14 -0
- package/src/components/data/Table/style.ts +97 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +164 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +207 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +90 -0
- package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +70 -0
- package/src/components/data/Table/subcomponents/Filter/field.tsx +127 -0
- package/src/components/data/Table/subcomponents/Filter/index.tsx +228 -0
- package/src/components/data/Table/subcomponents/Filter/style.ts +26 -0
- package/src/components/data/Table/subcomponents/Filter/types.ts +10 -0
- package/src/components/data/Table/subcomponents/Pagination/PagePicker.tsx +109 -0
- package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +37 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +49 -0
- package/src/components/data/index.ts +28 -0
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +77 -0
- package/src/components/dialogs/Dialog/DialogBody.tsx +64 -0
- package/src/components/dialogs/Dialog/DialogContent.tsx +44 -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 +75 -0
- package/src/components/feedback/Alert/Alert.test.tsx +8 -0
- package/src/components/feedback/Alert/Alert.test.tsx.snap +146 -0
- package/src/components/feedback/Alert/__snapshots__/Alert.test.tsx.snap +44 -0
- package/src/components/feedback/Alert/index.tsx +120 -0
- package/src/components/feedback/Alert/style.ts +97 -0
- package/src/components/feedback/Badge/Badge.stories.tsx +23 -0
- package/src/components/feedback/Badge/index.tsx +47 -0
- package/src/components/feedback/ErrorFallback/ErrorFallback.stories.tsx +10 -0
- package/src/components/feedback/ErrorFallback/index.tsx +49 -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/IconTooltip/IconTooltip.stories.tsx +22 -0
- package/src/components/feedback/IconTooltip/index.tsx +51 -0
- package/src/components/feedback/Loaders/Loaders.stories.tsx +28 -0
- package/src/components/feedback/Loaders/Loading.test.tsx +8 -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 +8 -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/__snapshots__/Loading.test.tsx.snap +141 -0
- package/src/components/feedback/Loaders/__snapshots__/Spinner.test.tsx.snap +10 -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 +8 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx.snap +3 -0
- package/src/components/feedback/NetworkDetector/__snapshots__/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 +15 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/__snapshots__/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/index.tsx +78 -0
- package/src/components/feedback/Popover/Popover.stories.tsx +33 -0
- package/src/components/feedback/Popover/PopoverContent.tsx +46 -0
- package/src/components/feedback/Popover/PopoverContext.tsx +21 -0
- package/src/components/feedback/Popover/PopoverTrigger.tsx +45 -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 +137 -0
- package/src/components/feedback/Skeleton/Skeleton.stories.tsx +33 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx +8 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx.snap +35 -0
- package/src/components/feedback/Skeleton/__snapshots__/Skeleton.test.tsx.snap +9 -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 +51 -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 +82 -0
- package/src/components/feedback/index.ts +37 -0
- package/src/components/feedback/snacks/CookieConsent/index.tsx +125 -0
- package/src/components/feedback/snacks/CookieConsent/style.ts +99 -0
- package/src/components/feedback/snacks/Default/default.stories.tsx +73 -0
- package/src/components/feedback/snacks/Default/index.tsx +78 -0
- package/src/components/feedback/snacks/Default/style.ts +58 -0
- package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +46 -0
- package/src/components/feedback/snacks/Drawer/index.tsx +85 -0
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +73 -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 +123 -0
- package/src/components/inputs/CheckBox/Generic.tsx +42 -0
- package/src/components/inputs/CheckBox/index.tsx +4 -0
- package/src/components/inputs/CheckBox/style.ts +56 -0
- package/src/components/inputs/CodeField/CodeField.stories.tsx +86 -0
- package/src/components/inputs/CodeField/index.tsx +174 -0
- package/src/components/inputs/CodeField/style.ts +50 -0
- package/src/components/inputs/Date/DatePicker/Controlled.tsx +103 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +267 -0
- package/src/components/inputs/Date/DatePicker/Generic.tsx +283 -0
- package/src/components/inputs/Date/DatePicker/formats.tsx +32 -0
- package/src/components/inputs/Date/DatePicker/style.ts +41 -0
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +123 -0
- package/src/components/inputs/Date/DateRangePicker/Controlled.tsx +74 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +37 -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/Generic.tsx +167 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +254 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/style.ts +40 -0
- package/src/components/inputs/Date/DateRangePicker/style.ts +65 -0
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +150 -0
- package/src/components/inputs/Date/subcomponents/Calendar/style.ts +61 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +170 -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 +34 -0
- package/src/components/inputs/Date/types.ts +14 -0
- package/src/components/inputs/DurationField/Controlled.tsx +69 -0
- package/src/components/inputs/DurationField/Duration.stories.tsx +57 -0
- package/src/components/inputs/DurationField/Generic.tsx +197 -0
- package/src/components/inputs/DurationField/__tests__/Generic.test.tsx +12 -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 +210 -0
- package/src/components/inputs/FileField/Generic.tsx +133 -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 +59 -0
- package/src/components/inputs/RadioGroup/Controlled.tsx +45 -0
- package/src/components/inputs/RadioGroup/Generic.tsx +34 -0
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +118 -0
- package/src/components/inputs/RadioGroup/RadioItem.tsx +130 -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/Switch/Controlled.tsx +57 -0
- package/src/components/inputs/Switch/Generic.tsx +40 -0
- package/src/components/inputs/Switch/Switch.stories.tsx +89 -0
- package/src/components/inputs/Switch/index.ts +5 -0
- package/src/components/inputs/Switch/style.ts +62 -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 +58 -0
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +99 -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 +138 -0
- package/src/components/inputs/TextField/TextField.stories.tsx +217 -0
- package/src/components/inputs/TextField/index.ts +5 -0
- package/src/components/inputs/TextField/style.ts +103 -0
- package/src/components/inputs/TextField/util.ts +24 -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 +72 -0
- package/src/components/inputs/layout/Description.tsx +33 -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 +50 -0
- package/src/components/inputs/layout/index.ts +8 -0
- package/src/components/inputs/layout/setAriaDescribedBy.ts +3 -0
- package/src/components/inputs/selects/SelectField/Controlled.tsx +127 -0
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +48 -0
- package/src/components/inputs/selects/SelectField/Generic/index.tsx +299 -0
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +252 -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 +110 -0
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +401 -0
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +280 -0
- package/src/components/inputs/selects/SelectQueryField/index.tsx +5 -0
- package/src/components/inputs/selects/SelectQueryField/style.ts +13 -0
- package/src/components/inputs/selects/SubComponents/Option.tsx +114 -0
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +18 -0
- package/src/components/inputs/selects/SubComponents/index.ts +10 -0
- package/src/components/inputs/selects/SubComponents/style.ts +51 -0
- package/src/components/inputs/selects/data.ts +123 -0
- package/src/components/inputs/selects/index.tsx +49 -0
- package/src/components/inputs/selects/sharedStyle.ts +76 -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 +29 -0
- package/src/components/navigation/HorizontalNav/index.tsx +13 -0
- package/src/components/navigation/HorizontalNav/style.ts +93 -0
- package/src/components/navigation/IconNav/IconNav.stories.tsx +46 -0
- package/src/components/navigation/IconNav/index.tsx +50 -0
- package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +90 -0
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +104 -0
- package/src/components/navigation/Steppers/SlimStepper/style.ts +85 -0
- package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +88 -0
- package/src/components/navigation/Steppers/Stepper/index.tsx +114 -0
- package/src/components/navigation/Steppers/Stepper/style.ts +106 -0
- package/src/components/navigation/Steppers/context.tsx +2 -0
- package/src/components/navigation/Steppers/provider.tsx +18 -0
- package/src/components/navigation/Steppers/reducer.ts +51 -0
- package/src/components/navigation/Steppers/stepStates.ts +5 -0
- package/src/components/navigation/Steppers/useStepper.ts +34 -0
- package/src/components/navigation/Tabs/Content.tsx +39 -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 +66 -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 +17 -0
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +81 -0
- package/src/components/other/ActionMenu/index.tsx +62 -0
- package/src/components/other/ActionMenu/style.ts +47 -0
- package/src/components/other/ClipBoard/ClipBoard.stories.tsx +14 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx +8 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx.snap +70 -0
- package/src/components/other/ClipBoard/__snapshots__/ClipBoard.test.tsx.snap +36 -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 +110 -0
- package/src/components/other/Collapsible/Collapsible.stories.tsx +19 -0
- package/src/components/other/Collapsible/CollapsibleContent.tsx +29 -0
- package/src/components/other/Collapsible/CollapsibleContext.tsx +17 -0
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +83 -0
- package/src/components/other/Collapsible/index.tsx +21 -0
- package/src/components/other/Company/index.tsx +44 -0
- package/src/components/other/Company/style.ts +58 -0
- package/src/components/other/Empty/Empty.stories.tsx +28 -0
- package/src/components/other/Empty/Empty.test.tsx +10 -0
- package/src/components/other/Empty/Empty.test.tsx.snap +85 -0
- package/src/components/other/Empty/__snapshots__/Empty.test.tsx.snap +21 -0
- package/src/components/other/Empty/index.tsx +85 -0
- package/src/components/other/PermissionsGuard/PermissionsGuard.stories.tsx +55 -0
- package/src/components/other/PermissionsGuard/hasPermissionsHelper.ts +18 -0
- package/src/components/other/PermissionsGuard/index.tsx +27 -0
- package/src/components/other/Plan/Plan.stories.tsx +21 -0
- package/src/components/other/Plan/index.tsx +92 -0
- package/src/components/other/Plan/style.ts +61 -0
- package/src/components/other/Usage/Usage.stories.tsx +21 -0
- package/src/components/other/Usage/Usage.tsx +35 -0
- package/src/components/other/Usage/UsageCard.stories.tsx +31 -0
- package/src/components/other/Usage/UsageCard.tsx +88 -0
- package/src/components/other/index.ts +27 -0
- package/src/components/visual/Card/Card.stories.tsx +22 -0
- package/src/components/visual/Card/CardBody.tsx +11 -0
- package/src/components/visual/Card/CardTitle.tsx +29 -0
- package/src/components/visual/Card/index.tsx +58 -0
- package/src/components/visual/Divider/Divider.stories.tsx +19 -0
- package/src/components/visual/Divider/Divider.test.tsx +8 -0
- package/src/components/visual/Divider/Divider.test.tsx.snap +35 -0
- package/src/components/visual/Divider/__snapshots__/Divider.test.tsx.snap +13 -0
- package/src/components/visual/Divider/index.tsx +88 -0
- package/src/components/visual/Flag/index.tsx +61 -0
- package/src/components/visual/index.ts +8 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/errors.ts +126 -0
- package/src/errors/index.ts +14 -0
- package/src/helpers/camelCaseToSpaces.ts +5 -0
- package/src/helpers/formatNumber.ts +6 -0
- package/src/helpers/getInitials.ts +16 -0
- package/src/helpers/getSnackbarProvider.tsx +57 -0
- package/src/helpers/getTransition.ts +9 -0
- package/src/helpers/index.ts +6 -0
- package/src/helpers/makeData.ts +34 -0
- package/src/helpers/regexprs.ts +9 -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 +12 -0
- package/src/hooks/useLocalStorage.tsx +35 -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 +61 -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.mdx +35 -0
- package/src/stories/Introduction.mdx +17 -0
- package/src/stories/Spacing.mdx +25 -0
- package/src/styled/GlobalStyle.ts +209 -0
- package/src/styled/Snackbar.tsx +41 -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/index.ts +10 -0
- package/src/styled/spacing.ts +38 -0
- package/src/styled/theme.tsx +110 -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 +34 -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 +14 -0
- package/vite.config.mts +17 -0
|
@@ -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
|
+
].map((format) => JSON.stringify(format));
|
|
25
|
+
|
|
26
|
+
export const dateFormats = [
|
|
27
|
+
DateTime.DATE_SHORT,
|
|
28
|
+
DateTime.DATE_MED,
|
|
29
|
+
DateTime.DATE_FULL,
|
|
30
|
+
DateTime.DATE_HUGE,
|
|
31
|
+
...DateAndTimeFormats,
|
|
32
|
+
].map((format) => JSON.stringify(format));
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
text-transform: capitalize;
|
|
17
|
+
z-index: ${({ theme }) => theme.zIndex.dropdown};
|
|
18
|
+
cursor: ${({ readOnly }) => (readOnly ? 'not-allowed' : 'pointer')};
|
|
19
|
+
user-select: none;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const ContentContainer = styled.div`
|
|
26
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const InnerContainer = styled.div`
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: row;
|
|
32
|
+
justify-content: space-between;
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const ButtonContainer = styled.div`
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
gap: ${({ theme }) => theme.spacing['1']};
|
|
40
|
+
margin-top: ${({ theme }) => theme.spacing['1']};
|
|
41
|
+
`;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { createContext, Dispatch, useContext } from 'react';
|
|
3
|
+
import { Tense, Unit } from '../types';
|
|
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
|
+
disabledOrReadOnly: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function reducer(state: DateRangePickerState, action: Action): DateRangePickerState {
|
|
23
|
+
if (state.disabledOrReadOnly && action.type !== 'toggle_disable_or_readonly') {
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
switch (action.type) {
|
|
28
|
+
case 'toggle_disable_or_readonly':
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
disabledOrReadOnly: action.payload.disabledOrReadOnly,
|
|
32
|
+
};
|
|
33
|
+
case 'toggle_quick_select_popover':
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
quickSelect: { ...state.quickSelect, show: action.payload.toggleQuickSelect },
|
|
37
|
+
};
|
|
38
|
+
case 'toggle_start_date_popover':
|
|
39
|
+
return {
|
|
40
|
+
...state,
|
|
41
|
+
friendlyRange: undefined,
|
|
42
|
+
showStartDate: action.payload.toggleStartDate,
|
|
43
|
+
};
|
|
44
|
+
case 'toggle_end_date_popover':
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
friendlyRange: undefined,
|
|
48
|
+
showEndDate: action.payload.toggleEndDate,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
case 'set_absolute_start_date':
|
|
52
|
+
return {
|
|
53
|
+
...state,
|
|
54
|
+
start: action.payload.startDate,
|
|
55
|
+
// If endDate is before new startDate, set endDate to new startDate
|
|
56
|
+
end: state.end < action.payload.startDate ? action.payload.startDate : state.end,
|
|
57
|
+
friendlyStartDate: undefined,
|
|
58
|
+
friendlyRange: undefined,
|
|
59
|
+
};
|
|
60
|
+
case 'set_relative_start_date':
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
start: action.payload.startDate,
|
|
64
|
+
friendlyStartDate: action.payload.friendlyStartDate,
|
|
65
|
+
friendlyRange: undefined,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
case 'set_quick_select':
|
|
69
|
+
return {
|
|
70
|
+
...state,
|
|
71
|
+
quickSelect: { ...state.quickSelect, ...action.payload.quickSelect },
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
case 'set_absolute_end_date':
|
|
75
|
+
return {
|
|
76
|
+
...state,
|
|
77
|
+
end: action.payload.endDate,
|
|
78
|
+
friendlyEndDate: undefined,
|
|
79
|
+
friendlyRange: undefined,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
case 'set_relative_end_date':
|
|
83
|
+
return {
|
|
84
|
+
...state,
|
|
85
|
+
end: action.payload.endDate,
|
|
86
|
+
friendlyEndDate: action.payload.friendlyEndDate,
|
|
87
|
+
friendlyRange: undefined,
|
|
88
|
+
};
|
|
89
|
+
case 'set_range':
|
|
90
|
+
return {
|
|
91
|
+
...state,
|
|
92
|
+
end: action.payload.endDate,
|
|
93
|
+
start: action.payload.startDate,
|
|
94
|
+
friendlyRange: action.payload.friendlyRange,
|
|
95
|
+
friendlyEndDate: undefined,
|
|
96
|
+
friendlyStartDate: undefined,
|
|
97
|
+
quickSelect: { ...state.quickSelect, show: false },
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type Action =
|
|
103
|
+
| { type: 'toggle_quick_select_popover'; payload: { toggleQuickSelect: boolean } }
|
|
104
|
+
| { type: 'toggle_start_date_popover'; payload: { toggleStartDate: boolean } }
|
|
105
|
+
| { type: 'toggle_end_date_popover'; payload: { toggleEndDate: boolean } }
|
|
106
|
+
| { type: 'set_quick_select'; payload: { quickSelect: DateRangePickerState['quickSelect'] } }
|
|
107
|
+
| { type: 'set_relative_start_date'; payload: { startDate: DateTime; friendlyStartDate?: string } }
|
|
108
|
+
| { type: 'set_absolute_start_date'; payload: { startDate: DateTime } }
|
|
109
|
+
| { type: 'set_relative_end_date'; payload: { endDate: DateTime; friendlyEndDate?: string } }
|
|
110
|
+
| { type: 'set_absolute_end_date'; payload: { endDate: DateTime } }
|
|
111
|
+
| { type: 'set_range'; payload: { startDate: DateTime; endDate: DateTime; friendlyRange?: string } }
|
|
112
|
+
| { type: 'toggle_disable_or_readonly'; payload: { disabledOrReadOnly: boolean } };
|
|
113
|
+
|
|
114
|
+
export const DateRangePickerContext = createContext<DateRangePickerState | null>(null);
|
|
115
|
+
export const DateRangePickerDispatchContext = createContext<Dispatch<Action> | null>(null);
|
|
116
|
+
|
|
117
|
+
export function useDateRangePickerContext() {
|
|
118
|
+
return useContext(DateRangePickerContext);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function useDateRangePickerDispatchContext() {
|
|
122
|
+
return useContext(DateRangePickerDispatchContext);
|
|
123
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { defaultInputProps, defaultInputPropsFactory, ControlledInputProps } from '../../InputProps';
|
|
3
|
+
import { useController } from 'react-hook-form';
|
|
4
|
+
import { GenericDateRangePicker, DateRangePickerProps } from './Generic';
|
|
5
|
+
import { Label, ErrorMessage, InputWrapper, Description } from '../../layout';
|
|
6
|
+
import { Container } from './style';
|
|
7
|
+
import { Skeleton } from '../../../../components';
|
|
8
|
+
|
|
9
|
+
export type ControlledDateRangePickerProps = ControlledInputProps & DateRangePickerProps;
|
|
10
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledDateRangePickerProps>(defaultInputProps);
|
|
11
|
+
|
|
12
|
+
export const ControlledDateRangePicker: FC<ControlledDateRangePickerProps> = (props) => {
|
|
13
|
+
const { label, name, size, hint, control, disabled, readOnly, required, loading, id, description, defaultValue } =
|
|
14
|
+
defaultsApplier(props);
|
|
15
|
+
|
|
16
|
+
const [showError, setShowError] = useState<boolean>(true);
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
field,
|
|
20
|
+
fieldState: { error },
|
|
21
|
+
} = useController({
|
|
22
|
+
name,
|
|
23
|
+
control,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const handleOnFocus = () => {
|
|
27
|
+
setShowError(false);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handleOnBlur = () => {
|
|
31
|
+
field.onBlur();
|
|
32
|
+
setShowError(true);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<InputWrapper>
|
|
37
|
+
<Container>
|
|
38
|
+
{label && (
|
|
39
|
+
<Label
|
|
40
|
+
required={required}
|
|
41
|
+
hint={hint}
|
|
42
|
+
htmlFor={name}
|
|
43
|
+
error={!!error}
|
|
44
|
+
size={size}
|
|
45
|
+
text={label}
|
|
46
|
+
disabled={disabled}
|
|
47
|
+
position="top"
|
|
48
|
+
/>
|
|
49
|
+
)}
|
|
50
|
+
{loading ? (
|
|
51
|
+
<Skeleton variant="text" width="100%" height="38px" />
|
|
52
|
+
) : (
|
|
53
|
+
<GenericDateRangePicker
|
|
54
|
+
onChange={field.onChange}
|
|
55
|
+
onBlur={handleOnBlur}
|
|
56
|
+
onFocus={handleOnFocus}
|
|
57
|
+
id={id}
|
|
58
|
+
name={name}
|
|
59
|
+
readOnly={readOnly}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
defaultValue={defaultValue}
|
|
62
|
+
required={required}
|
|
63
|
+
size={size}
|
|
64
|
+
hasError={!!error}
|
|
65
|
+
value={field.value}
|
|
66
|
+
hasDescription={!!description}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
{showError && error?.message && <ErrorMessage message={error.message} />}
|
|
70
|
+
</Container>
|
|
71
|
+
{description && <Description description={description} inputName={name} />}
|
|
72
|
+
</InputWrapper>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { GenericDateRangePicker, GenericDateRangePickerProps } from './Generic';
|
|
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: GenericDateRangePicker,
|
|
14
|
+
args: {
|
|
15
|
+
readOnly: false,
|
|
16
|
+
hasDescription: false,
|
|
17
|
+
hasError: false,
|
|
18
|
+
},
|
|
19
|
+
} as Meta<GenericDateRangePickerProps>;
|
|
20
|
+
|
|
21
|
+
export const Default: StoryFn<GenericDateRangePickerProps> = (args) => {
|
|
22
|
+
const handleOnChange = () => {};
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Wrapper>
|
|
26
|
+
<GenericDateRangePicker
|
|
27
|
+
hasDescription={args.hasDescription}
|
|
28
|
+
hasError={args.hasError}
|
|
29
|
+
name="daterangepicker"
|
|
30
|
+
readOnly={args.readOnly}
|
|
31
|
+
id="date"
|
|
32
|
+
onChange={handleOnChange}
|
|
33
|
+
value="2021-01-01"
|
|
34
|
+
/>
|
|
35
|
+
</Wrapper>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -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,167 @@
|
|
|
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 } from './QuickSelect';
|
|
10
|
+
import { Tense, Unit } from '../types';
|
|
11
|
+
import { DateRangePickerContainer, QuickSelectContainer, ItemContainer } from './style';
|
|
12
|
+
import { DateSelector } from './DateSelector';
|
|
13
|
+
import { DateRangePickerDispatchContext, DateRangePickerContext, reducer } from './Context';
|
|
14
|
+
import { useTheme } from '../../../../hooks';
|
|
15
|
+
import { GenericInputProps } from '../../InputProps';
|
|
16
|
+
|
|
17
|
+
export type DateRange = { start: DateTime<true>; end: DateTime<true> };
|
|
18
|
+
|
|
19
|
+
export interface DateRangePickerProps {
|
|
20
|
+
defaultValue?: DateRange;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
id: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type GenericDateRangePickerProps = GenericInputProps<string, HTMLInputElement> & DateRangePickerProps;
|
|
27
|
+
export const GenericDateRangePicker: FC<GenericDateRangePickerProps> = ({
|
|
28
|
+
readOnly = false,
|
|
29
|
+
disabled = false,
|
|
30
|
+
id,
|
|
31
|
+
onChange,
|
|
32
|
+
defaultValue = {
|
|
33
|
+
start: DateTime.local().startOf('day'),
|
|
34
|
+
end: DateTime.local().endOf('day'),
|
|
35
|
+
},
|
|
36
|
+
}) => {
|
|
37
|
+
const [state, dispatch] = useReducer(reducer, {
|
|
38
|
+
quickSelect: {
|
|
39
|
+
show: false,
|
|
40
|
+
tense: Tense.Last,
|
|
41
|
+
step: 15,
|
|
42
|
+
unit: Unit.Minutes,
|
|
43
|
+
},
|
|
44
|
+
showStartDate: false,
|
|
45
|
+
showEndDate: false,
|
|
46
|
+
start: defaultValue.start,
|
|
47
|
+
end: defaultValue.end,
|
|
48
|
+
friendlyRange: undefined,
|
|
49
|
+
disabledOrReadOnly: disabled || readOnly,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (disabled || readOnly) {
|
|
54
|
+
dispatch({ type: 'toggle_disable_or_readonly', payload: { disabledOrReadOnly: true } });
|
|
55
|
+
} else {
|
|
56
|
+
dispatch({ type: 'toggle_disable_or_readonly', payload: { disabledOrReadOnly: false } });
|
|
57
|
+
}
|
|
58
|
+
}, [disabled, readOnly]);
|
|
59
|
+
|
|
60
|
+
const theme = useTheme();
|
|
61
|
+
const [hasError, setHasError] = useState<boolean>(false);
|
|
62
|
+
const iconColor = disabled ? theme.colors.backgroundAccent : theme.colors.white;
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (state.start > state.end) {
|
|
66
|
+
setHasError(true);
|
|
67
|
+
} else {
|
|
68
|
+
setHasError(false);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (onChange) {
|
|
72
|
+
const event = {
|
|
73
|
+
target: { value: { start: state.start.toISO(), end: state.end.toISO() }, name },
|
|
74
|
+
preventDefault: () => {},
|
|
75
|
+
stopPropagation: () => {},
|
|
76
|
+
} as unknown as React.ChangeEvent<HTMLInputElement>;
|
|
77
|
+
onChange(event);
|
|
78
|
+
}
|
|
79
|
+
}, [state.start, state.end]);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<DateRangePickerContext.Provider value={state}>
|
|
83
|
+
<DateRangePickerDispatchContext.Provider value={dispatch}>
|
|
84
|
+
<DateRangePickerContainer
|
|
85
|
+
hasError={hasError}
|
|
86
|
+
isOpen={state.quickSelect.show || state.showStartDate || state.showEndDate}
|
|
87
|
+
>
|
|
88
|
+
<Popover
|
|
89
|
+
open={state.quickSelect.show}
|
|
90
|
+
onOpenChange={(open) =>
|
|
91
|
+
dispatch({ type: 'toggle_quick_select_popover', payload: { toggleQuickSelect: open } })
|
|
92
|
+
}
|
|
93
|
+
>
|
|
94
|
+
<Popover.Trigger asChild>
|
|
95
|
+
<QuickSelectContainer
|
|
96
|
+
readOnly={readOnly}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
onClick={() =>
|
|
99
|
+
dispatch({
|
|
100
|
+
type: 'toggle_quick_select_popover',
|
|
101
|
+
payload: { toggleQuickSelect: !state.quickSelect.show },
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
>
|
|
105
|
+
<CalendarIcon fill={iconColor} size={18} />
|
|
106
|
+
<DownIcon fill={iconColor} size={18} />
|
|
107
|
+
</QuickSelectContainer>
|
|
108
|
+
</Popover.Trigger>
|
|
109
|
+
<Popover.Content>
|
|
110
|
+
<QuickSelect id={`quick-select-${id}`} />
|
|
111
|
+
</Popover.Content>
|
|
112
|
+
</Popover>
|
|
113
|
+
<Popover
|
|
114
|
+
open={state.showStartDate}
|
|
115
|
+
onOpenChange={(open) => {
|
|
116
|
+
dispatch({ type: 'toggle_start_date_popover', payload: { toggleStartDate: open } });
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<Popover.Trigger asChild>
|
|
120
|
+
<ItemContainer
|
|
121
|
+
disabled={disabled}
|
|
122
|
+
readOnly={readOnly}
|
|
123
|
+
onClick={() => {
|
|
124
|
+
dispatch({ type: 'toggle_start_date_popover', payload: { toggleStartDate: !state.showStartDate } });
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
{state.friendlyStartDate ??
|
|
128
|
+
state.friendlyRange ??
|
|
129
|
+
// e.g. Aug 2, 2023 @ 00:00:00.000
|
|
130
|
+
state.start.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')}
|
|
131
|
+
</ItemContainer>
|
|
132
|
+
</Popover.Trigger>
|
|
133
|
+
<Popover.Content>
|
|
134
|
+
<DateSelector isStart />
|
|
135
|
+
</Popover.Content>
|
|
136
|
+
</Popover>
|
|
137
|
+
{!state.friendlyRange && (
|
|
138
|
+
<>
|
|
139
|
+
<ArrowRightIcon fill={iconColor} size={18} style={{ marginLeft: '10px', marginRight: '10px' }} />
|
|
140
|
+
<Popover
|
|
141
|
+
open={state.showEndDate}
|
|
142
|
+
onOpenChange={(open) => {
|
|
143
|
+
dispatch({ type: 'toggle_end_date_popover', payload: { toggleEndDate: open } });
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<Popover.Trigger asChild>
|
|
147
|
+
<ItemContainer
|
|
148
|
+
disabled={disabled}
|
|
149
|
+
readOnly={readOnly}
|
|
150
|
+
onClick={() => {
|
|
151
|
+
dispatch({ type: 'toggle_end_date_popover', payload: { toggleEndDate: !state.showEndDate } });
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
{state.friendlyEndDate ?? state.end.toFormat('LLL d, yyyy @ HH:mm:ss.SSS')}
|
|
155
|
+
</ItemContainer>
|
|
156
|
+
</Popover.Trigger>
|
|
157
|
+
<Popover.Content>
|
|
158
|
+
<DateSelector isStart={false} />
|
|
159
|
+
</Popover.Content>
|
|
160
|
+
</Popover>
|
|
161
|
+
</>
|
|
162
|
+
)}
|
|
163
|
+
</DateRangePickerContainer>
|
|
164
|
+
</DateRangePickerDispatchContext.Provider>
|
|
165
|
+
</DateRangePickerContext.Provider>
|
|
166
|
+
);
|
|
167
|
+
};
|