@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,254 @@
|
|
|
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
|
+
import { Tense, Unit } from '../../types';
|
|
10
|
+
|
|
11
|
+
interface FormInputs {
|
|
12
|
+
tense: string;
|
|
13
|
+
step: number;
|
|
14
|
+
unit: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface QuickSelectProps {
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const QuickSelect: FC<QuickSelectProps> = ({ id }) => {
|
|
22
|
+
const state = useDateRangePickerContext();
|
|
23
|
+
const dispatch = useDateRangePickerDispatchContext();
|
|
24
|
+
|
|
25
|
+
if (!dispatch) {
|
|
26
|
+
throw new Error('useDateRangePickerDispatchContext must be used within a DateRangePickerProvider');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const validationSchema = useMemo(
|
|
30
|
+
() =>
|
|
31
|
+
z.object({
|
|
32
|
+
tense: z.nativeEnum(Tense),
|
|
33
|
+
step: z.number().positive(),
|
|
34
|
+
unit: z.nativeEnum(Unit),
|
|
35
|
+
}),
|
|
36
|
+
[],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const { control, handleSubmit } = useForm<FormInputs>({
|
|
40
|
+
mode: 'onSubmit',
|
|
41
|
+
resolver: zodResolver(validationSchema),
|
|
42
|
+
defaultValues: {
|
|
43
|
+
step: state?.quickSelect.step,
|
|
44
|
+
tense: state?.quickSelect.tense,
|
|
45
|
+
unit: state?.quickSelect.unit,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const onSubmit: SubmitHandler<FormInputs> = ({ tense, step, unit }) => {
|
|
50
|
+
const baseDate =
|
|
51
|
+
tense === Tense.Last ? DateTime.local() : DateTime.local().startOf(unit.toLowerCase() as DateTimeUnit);
|
|
52
|
+
const action = tense === Tense.Last ? 'minus' : 'plus';
|
|
53
|
+
const range = { [unit.toLowerCase()]: step };
|
|
54
|
+
const otherDate = baseDate[action](range);
|
|
55
|
+
|
|
56
|
+
const startDate = tense === Tense.Last ? otherDate : baseDate;
|
|
57
|
+
const endDate = tense === Tense.Last ? baseDate : otherDate;
|
|
58
|
+
const friendlyRangeName = `${tense} ${step} ${unit.toLowerCase()}`;
|
|
59
|
+
|
|
60
|
+
dispatch({
|
|
61
|
+
type: 'set_quick_select',
|
|
62
|
+
payload: {
|
|
63
|
+
quickSelect: {
|
|
64
|
+
show: false,
|
|
65
|
+
tense: tense as Tense,
|
|
66
|
+
step,
|
|
67
|
+
unit: unit as Unit,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
dispatch({
|
|
73
|
+
type: 'set_range',
|
|
74
|
+
payload: {
|
|
75
|
+
startDate,
|
|
76
|
+
endDate,
|
|
77
|
+
friendlyRange: friendlyRangeName,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Container>
|
|
84
|
+
<h4>Quick select</h4>
|
|
85
|
+
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
|
86
|
+
<InputsContainer>
|
|
87
|
+
<SelectField
|
|
88
|
+
control={control}
|
|
89
|
+
name="tense"
|
|
90
|
+
render={(selectedItems) => (
|
|
91
|
+
<div>
|
|
92
|
+
{selectedItems.length > 0 ? Object.values(Tense).find((v) => v === selectedItems[0].value) : Tense.Last}
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
>
|
|
96
|
+
<SelectField.OptionGroup>
|
|
97
|
+
{Object.values(Tense).map((val: string) => (
|
|
98
|
+
<SelectField.Option key={`${val}-${id}`} value={val} label={val}>
|
|
99
|
+
<span>{val}</span>
|
|
100
|
+
</SelectField.Option>
|
|
101
|
+
))}
|
|
102
|
+
</SelectField.OptionGroup>
|
|
103
|
+
</SelectField>
|
|
104
|
+
|
|
105
|
+
<TextField control={control} type="number" name="step" />
|
|
106
|
+
|
|
107
|
+
<SelectField
|
|
108
|
+
control={control}
|
|
109
|
+
name="unit"
|
|
110
|
+
render={(selectedItems) => (
|
|
111
|
+
<div>
|
|
112
|
+
{selectedItems.length > 0
|
|
113
|
+
? Object.values(Unit).find((v) => v === selectedItems[0].value)
|
|
114
|
+
: Unit.Minutes}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
117
|
+
>
|
|
118
|
+
<SelectField.OptionGroup>
|
|
119
|
+
{Object.values(Unit).map((val: string) => (
|
|
120
|
+
<SelectField.Option key={`${val}-${id}`} value={val} label={val}>
|
|
121
|
+
<span>{val}</span>
|
|
122
|
+
</SelectField.Option>
|
|
123
|
+
))}
|
|
124
|
+
</SelectField.OptionGroup>
|
|
125
|
+
</SelectField>
|
|
126
|
+
</InputsContainer>
|
|
127
|
+
<Button type="submit">Apply</Button>
|
|
128
|
+
</StyledForm>
|
|
129
|
+
|
|
130
|
+
<Divider fullWidth />
|
|
131
|
+
<h4>Commonly used</h4>
|
|
132
|
+
<CommonlyUsedGrid>
|
|
133
|
+
<li
|
|
134
|
+
onClick={() =>
|
|
135
|
+
dispatch({
|
|
136
|
+
type: 'set_range',
|
|
137
|
+
payload: {
|
|
138
|
+
startDate: DateTime.local().startOf('day'),
|
|
139
|
+
endDate: DateTime.local().endOf('day'),
|
|
140
|
+
friendlyRange: 'Today',
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
Today
|
|
146
|
+
</li>
|
|
147
|
+
|
|
148
|
+
<li
|
|
149
|
+
onClick={() => {
|
|
150
|
+
dispatch({
|
|
151
|
+
type: 'set_range',
|
|
152
|
+
payload: {
|
|
153
|
+
startDate: DateTime.local().startOf('week'),
|
|
154
|
+
endDate: DateTime.local().endOf('week'),
|
|
155
|
+
friendlyRange: 'This week',
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
This week
|
|
161
|
+
</li>
|
|
162
|
+
<li
|
|
163
|
+
onClick={() => {
|
|
164
|
+
dispatch({
|
|
165
|
+
type: 'set_range',
|
|
166
|
+
payload: {
|
|
167
|
+
startDate: DateTime.local().minus({ minutes: 15 }),
|
|
168
|
+
endDate: DateTime.local(),
|
|
169
|
+
friendlyRange: 'Last 15 minutes',
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
Last 15 minutes
|
|
175
|
+
</li>
|
|
176
|
+
|
|
177
|
+
<li
|
|
178
|
+
onClick={() => {
|
|
179
|
+
dispatch({
|
|
180
|
+
type: 'set_range',
|
|
181
|
+
payload: {
|
|
182
|
+
startDate: DateTime.local().minus({ minutes: 30 }),
|
|
183
|
+
endDate: DateTime.local(),
|
|
184
|
+
friendlyRange: 'Last 30 minutes',
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
Last 30 minutes
|
|
190
|
+
</li>
|
|
191
|
+
|
|
192
|
+
<li
|
|
193
|
+
onClick={() => {
|
|
194
|
+
dispatch({
|
|
195
|
+
type: 'set_range',
|
|
196
|
+
payload: {
|
|
197
|
+
startDate: DateTime.local().minus({ hours: 1 }),
|
|
198
|
+
endDate: DateTime.local(),
|
|
199
|
+
friendlyRange: 'Last hour',
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}}
|
|
203
|
+
>
|
|
204
|
+
Last 1 hour
|
|
205
|
+
</li>
|
|
206
|
+
|
|
207
|
+
<li
|
|
208
|
+
onClick={() => {
|
|
209
|
+
dispatch({
|
|
210
|
+
type: 'set_range',
|
|
211
|
+
payload: {
|
|
212
|
+
startDate: DateTime.local().minus({ hours: 24 }),
|
|
213
|
+
endDate: DateTime.local(),
|
|
214
|
+
friendlyRange: 'Last 24 hours',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
Last 24 hours
|
|
220
|
+
</li>
|
|
221
|
+
|
|
222
|
+
<li
|
|
223
|
+
onClick={() => {
|
|
224
|
+
dispatch({
|
|
225
|
+
type: 'set_range',
|
|
226
|
+
payload: {
|
|
227
|
+
startDate: DateTime.local().minus({ days: 7 }),
|
|
228
|
+
endDate: DateTime.local(),
|
|
229
|
+
friendlyRange: 'Last 7 days',
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
}}
|
|
233
|
+
>
|
|
234
|
+
Last 7 days
|
|
235
|
+
</li>
|
|
236
|
+
|
|
237
|
+
<li
|
|
238
|
+
onClick={() => {
|
|
239
|
+
dispatch({
|
|
240
|
+
type: 'set_range',
|
|
241
|
+
payload: {
|
|
242
|
+
startDate: DateTime.local().minus({ days: 30 }),
|
|
243
|
+
endDate: DateTime.local(),
|
|
244
|
+
friendlyRange: 'Last 30 days',
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
Last 30 days
|
|
250
|
+
</li>
|
|
251
|
+
</CommonlyUsedGrid>
|
|
252
|
+
</Container>
|
|
253
|
+
);
|
|
254
|
+
};
|
|
@@ -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,65 @@
|
|
|
1
|
+
import { styled } from '../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
width: 100%;
|
|
5
|
+
position: relative;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const DateRangePickerContainer = styled.div<{
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
}>`
|
|
12
|
+
width: 100%;
|
|
13
|
+
position: relative;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: row;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justyfy-content: flex-start;
|
|
18
|
+
text-align: left;
|
|
19
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
20
|
+
width: fit-content;
|
|
21
|
+
font-family: inherit;
|
|
22
|
+
outline: 0;
|
|
23
|
+
font-weight: 500;
|
|
24
|
+
text-transform: capitalize;
|
|
25
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
26
|
+
border: 0.1rem solid
|
|
27
|
+
${({ theme, isOpen, hasError }) => {
|
|
28
|
+
if (hasError) return theme.colors.error;
|
|
29
|
+
return isOpen ? theme.colors.primary : theme.colors.backgroundAccent;
|
|
30
|
+
}};
|
|
31
|
+
|
|
32
|
+
&:focus {
|
|
33
|
+
border-color: ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
flex-shrink: 0;
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const ItemContainer = styled.div<{ readOnly: boolean; disabled: boolean }>`
|
|
40
|
+
cursor: ${({ readOnly, disabled }) => {
|
|
41
|
+
if (disabled) return 'not-allowed';
|
|
42
|
+
if (readOnly) return 'default';
|
|
43
|
+
return 'pointer';
|
|
44
|
+
}};
|
|
45
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']}`};
|
|
46
|
+
color: ${({ theme, disabled }) => (disabled ? theme.colors.backgroundAccent : theme.colors.text)};
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
export const QuickSelectContainer = styled.div<{ readOnly: boolean; disabled: boolean }>`
|
|
50
|
+
border-radius: ${({ theme }) => `${theme.borderRadius.medium} 0 0 ${theme.borderRadius.medium};`};
|
|
51
|
+
height: 100%;
|
|
52
|
+
cursor: ${({ readOnly, disabled }) => {
|
|
53
|
+
if (disabled) return 'not-allowed';
|
|
54
|
+
if (readOnly) return 'default';
|
|
55
|
+
return 'pointer';
|
|
56
|
+
}};
|
|
57
|
+
gap: ${({ theme }) => theme.spacing['0_25']};
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
padding: ${({ theme }) => `0 ${theme.spacing['0_75']}`};
|
|
62
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
63
|
+
border-right: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
64
|
+
flex-shrink: 0;
|
|
65
|
+
`;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { DateTime, Interval } from 'luxon';
|
|
2
|
+
import { FC, useCallback, useState } from 'react';
|
|
3
|
+
import { Header, Wrapper, DaysGrid, DayButton, DayWrapper, DayOfWeekGrid } from './style';
|
|
4
|
+
import { IconButton, Tooltip } from '../../../../../components';
|
|
5
|
+
import {
|
|
6
|
+
MdOutlineKeyboardArrowRight as ChevronRightIcon,
|
|
7
|
+
MdOutlineKeyboardArrowLeft as ChevronLeftIcon,
|
|
8
|
+
MdOutlineKeyboardDoubleArrowLeft as DoubleChevronLeftIcon,
|
|
9
|
+
MdOutlineKeyboardDoubleArrowRight as DoubleChevronRightIcon,
|
|
10
|
+
} from 'react-icons/md';
|
|
11
|
+
|
|
12
|
+
interface CalendarProps {
|
|
13
|
+
onDateClick: (date: DateTime) => void;
|
|
14
|
+
selectedDate: DateTime;
|
|
15
|
+
id: string;
|
|
16
|
+
allowedPastDates?: boolean;
|
|
17
|
+
allowedFutureDates?: boolean;
|
|
18
|
+
customDateFilter?: (date: DateTime) => boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const Calendar: FC<CalendarProps> = ({
|
|
22
|
+
onDateClick,
|
|
23
|
+
selectedDate,
|
|
24
|
+
id,
|
|
25
|
+
allowedPastDates = true,
|
|
26
|
+
allowedFutureDates = true,
|
|
27
|
+
customDateFilter,
|
|
28
|
+
}) => {
|
|
29
|
+
const today = DateTime.local().startOf('day');
|
|
30
|
+
const [currentMonth, setCurrentMonth] = useState<DateTime>(selectedDate.startOf('month'));
|
|
31
|
+
|
|
32
|
+
// days of month
|
|
33
|
+
const days = Interval.fromDateTimes(currentMonth, currentMonth.endOf('month'))
|
|
34
|
+
.splitBy({ days: 1 })
|
|
35
|
+
.map((day) => day.start!);
|
|
36
|
+
|
|
37
|
+
const isDateSelectable = useCallback(
|
|
38
|
+
(date: DateTime) => {
|
|
39
|
+
// If past dates are allowed, then all dates up to today are acceptable.
|
|
40
|
+
// If not, then only dates from today onwards are acceptable.
|
|
41
|
+
const isPastAllowed = allowedPastDates ? true : date >= today;
|
|
42
|
+
|
|
43
|
+
// If future dates are allowed, then all dates from today onwards are acceptable.
|
|
44
|
+
// If not, then only dates up to today are acceptable.
|
|
45
|
+
const isFutureAllowed = allowedFutureDates ? true : date <= today;
|
|
46
|
+
|
|
47
|
+
// Check if the date passes the custom filter, if provided.
|
|
48
|
+
const isCustomFilterPassed = customDateFilter ? customDateFilter(date) : true;
|
|
49
|
+
|
|
50
|
+
return isPastAllowed && isFutureAllowed && isCustomFilterPassed;
|
|
51
|
+
},
|
|
52
|
+
[allowedPastDates, allowedFutureDates, customDateFilter, today],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const previousMonth = useCallback(() => {
|
|
56
|
+
const firstDayPreviousMonth = currentMonth.minus({ months: 1 });
|
|
57
|
+
setCurrentMonth(firstDayPreviousMonth);
|
|
58
|
+
}, [currentMonth]);
|
|
59
|
+
|
|
60
|
+
const nextMonth = useCallback(() => {
|
|
61
|
+
const firstDayNextMonth = currentMonth.plus({ months: 1 });
|
|
62
|
+
setCurrentMonth(firstDayNextMonth);
|
|
63
|
+
}, [currentMonth]);
|
|
64
|
+
|
|
65
|
+
const nextYear = useCallback(() => {
|
|
66
|
+
const firstDayNextMonth = currentMonth.plus({ year: 1 });
|
|
67
|
+
setCurrentMonth(firstDayNextMonth);
|
|
68
|
+
}, [currentMonth]);
|
|
69
|
+
|
|
70
|
+
const previousYear = useCallback(() => {
|
|
71
|
+
const firstDayPreviousMonth = currentMonth.minus({ year: 1 });
|
|
72
|
+
setCurrentMonth(firstDayPreviousMonth);
|
|
73
|
+
}, [currentMonth]);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Wrapper>
|
|
77
|
+
<Header style={{ display: 'flex', alignItems: 'center' }}>
|
|
78
|
+
<Tooltip>
|
|
79
|
+
<Tooltip.Trigger>
|
|
80
|
+
<IconButton onClick={previousYear} icon={<DoubleChevronLeftIcon />} ariaLabel="Previous year" />
|
|
81
|
+
</Tooltip.Trigger>
|
|
82
|
+
<Tooltip.Content>Previous year</Tooltip.Content>
|
|
83
|
+
</Tooltip>
|
|
84
|
+
|
|
85
|
+
<Tooltip>
|
|
86
|
+
<Tooltip.Trigger>
|
|
87
|
+
<IconButton onClick={previousMonth} icon={<ChevronLeftIcon />} ariaLabel="Previous month" />
|
|
88
|
+
</Tooltip.Trigger>
|
|
89
|
+
<Tooltip.Content>Previous month</Tooltip.Content>
|
|
90
|
+
</Tooltip>
|
|
91
|
+
|
|
92
|
+
<h2 style={{ flex: '1 1 auto', textAlign: 'center' }}>{currentMonth.toFormat('MMMM yyyy')}</h2>
|
|
93
|
+
|
|
94
|
+
<Tooltip>
|
|
95
|
+
<Tooltip.Trigger>
|
|
96
|
+
<IconButton onClick={nextMonth} icon={<ChevronRightIcon />} ariaLabel="Next month" />
|
|
97
|
+
</Tooltip.Trigger>
|
|
98
|
+
<Tooltip.Content>Next month</Tooltip.Content>
|
|
99
|
+
</Tooltip>
|
|
100
|
+
<Tooltip>
|
|
101
|
+
<Tooltip.Trigger>
|
|
102
|
+
<IconButton onClick={nextYear} icon={<DoubleChevronRightIcon />} ariaLabel="Next year" />
|
|
103
|
+
</Tooltip.Trigger>
|
|
104
|
+
<Tooltip.Content>Next year</Tooltip.Content>
|
|
105
|
+
</Tooltip>
|
|
106
|
+
</Header>
|
|
107
|
+
<DayOfWeekGrid>
|
|
108
|
+
<div>M</div>
|
|
109
|
+
<div>T</div>
|
|
110
|
+
<div>W</div>
|
|
111
|
+
<div>T</div>
|
|
112
|
+
<div>F</div>
|
|
113
|
+
<div>S</div>
|
|
114
|
+
<div>S</div>
|
|
115
|
+
</DayOfWeekGrid>
|
|
116
|
+
<DaysGrid>
|
|
117
|
+
{days.map((day, dayIdx) => {
|
|
118
|
+
const isSelectable = isDateSelectable(day);
|
|
119
|
+
return (
|
|
120
|
+
<DayWrapper key={`${id}-${day?.toString()}`} isFirstDay={dayIdx === 0} dayNumber={day.weekday}>
|
|
121
|
+
<DayButton
|
|
122
|
+
key={`${id}-day-button`}
|
|
123
|
+
type="button"
|
|
124
|
+
disabled={!isSelectable}
|
|
125
|
+
onClick={() => {
|
|
126
|
+
if (isSelectable) {
|
|
127
|
+
const newDate = day.set({
|
|
128
|
+
hour: selectedDate.hour,
|
|
129
|
+
minute: selectedDate.minute,
|
|
130
|
+
second: selectedDate.second,
|
|
131
|
+
millisecond: selectedDate.millisecond,
|
|
132
|
+
});
|
|
133
|
+
onDateClick(newDate);
|
|
134
|
+
}
|
|
135
|
+
}}
|
|
136
|
+
isSelected={day.hasSame(selectedDate, 'day') ?? false}
|
|
137
|
+
isToday={day.hasSame(today, 'day') ?? false}
|
|
138
|
+
isSameMonth={day.hasSame(currentMonth, 'month') ?? false}
|
|
139
|
+
>
|
|
140
|
+
<time key={`${id}-time`} dateTime={day?.toFormat('yyyy-MM-dd')}>
|
|
141
|
+
{day?.toFormat('d')}
|
|
142
|
+
</time>
|
|
143
|
+
</DayButton>
|
|
144
|
+
</DayWrapper>
|
|
145
|
+
);
|
|
146
|
+
})}
|
|
147
|
+
</DaysGrid>
|
|
148
|
+
</Wrapper>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { shade } from 'polished';
|
|
2
|
+
import { styled } from '../../../../../styled';
|
|
3
|
+
|
|
4
|
+
export const Wrapper = styled.div`
|
|
5
|
+
width: 100%;
|
|
6
|
+
min-width: 300px;
|
|
7
|
+
padding: ${({ theme }) => `0 ${theme.spacing[2]}`};
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
export const Header = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const DayButton = styled.button<{ isSelected: boolean; isToday: boolean; isSameMonth?: boolean }>`
|
|
16
|
+
display: flex;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: center;
|
|
19
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
20
|
+
height: 2rem;
|
|
21
|
+
width: 2rem;
|
|
22
|
+
margin-left: auto;
|
|
23
|
+
margin-right: auto;
|
|
24
|
+
background-color: ${({ theme, isSelected }) => (isSelected ? shade(0.5, theme.colors.primary) : 'transparent')};
|
|
25
|
+
border: 1px solid ${({ theme, isSelected }) => (isSelected ? theme.colors.primary : 'transparent')};
|
|
26
|
+
color: white;
|
|
27
|
+
padding: ${({ theme }) => theme.spacing['1_5']};
|
|
28
|
+
margin: 0;
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
background-color: ${({ theme, isSelected }) =>
|
|
32
|
+
isSelected ? shade(0.5, theme.colors.primary) : theme.colors.secondary};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:disabled {
|
|
36
|
+
color: ${({ theme }) => theme.colors.textAlt};
|
|
37
|
+
|
|
38
|
+
&:hover {
|
|
39
|
+
background-color: transparent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
export const DayOfWeekGrid = styled.div`
|
|
45
|
+
display: grid;
|
|
46
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
47
|
+
text-align: center;
|
|
48
|
+
margin-top: ${({ theme }) => theme.spacing['1_5']};
|
|
49
|
+
color: ${({ theme }) => theme.colors.textAlt};
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const DaysGrid = styled.div`
|
|
53
|
+
display: grid;
|
|
54
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
55
|
+
line-height: 1.5;
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
export const DayWrapper = styled.div<{ dayNumber: number; isFirstDay: boolean }>`
|
|
59
|
+
${({ dayNumber, isFirstDay }) => isFirstDay && `grid-column-start: ${dayNumber};`}
|
|
60
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']}`};
|
|
61
|
+
`;
|