@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,170 @@
|
|
|
1
|
+
import { FC, useMemo } from 'react';
|
|
2
|
+
import { Button, Divider, SelectField, TextField } from '../../../../../components';
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
4
|
+
import { DateTime } from 'luxon';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
7
|
+
import { Container, StyledForm, InputsContainer, QuickSelectGrid, TenseGrid } from './style';
|
|
8
|
+
|
|
9
|
+
export type timeDirection = 'past' | 'future' | 'pastAndFuture';
|
|
10
|
+
import { Tense, Unit } from '../../types';
|
|
11
|
+
|
|
12
|
+
interface RelativePickerProps {
|
|
13
|
+
onChange: (value: DateTime, friendlyName?: string) => void;
|
|
14
|
+
timeDirection?: timeDirection;
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface QuickSelectOption {
|
|
19
|
+
unit: Unit;
|
|
20
|
+
step: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const quickSelectOptions: QuickSelectOption[] = [
|
|
24
|
+
{ unit: Unit.Minutes, step: 5 },
|
|
25
|
+
{ unit: Unit.Minutes, step: 15 },
|
|
26
|
+
{ unit: Unit.Minutes, step: 30 },
|
|
27
|
+
{ unit: Unit.Hours, step: 1 },
|
|
28
|
+
{ unit: Unit.Days, step: 1 },
|
|
29
|
+
{ unit: Unit.Days, step: 7 },
|
|
30
|
+
{ unit: Unit.Days, step: 30 },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export const RelativePicker: FC<RelativePickerProps> = ({ onChange, id, timeDirection = 'pastAndFuture' }) => {
|
|
34
|
+
interface IFormInputs {
|
|
35
|
+
step: number;
|
|
36
|
+
tense: Tense;
|
|
37
|
+
unit: Unit;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const validationSchema = useMemo(
|
|
41
|
+
() =>
|
|
42
|
+
z.object({
|
|
43
|
+
tense: z.nativeEnum(Tense),
|
|
44
|
+
step: z.number().positive(),
|
|
45
|
+
unit: z.nativeEnum(Unit),
|
|
46
|
+
}),
|
|
47
|
+
[],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const defaultTense = () => {
|
|
51
|
+
switch (timeDirection) {
|
|
52
|
+
case 'past':
|
|
53
|
+
return Tense.Last;
|
|
54
|
+
case 'future':
|
|
55
|
+
return Tense.Next;
|
|
56
|
+
case 'pastAndFuture':
|
|
57
|
+
return Tense.Last;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const { control, handleSubmit } = useForm<IFormInputs>({
|
|
62
|
+
mode: 'onSubmit',
|
|
63
|
+
defaultValues: {
|
|
64
|
+
tense: defaultTense(),
|
|
65
|
+
},
|
|
66
|
+
resolver: zodResolver(validationSchema),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const handleChange = ({ tense, step, unit }: IFormInputs) => {
|
|
70
|
+
const isPast = tense === Tense.Last;
|
|
71
|
+
|
|
72
|
+
const friendlyTense = tense === Tense.Next ? 'from now' : 'ago';
|
|
73
|
+
const friendlyRangeName = `${step} ${unit.toLowerCase()} ${friendlyTense}`;
|
|
74
|
+
|
|
75
|
+
let selectedDate = DateTime.now();
|
|
76
|
+
selectedDate = isPast ? selectedDate.minus({ [unit]: step }) : selectedDate.plus({ [unit]: step });
|
|
77
|
+
|
|
78
|
+
onChange(selectedDate, friendlyRangeName);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
<Container>
|
|
84
|
+
{/* Relative manual selection */}
|
|
85
|
+
<StyledForm onSubmit={handleSubmit(handleChange)}>
|
|
86
|
+
<InputsContainer>
|
|
87
|
+
<SelectField
|
|
88
|
+
control={control}
|
|
89
|
+
readOnly={timeDirection !== 'pastAndFuture'}
|
|
90
|
+
name="tense"
|
|
91
|
+
render={(selectedItems) => (
|
|
92
|
+
<div>
|
|
93
|
+
{selectedItems.length > 0
|
|
94
|
+
? Object.values(Tense).find((v) => v === selectedItems[0].value)
|
|
95
|
+
: Tense.Last}
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
<SelectField.OptionGroup>
|
|
100
|
+
{Object.values(Tense).map((val: string) => (
|
|
101
|
+
<SelectField.Option key={`relative-tense-${val}-${id}`} value={val} label={val}>
|
|
102
|
+
<span>{val}</span>
|
|
103
|
+
</SelectField.Option>
|
|
104
|
+
))}
|
|
105
|
+
</SelectField.OptionGroup>
|
|
106
|
+
</SelectField>
|
|
107
|
+
<TextField control={control} type="number" name="step" />
|
|
108
|
+
<SelectField
|
|
109
|
+
control={control}
|
|
110
|
+
name="unit"
|
|
111
|
+
render={(selectedItems) => (
|
|
112
|
+
<div>
|
|
113
|
+
{selectedItems.length > 0
|
|
114
|
+
? Object.values(Unit).find((v) => v === selectedItems[0].value)
|
|
115
|
+
: Unit.Minutes}
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
<SelectField.OptionGroup>
|
|
120
|
+
{Object.values(Unit).map((val: string) => (
|
|
121
|
+
<SelectField.Option key={`relative-unit-${val}-${id}`} value={val} label={val}>
|
|
122
|
+
<span>{val}</span>
|
|
123
|
+
</SelectField.Option>
|
|
124
|
+
))}
|
|
125
|
+
</SelectField.OptionGroup>
|
|
126
|
+
</SelectField>
|
|
127
|
+
</InputsContainer>
|
|
128
|
+
<Button type="submit">Apply</Button>
|
|
129
|
+
</StyledForm>
|
|
130
|
+
|
|
131
|
+
<Divider fullWidth />
|
|
132
|
+
<h4>Commonly used</h4>
|
|
133
|
+
<TenseGrid>
|
|
134
|
+
{timeDirection !== 'future' && (
|
|
135
|
+
<div>
|
|
136
|
+
<h5>Past</h5>
|
|
137
|
+
<QuickSelectGrid>
|
|
138
|
+
{quickSelectOptions.map(({ unit, step }) => (
|
|
139
|
+
<li
|
|
140
|
+
key={`quick-select-${unit}-${step}-${id}-last`}
|
|
141
|
+
onClick={() => handleChange({ unit, step, tense: Tense.Last })}
|
|
142
|
+
>
|
|
143
|
+
{step} {unit.toLowerCase()} ago
|
|
144
|
+
</li>
|
|
145
|
+
))}
|
|
146
|
+
</QuickSelectGrid>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{timeDirection !== 'past' && (
|
|
151
|
+
<div>
|
|
152
|
+
<h5>Future</h5>
|
|
153
|
+
<QuickSelectGrid>
|
|
154
|
+
{quickSelectOptions.map(({ unit, step }) => (
|
|
155
|
+
<li
|
|
156
|
+
key={`quick-select-${unit}-${step}-${id}-last`}
|
|
157
|
+
onClick={() => handleChange({ unit, step, tense: Tense.Next })}
|
|
158
|
+
>
|
|
159
|
+
{step} {unit.toLowerCase()} from now
|
|
160
|
+
</li>
|
|
161
|
+
))}
|
|
162
|
+
</QuickSelectGrid>
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
</TenseGrid>
|
|
166
|
+
</Container>
|
|
167
|
+
{/* Quick select*/}
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { styled } from '../../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
align-items: flex-start;
|
|
7
|
+
justify-content: flex-start;
|
|
8
|
+
|
|
9
|
+
h4,
|
|
10
|
+
h5 {
|
|
11
|
+
margin-bottom: ${({ theme }) => theme.spacing['0_5']};
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const StyledForm = styled.form`
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const InputsContainer = styled.div`
|
|
23
|
+
display: grid;
|
|
24
|
+
grid-template-columns: 0.5fr 0.5fr 1fr;
|
|
25
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
26
|
+
align-items: center;
|
|
27
|
+
div {
|
|
28
|
+
margin-bottom: 0;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
export const TenseGrid = styled.div`
|
|
33
|
+
display: grid;
|
|
34
|
+
width: 100%;
|
|
35
|
+
grid-template-columns: repeat(2, 1fr);
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export const QuickSelectGrid = styled.ul`
|
|
39
|
+
display: grid;
|
|
40
|
+
|
|
41
|
+
grid-auto-flow: column;
|
|
42
|
+
grid-template-rows: repeat(5, 1fr);
|
|
43
|
+
grid-template-columns: repeat(2, 1fr);
|
|
44
|
+
gap: ${({ theme }) => `0 ${theme.spacing[1]}`};
|
|
45
|
+
|
|
46
|
+
li {
|
|
47
|
+
text-align: left;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { TimePicker, TimePickerProps } from '.';
|
|
4
|
+
import { DateTime } from 'luxon';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Inputs/TimePicker',
|
|
8
|
+
component: TimePicker,
|
|
9
|
+
args: {
|
|
10
|
+
readOnly: false,
|
|
11
|
+
hasDescription: false,
|
|
12
|
+
hasError: false,
|
|
13
|
+
},
|
|
14
|
+
} as Meta<TimePickerProps>;
|
|
15
|
+
|
|
16
|
+
export const Default: StoryFn<TimePickerProps> = () => {
|
|
17
|
+
const [selectedTime, setSelectedTime] = React.useState<DateTime>(DateTime.local().startOf('day'));
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
timepicker should not be used separately, instead use datepicker and select a time format
|
|
22
|
+
<TimePicker selectedDate={selectedTime} onChange={(newTime) => setSelectedTime(newTime)} />
|
|
23
|
+
</>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FC, useLayoutEffect } from 'react';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import { List, Item } from './style';
|
|
4
|
+
|
|
5
|
+
export interface TimePickerProps {
|
|
6
|
+
onChange: (date: DateTime) => void;
|
|
7
|
+
selectedDate: DateTime;
|
|
8
|
+
|
|
9
|
+
// Interval in minutes between each time slot
|
|
10
|
+
// e.g. interval = 30 means each slot is 30 minutes apart
|
|
11
|
+
// resulting in 48 slots
|
|
12
|
+
interval?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const TimePicker: FC<TimePickerProps> = ({ onChange, selectedDate, interval = 30 }) => {
|
|
16
|
+
let date = selectedDate.startOf('day');
|
|
17
|
+
|
|
18
|
+
// calculate number of slots
|
|
19
|
+
const numberOfSlots = Math.floor((24 * 60) / interval);
|
|
20
|
+
|
|
21
|
+
// scroll selected time into view using ref
|
|
22
|
+
useLayoutEffect(() => {}, [selectedDate]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<List role="listbox">
|
|
26
|
+
{Array.from({ length: numberOfSlots }).map(() => {
|
|
27
|
+
const nextTime = date.plus({ minutes: interval });
|
|
28
|
+
const formattedTime = date.toFormat('HH:mm');
|
|
29
|
+
const isSelected = date.hasSame(selectedDate, 'hour') && date.hasSame(selectedDate, 'minute');
|
|
30
|
+
const returnValue = date;
|
|
31
|
+
date = nextTime;
|
|
32
|
+
return (
|
|
33
|
+
<Item role="option" isSelected={isSelected} key={formattedTime} onClick={() => onChange(returnValue)}>
|
|
34
|
+
{formattedTime}
|
|
35
|
+
</Item>
|
|
36
|
+
);
|
|
37
|
+
})}
|
|
38
|
+
</List>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { shade } from 'polished';
|
|
2
|
+
import { styled } from '../../../../../styled';
|
|
3
|
+
|
|
4
|
+
export const List = styled.ul`
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
width: fit-content;
|
|
8
|
+
flex-grow: 1;
|
|
9
|
+
align-items: center;
|
|
10
|
+
height: 100%;
|
|
11
|
+
gap: ${({ theme }) => theme.spacing['0_5']};
|
|
12
|
+
max-height: 300px;
|
|
13
|
+
overflow-x: hidden;
|
|
14
|
+
overflow-y: scroll;
|
|
15
|
+
padding: ${({ theme }) => `${theme.spacing[1]} ${theme.spacing['0_75']}`};
|
|
16
|
+
scrollbar-width: thin;
|
|
17
|
+
scrollbar-color: #69707d80 #0000;
|
|
18
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
19
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
20
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export const Item = styled.li<{ isSelected: boolean }>`
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
background-color: ${({ theme, isSelected }) => (isSelected ? shade(0.5, theme.colors.primary) : 'transparent')};
|
|
26
|
+
border: 1px solid ${({ theme, isSelected }) => (isSelected ? theme.colors.primary : 'transparent')};
|
|
27
|
+
padding: ${({ theme }) => theme.spacing['0_5']};
|
|
28
|
+
border-radius: ${({ theme }) => theme.borderRadius.small};
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
background-color: ${({ theme, isSelected }) =>
|
|
32
|
+
isSelected ? shade(0.5, theme.colors.primary) : theme.colors.background};
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
4
|
+
import { DurationProps, GenericDurationField } from './Generic';
|
|
5
|
+
import { Container } from './style';
|
|
6
|
+
import { InputWrapper, Description, ErrorMessage, Label } from '../layout';
|
|
7
|
+
|
|
8
|
+
export type ControlledDurationFieldProps = DurationProps & ControlledInputProps;
|
|
9
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledDurationFieldProps>(defaultInputProps);
|
|
10
|
+
|
|
11
|
+
export const ControlledDurationField: FC<ControlledDurationFieldProps> = (props) => {
|
|
12
|
+
const { name, required, readOnly, disabled, size, label, placeholder, control, hint, description, canClear } =
|
|
13
|
+
defaultsApplier(props);
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
field,
|
|
17
|
+
fieldState: { error },
|
|
18
|
+
} = useController({
|
|
19
|
+
name,
|
|
20
|
+
control,
|
|
21
|
+
});
|
|
22
|
+
const [showError, setShowError] = useState<boolean>(false);
|
|
23
|
+
|
|
24
|
+
const handleOnBlur = () => {
|
|
25
|
+
field.onBlur();
|
|
26
|
+
setShowError(true);
|
|
27
|
+
};
|
|
28
|
+
const handleOnFocus = () => {
|
|
29
|
+
setShowError(false);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<InputWrapper>
|
|
34
|
+
<Container>
|
|
35
|
+
{label && (
|
|
36
|
+
<Label
|
|
37
|
+
text={label}
|
|
38
|
+
htmlFor={name}
|
|
39
|
+
error={false}
|
|
40
|
+
disabled={disabled}
|
|
41
|
+
required={required}
|
|
42
|
+
position="top"
|
|
43
|
+
size="medium"
|
|
44
|
+
hint={hint}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
|
|
48
|
+
<GenericDurationField
|
|
49
|
+
readOnly={readOnly}
|
|
50
|
+
size={size}
|
|
51
|
+
name={name}
|
|
52
|
+
id={name}
|
|
53
|
+
ref={field.ref}
|
|
54
|
+
onBlur={handleOnBlur}
|
|
55
|
+
onFocus={handleOnFocus}
|
|
56
|
+
onChange={field.onChange}
|
|
57
|
+
placeholder={placeholder}
|
|
58
|
+
hasError={!!error}
|
|
59
|
+
hasDescription={!!description}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
value={field.value}
|
|
62
|
+
canClear={canClear}
|
|
63
|
+
/>
|
|
64
|
+
{error && error.message && showError && <ErrorMessage message={error.message} />}
|
|
65
|
+
</Container>
|
|
66
|
+
{description && <Description description={description} inputName={name} />}
|
|
67
|
+
</InputWrapper>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DurationField, DurationFieldProps } from '../../../components';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { StoryFn, Meta } from '@storybook/react';
|
|
5
|
+
import { useForm, SubmitHandler } from 'react-hook-form';
|
|
6
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'Inputs/DurationField',
|
|
10
|
+
component: DurationField,
|
|
11
|
+
args: {
|
|
12
|
+
label: 'Duration',
|
|
13
|
+
placeholder: 'this is the placeholder',
|
|
14
|
+
description: 'This is the description',
|
|
15
|
+
hint: 'this is the hint',
|
|
16
|
+
disabled: false,
|
|
17
|
+
readOnly: false,
|
|
18
|
+
required: false,
|
|
19
|
+
size: 'medium',
|
|
20
|
+
},
|
|
21
|
+
} as Meta<DurationFieldProps>;
|
|
22
|
+
|
|
23
|
+
export const Default: StoryFn<DurationFieldProps> = (args) => {
|
|
24
|
+
const [result, setResult] = React.useState<number | undefined>(undefined);
|
|
25
|
+
|
|
26
|
+
const validationSchema = z.object({
|
|
27
|
+
duration: z.number().positive(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { control, handleSubmit } = useForm<z.infer<typeof validationSchema>>({
|
|
31
|
+
resolver: zodResolver(validationSchema),
|
|
32
|
+
});
|
|
33
|
+
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = ({ duration }) => {
|
|
34
|
+
setResult(duration);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
40
|
+
<DurationField
|
|
41
|
+
loading={false}
|
|
42
|
+
control={control}
|
|
43
|
+
description={args.description}
|
|
44
|
+
hint={args.hint}
|
|
45
|
+
label={args.label}
|
|
46
|
+
name="duration"
|
|
47
|
+
placeholder={args.placeholder}
|
|
48
|
+
required={args.required}
|
|
49
|
+
size={args.size}
|
|
50
|
+
disabled={args.disabled}
|
|
51
|
+
readOnly={args.readOnly}
|
|
52
|
+
/>
|
|
53
|
+
</form>
|
|
54
|
+
<p>Result: {result ? result : ''}</p>
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { SelectField, TextField } from '..';
|
|
2
|
+
import { useForm, SubmitHandler, useFieldArray } from 'react-hook-form';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { MouseEvent, useState, forwardRef, useEffect } from 'react';
|
|
5
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
6
|
+
import { DurationContainer, FieldContainer, InnerContent, ButtonContainer } from './style';
|
|
7
|
+
import { Button, IconButton, Popover, Tooltip } from '../../../components';
|
|
8
|
+
import { Duration } from 'luxon';
|
|
9
|
+
import { GenericInputPropsFunctionHandlers } from '../InputProps';
|
|
10
|
+
import {
|
|
11
|
+
AiOutlineDelete as RemoveIcon,
|
|
12
|
+
AiOutlinePlus as AddIcon,
|
|
13
|
+
AiOutlineClose as ResetIcon,
|
|
14
|
+
AiOutlineDown as ArrowIcon,
|
|
15
|
+
} from 'react-icons/ai';
|
|
16
|
+
|
|
17
|
+
const durationObjectToUnitAndValue = (millis: number): { unit: LuxonUnit; value: number }[] => {
|
|
18
|
+
// fallback, otherwise there is is no option to set a new duration.
|
|
19
|
+
if (millis === 0) {
|
|
20
|
+
return [{ unit: 'milliseconds', value: 0 }];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const obj = Duration.fromMillis(millis).rescale().toObject();
|
|
24
|
+
return Object.entries(obj).map(([unit, value]) => {
|
|
25
|
+
return { unit: unit as LuxonUnit, value: value || 0 };
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export interface DurationProps {
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
canClear?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type LuxonUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
|
|
35
|
+
const luxonUnits = ['milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'] as const;
|
|
36
|
+
|
|
37
|
+
const validationSchema = z.object({
|
|
38
|
+
durations: z.array(
|
|
39
|
+
z.object({
|
|
40
|
+
value: z.number().positive(),
|
|
41
|
+
unit: z.enum(luxonUnits), // Use updated units array
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export type GenericDurationFieldProps = DurationProps & GenericInputPropsFunctionHandlers<number, HTMLDivElement>;
|
|
47
|
+
export const GenericDurationField = forwardRef<HTMLDivElement, GenericDurationFieldProps>(function GenericDurationField(
|
|
48
|
+
{
|
|
49
|
+
onChange,
|
|
50
|
+
hasError,
|
|
51
|
+
value,
|
|
52
|
+
name,
|
|
53
|
+
disabled = false,
|
|
54
|
+
readOnly = false,
|
|
55
|
+
canClear = false,
|
|
56
|
+
placeholder = 'Select a duration',
|
|
57
|
+
onBlur,
|
|
58
|
+
onFocus,
|
|
59
|
+
},
|
|
60
|
+
ref,
|
|
61
|
+
) {
|
|
62
|
+
const { control, handleSubmit, setValue } = useForm<z.infer<typeof validationSchema>>({
|
|
63
|
+
mode: 'onSubmit',
|
|
64
|
+
resolver: zodResolver(validationSchema),
|
|
65
|
+
defaultValues: {
|
|
66
|
+
durations: value || value === 0 ? durationObjectToUnitAndValue(value) : [],
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const { fields, remove: removeField, append: addField } = useFieldArray({ control, name: 'durations' });
|
|
71
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (open && value == undefined && fields.length === 0) {
|
|
75
|
+
addField({ value: 0, unit: 'seconds' });
|
|
76
|
+
}
|
|
77
|
+
}, [open]);
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (value || value == 0) {
|
|
81
|
+
setValue('durations', durationObjectToUnitAndValue(value));
|
|
82
|
+
}
|
|
83
|
+
}, [value]);
|
|
84
|
+
|
|
85
|
+
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = ({ durations }) => {
|
|
86
|
+
const totalDuration = durations.reduce((accumulator, { value, unit }) => {
|
|
87
|
+
const duration = Duration.fromObject({ [unit]: value });
|
|
88
|
+
return accumulator.plus(duration);
|
|
89
|
+
}, Duration.fromMillis(0));
|
|
90
|
+
onChange(totalDuration.toMillis());
|
|
91
|
+
setOpen(false);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const handleReset = (e: MouseEvent) => {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
onChange(undefined as unknown as number);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const formId = `${name}-form`;
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
103
|
+
<Popover.Trigger asChild>
|
|
104
|
+
<DurationContainer
|
|
105
|
+
disabled={disabled}
|
|
106
|
+
readOnly={readOnly}
|
|
107
|
+
aria-disabled={disabled}
|
|
108
|
+
aria-readonly={readOnly}
|
|
109
|
+
ref={ref}
|
|
110
|
+
hasError={hasError}
|
|
111
|
+
aria-labelledby={name}
|
|
112
|
+
onFocus={onFocus}
|
|
113
|
+
onBlur={onBlur}
|
|
114
|
+
onClick={() => !readOnly && !disabled && setOpen(!open)}
|
|
115
|
+
>
|
|
116
|
+
{value ? Duration.fromMillis(value).rescale().toHuman({ listStyle: 'long' }) : placeholder}
|
|
117
|
+
|
|
118
|
+
{canClear && !readOnly && !disabled && value && !open ? (
|
|
119
|
+
<IconButton icon={<ResetIcon />} ariaLabel="Reset duration" onClick={handleReset} />
|
|
120
|
+
) : (
|
|
121
|
+
<ArrowIcon size={16} />
|
|
122
|
+
)}
|
|
123
|
+
</DurationContainer>
|
|
124
|
+
</Popover.Trigger>
|
|
125
|
+
<Popover.Content>
|
|
126
|
+
<InnerContent>
|
|
127
|
+
<form id={formId}>
|
|
128
|
+
<h2>Select a duration</h2>
|
|
129
|
+
{fields.map((field, index) => (
|
|
130
|
+
<FieldContainer hasMultipleFields={fields.length > 1} key={`${name}-${field.id}-${index}`} id={field.id}>
|
|
131
|
+
<TextField
|
|
132
|
+
key={`${name}-${index}-value`}
|
|
133
|
+
name={`durations.${index}.value`}
|
|
134
|
+
control={control}
|
|
135
|
+
type="number"
|
|
136
|
+
/>
|
|
137
|
+
<SelectField
|
|
138
|
+
key={`${name}-${index}-unit`}
|
|
139
|
+
control={control}
|
|
140
|
+
name={`durations.${index}.unit`}
|
|
141
|
+
multiple={false}
|
|
142
|
+
render={(selectedItems) => {
|
|
143
|
+
if (selectedItems.length === 0) {
|
|
144
|
+
return <div>Select...</div>;
|
|
145
|
+
}
|
|
146
|
+
return <div>{selectedItems[0].label}</div>;
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<SelectField.OptionGroup key={`${name}-${index}-option-group`}>
|
|
150
|
+
{luxonUnits.map((unit) => (
|
|
151
|
+
<SelectField.Option key={`${name}-${index}-option-${unit}`} value={unit} label={unit}>
|
|
152
|
+
{unit}
|
|
153
|
+
</SelectField.Option>
|
|
154
|
+
))}
|
|
155
|
+
</SelectField.OptionGroup>
|
|
156
|
+
</SelectField>
|
|
157
|
+
{fields.length !== 1 && (
|
|
158
|
+
<Tooltip key={`${name}-${index}-remove-field`}>
|
|
159
|
+
<Tooltip.Trigger>
|
|
160
|
+
<IconButton ariaLabel="Remove field" icon={<RemoveIcon />} onClick={() => removeField(index)} />
|
|
161
|
+
</Tooltip.Trigger>
|
|
162
|
+
<Tooltip.Content>Remove field</Tooltip.Content>
|
|
163
|
+
</Tooltip>
|
|
164
|
+
)}
|
|
165
|
+
{index === fields.length - 1 && fields.length < luxonUnits.length && (
|
|
166
|
+
<Tooltip key={`${name}-${index}-add-field`}>
|
|
167
|
+
<Tooltip.Trigger>
|
|
168
|
+
<IconButton
|
|
169
|
+
icon={<AddIcon />}
|
|
170
|
+
ariaLabel="Add field"
|
|
171
|
+
onClick={() => addField({ value: 0, unit: 'seconds' })}
|
|
172
|
+
/>
|
|
173
|
+
</Tooltip.Trigger>
|
|
174
|
+
<Tooltip.Content>Add field</Tooltip.Content>
|
|
175
|
+
</Tooltip>
|
|
176
|
+
)}
|
|
177
|
+
</FieldContainer>
|
|
178
|
+
))}
|
|
179
|
+
<ButtonContainer>
|
|
180
|
+
<Button
|
|
181
|
+
form={formId}
|
|
182
|
+
type="submit"
|
|
183
|
+
fullWidth
|
|
184
|
+
onClick={(e) => {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
handleSubmit(onSubmit)();
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
Apply
|
|
190
|
+
</Button>
|
|
191
|
+
</ButtonContainer>
|
|
192
|
+
</form>
|
|
193
|
+
</InnerContent>
|
|
194
|
+
</Popover.Content>
|
|
195
|
+
</Popover>
|
|
196
|
+
);
|
|
197
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Duration } from 'luxon';
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('DurationField - Luxon year conversion bug', () => {
|
|
5
|
+
it('should correctly round-trip 20 years through milliseconds without rescale drift', () => {
|
|
6
|
+
const originalYears = 20;
|
|
7
|
+
const millis = Duration.fromObject({ years: originalYears }).toMillis();
|
|
8
|
+
const rescaled = Duration.fromMillis(millis).rescale().toObject();
|
|
9
|
+
|
|
10
|
+
expect(rescaled).toEqual({ years: originalYears });
|
|
11
|
+
});
|
|
12
|
+
});
|