@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,155 @@
|
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { Button, TextField, CollapseList, Chip, RadioGroup, Switch, Drawer, DrawerSkeleton } from '../../../components';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
import { DrawerOptions } from './useDrawer';
|
|
9
|
+
|
|
10
|
+
const ButtonContainer = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
gap: ${({ theme }) => theme.spacing[2]};
|
|
14
|
+
`;
|
|
15
|
+
const Status = styled.div`
|
|
16
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: 'data/Drawer',
|
|
21
|
+
component: Drawer,
|
|
22
|
+
args: {
|
|
23
|
+
promptCloseConfirmation: false,
|
|
24
|
+
},
|
|
25
|
+
} as Meta<DrawerOptions>;
|
|
26
|
+
|
|
27
|
+
export const Loading: StoryFn = () => {
|
|
28
|
+
return <DrawerSkeleton />;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface FormFields {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
priceType: 'fixed' | 'variable';
|
|
35
|
+
generateLicenseKeys: boolean;
|
|
36
|
+
redirectAfterPurchase: boolean;
|
|
37
|
+
onStoreFront: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Default: StoryFn<DrawerOptions> = ({ promptCloseConfirmation }) => {
|
|
41
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
42
|
+
|
|
43
|
+
const validationSchema = useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
z.object({
|
|
46
|
+
name: z.string().min(1, 'Name field is required'),
|
|
47
|
+
description: z.string().min(20, 'description must be at least 20 characters'),
|
|
48
|
+
priceType: z.enum(['fixed', 'variable']),
|
|
49
|
+
}),
|
|
50
|
+
[],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const { handleSubmit, control } = useForm<FormFields>({
|
|
54
|
+
resolver: zodResolver(validationSchema),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const onSubmit: SubmitHandler<FormFields> = async () => {
|
|
58
|
+
setOpen(false);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<Button onClick={() => setOpen(true)}>Open drawer</Button>
|
|
64
|
+
<Drawer open={open} onOpenChange={setOpen} promptCloseConfirmation={promptCloseConfirmation}>
|
|
65
|
+
<Drawer.Content>
|
|
66
|
+
<Drawer.Heading>Product Details</Drawer.Heading>
|
|
67
|
+
<Drawer.Body>
|
|
68
|
+
<Status>
|
|
69
|
+
Status: <Chip label="active" color="success" variant="outline" />
|
|
70
|
+
</Status>
|
|
71
|
+
<form id="myform" onSubmit={handleSubmit(onSubmit)}>
|
|
72
|
+
<CollapseList>
|
|
73
|
+
<CollapseList.Item title="General">
|
|
74
|
+
<TextField
|
|
75
|
+
label="Name"
|
|
76
|
+
name="name"
|
|
77
|
+
required
|
|
78
|
+
control={control}
|
|
79
|
+
description={
|
|
80
|
+
'Give your product a short and clear name.\n50-60 characters is the recommended length for search engines.'
|
|
81
|
+
}
|
|
82
|
+
/>
|
|
83
|
+
<TextField
|
|
84
|
+
label="Description"
|
|
85
|
+
name="description"
|
|
86
|
+
required
|
|
87
|
+
control={control}
|
|
88
|
+
description="Give your product a short and clear description. 120-160 characters is the recommended length for search engines"
|
|
89
|
+
/>
|
|
90
|
+
</CollapseList.Item>
|
|
91
|
+
<CollapseList.Item title="Pricing">
|
|
92
|
+
<RadioGroup control={control} label="Selection a price type" name="priceType">
|
|
93
|
+
{[
|
|
94
|
+
{
|
|
95
|
+
label: 'Fixed',
|
|
96
|
+
labelPosition: 'left',
|
|
97
|
+
value: 'fixed',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
label: 'Variable',
|
|
101
|
+
labelPosition: 'left',
|
|
102
|
+
value: 'variable',
|
|
103
|
+
},
|
|
104
|
+
].map(({ value, label }) => (
|
|
105
|
+
<div
|
|
106
|
+
key={`gender-${value}`}
|
|
107
|
+
style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginBottom: '1rem' }}
|
|
108
|
+
>
|
|
109
|
+
<RadioGroup.Item value={value} id={value} />
|
|
110
|
+
<label htmlFor={value}>{label}</label>
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
</RadioGroup>
|
|
114
|
+
</CollapseList.Item>
|
|
115
|
+
</CollapseList>
|
|
116
|
+
<CollapseList.Item title="Settings">
|
|
117
|
+
<Switch
|
|
118
|
+
control={control}
|
|
119
|
+
label="Generate License Keys"
|
|
120
|
+
name="generateLicenseKeys"
|
|
121
|
+
size="tiny"
|
|
122
|
+
description="Issue each sutomer a unique license key after purchase"
|
|
123
|
+
/>
|
|
124
|
+
<Switch
|
|
125
|
+
control={control}
|
|
126
|
+
label="Redirect customers after purchase"
|
|
127
|
+
name="redirectAfterPurchase"
|
|
128
|
+
size="small"
|
|
129
|
+
description="Redirect customers to a custom URL after making a purchase"
|
|
130
|
+
/>
|
|
131
|
+
<Switch
|
|
132
|
+
control={control}
|
|
133
|
+
label="Display product on storefront?"
|
|
134
|
+
name="onStoreFront"
|
|
135
|
+
description="Show this product on your storefront"
|
|
136
|
+
size="small"
|
|
137
|
+
/>
|
|
138
|
+
</CollapseList.Item>
|
|
139
|
+
</form>
|
|
140
|
+
</Drawer.Body>
|
|
141
|
+
<Drawer.Footer>
|
|
142
|
+
<ButtonContainer>
|
|
143
|
+
<Button onClick={() => setOpen(false)} color="background">
|
|
144
|
+
Cancel
|
|
145
|
+
</Button>
|
|
146
|
+
<Button fullWidth type="submit" form="myform">
|
|
147
|
+
Save changes
|
|
148
|
+
</Button>
|
|
149
|
+
</ButtonContainer>
|
|
150
|
+
</Drawer.Footer>
|
|
151
|
+
</Drawer.Content>
|
|
152
|
+
</Drawer>
|
|
153
|
+
</>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FC, PropsWithChildren, useId, useLayoutEffect } from 'react';
|
|
2
|
+
import { useDrawerContext } from './DrawerContext';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
|
|
5
|
+
const Container = styled.div<{ canDrag: boolean }>`
|
|
6
|
+
position: relative;
|
|
7
|
+
/* Large left padding is for the drawer handle */
|
|
8
|
+
padding: ${({ theme, canDrag }) =>
|
|
9
|
+
`0 ${theme.spacing['2_5']} ${theme.spacing[2]} ${canDrag ? theme.spacing['4'] : theme.spacing['2_5']}`};
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const DrawerBody: FC<PropsWithChildren> = ({ children }) => {
|
|
13
|
+
const { setLabelId, canDrag } = useDrawerContext();
|
|
14
|
+
const id = useId();
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
setLabelId(id);
|
|
18
|
+
return () => setLabelId(undefined);
|
|
19
|
+
}, [id, setLabelId]);
|
|
20
|
+
|
|
21
|
+
return <Container canDrag={canDrag}>{children}</Container>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { forwardRef, HTMLProps, useState } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
import { Button } from '../../../components';
|
|
4
|
+
import { AnimatePresence, motion, PanInfo } from 'framer-motion';
|
|
5
|
+
import SimpleBar from 'simplebar-react';
|
|
6
|
+
|
|
7
|
+
import { FloatingFocusManager, FloatingPortal, useMergeRefs, FloatingOverlay } from '@floating-ui/react';
|
|
8
|
+
import { useDrawerContext } from './DrawerContext';
|
|
9
|
+
|
|
10
|
+
const Container = styled(motion.div)`
|
|
11
|
+
position: relative;
|
|
12
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
13
|
+
width: 700px;
|
|
14
|
+
height: 100%;
|
|
15
|
+
z-index: ${({ theme }) => theme.zIndex.drawer};
|
|
16
|
+
border-left: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const ButtonContainer = styled.div`
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: flex-start;
|
|
23
|
+
gap: ${({ theme }) => theme.spacing[1]};
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const CloseConfirmationWrapper = styled.div`
|
|
27
|
+
position: absolute;
|
|
28
|
+
top: 0;
|
|
29
|
+
left: 0;
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
background: rgba(0, 0, 0, 0.8);
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const CloseConfirmationContainer = styled.div`
|
|
39
|
+
height: 150px;
|
|
40
|
+
padding: ${({ theme }) => theme.spacing[2]};
|
|
41
|
+
width: calc(100% - 200px);
|
|
42
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
43
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
44
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
45
|
+
|
|
46
|
+
h2,
|
|
47
|
+
p {
|
|
48
|
+
margin-bottom: ${({ theme }) => theme.spacing[1]};
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const HandleContainer = styled.div`
|
|
53
|
+
height: 80vh;
|
|
54
|
+
top: 10vh;
|
|
55
|
+
width: 15px;
|
|
56
|
+
left: 5px;
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
position: absolute;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
|
|
62
|
+
/* handle */
|
|
63
|
+
div {
|
|
64
|
+
background-color: ${({ theme }) => theme.colors.backgroundAccent};
|
|
65
|
+
height: 100px;
|
|
66
|
+
width: 0.8rem;
|
|
67
|
+
border-radius: 9999px;
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
export const DrawerContent = forwardRef<HTMLElement, HTMLProps<HTMLDivElement>>(function DrawerContent(props, propRef) {
|
|
72
|
+
const {
|
|
73
|
+
context,
|
|
74
|
+
labelId,
|
|
75
|
+
descriptionId,
|
|
76
|
+
getFloatingProps,
|
|
77
|
+
setOpen,
|
|
78
|
+
canDrag,
|
|
79
|
+
showConfirmDialog,
|
|
80
|
+
setShowConfirmDialog,
|
|
81
|
+
} = useDrawerContext();
|
|
82
|
+
|
|
83
|
+
const ref = useMergeRefs([context.refs.setFloating, propRef]);
|
|
84
|
+
const [dragPosition, setDragPosition] = useState<number>(0);
|
|
85
|
+
|
|
86
|
+
const root = document.getElementById('drawer');
|
|
87
|
+
if (!root) {
|
|
88
|
+
throw new Error('Drawer needs to render in a <div id="drawer"></div>');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const handleDrag = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
|
92
|
+
const newPosition = Math.min(Math.max(info.offset.x / 650, 0), 1);
|
|
93
|
+
setDragPosition(newPosition);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleDragEnd = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
|
97
|
+
// Snap back to position if dragged to the right
|
|
98
|
+
if (info.offset.x > 450) {
|
|
99
|
+
setOpen(false);
|
|
100
|
+
} else if (info.offset.x >= 0) {
|
|
101
|
+
setDragPosition(0);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<FloatingPortal root={root}>
|
|
107
|
+
<AnimatePresence>
|
|
108
|
+
{context.open && (
|
|
109
|
+
<FloatingOverlay
|
|
110
|
+
lockScroll
|
|
111
|
+
style={{
|
|
112
|
+
placeItems: 'end',
|
|
113
|
+
maxHeight: '100vh',
|
|
114
|
+
maxWidth: '100vw',
|
|
115
|
+
overflow: 'hidden!important',
|
|
116
|
+
display: 'grid',
|
|
117
|
+
background: `rgba(0, 0, 0, ${Math.max(0.8 - dragPosition, 0.4)})`,
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<FloatingFocusManager context={context}>
|
|
121
|
+
<Container
|
|
122
|
+
ref={ref}
|
|
123
|
+
aria-labelledby={labelId}
|
|
124
|
+
aria-describedby={descriptionId}
|
|
125
|
+
{...getFloatingProps(props)}
|
|
126
|
+
initial={{ x: '100%' }}
|
|
127
|
+
animate={{
|
|
128
|
+
x: 0,
|
|
129
|
+
}}
|
|
130
|
+
exit={{
|
|
131
|
+
x: '100%',
|
|
132
|
+
}}
|
|
133
|
+
drag={canDrag ? 'x' : false}
|
|
134
|
+
dragConstraints={{ left: 0, right: 0 }}
|
|
135
|
+
onDrag={handleDrag}
|
|
136
|
+
onDragEnd={handleDragEnd}
|
|
137
|
+
dragElastic={{ left: 0, right: 0.4 }}
|
|
138
|
+
layout
|
|
139
|
+
>
|
|
140
|
+
{canDrag && (
|
|
141
|
+
<HandleContainer>
|
|
142
|
+
<div />
|
|
143
|
+
</HandleContainer>
|
|
144
|
+
)}
|
|
145
|
+
<SimpleBar style={{ maxHeight: '92vh' }}>{props.children}</SimpleBar>
|
|
146
|
+
{showConfirmDialog && (
|
|
147
|
+
<CloseConfirmationWrapper>
|
|
148
|
+
<CloseConfirmationContainer>
|
|
149
|
+
<h2>Your progress will be lost</h2>
|
|
150
|
+
<p>Are you sure you want to exit? Your progress will not be saved.</p>
|
|
151
|
+
<ButtonContainer>
|
|
152
|
+
<Button color="secondary" onClick={() => setShowConfirmDialog(false)}>
|
|
153
|
+
Cancel
|
|
154
|
+
</Button>
|
|
155
|
+
<Button onClick={() => setOpen(false)} color="error">
|
|
156
|
+
Discard changes
|
|
157
|
+
</Button>
|
|
158
|
+
</ButtonContainer>
|
|
159
|
+
</CloseConfirmationContainer>
|
|
160
|
+
</CloseConfirmationWrapper>
|
|
161
|
+
)}
|
|
162
|
+
</Container>
|
|
163
|
+
</FloatingFocusManager>
|
|
164
|
+
</FloatingOverlay>
|
|
165
|
+
)}
|
|
166
|
+
</AnimatePresence>
|
|
167
|
+
</FloatingPortal>
|
|
168
|
+
);
|
|
169
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useContext, createContext, SetStateAction, Dispatch } from 'react';
|
|
2
|
+
import { useDrawer } from './useDrawer';
|
|
3
|
+
|
|
4
|
+
type ContextType =
|
|
5
|
+
| (ReturnType<typeof useDrawer> & {
|
|
6
|
+
setLabelId: Dispatch<SetStateAction<string | undefined>>;
|
|
7
|
+
setDescriptionId: Dispatch<SetStateAction<string | undefined>>;
|
|
8
|
+
})
|
|
9
|
+
| null;
|
|
10
|
+
|
|
11
|
+
export const DrawerContext = createContext<ContextType>(null);
|
|
12
|
+
|
|
13
|
+
export const useDrawerContext = () => {
|
|
14
|
+
const context = useContext(DrawerContext);
|
|
15
|
+
|
|
16
|
+
if (context == null) {
|
|
17
|
+
throw new Error('Dialog components must be wrapped in <Dialog />');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return context;
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.div`
|
|
5
|
+
/* Should match width of drawercontent */
|
|
6
|
+
width: calc(700px - 1px);
|
|
7
|
+
position: fixed;
|
|
8
|
+
bottom: 0;
|
|
9
|
+
/* should be shown above the rest of drawer (this is relative to DrawerContent) */
|
|
10
|
+
z-index: 1;
|
|
11
|
+
border-top: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
12
|
+
|
|
13
|
+
padding: ${({ theme }) => theme.spacing[2]};
|
|
14
|
+
background-color: ${({ theme }) => theme.colors.background};
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const DrawerFooter: FC<PropsWithChildren> = ({ children }) => {
|
|
18
|
+
return <Container>{children}</Container>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { forwardRef, HTMLProps, useId, useLayoutEffect } from 'react';
|
|
2
|
+
import { useDrawerContext } from './DrawerContext';
|
|
3
|
+
import { AiOutlineClose as CloseIcon } from 'react-icons/ai';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
import { IconButton, Tooltip } from '../../../components';
|
|
6
|
+
|
|
7
|
+
const Container = styled.div`
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
12
|
+
padding: ${({ theme }) => `${theme.spacing[2]} ${theme.spacing['2_5']}`};
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
interface DialogHeadingProps extends HTMLProps<HTMLHeadingElement> {
|
|
16
|
+
hasClose?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DrawerHeading = forwardRef<HTMLHeadingElement, DialogHeadingProps>(function DrawerHeading(
|
|
20
|
+
{ children, hasClose = true, ...props },
|
|
21
|
+
ref,
|
|
22
|
+
) {
|
|
23
|
+
const { setLabelId, setOpen } = useDrawerContext();
|
|
24
|
+
const id = useId();
|
|
25
|
+
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
setLabelId(id);
|
|
28
|
+
return () => setLabelId(undefined);
|
|
29
|
+
}, [id, setLabelId]);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Container>
|
|
33
|
+
<h2 {...props} ref={ref} id={id}>
|
|
34
|
+
{children}
|
|
35
|
+
</h2>
|
|
36
|
+
{hasClose && (
|
|
37
|
+
<Tooltip>
|
|
38
|
+
<Tooltip.Trigger asChild>
|
|
39
|
+
<IconButton
|
|
40
|
+
onClick={() => setOpen(false)}
|
|
41
|
+
icon={<CloseIcon size={18} cursor="pointer" />}
|
|
42
|
+
ariaLabel="Close"
|
|
43
|
+
/>
|
|
44
|
+
</Tooltip.Trigger>
|
|
45
|
+
<Tooltip.Content>Close</Tooltip.Content>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
)}
|
|
48
|
+
</Container>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Skeleton, Drawer } from '../../../components';
|
|
2
|
+
import { styled } from '../../../styled';
|
|
3
|
+
|
|
4
|
+
const Inner = styled.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
gap: ${({ theme }) => theme.spacing[2]};
|
|
8
|
+
margin-top: ${({ theme }) => theme.spacing[2]};
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const DrawerSkeleton = () => {
|
|
12
|
+
return (
|
|
13
|
+
<Drawer initialOpen>
|
|
14
|
+
<Drawer.Content>
|
|
15
|
+
<Drawer.Body>
|
|
16
|
+
<Inner>
|
|
17
|
+
<Skeleton width="100%" height="8vh" variant="rectangular" />
|
|
18
|
+
<Skeleton width="100%" height="12vh" variant="rectangular" />
|
|
19
|
+
<Skeleton width="100%" height="5vh" variant="rectangular" />
|
|
20
|
+
<Skeleton width="100%" height="10vh" variant="rectangular" />
|
|
21
|
+
<Skeleton width="100%" height="15vh" variant="rectangular" />
|
|
22
|
+
<Skeleton width="100%" height="16vh" variant="rectangular" />
|
|
23
|
+
<Skeleton width="100%" height="5vh" variant="rectangular" />
|
|
24
|
+
</Inner>
|
|
25
|
+
</Drawer.Body>
|
|
26
|
+
</Drawer.Content>
|
|
27
|
+
</Drawer>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DrawerOptions, useDrawer } from './useDrawer';
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
import { DrawerContext } from './DrawerContext';
|
|
4
|
+
import { DrawerContent } from './DrawerContent';
|
|
5
|
+
import { DrawerHeading } from './DrawerHeading';
|
|
6
|
+
import { DrawerBody } from './DrawerBody';
|
|
7
|
+
import { DrawerFooter } from './DrawerFooter';
|
|
8
|
+
|
|
9
|
+
type SubComponentTypes = {
|
|
10
|
+
Content: typeof DrawerContent;
|
|
11
|
+
Heading: typeof DrawerHeading;
|
|
12
|
+
Body: typeof DrawerBody;
|
|
13
|
+
Footer: typeof DrawerFooter;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Drawer: FC<PropsWithChildren<DrawerOptions>> & SubComponentTypes = ({ children, ...options }) => {
|
|
17
|
+
return <DrawerContext.Provider value={useDrawer(options)}>{children}</DrawerContext.Provider>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Drawer.Content = DrawerContent;
|
|
21
|
+
Drawer.Heading = DrawerHeading;
|
|
22
|
+
Drawer.Body = DrawerBody;
|
|
23
|
+
Drawer.Footer = DrawerFooter;
|
|
24
|
+
|
|
25
|
+
export { DrawerSkeleton } from './DrawerSkeleton';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import { useClick, useDismiss, useFloating, useInteractions } from '@floating-ui/react';
|
|
3
|
+
|
|
4
|
+
export interface DrawerOptions {
|
|
5
|
+
open?: boolean;
|
|
6
|
+
initialOpen?: boolean;
|
|
7
|
+
onOpenChange?: (open: boolean) => void;
|
|
8
|
+
canDrag?: boolean;
|
|
9
|
+
promptCloseConfirmation?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useDrawer({
|
|
13
|
+
initialOpen = false,
|
|
14
|
+
canDrag = false,
|
|
15
|
+
open: controlledOpen,
|
|
16
|
+
promptCloseConfirmation = false,
|
|
17
|
+
onOpenChange: setControlledOpen,
|
|
18
|
+
}: DrawerOptions) {
|
|
19
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(initialOpen);
|
|
20
|
+
const [labelId, setLabelId] = useState<string | undefined>();
|
|
21
|
+
const [descriptionId, setDescriptionId] = useState<string | undefined>();
|
|
22
|
+
const [showConfirmDialog, setShowConfirmDialog] = useState<boolean>(false);
|
|
23
|
+
|
|
24
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
25
|
+
const setOpen = setControlledOpen ?? setUncontrolledOpen;
|
|
26
|
+
|
|
27
|
+
const data = useFloating({
|
|
28
|
+
open,
|
|
29
|
+
onOpenChange: setOpen,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const context = data.context;
|
|
33
|
+
|
|
34
|
+
const interactions = useInteractions([
|
|
35
|
+
useClick(context, {
|
|
36
|
+
enabled: controlledOpen == null,
|
|
37
|
+
}),
|
|
38
|
+
useDismiss(context, {
|
|
39
|
+
outsidePressEvent: 'mousedown',
|
|
40
|
+
outsidePress: (_mouseEvent) => {
|
|
41
|
+
if (promptCloseConfirmation === true) {
|
|
42
|
+
setShowConfirmDialog(true);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
return useMemo(
|
|
51
|
+
() => ({
|
|
52
|
+
open,
|
|
53
|
+
setOpen,
|
|
54
|
+
showConfirmDialog,
|
|
55
|
+
setShowConfirmDialog,
|
|
56
|
+
...interactions,
|
|
57
|
+
...data,
|
|
58
|
+
labelId,
|
|
59
|
+
descriptionId,
|
|
60
|
+
setLabelId,
|
|
61
|
+
setDescriptionId,
|
|
62
|
+
canDrag,
|
|
63
|
+
}),
|
|
64
|
+
[open, setOpen, interactions, data, labelId, descriptionId, showConfirmDialog],
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { InfiniteScroll, InfiniteScrollProps } from '.';
|
|
4
|
+
import { styled } from '../../../styled';
|
|
5
|
+
|
|
6
|
+
const Wrapper = styled.div`
|
|
7
|
+
height: 100vh;
|
|
8
|
+
overflow: scroll;
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
const Filler = styled.div`
|
|
12
|
+
height: 100vh;
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: 'Data/InfiniteScroll',
|
|
17
|
+
component: InfiniteScroll,
|
|
18
|
+
args: {
|
|
19
|
+
hasNextPage: true,
|
|
20
|
+
isFetching: false,
|
|
21
|
+
isFetchingNextPage: false,
|
|
22
|
+
fetchNextPage: () => {},
|
|
23
|
+
},
|
|
24
|
+
} as Meta<InfiniteScrollProps>;
|
|
25
|
+
|
|
26
|
+
export const Default: StoryFn<InfiniteScrollProps> = (args) => {
|
|
27
|
+
return (
|
|
28
|
+
<Wrapper>
|
|
29
|
+
<Filler />
|
|
30
|
+
<InfiniteScroll {...args} />
|
|
31
|
+
</Wrapper>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { forwardRef, useEffect } from 'react';
|
|
2
|
+
import { useInView } from 'react-intersection-observer';
|
|
3
|
+
import { useMergeRefs } from '@floating-ui/react';
|
|
4
|
+
import { Button, Spinner } from '../../../components';
|
|
5
|
+
|
|
6
|
+
export interface InfiniteScrollProps {
|
|
7
|
+
isFetchingNextPage: boolean;
|
|
8
|
+
fetchNextPage: () => void;
|
|
9
|
+
isFetching: boolean;
|
|
10
|
+
hasNextPage?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const InfiniteScroll = forwardRef<HTMLElement, InfiniteScrollProps>(function InfiniteScroll(
|
|
14
|
+
{ hasNextPage = false, fetchNextPage, isFetching, isFetchingNextPage },
|
|
15
|
+
propRef,
|
|
16
|
+
) {
|
|
17
|
+
const { ref: viewRef, inView } = useInView();
|
|
18
|
+
const ref = useMergeRefs([propRef, viewRef]);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (inView) {
|
|
22
|
+
fetchNextPage();
|
|
23
|
+
}
|
|
24
|
+
}, [inView]);
|
|
25
|
+
|
|
26
|
+
// Fallback: sometimes the inView event does not trigger automatically.
|
|
27
|
+
// the user will have to manually click the button to fetch the next page.
|
|
28
|
+
const handleOnClick = () => {
|
|
29
|
+
fetchNextPage();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{!isFetchingNextPage && hasNextPage && !isFetching && (
|
|
35
|
+
<div
|
|
36
|
+
ref={ref}
|
|
37
|
+
style={{ display: 'flex', height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center' }}
|
|
38
|
+
>
|
|
39
|
+
<Button ref={ref} onClick={handleOnClick}>
|
|
40
|
+
Load more
|
|
41
|
+
</Button>
|
|
42
|
+
</div>
|
|
43
|
+
)}
|
|
44
|
+
{hasNextPage && isFetchingNextPage && (
|
|
45
|
+
<div
|
|
46
|
+
ref={ref}
|
|
47
|
+
style={{ display: 'flex', height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center' }}
|
|
48
|
+
>
|
|
49
|
+
<Spinner size="medium" />
|
|
50
|
+
</div>
|
|
51
|
+
)}
|
|
52
|
+
</>
|
|
53
|
+
);
|
|
54
|
+
});
|