@takaro/lib-components 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +7 -0
- package/@types/files.d.ts +23 -0
- package/@types/react-table-config.d.ts +121 -0
- package/Dockerfile.dev +21 -0
- package/package.json +76 -0
- package/public/images/7-days-to-die/logo.png +0 -0
- package/public/images/csmm-icon.png +0 -0
- package/public/images/milk.png +0 -0
- package/public/images/placeholder-01.jpeg +0 -0
- package/public/images/placeholder-02.jpeg +0 -0
- package/public/images/placeholder-03.jpeg +0 -0
- package/public/images/rust/logo.png +0 -0
- package/readme.md +10 -0
- package/src/components/actions/Button/Button.stories.tsx +170 -0
- package/src/components/actions/Button/Button.test.tsx +7 -0
- package/src/components/actions/Button/Button.test.tsx.snap +89 -0
- package/src/components/actions/Button/index.tsx +99 -0
- package/src/components/actions/Button/style.ts +148 -0
- package/src/components/actions/ContextMenu/ContextMenu.stories.tsx +40 -0
- package/src/components/actions/ContextMenu/Group.tsx +34 -0
- package/src/components/actions/ContextMenu/MenuItem.tsx +66 -0
- package/src/components/actions/ContextMenu/index.tsx +217 -0
- package/src/components/actions/Dropdown/Dropdown.stories.tsx +88 -0
- package/src/components/actions/Dropdown/DropdownContext.tsx +21 -0
- package/src/components/actions/Dropdown/DropdownMenu.tsx +67 -0
- package/src/components/actions/Dropdown/DropdownMenuGroup.tsx +37 -0
- package/src/components/actions/Dropdown/DropdownMenuItem.tsx +128 -0
- package/src/components/actions/Dropdown/DropdownTrigger.tsx +89 -0
- package/src/components/actions/Dropdown/index.tsx +22 -0
- package/src/components/actions/Dropdown/useDropdown.tsx +82 -0
- package/src/components/actions/DropdownButton/DropdownButton.stories.tsx +88 -0
- package/src/components/actions/DropdownButton/index.tsx +113 -0
- package/src/components/actions/IconButton/IconButton.stories.tsx +54 -0
- package/src/components/actions/IconButton/IconButton.test.tsx +7 -0
- package/src/components/actions/IconButton/IconButton.test.tsx.snap +46 -0
- package/src/components/actions/IconButton/index.tsx +40 -0
- package/src/components/actions/IconButton/style.ts +75 -0
- package/src/components/actions/ToggleButton/ToggleButton.stories.tsx +84 -0
- package/src/components/actions/ToggleButton/ToggleButton.tsx +48 -0
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +99 -0
- package/src/components/actions/ToggleButton/index.tsx +2 -0
- package/src/components/actions/ToggleButton/style.ts +76 -0
- package/src/components/actions/index.ts +16 -0
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +104 -0
- package/src/components/charts/AreaChart/index.tsx +379 -0
- package/src/components/charts/BarChart/BarChart.stories.tsx +32 -0
- package/src/components/charts/BarChart/index.tsx +287 -0
- package/src/components/charts/BrushHandle.tsx +21 -0
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +65 -0
- package/src/components/charts/GeoMercator/index.tsx +141 -0
- package/src/components/charts/GeoMercator/world.d.ts +1 -0
- package/src/components/charts/GeoMercator/world.json +99485 -0
- package/src/components/charts/Heatmap/Heatmap.stories.tsx +55 -0
- package/src/components/charts/Heatmap/index.tsx +228 -0
- package/src/components/charts/LineChart/LineChart.stories.tsx +37 -0
- package/src/components/charts/LineChart/index.tsx +233 -0
- package/src/components/charts/PieChart/PieChart.stories.tsx +43 -0
- package/src/components/charts/PieChart/index.tsx +163 -0
- package/src/components/charts/PointHighlight.tsx +49 -0
- package/src/components/charts/RadarChart/RadarChart.stories.tsx +38 -0
- package/src/components/charts/RadarChart/generators.ts +30 -0
- package/src/components/charts/RadarChart/index.tsx +175 -0
- package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +34 -0
- package/src/components/charts/RadialBarChart/index.tsx +165 -0
- package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +26 -0
- package/src/components/charts/RadialLineChart/index.tsx +141 -0
- package/src/components/charts/index.tsx +20 -0
- package/src/components/charts/useGradients.tsx +37 -0
- package/src/components/charts/util.ts +40 -0
- package/src/components/data/Avatar/Avatar.stories.tsx +93 -0
- package/src/components/data/Avatar/context.tsx +20 -0
- package/src/components/data/Avatar/index.tsx +132 -0
- package/src/components/data/Avatar/style.ts +124 -0
- package/src/components/data/Avatar/useImageLoadingStatus.tsx +32 -0
- package/src/components/data/Chip/Chip.stories.tsx +67 -0
- package/src/components/data/Chip/Chip.test.tsx +7 -0
- package/src/components/data/Chip/Chip.test.tsx.snap +50 -0
- package/src/components/data/Chip/index.tsx +76 -0
- package/src/components/data/Chip/style.ts +84 -0
- package/src/components/data/Console/Console.stories.tsx +51 -0
- package/src/components/data/Console/Console.tsx +125 -0
- package/src/components/data/Console/ConsoleInput/index.tsx +87 -0
- package/src/components/data/Console/ConsoleInput/style.ts +41 -0
- package/src/components/data/Console/ConsoleLine/index.tsx +127 -0
- package/src/components/data/Console/ConsoleLine/style.ts +76 -0
- package/src/components/data/Console/MessageModel.ts +9 -0
- package/src/components/data/Console/index.tsx +4 -0
- package/src/components/data/Console/style.ts +31 -0
- package/src/components/data/Console/useConsoleLiveMode.ts +42 -0
- package/src/components/data/CopyId/CopyId.stories.tsx +36 -0
- package/src/components/data/CopyId/index.tsx +38 -0
- package/src/components/data/DateFormatter/DateFormatter.stories.tsx +26 -0
- package/src/components/data/DateFormatter/index.tsx +15 -0
- package/src/components/data/Drawer/Drawer.stories.tsx +144 -0
- package/src/components/data/Drawer/DrawerBody.tsx +22 -0
- package/src/components/data/Drawer/DrawerContent.tsx +110 -0
- package/src/components/data/Drawer/DrawerContext.tsx +21 -0
- package/src/components/data/Drawer/DrawerFooter.tsx +19 -0
- package/src/components/data/Drawer/DrawerHeading.tsx +49 -0
- package/src/components/data/Drawer/DrawerSkeleton.tsx +29 -0
- package/src/components/data/Drawer/index.tsx +25 -0
- package/src/components/data/Drawer/useDrawer.tsx +52 -0
- package/src/components/data/InfiniteScroll/InfiniteScroll.stories.tsx +33 -0
- package/src/components/data/InfiniteScroll/index.tsx +51 -0
- package/src/components/data/LinkCard/index.tsx +28 -0
- package/src/components/data/Stats/Stat.tsx +99 -0
- package/src/components/data/Stats/Stats.stories.tsx +72 -0
- package/src/components/data/Stats/context.tsx +11 -0
- package/src/components/data/Stats/index.tsx +50 -0
- package/src/components/data/Table/Table.stories.tsx +142 -0
- package/src/components/data/Table/index.tsx +365 -0
- package/src/components/data/Table/react-table.d.ts +11 -0
- package/src/components/data/Table/style.ts +75 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +161 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +207 -0
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +89 -0
- package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +61 -0
- package/src/components/data/Table/subcomponents/Filter/field.tsx +129 -0
- package/src/components/data/Table/subcomponents/Filter/index.tsx +239 -0
- package/src/components/data/Table/subcomponents/Filter/style.ts +26 -0
- package/src/components/data/Table/subcomponents/Pagination/index.tsx +108 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +49 -0
- package/src/components/data/Table/subcomponents/index.ts +4 -0
- package/src/components/data/index.ts +28 -0
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +74 -0
- package/src/components/dialogs/Dialog/DialogBody.tsx +62 -0
- package/src/components/dialogs/Dialog/DialogContent.tsx +46 -0
- package/src/components/dialogs/Dialog/DialogContext.tsx +21 -0
- package/src/components/dialogs/Dialog/DialogHeading.tsx +56 -0
- package/src/components/dialogs/Dialog/index.tsx +20 -0
- package/src/components/dialogs/Dialog/useDialog.tsx +50 -0
- package/src/components/feedback/Alert/Alert.stories.tsx +77 -0
- package/src/components/feedback/Alert/Alert.test.tsx +7 -0
- package/src/components/feedback/Alert/Alert.test.tsx.snap +146 -0
- package/src/components/feedback/Alert/index.tsx +109 -0
- package/src/components/feedback/Alert/style.ts +87 -0
- package/src/components/feedback/ErrorFallback/ErrorFallback.stories.tsx +10 -0
- package/src/components/feedback/ErrorFallback/index.tsx +48 -0
- package/src/components/feedback/ErrorPage/ErrorPage.stories.tsx +31 -0
- package/src/components/feedback/ErrorPage/index.tsx +193 -0
- package/src/components/feedback/FormError/FormError.stories.tsx +25 -0
- package/src/components/feedback/FormError/index.tsx +54 -0
- package/src/components/feedback/Loaders/Loaders.stories.tsx +28 -0
- package/src/components/feedback/Loaders/Loading.test.tsx +7 -0
- package/src/components/feedback/Loaders/Loading.test.tsx.snap +141 -0
- package/src/components/feedback/Loaders/Loading.tsx +107 -0
- package/src/components/feedback/Loaders/Spinner.test.tsx +7 -0
- package/src/components/feedback/Loaders/Spinner.test.tsx.snap +18 -0
- package/src/components/feedback/Loaders/Spinner.tsx +74 -0
- package/src/components/feedback/Loaders/index.ts +2 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.stories.tsx +21 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx +7 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx.snap +3 -0
- package/src/components/feedback/NetworkDetector/index.tsx +41 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.stories.tsx +13 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +14 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/index.tsx +79 -0
- package/src/components/feedback/Popover/Popover.stories.tsx +33 -0
- package/src/components/feedback/Popover/PopoverContent.tsx +43 -0
- package/src/components/feedback/Popover/PopoverContext.tsx +21 -0
- package/src/components/feedback/Popover/PopoverTrigger.tsx +43 -0
- package/src/components/feedback/Popover/index.tsx +22 -0
- package/src/components/feedback/Popover/usePopover.tsx +87 -0
- package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +38 -0
- package/src/components/feedback/ProgressBar/index.tsx +103 -0
- package/src/components/feedback/QuestionTooltip/QuestionTooltip.stories.tsx +20 -0
- package/src/components/feedback/QuestionTooltip/index.tsx +36 -0
- package/src/components/feedback/Skeleton/Skeleton.stories.tsx +33 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx +7 -0
- package/src/components/feedback/Skeleton/Skeleton.test.tsx.snap +35 -0
- package/src/components/feedback/Skeleton/index.tsx +62 -0
- package/src/components/feedback/Tooltip/Tooltip.stories.tsx +69 -0
- package/src/components/feedback/Tooltip/TooltipContent.tsx +50 -0
- package/src/components/feedback/Tooltip/TooltipContext.tsx +13 -0
- package/src/components/feedback/Tooltip/TooltipTrigger.tsx +39 -0
- package/src/components/feedback/Tooltip/index.tsx +26 -0
- package/src/components/feedback/Tooltip/useTooltip.tsx +79 -0
- package/src/components/feedback/index.ts +33 -0
- package/src/components/feedback/snacks/CookieConsent/index.tsx +122 -0
- package/src/components/feedback/snacks/CookieConsent/style.ts +100 -0
- package/src/components/feedback/snacks/Default/default.stories.tsx +72 -0
- package/src/components/feedback/snacks/Default/index.tsx +77 -0
- package/src/components/feedback/snacks/Default/style.ts +59 -0
- package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +46 -0
- package/src/components/feedback/snacks/Drawer/index.tsx +70 -0
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +70 -0
- package/src/components/feedback/snacks/index.d.ts +15 -0
- package/src/components/feedback/snacks/index.ts +8 -0
- package/src/components/index.ts +9 -0
- package/src/components/inputs/CheckBox/CheckBox.stories.tsx +64 -0
- package/src/components/inputs/CheckBox/Controlled.tsx +124 -0
- package/src/components/inputs/CheckBox/Generic.tsx +96 -0
- package/src/components/inputs/CheckBox/index.tsx +4 -0
- package/src/components/inputs/CheckBox/style.ts +113 -0
- package/src/components/inputs/CodeField/CodeField.stories.tsx +87 -0
- package/src/components/inputs/CodeField/index.tsx +173 -0
- package/src/components/inputs/CodeField/style.ts +50 -0
- package/src/components/inputs/Date/DatePicker/Controlled.tsx +101 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +234 -0
- package/src/components/inputs/Date/DatePicker/Generic.tsx +253 -0
- package/src/components/inputs/Date/DatePicker/formats.tsx +32 -0
- package/src/components/inputs/Date/DatePicker/style.ts +43 -0
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +112 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +32 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Absolute.tsx +98 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Relative.tsx +54 -0
- package/src/components/inputs/Date/DateRangePicker/DateSelector/index.tsx +49 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +270 -0
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/style.ts +40 -0
- package/src/components/inputs/Date/DateRangePicker/index.tsx +134 -0
- package/src/components/inputs/Date/DateRangePicker/style.ts +51 -0
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +150 -0
- package/src/components/inputs/Date/subcomponents/Calendar/style.ts +59 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +186 -0
- package/src/components/inputs/Date/subcomponents/RelativePicker/style.ts +50 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/TimePicker.stories.tsx +25 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/index.tsx +40 -0
- package/src/components/inputs/Date/subcomponents/TimePicker/style.ts +32 -0
- package/src/components/inputs/DurationField/Controlled.tsx +69 -0
- package/src/components/inputs/DurationField/Duration.stories.tsx +54 -0
- package/src/components/inputs/DurationField/Generic.tsx +200 -0
- package/src/components/inputs/DurationField/index.tsx +5 -0
- package/src/components/inputs/DurationField/style.ts +42 -0
- package/src/components/inputs/EditableField/EditableField.stories.tsx +65 -0
- package/src/components/inputs/EditableField/index.tsx +135 -0
- package/src/components/inputs/EditableField/style.ts +11 -0
- package/src/components/inputs/FileField/Controlled.tsx +104 -0
- package/src/components/inputs/FileField/FileField.stories.tsx +211 -0
- package/src/components/inputs/FileField/Generic.tsx +131 -0
- package/src/components/inputs/FileField/index.tsx +5 -0
- package/src/components/inputs/FileField/style.ts +34 -0
- package/src/components/inputs/InputProps.ts +61 -0
- package/src/components/inputs/RadioGroup/Controlled.tsx +46 -0
- package/src/components/inputs/RadioGroup/Generic.tsx +34 -0
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +116 -0
- package/src/components/inputs/RadioGroup/RadioItem.tsx +129 -0
- package/src/components/inputs/RadioGroup/context.tsx +20 -0
- package/src/components/inputs/RadioGroup/index.ts +5 -0
- package/src/components/inputs/RadioGroup/style.ts +3 -0
- package/src/components/inputs/Slider/Controlled.tsx +87 -0
- package/src/components/inputs/Slider/Generic.tsx +73 -0
- package/src/components/inputs/Slider/Slider.stories.tsx +101 -0
- package/src/components/inputs/Slider/handle.tsx +31 -0
- package/src/components/inputs/Slider/index.tsx +5 -0
- package/src/components/inputs/Slider/style.ts +140 -0
- package/src/components/inputs/Switch/Controlled.tsx +58 -0
- package/src/components/inputs/Switch/Generic.tsx +67 -0
- package/src/components/inputs/Switch/Switch.stories.tsx +91 -0
- package/src/components/inputs/Switch/index.ts +5 -0
- package/src/components/inputs/Switch/style.ts +56 -0
- package/src/components/inputs/TagField/Controlled.tsx +103 -0
- package/src/components/inputs/TagField/Generic.tsx +138 -0
- package/src/components/inputs/TagField/TagField.stories.tsx +68 -0
- package/src/components/inputs/TagField/index.ts +5 -0
- package/src/components/inputs/TagField/style.ts +25 -0
- package/src/components/inputs/TagField/util.ts +34 -0
- package/src/components/inputs/TextAreaField/Controlled.tsx +101 -0
- package/src/components/inputs/TextAreaField/Generic.tsx +56 -0
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +98 -0
- package/src/components/inputs/TextAreaField/index.ts +5 -0
- package/src/components/inputs/TextAreaField/style.ts +28 -0
- package/src/components/inputs/TextField/Controlled.tsx +120 -0
- package/src/components/inputs/TextField/Generic.tsx +113 -0
- package/src/components/inputs/TextField/TextField.stories.tsx +196 -0
- package/src/components/inputs/TextField/index.ts +5 -0
- package/src/components/inputs/TextField/style.ts +97 -0
- package/src/components/inputs/TextField/util.ts +19 -0
- package/src/components/inputs/ValueConfirmationField/ValueConfirmationField.stories.tsx +33 -0
- package/src/components/inputs/ValueConfirmationField/index.tsx +54 -0
- package/src/components/inputs/index.ts +67 -0
- package/src/components/inputs/layout/Description.tsx +40 -0
- package/src/components/inputs/layout/ErrorMessage/ErrorMessage.stories.tsx +28 -0
- package/src/components/inputs/layout/ErrorMessage/index.tsx +63 -0
- package/src/components/inputs/layout/InputWrapper.ts +6 -0
- package/src/components/inputs/layout/Label/index.tsx +71 -0
- package/src/components/inputs/layout/Label/style.ts +51 -0
- package/src/components/inputs/layout/index.ts +6 -0
- package/src/components/inputs/selects/SelectField/Controlled.tsx +130 -0
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +45 -0
- package/src/components/inputs/selects/SelectField/Generic/index.tsx +302 -0
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +253 -0
- package/src/components/inputs/selects/SelectField/index.ts +5 -0
- package/src/components/inputs/selects/SelectField/style.ts +29 -0
- package/src/components/inputs/selects/SelectQueryField/Controlled.tsx +100 -0
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +300 -0
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +260 -0
- package/src/components/inputs/selects/SelectQueryField/index.tsx +5 -0
- package/src/components/inputs/selects/SelectQueryField/style.ts +14 -0
- package/src/components/inputs/selects/SubComponents/Option.tsx +114 -0
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +16 -0
- package/src/components/inputs/selects/SubComponents/index.ts +10 -0
- package/src/components/inputs/selects/SubComponents/style.ts +39 -0
- package/src/components/inputs/selects/data.ts +123 -0
- package/src/components/inputs/selects/index.tsx +47 -0
- package/src/components/inputs/selects/sharedStyle.ts +78 -0
- package/src/components/layout/Container/index.ts +21 -0
- package/src/components/layout/index.ts +1 -0
- package/src/components/navigation/HorizontalNav/HorizontalNav.stories.tsx +45 -0
- package/src/components/navigation/HorizontalNav/index.tsx +40 -0
- package/src/components/navigation/HorizontalNav/style.ts +83 -0
- package/src/components/navigation/IconNav/IconNav.stories.tsx +46 -0
- package/src/components/navigation/IconNav/index.tsx +49 -0
- package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +89 -0
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +104 -0
- package/src/components/navigation/Steppers/SlimStepper/style.ts +86 -0
- package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +87 -0
- package/src/components/navigation/Steppers/Stepper/index.tsx +114 -0
- package/src/components/navigation/Steppers/Stepper/style.ts +105 -0
- package/src/components/navigation/Steppers/context.tsx +49 -0
- package/src/components/navigation/Steppers/reducer.ts +51 -0
- package/src/components/navigation/Steppers/stepStates.ts +5 -0
- package/src/components/navigation/Tabs/Content.tsx +36 -0
- package/src/components/navigation/Tabs/Context.tsx +21 -0
- package/src/components/navigation/Tabs/List.tsx +17 -0
- package/src/components/navigation/Tabs/Tabs.stories.tsx +119 -0
- package/src/components/navigation/Tabs/Trigger.tsx +65 -0
- package/src/components/navigation/Tabs/index.tsx +35 -0
- package/src/components/navigation/Tabs/useTabs.tsx +28 -0
- package/src/components/navigation/index.ts +16 -0
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +86 -0
- package/src/components/other/ActionMenu/index.tsx +55 -0
- package/src/components/other/ActionMenu/style.ts +48 -0
- package/src/components/other/ClipBoard/ClipBoard.stories.tsx +14 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx +7 -0
- package/src/components/other/ClipBoard/ClipBoard.test.tsx.snap +70 -0
- package/src/components/other/ClipBoard/index.tsx +70 -0
- package/src/components/other/CollapseList/CollapseList.stories.tsx +21 -0
- package/src/components/other/CollapseList/index.tsx +115 -0
- package/src/components/other/Collapsible/Collapsible.stories.tsx +19 -0
- package/src/components/other/Collapsible/CollapsibleContent.tsx +22 -0
- package/src/components/other/Collapsible/CollapsibleContext.tsx +17 -0
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +67 -0
- package/src/components/other/Collapsible/index.tsx +21 -0
- package/src/components/other/Company/index.tsx +45 -0
- package/src/components/other/Company/style.ts +58 -0
- package/src/components/other/Empty/Empty.stories.tsx +24 -0
- package/src/components/other/Empty/Empty.test.tsx +7 -0
- package/src/components/other/Empty/Empty.test.tsx.snap +85 -0
- package/src/components/other/Empty/index.tsx +87 -0
- package/src/components/other/PermissionsGuard/PermissionsGuard.stories.tsx +54 -0
- package/src/components/other/PermissionsGuard/index.tsx +43 -0
- package/src/components/other/index.ts +19 -0
- package/src/components/visual/Card/Card.stories.tsx +19 -0
- package/src/components/visual/Card/index.tsx +49 -0
- package/src/components/visual/Divider/Divider.stories.tsx +19 -0
- package/src/components/visual/Divider/Divider.test.tsx +7 -0
- package/src/components/visual/Divider/Divider.test.tsx.snap +35 -0
- package/src/components/visual/Divider/index.tsx +85 -0
- package/src/components/visual/index.ts +5 -0
- package/src/errors/base.ts +11 -0
- package/src/errors/errors.ts +109 -0
- package/src/errors/index.ts +14 -0
- package/src/helpers/camelCaseToSpaces.ts +5 -0
- package/src/helpers/getInitials.ts +15 -0
- package/src/helpers/getSnackbarProvider.tsx +57 -0
- package/src/helpers/getTransition.ts +9 -0
- package/src/helpers/index.ts +5 -0
- package/src/helpers/makeData.ts +34 -0
- package/src/helpers/regexprs.ts +7 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useCallbackRef.tsx +17 -0
- package/src/hooks/useDebounce.tsx +22 -0
- package/src/hooks/useFocus.tsx +10 -0
- package/src/hooks/useLocalStorage.tsx +38 -0
- package/src/hooks/useLockScroll.ts +26 -0
- package/src/hooks/useOnScreen.ts +24 -0
- package/src/hooks/useOutsideAlerter.tsx +15 -0
- package/src/hooks/useTableActions.ts +56 -0
- package/src/hooks/useTheme.tsx +7 -0
- package/src/images/company-icon-primary.svg +3 -0
- package/src/images/company-icon-secondary.svg +3 -0
- package/src/images/index.ts +4 -0
- package/src/index.ts +9 -0
- package/src/stories/Colors.stories.mdx +35 -0
- package/src/stories/Elevation.stories.mdx +56 -0
- package/src/stories/Introduction.stories.mdx +17 -0
- package/src/stories/Spacing.stories.mdx +25 -0
- package/src/styled/GlobalStyle.ts +207 -0
- package/src/styled/Snackbar.tsx +42 -0
- package/src/styled/animations.ts +36 -0
- package/src/styled/breakpoint.ts +7 -0
- package/src/styled/device.ts +10 -0
- package/src/styled/elevation.ts +20 -0
- package/src/styled/index.ts +11 -0
- package/src/styled/spacing.ts +38 -0
- package/src/styled/theme.ts +87 -0
- package/src/styled/types.ts +5 -0
- package/src/styled/zIndex.ts +31 -0
- package/src/test/__mocks__/fileMock.ts +2 -0
- package/src/test/setupTests.ts +3 -0
- package/src/test/snapshotResolver.js +21 -0
- package/src/test/testUtils.tsx +31 -0
- package/src/types/index.ts +1 -0
- package/src/types/json.ts +5 -0
- package/src/views/LoadingPage.tsx +36 -0
- package/src/views/index.ts +1 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Column, ColumnOrderState, Header, Table, flexRender } from '@tanstack/react-table';
|
|
2
|
+
import { useDrag, useDragLayer, useDrop, XYCoord } from 'react-dnd';
|
|
3
|
+
import { ColumnSettings } from './ColumnSettings';
|
|
4
|
+
import { Identifier } from 'dnd-core';
|
|
5
|
+
import { styled } from '../../../../../styled';
|
|
6
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { getEmptyImage } from 'react-dnd-html5-backend';
|
|
8
|
+
import { Target, Content, Th, ResizeHandle, InnerTh } from './style';
|
|
9
|
+
|
|
10
|
+
const ItemTypes = {
|
|
11
|
+
COLUMN: 'column',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface CollectedProps {
|
|
15
|
+
handlerId: Identifier | null;
|
|
16
|
+
isActive: boolean;
|
|
17
|
+
isRight: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ColumnHeaderProps<DataType extends object> {
|
|
21
|
+
header: Header<DataType, unknown>;
|
|
22
|
+
table: Table<DataType>;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const reorder = (draggedColumnId: string, targetColumnId: string, columnOrder: string[]): ColumnOrderState => {
|
|
27
|
+
columnOrder.splice(
|
|
28
|
+
columnOrder.indexOf(targetColumnId),
|
|
29
|
+
0,
|
|
30
|
+
columnOrder.splice(columnOrder.indexOf(draggedColumnId), 1)[0] as string
|
|
31
|
+
);
|
|
32
|
+
return [...columnOrder];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function ColumnHeader<DataType extends object>({ header, table, isLoading }: ColumnHeaderProps<DataType>) {
|
|
36
|
+
const { getState, setColumnOrder } = table;
|
|
37
|
+
const { columnOrder } = getState();
|
|
38
|
+
const { column } = header;
|
|
39
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
40
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
41
|
+
const canDrag = !isLoading;
|
|
42
|
+
|
|
43
|
+
const [{ isActive, isRight }, dropRef] = useDrop<Column<DataType>, void, CollectedProps>({
|
|
44
|
+
accept: ItemTypes.COLUMN,
|
|
45
|
+
collect: (monitor) => ({
|
|
46
|
+
isActive: monitor.canDrop() && monitor.isOver(),
|
|
47
|
+
// check if the dragged element is situated on the right or left of the current element
|
|
48
|
+
isRight: columnOrder.indexOf(column.id) > columnOrder.indexOf(monitor.getItem()?.id),
|
|
49
|
+
handlerId: monitor.getHandlerId(),
|
|
50
|
+
}),
|
|
51
|
+
drop: (draggedColumn: Column<DataType>) => {
|
|
52
|
+
const newColumnOrder = reorder(draggedColumn.id, column.id, columnOrder);
|
|
53
|
+
setColumnOrder(newColumnOrder);
|
|
54
|
+
},
|
|
55
|
+
canDrop: (draggedColumn: Column<DataType>) => draggedColumn.id !== column.id,
|
|
56
|
+
hover: (draggedColumn: Column<DataType>, monitor) => {
|
|
57
|
+
if (!ref.current) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const hoverIndex = columnOrder.indexOf(column.id);
|
|
61
|
+
const draggedIndex = columnOrder.indexOf(draggedColumn.id);
|
|
62
|
+
|
|
63
|
+
// Don't replace items with themselves
|
|
64
|
+
if (draggedIndex === hoverIndex) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Determine rectangle on screen
|
|
69
|
+
const hoverBoundingRect = ref.current.getBoundingClientRect();
|
|
70
|
+
|
|
71
|
+
// Get vertical middle
|
|
72
|
+
const hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2;
|
|
73
|
+
|
|
74
|
+
// Determine mouse position
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
76
|
+
const clientOffset = monitor.getClientOffset()!;
|
|
77
|
+
|
|
78
|
+
// Get pixels to the top
|
|
79
|
+
const hoverClientX = clientOffset.x - hoverBoundingRect.left;
|
|
80
|
+
|
|
81
|
+
// Dragging left
|
|
82
|
+
if (draggedIndex < hoverIndex && hoverClientX < hoverMiddleX) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Dragging right
|
|
87
|
+
if (draggedIndex > hoverIndex && hoverClientX > hoverMiddleX) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Time to actually perform the action
|
|
92
|
+
const newColumnOrder = reorder(draggedColumn.id, column.id, columnOrder);
|
|
93
|
+
setColumnOrder(newColumnOrder);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const [{ isDragging }, dragRef, previewRef] = useDrag({
|
|
98
|
+
collect: (monitor) => ({
|
|
99
|
+
isDragging: monitor.isDragging(),
|
|
100
|
+
}),
|
|
101
|
+
item: () => ({
|
|
102
|
+
...column,
|
|
103
|
+
draggedIndex: columnOrder.indexOf(column.id),
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
// Disable dragging whnen loading
|
|
107
|
+
canDrag: !isLoading,
|
|
108
|
+
type: ItemTypes.COLUMN,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
previewRef(getEmptyImage(), { captureDraggingState: true });
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const node = ref.current;
|
|
117
|
+
if (node) {
|
|
118
|
+
dragRef(node);
|
|
119
|
+
dropRef(node);
|
|
120
|
+
}
|
|
121
|
+
}, [dragRef, dropRef]);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Th
|
|
125
|
+
canDrag={canDrag}
|
|
126
|
+
colSpan={header.colSpan}
|
|
127
|
+
scope="col"
|
|
128
|
+
isDragging={isDragging}
|
|
129
|
+
isActive={isActive}
|
|
130
|
+
isRight={isRight}
|
|
131
|
+
width={header.getSize()}
|
|
132
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
133
|
+
onMouseLeave={() => setIsHovered(false)}
|
|
134
|
+
isRowSelection={false}
|
|
135
|
+
>
|
|
136
|
+
<InnerTh>
|
|
137
|
+
<Target ref={ref} isDragging={isDragging} role="DraggableBox" draggable={true} aria-dropeffect="move">
|
|
138
|
+
<CustomDragLayer />
|
|
139
|
+
<Content canDrag={canDrag}>
|
|
140
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
|
141
|
+
</Content>
|
|
142
|
+
</Target>
|
|
143
|
+
|
|
144
|
+
{/* Only show columnSettings when sorting and filtering is enabled
|
|
145
|
+
NOTE: getCanGlobalFilter cannot be used to base render logic on because it is set to false when the table has no data.
|
|
146
|
+
*/}
|
|
147
|
+
{column.getCanFilter() && column.getCanSort() && (
|
|
148
|
+
<ColumnSettings columnIsHovered={isHovered} header={header} table={table} />
|
|
149
|
+
)}
|
|
150
|
+
</InnerTh>
|
|
151
|
+
{header.column.getCanResize() && !isLoading && (
|
|
152
|
+
<ResizeHandle
|
|
153
|
+
onMouseDown={header.getResizeHandler()}
|
|
154
|
+
onTouchStart={header.getResizeHandler()}
|
|
155
|
+
isResizing={header.column.getIsResizing()}
|
|
156
|
+
onDoubleClick={() => header.column.resetSize()}
|
|
157
|
+
></ResizeHandle>
|
|
158
|
+
)}
|
|
159
|
+
</Th>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export const Wrapper = styled.div`
|
|
164
|
+
position: fixed;
|
|
165
|
+
pointer-events: none;
|
|
166
|
+
z-index: 100;
|
|
167
|
+
left: 0;
|
|
168
|
+
top: 0;
|
|
169
|
+
width: 100%;
|
|
170
|
+
height: 100%;
|
|
171
|
+
`;
|
|
172
|
+
|
|
173
|
+
export const Inner = styled.div<{ initialOffset: XYCoord | null; currentOffset: XYCoord | null }>`
|
|
174
|
+
display: ${({ initialOffset, currentOffset }) => (!initialOffset || !currentOffset ? 'none' : 'block')};
|
|
175
|
+
transform: ${({ currentOffset }) => `translate(${currentOffset?.x}px, ${currentOffset?.y}px)`};
|
|
176
|
+
`;
|
|
177
|
+
|
|
178
|
+
export const CustomDragLayer = forwardRef<HTMLDivElement>((_, ref) => {
|
|
179
|
+
const { itemType, isDragging, initialOffset, currentOffset } = useDragLayer((monitor) => ({
|
|
180
|
+
item: monitor.getItem(),
|
|
181
|
+
itemType: monitor.getItemType(),
|
|
182
|
+
initialOffset: monitor.getInitialSourceClientOffset(),
|
|
183
|
+
currentOffset: monitor.getSourceClientOffset(),
|
|
184
|
+
isDragging: monitor.isDragging(),
|
|
185
|
+
}));
|
|
186
|
+
|
|
187
|
+
function renderItem() {
|
|
188
|
+
switch (itemType) {
|
|
189
|
+
case ItemTypes.COLUMN:
|
|
190
|
+
return <div></div>;
|
|
191
|
+
default:
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!isDragging) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<Wrapper ref={ref}>
|
|
202
|
+
<Inner initialOffset={initialOffset} currentOffset={currentOffset}>
|
|
203
|
+
{renderItem()}
|
|
204
|
+
</Inner>
|
|
205
|
+
</Wrapper>
|
|
206
|
+
);
|
|
207
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { styled } from '../../../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Th = styled.th<{
|
|
4
|
+
isActive: boolean;
|
|
5
|
+
isRight: boolean;
|
|
6
|
+
isDragging: boolean;
|
|
7
|
+
width: number;
|
|
8
|
+
canDrag: boolean;
|
|
9
|
+
isRowSelection: boolean;
|
|
10
|
+
}>`
|
|
11
|
+
position: relative;
|
|
12
|
+
width: ${({ width }) => width}px;
|
|
13
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']} 0`};
|
|
14
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
15
|
+
|
|
16
|
+
&:first-child {
|
|
17
|
+
padding-left: ${({ theme, isRowSelection }) => (isRowSelection ? 0 : theme.spacing['1'])};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&:last-of-type {
|
|
21
|
+
padding-right: ${({ theme }) => theme.spacing['1']};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
& > div {
|
|
25
|
+
font-weight: 600;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* NOTE: Required to match with the resizeHandle */
|
|
29
|
+
border-right: ${({ theme, isActive, isRight }) =>
|
|
30
|
+
isActive && isRight ? `4px solid ${theme.colors.primary}` : `1px solid ${theme.colors.background}`};
|
|
31
|
+
border-left: ${({ theme, isActive, isRight }) =>
|
|
32
|
+
isActive && !isRight ? `4px solid ${theme.colors.primary}` : `1px solid ${theme.colors.background}`};
|
|
33
|
+
|
|
34
|
+
&:first-child {
|
|
35
|
+
border-left: ${({ theme, isActive, isRight }) =>
|
|
36
|
+
isActive && !isRight ? `4px solid ${theme.colors.primary}` : 'none'};
|
|
37
|
+
border-top-left-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
38
|
+
border-bottom-left-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:last-of-type {
|
|
42
|
+
border-top-right-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
43
|
+
border-right: ${({ theme, isActive, isRight }) =>
|
|
44
|
+
isActive && isRight ? `4px solid ${theme.colors.primary}` : `1px solid ${theme.colors.background}`};
|
|
45
|
+
border-bottom-right-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
export const InnerTh = styled.div`
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: flex-start;
|
|
53
|
+
gap: ${({ theme }) => theme.spacing['0_5']};
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
export const Target = styled.div<{ isDragging: boolean }>`
|
|
57
|
+
opacity: ${({ isDragging }) => (isDragging ? 0.1 : 1)};
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
export const Content = styled.span<{ canDrag: boolean }>`
|
|
61
|
+
cursor: ${({ canDrag }) => (canDrag ? 'grabbing' : 'default')};
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export const ResizeHandle = styled.span<{ isResizing: boolean }>`
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 0;
|
|
67
|
+
right: 0;
|
|
68
|
+
width: 4px;
|
|
69
|
+
right: -1px;
|
|
70
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
71
|
+
height: 100vh;
|
|
72
|
+
cursor: col-resize;
|
|
73
|
+
user-select: none;
|
|
74
|
+
/* prevents from scrolling while dragging on touch devices */
|
|
75
|
+
touch-action: none;
|
|
76
|
+
opacity: ${({ isResizing }) => (isResizing ? 1 : 0)};
|
|
77
|
+
background-color: ${({ theme, isResizing }) => (isResizing ? theme.colors.primary : theme.colors.backgroundAccent)};
|
|
78
|
+
transition: opacity 0.1s ease-out;
|
|
79
|
+
|
|
80
|
+
&:hover {
|
|
81
|
+
opacity: 1;
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
export const MenuTrigger = styled.div<{ isVisible: boolean }>`
|
|
86
|
+
display: inline-block;
|
|
87
|
+
opacity: ${({ isVisible }) => (isVisible ? 1 : 0)};
|
|
88
|
+
transition: opacity 0.2s ease-in-out;
|
|
89
|
+
`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Table } from '@tanstack/react-table';
|
|
2
|
+
import { Dropdown, IconButton } from '../../../../../components';
|
|
3
|
+
import { AiOutlineEye as EyeIcon } from 'react-icons/ai';
|
|
4
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
5
|
+
import { camelCaseToSpaces } from '../../../../../helpers';
|
|
6
|
+
|
|
7
|
+
interface ColumnVisibilityProps<DataType extends object> {
|
|
8
|
+
table: Table<DataType>;
|
|
9
|
+
setOpenColumnVisibilityTooltip: Dispatch<SetStateAction<boolean>>;
|
|
10
|
+
openColumnVisibilityTooltip: boolean;
|
|
11
|
+
setHasShownColumnVisibilityTooltip: Dispatch<SetStateAction<boolean>>;
|
|
12
|
+
hasShownColumnVisibilityTooltip: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ColumnVisibility<DataType extends object>({
|
|
16
|
+
table,
|
|
17
|
+
setOpenColumnVisibilityTooltip,
|
|
18
|
+
openColumnVisibilityTooltip,
|
|
19
|
+
setHasShownColumnVisibilityTooltip,
|
|
20
|
+
}: ColumnVisibilityProps<DataType>) {
|
|
21
|
+
const viableColumns = table.getAllLeafColumns().filter((column) => column.getCanHide() === true);
|
|
22
|
+
const hiddenColumns = viableColumns.filter((column) => column.getIsVisible() === false);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Dropdown>
|
|
26
|
+
<Dropdown.Trigger
|
|
27
|
+
asChild
|
|
28
|
+
tooltipOptions={{
|
|
29
|
+
onOpenChange: setOpenColumnVisibilityTooltip,
|
|
30
|
+
open: openColumnVisibilityTooltip,
|
|
31
|
+
content: 'Show or hide columns',
|
|
32
|
+
placement: 'right',
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
<IconButton
|
|
36
|
+
badge={hiddenColumns.length > 0 ? (hiddenColumns.length as unknown as string) : ''}
|
|
37
|
+
size="large"
|
|
38
|
+
icon={<EyeIcon />}
|
|
39
|
+
ariaLabel="Columns"
|
|
40
|
+
/>
|
|
41
|
+
</Dropdown.Trigger>
|
|
42
|
+
<Dropdown.Menu>
|
|
43
|
+
<Dropdown.Menu.Group label="Visibility of columns">
|
|
44
|
+
{viableColumns.map((column) => (
|
|
45
|
+
<Dropdown.Menu.Item
|
|
46
|
+
key={column.id}
|
|
47
|
+
onClick={() => {
|
|
48
|
+
// In case they open the dropdown they already know about the column visibility
|
|
49
|
+
setHasShownColumnVisibilityTooltip(true);
|
|
50
|
+
column.toggleVisibility();
|
|
51
|
+
}}
|
|
52
|
+
label={camelCaseToSpaces(column.id)}
|
|
53
|
+
activeStyle="checkmark"
|
|
54
|
+
active={column.getIsVisible()}
|
|
55
|
+
/>
|
|
56
|
+
))}
|
|
57
|
+
</Dropdown.Menu.Group>
|
|
58
|
+
</Dropdown.Menu>
|
|
59
|
+
</Dropdown>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Control, UseFormSetValue, useWatch } from 'react-hook-form';
|
|
2
|
+
import { SelectField, TextField } from '../../../../../components';
|
|
3
|
+
import { FilterInputType, IFormInputs } from '.';
|
|
4
|
+
import { Operators } from '.';
|
|
5
|
+
import { Column } from '@tanstack/react-table';
|
|
6
|
+
import { useLayoutEffect } from 'react';
|
|
7
|
+
import { camelCaseToSpaces } from '../../../../../helpers';
|
|
8
|
+
|
|
9
|
+
interface FilterFieldProps<DataType> {
|
|
10
|
+
index: number;
|
|
11
|
+
id: string;
|
|
12
|
+
columnIds: string[];
|
|
13
|
+
control: Control<IFormInputs>;
|
|
14
|
+
getColumn: (columnId: string) => Column<DataType, unknown> | undefined;
|
|
15
|
+
setValue: UseFormSetValue<IFormInputs>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function FilterRow<DataType extends object>({
|
|
19
|
+
id,
|
|
20
|
+
columnIds,
|
|
21
|
+
index,
|
|
22
|
+
control,
|
|
23
|
+
setValue,
|
|
24
|
+
getColumn,
|
|
25
|
+
}: FilterFieldProps<DataType>) {
|
|
26
|
+
const currentColumn = useWatch<IFormInputs>({
|
|
27
|
+
control,
|
|
28
|
+
name: `filters.${index}.column`,
|
|
29
|
+
});
|
|
30
|
+
const currentOperator = useWatch<IFormInputs>({
|
|
31
|
+
control,
|
|
32
|
+
name: `filters.${index}.operator`,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const getOperators = (columnId: string | undefined) => {
|
|
36
|
+
const defaultOperators = [Operators.is, Operators.contains];
|
|
37
|
+
|
|
38
|
+
if (!columnId) {
|
|
39
|
+
return defaultOperators;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const column = getColumn(columnId);
|
|
43
|
+
if (!column) {
|
|
44
|
+
return defaultOperators;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const meta = column?.columnDef?.meta as Record<string, unknown> | undefined;
|
|
48
|
+
switch (meta?.type) {
|
|
49
|
+
case 'uuid':
|
|
50
|
+
case 'datetime':
|
|
51
|
+
return [Operators.is];
|
|
52
|
+
default:
|
|
53
|
+
return defaultOperators;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const operators = getOperators(currentColumn.toString());
|
|
58
|
+
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
const column = getColumn(currentColumn.toString());
|
|
61
|
+
const meta = column?.columnDef.meta;
|
|
62
|
+
|
|
63
|
+
setValue(`filters.${index}.operator`, Operators.is);
|
|
64
|
+
setValue(`filters.${index}.type`, (meta?.dataType as string | undefined as FilterInputType) ?? 'string');
|
|
65
|
+
}, [currentColumn]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<SelectField
|
|
70
|
+
key={`column-${id}`}
|
|
71
|
+
control={control}
|
|
72
|
+
name={`filters.${index}.column`}
|
|
73
|
+
label="Column"
|
|
74
|
+
inPortal
|
|
75
|
+
render={(selectedItems) => {
|
|
76
|
+
if (selectedItems.length === 0) {
|
|
77
|
+
return 'Select a column';
|
|
78
|
+
}
|
|
79
|
+
const col = columnIds.find((col) => col === selectedItems[0].value);
|
|
80
|
+
return camelCaseToSpaces(col);
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
<SelectField.OptionGroup>
|
|
84
|
+
{columnIds.map((col) => (
|
|
85
|
+
<SelectField.Option key={col} value={col} label={col}>
|
|
86
|
+
<div>
|
|
87
|
+
<span>{camelCaseToSpaces(col)}</span>
|
|
88
|
+
</div>
|
|
89
|
+
</SelectField.Option>
|
|
90
|
+
))}
|
|
91
|
+
</SelectField.OptionGroup>
|
|
92
|
+
</SelectField>
|
|
93
|
+
|
|
94
|
+
<SelectField
|
|
95
|
+
key={`operator-${id}`}
|
|
96
|
+
control={control}
|
|
97
|
+
name={`filters.${index}.operator`}
|
|
98
|
+
label="Condition"
|
|
99
|
+
inPortal
|
|
100
|
+
render={() => {
|
|
101
|
+
const operator = currentOperator?.toString();
|
|
102
|
+
|
|
103
|
+
if (operator === '') {
|
|
104
|
+
return 'Select a condition';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return operator;
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<SelectField.OptionGroup>
|
|
111
|
+
{operators.map((operator) => (
|
|
112
|
+
<SelectField.Option key={operator} value={operator} label={operator}>
|
|
113
|
+
<div>
|
|
114
|
+
<span>{operator}</span>
|
|
115
|
+
</div>
|
|
116
|
+
</SelectField.Option>
|
|
117
|
+
))}
|
|
118
|
+
</SelectField.OptionGroup>
|
|
119
|
+
</SelectField>
|
|
120
|
+
<TextField
|
|
121
|
+
key={`value-${id}`}
|
|
122
|
+
control={control}
|
|
123
|
+
name={`filters.${index}.value`}
|
|
124
|
+
label="Value"
|
|
125
|
+
placeholder="Enter a value"
|
|
126
|
+
/>
|
|
127
|
+
</>
|
|
128
|
+
);
|
|
129
|
+
}
|