@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,73 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { styled } from '../../../../styled';
|
|
3
|
+
import { useTheme } from '../../../../hooks';
|
|
4
|
+
import { FiWifi as WifiIcon, FiWifiOff as WifiOffIcon } from 'react-icons/fi';
|
|
5
|
+
import { AiOutlineClose as CloseIcon } from 'react-icons/ai';
|
|
6
|
+
import { CustomContentProps, useSnackbar } from 'notistack';
|
|
7
|
+
|
|
8
|
+
const Container = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
padding: 1.2rem;
|
|
13
|
+
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
14
|
+
width: 300px;
|
|
15
|
+
background-color: white;
|
|
16
|
+
p {
|
|
17
|
+
font-size: 1.325rem;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
const CloseIconContainer = styled.div`
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
padding: 0.3rem;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
|
|
25
|
+
&:hover {
|
|
26
|
+
background-color: ${({ theme }): string => theme.colors.background};
|
|
27
|
+
svg {
|
|
28
|
+
fill: white;
|
|
29
|
+
stroke: white;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const NetworkDetectorOfflineSnack = forwardRef<HTMLDivElement, CustomContentProps>(
|
|
35
|
+
function NetworkDetectorOfflineSnack({ id, message }, ref) {
|
|
36
|
+
const { closeSnackbar } = useSnackbar();
|
|
37
|
+
|
|
38
|
+
const handleClose = () => {
|
|
39
|
+
closeSnackbar(id);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Container ref={ref}>
|
|
44
|
+
<WifiOffIcon size={18} style={{ stroke: 'black' }} />
|
|
45
|
+
<p>{message}</p>
|
|
46
|
+
<CloseIconContainer>
|
|
47
|
+
<CloseIcon onClick={handleClose} size={18} style={{ cursor: 'pointer' }} />
|
|
48
|
+
</CloseIconContainer>
|
|
49
|
+
</Container>
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const NetworkDetectorOnlineSnack = forwardRef<HTMLDivElement, CustomContentProps>(
|
|
55
|
+
function NetworkDetectorOnlineSnack({ id, message }, ref) {
|
|
56
|
+
const theme = useTheme();
|
|
57
|
+
const { closeSnackbar } = useSnackbar();
|
|
58
|
+
|
|
59
|
+
const handleClose = () => {
|
|
60
|
+
closeSnackbar(id);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Container ref={ref}>
|
|
65
|
+
<WifiIcon size={20} style={{ stroke: theme.colors.success }} />
|
|
66
|
+
<p>{message}</p>
|
|
67
|
+
<CloseIconContainer>
|
|
68
|
+
<CloseIcon onClick={handleClose} size={18} style={{ cursor: 'pointer' }} />
|
|
69
|
+
</CloseIconContainer>
|
|
70
|
+
</Container>
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DefaultSnackProps } from './Default';
|
|
2
|
+
import { DrawerSnackProps } from './Drawer';
|
|
3
|
+
|
|
4
|
+
declare module 'notistack' {
|
|
5
|
+
interface VariantOverrides {
|
|
6
|
+
// disable default variants
|
|
7
|
+
success: false;
|
|
8
|
+
error: false;
|
|
9
|
+
info: false;
|
|
10
|
+
warning: false;
|
|
11
|
+
|
|
12
|
+
default: DefaultSnackProps;
|
|
13
|
+
draw: DrawerSnackProps;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { DefaultSnack } from './Default';
|
|
2
|
+
export type { DefaultSnackProps } from './Default';
|
|
3
|
+
|
|
4
|
+
export { DrawerSnack } from './Drawer';
|
|
5
|
+
|
|
6
|
+
export { NetworkDetectorOfflineSnack, NetworkDetectorOnlineSnack } from './NetworkDetector';
|
|
7
|
+
|
|
8
|
+
export { CookieConsentSnack } from './CookieConsent';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { CheckBox, CheckBoxProps, Button } from '../../../components';
|
|
5
|
+
import { SubmitHandler, useForm, useWatch } from 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
const Wrapper = styled.div`
|
|
8
|
+
padding: 5rem;
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Inputs/Checkbox',
|
|
13
|
+
component: CheckBox,
|
|
14
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
15
|
+
args: {
|
|
16
|
+
name: 'checkbox',
|
|
17
|
+
loading: false,
|
|
18
|
+
defaultValue: false,
|
|
19
|
+
readOnly: false,
|
|
20
|
+
label: 'this is the label',
|
|
21
|
+
labelPosition: 'left',
|
|
22
|
+
disabled: false,
|
|
23
|
+
required: true,
|
|
24
|
+
size: 'medium',
|
|
25
|
+
},
|
|
26
|
+
} as Meta<CheckBoxProps>;
|
|
27
|
+
|
|
28
|
+
export const OnSubmit: StoryFn<CheckBoxProps & { defaultValue: boolean }> = (args) => {
|
|
29
|
+
type FormFields = { checkbox: boolean };
|
|
30
|
+
|
|
31
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
32
|
+
defaultValues: {
|
|
33
|
+
checkbox: args.defaultValue,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const [result, setResult] = React.useState<boolean>(false);
|
|
37
|
+
|
|
38
|
+
const onSubmit: SubmitHandler<FormFields> = (values) => {
|
|
39
|
+
setResult(values[args.name]);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
45
|
+
<CheckBox {...args} control={control} />
|
|
46
|
+
<Button type="submit">submit</Button>
|
|
47
|
+
</form>
|
|
48
|
+
<pre>value: {result ? 'true' : 'false'}</pre>
|
|
49
|
+
<p>NOTE: defaultValue will only be set on initial load. Limitation of react-hook-form.</p>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const OnChange: StoryFn<CheckBoxProps> = (args) => {
|
|
55
|
+
const { control } = useForm();
|
|
56
|
+
const CheckBoxValue = useWatch({ control, name: args.name });
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<CheckBox {...args} control={control} />
|
|
61
|
+
<pre>value: {CheckBoxValue ? 'true' : 'false'}</pre>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { GenericCheckBox } from '.';
|
|
4
|
+
import { Container, LoadingCheckBox } from './style';
|
|
5
|
+
|
|
6
|
+
import { defaultInputProps, defaultInputPropsFactory, ControlledInputProps } from '../InputProps';
|
|
7
|
+
import { Label, ErrorMessage, InputWrapper, Description } from '../layout';
|
|
8
|
+
|
|
9
|
+
export interface CheckBoxProps {
|
|
10
|
+
labelPosition?: 'left' | 'right';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ControlledCheckBoxProps = ControlledInputProps & CheckBoxProps;
|
|
14
|
+
|
|
15
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledCheckBoxProps>(defaultInputProps);
|
|
16
|
+
|
|
17
|
+
export const ControlledCheckBox: FC<ControlledCheckBoxProps> = (props) => {
|
|
18
|
+
const {
|
|
19
|
+
name,
|
|
20
|
+
size,
|
|
21
|
+
label,
|
|
22
|
+
loading,
|
|
23
|
+
required,
|
|
24
|
+
readOnly,
|
|
25
|
+
disabled,
|
|
26
|
+
description,
|
|
27
|
+
labelPosition = 'left',
|
|
28
|
+
hint,
|
|
29
|
+
control,
|
|
30
|
+
} = defaultsApplier(props);
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
field,
|
|
34
|
+
fieldState: { error },
|
|
35
|
+
} = useController({
|
|
36
|
+
name,
|
|
37
|
+
control,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (loading) {
|
|
41
|
+
return (
|
|
42
|
+
<InputWrapper>
|
|
43
|
+
<Container>
|
|
44
|
+
{/* CASE: Show label before <CheckBox /> */}
|
|
45
|
+
{labelPosition === 'left' && label && (
|
|
46
|
+
<Label
|
|
47
|
+
error={!!error}
|
|
48
|
+
position={labelPosition}
|
|
49
|
+
size={size}
|
|
50
|
+
text={label}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
required={required}
|
|
53
|
+
hint={hint}
|
|
54
|
+
htmlFor={name}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
<LoadingCheckBox className="placeholder" />
|
|
58
|
+
{/* CASE: show label after <CheckBox /> */}
|
|
59
|
+
{labelPosition === 'right' && label && (
|
|
60
|
+
<Label
|
|
61
|
+
error={!!error}
|
|
62
|
+
position={labelPosition}
|
|
63
|
+
size={size}
|
|
64
|
+
text={label}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
required={required}
|
|
67
|
+
hint={hint}
|
|
68
|
+
htmlFor={name}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</Container>
|
|
72
|
+
{description && <Description description={description} inputName={name} />}
|
|
73
|
+
</InputWrapper>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<InputWrapper>
|
|
79
|
+
<Container>
|
|
80
|
+
{/* CASE: Show label before <CheckBox /> */}
|
|
81
|
+
{labelPosition === 'left' && label && (
|
|
82
|
+
<Label
|
|
83
|
+
error={!!error}
|
|
84
|
+
position={labelPosition}
|
|
85
|
+
size={size}
|
|
86
|
+
text={label}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
required={required}
|
|
89
|
+
htmlFor={name}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
<GenericCheckBox
|
|
93
|
+
id={name}
|
|
94
|
+
hasError={!!error}
|
|
95
|
+
hasDescription={!!description}
|
|
96
|
+
name={name}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
size={size}
|
|
99
|
+
readOnly={readOnly}
|
|
100
|
+
required={required}
|
|
101
|
+
onChange={field.onChange}
|
|
102
|
+
onBlur={field.onBlur}
|
|
103
|
+
value={field.value}
|
|
104
|
+
/>
|
|
105
|
+
|
|
106
|
+
{/* CASE: show label after <CheckBox /> */}
|
|
107
|
+
{labelPosition === 'right' && label && (
|
|
108
|
+
<Label
|
|
109
|
+
error={!!error}
|
|
110
|
+
position={labelPosition}
|
|
111
|
+
text={label}
|
|
112
|
+
disabled={disabled}
|
|
113
|
+
required={required}
|
|
114
|
+
htmlFor={name}
|
|
115
|
+
size={size}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
{error && error.message && <ErrorMessage message={error.message} />}
|
|
119
|
+
</Container>
|
|
120
|
+
{description && <Description description={description} inputName={name} />}
|
|
121
|
+
</InputWrapper>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChangeEvent, forwardRef } from 'react';
|
|
2
|
+
import { Input } from './style';
|
|
3
|
+
import { defaultInputPropsFactory, defaultInputProps, GenericInputProps } from '../InputProps';
|
|
4
|
+
|
|
5
|
+
export type GenericCheckBoxProps = GenericInputProps<boolean, HTMLInputElement>;
|
|
6
|
+
const defaultsApplier = defaultInputPropsFactory<GenericCheckBoxProps>(defaultInputProps);
|
|
7
|
+
|
|
8
|
+
// TODO: write a test that checks if the value is being processed as a boolean.
|
|
9
|
+
export const GenericCheckBox = forwardRef<HTMLInputElement, GenericCheckBoxProps>(function Switch(props, ref) {
|
|
10
|
+
const {
|
|
11
|
+
readOnly,
|
|
12
|
+
disabled,
|
|
13
|
+
value = false,
|
|
14
|
+
hasError,
|
|
15
|
+
onChange,
|
|
16
|
+
id,
|
|
17
|
+
name,
|
|
18
|
+
hasDescription,
|
|
19
|
+
required,
|
|
20
|
+
} = defaultsApplier(props);
|
|
21
|
+
|
|
22
|
+
function handleOnChange(e: ChangeEvent<HTMLInputElement>) {
|
|
23
|
+
if (readOnly || disabled) return;
|
|
24
|
+
onChange(e);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Input
|
|
29
|
+
name={name}
|
|
30
|
+
type="checkbox"
|
|
31
|
+
hasError={hasError}
|
|
32
|
+
hasDescription={hasDescription}
|
|
33
|
+
aria-required={required}
|
|
34
|
+
checked={value}
|
|
35
|
+
readOnly={readOnly}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
id={id}
|
|
38
|
+
onChange={handleOnChange}
|
|
39
|
+
ref={ref}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
position: relative;
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: row;
|
|
7
|
+
text-align: left;
|
|
8
|
+
margin-bottom: ${({ theme }) => theme.spacing['0_5']};
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const LoadingCheckBox = styled.div`
|
|
12
|
+
&.placeholder {
|
|
13
|
+
border: none;
|
|
14
|
+
border-radius: ${({ theme }) => theme.borderRadius.small};
|
|
15
|
+
width: 2rem;
|
|
16
|
+
height: 2rem;
|
|
17
|
+
cursor: default;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const Input = styled.input<{ hasError: boolean; hasDescription: boolean }>`
|
|
22
|
+
width: 2rem;
|
|
23
|
+
height: 2rem;
|
|
24
|
+
border: 0.1rem solid ${({ theme, hasError }) => (hasError ? theme.colors.error : theme.colors.backgroundAccent)};
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
position: relative;
|
|
27
|
+
padding: ${({ theme }) => theme.spacing['0_75']};
|
|
28
|
+
background: ${({ theme }) => theme.colors.backgroundAlt};
|
|
29
|
+
transition: 0.15ms linear background;
|
|
30
|
+
vertical-align: middle;
|
|
31
|
+
|
|
32
|
+
:disabled {
|
|
33
|
+
background: ${({ theme }) => theme.colors.disabled};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:checked {
|
|
37
|
+
background: ${({ theme }) => theme.colors.primary};
|
|
38
|
+
|
|
39
|
+
:disabled {
|
|
40
|
+
background: ${({ theme }) => theme.colors.disabled};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
::after {
|
|
44
|
+
position: absolute;
|
|
45
|
+
content: '';
|
|
46
|
+
display: block;
|
|
47
|
+
left: 6px;
|
|
48
|
+
width: 4px;
|
|
49
|
+
top: 3px;
|
|
50
|
+
height: 8px;
|
|
51
|
+
border: solid white;
|
|
52
|
+
border-width: 0 2px 2px 0;
|
|
53
|
+
transform: rotate(45deg);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { CodeField, CodeFieldProps } from '../../../components';
|
|
4
|
+
import { useForm, SubmitHandler } from 'react-hook-form';
|
|
5
|
+
import { Button } from '../../actions';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Inputs/CodeField',
|
|
11
|
+
component: CodeField,
|
|
12
|
+
args: {
|
|
13
|
+
required: true,
|
|
14
|
+
disabled: false,
|
|
15
|
+
loading: false,
|
|
16
|
+
readOnly: false,
|
|
17
|
+
fields: 6,
|
|
18
|
+
label: 'Code field',
|
|
19
|
+
size: 'medium',
|
|
20
|
+
},
|
|
21
|
+
} as Meta<CodeFieldProps>;
|
|
22
|
+
|
|
23
|
+
type FormFields = { code: string };
|
|
24
|
+
|
|
25
|
+
export const OnSubmit: StoryFn<CodeFieldProps> = (args) => {
|
|
26
|
+
const [result, setResult] = useState<string>();
|
|
27
|
+
|
|
28
|
+
const validationSchema = useMemo(
|
|
29
|
+
() =>
|
|
30
|
+
z.object({
|
|
31
|
+
code: z.string().min(args.fields).max(args.fields),
|
|
32
|
+
}),
|
|
33
|
+
[args.fields],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const { handleSubmit, control } = useForm<FormFields>({
|
|
37
|
+
mode: 'onSubmit',
|
|
38
|
+
resolver: zodResolver(validationSchema),
|
|
39
|
+
});
|
|
40
|
+
const onSubmit: SubmitHandler<FormFields> = async ({ code }) => {
|
|
41
|
+
setResult(code);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
47
|
+
<CodeField
|
|
48
|
+
control={control}
|
|
49
|
+
fields={args.fields}
|
|
50
|
+
name="code"
|
|
51
|
+
loading={args.loading}
|
|
52
|
+
disabled={args.disabled}
|
|
53
|
+
required={args.required}
|
|
54
|
+
readOnly={args.readOnly}
|
|
55
|
+
label={args.label}
|
|
56
|
+
size={args.size}
|
|
57
|
+
/>
|
|
58
|
+
<Button type="submit">Submit form</Button>
|
|
59
|
+
</form>
|
|
60
|
+
<div>{result}</div>
|
|
61
|
+
</>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const AutoSubmit: StoryFn<CodeFieldProps> = () => {
|
|
66
|
+
const [result, setResult] = useState<string>();
|
|
67
|
+
const { control, handleSubmit } = useForm<FormFields>();
|
|
68
|
+
const [loading, setLoading] = useState(false);
|
|
69
|
+
|
|
70
|
+
const onSubmit: SubmitHandler<FormFields> = async ({ code }) => {
|
|
71
|
+
setLoading(true);
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
setResult(code);
|
|
75
|
+
}, 2000);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
81
|
+
<CodeField autoSubmit={handleSubmit(onSubmit)} control={control} fields={6} loading={loading} name="code" />
|
|
82
|
+
</form>
|
|
83
|
+
<div>Result: {result}</div>
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React, { KeyboardEvent, FC, useRef, useEffect, ChangeEvent, useState } from 'react';
|
|
2
|
+
import { Container, InputContainer, Input, LoadingField } from './style';
|
|
3
|
+
import { defaultInputProps, defaultInputPropsFactory, ControlledInputProps } from '../InputProps';
|
|
4
|
+
import { useController } from 'react-hook-form';
|
|
5
|
+
import { Label, ErrorMessage, Description, setAriaDescribedBy } from '../layout';
|
|
6
|
+
|
|
7
|
+
export type CodeFieldProps = Omit<ControlledInputProps, 'hasError'> & {
|
|
8
|
+
name: string;
|
|
9
|
+
fields: number;
|
|
10
|
+
allowedCharacters?: RegExp;
|
|
11
|
+
autoSubmit?: () => unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const defaultsApplier = defaultInputPropsFactory<CodeFieldProps>(defaultInputProps);
|
|
15
|
+
|
|
16
|
+
export const CodeField: FC<CodeFieldProps> = (props) => {
|
|
17
|
+
const {
|
|
18
|
+
loading,
|
|
19
|
+
name,
|
|
20
|
+
fields,
|
|
21
|
+
autoSubmit,
|
|
22
|
+
allowedCharacters = /[0-9]/,
|
|
23
|
+
hint,
|
|
24
|
+
size,
|
|
25
|
+
disabled,
|
|
26
|
+
control,
|
|
27
|
+
required,
|
|
28
|
+
description,
|
|
29
|
+
readOnly,
|
|
30
|
+
label,
|
|
31
|
+
} = defaultsApplier(props);
|
|
32
|
+
|
|
33
|
+
const [showError, setShowError] = useState<boolean>(false);
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
field,
|
|
37
|
+
fieldState: { error },
|
|
38
|
+
} = useController({ name, control });
|
|
39
|
+
|
|
40
|
+
const fieldRefs = useRef<HTMLInputElement[]>([]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (fieldRefs.current.length) {
|
|
44
|
+
fieldRefs.current[0].focus();
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
const sendResult = () => {
|
|
49
|
+
const res = fieldRefs.current.map((field) => field.value).join('');
|
|
50
|
+
field.onChange(res);
|
|
51
|
+
|
|
52
|
+
if (res.length === fields) {
|
|
53
|
+
if (autoSubmit) autoSubmit();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
58
|
+
if (disabled) return;
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
target: { value, nextElementSibling },
|
|
62
|
+
} = e;
|
|
63
|
+
|
|
64
|
+
if (value.match(allowedCharacters)) {
|
|
65
|
+
if (nextElementSibling !== null) {
|
|
66
|
+
(nextElementSibling as HTMLInputElement).focus();
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
e.target.value = '';
|
|
70
|
+
}
|
|
71
|
+
sendResult();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleOnFocus = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
75
|
+
if (disabled) return;
|
|
76
|
+
setShowError(true);
|
|
77
|
+
e.target.select();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
81
|
+
const target = e.target as HTMLInputElement;
|
|
82
|
+
|
|
83
|
+
if (e.key === 'Backspace') {
|
|
84
|
+
if (target.value === '' && target.previousElementSibling !== null) {
|
|
85
|
+
if (target.previousElementSibling !== null) {
|
|
86
|
+
(target.previousElementSibling as HTMLInputElement).focus();
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
target.value = '';
|
|
91
|
+
}
|
|
92
|
+
sendResult();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleOnBlur = () => {
|
|
97
|
+
if (disabled) return;
|
|
98
|
+
field.onBlur();
|
|
99
|
+
setShowError(false);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const handleOnPaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
|
|
103
|
+
const value = e.clipboardData.getData('Text');
|
|
104
|
+
if (value.match(allowedCharacters)) {
|
|
105
|
+
for (let i = 0; i < fields && i < value.length; i++) {
|
|
106
|
+
fieldRefs.current[i].value = value.charAt(i);
|
|
107
|
+
if (fieldRefs.current[i].nextElementSibling !== null) {
|
|
108
|
+
(fieldRefs.current[i].nextElementSibling as HTMLInputElement).focus();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
sendResult();
|
|
112
|
+
}
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (loading) {
|
|
117
|
+
return (
|
|
118
|
+
<Container>
|
|
119
|
+
<InputContainer fields={fields}>
|
|
120
|
+
{Array.from(Array(fields).keys()).map((_, idx) => (
|
|
121
|
+
<LoadingField key={`loading-field-array-${idx}`} className="placeholder" />
|
|
122
|
+
))}
|
|
123
|
+
</InputContainer>
|
|
124
|
+
</Container>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Container>
|
|
130
|
+
{label && (
|
|
131
|
+
<Label
|
|
132
|
+
required={required}
|
|
133
|
+
disabled={disabled}
|
|
134
|
+
size={size}
|
|
135
|
+
hint={hint}
|
|
136
|
+
text={label}
|
|
137
|
+
position="top"
|
|
138
|
+
error={!!error}
|
|
139
|
+
htmlFor={`${name}-0`}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
<InputContainer fields={fields} aria-describedby={setAriaDescribedBy(name, !!description)}>
|
|
143
|
+
{Array.from(Array(fields).keys()).map((_, i) => (
|
|
144
|
+
<Input
|
|
145
|
+
key={`${name}-${i}`}
|
|
146
|
+
autoCapitalize="off"
|
|
147
|
+
autoComplete="off"
|
|
148
|
+
hasError={!!error}
|
|
149
|
+
isDisabled={disabled}
|
|
150
|
+
disabled={disabled}
|
|
151
|
+
id={`${name}-${i}`}
|
|
152
|
+
maxLength={1}
|
|
153
|
+
name={`${name}-${i}`}
|
|
154
|
+
aria-required={required}
|
|
155
|
+
onChange={handleOnChange}
|
|
156
|
+
onFocus={handleOnFocus}
|
|
157
|
+
onBlur={handleOnBlur}
|
|
158
|
+
onKeyDown={handleKeyDown}
|
|
159
|
+
onPaste={handleOnPaste}
|
|
160
|
+
readOnly={readOnly}
|
|
161
|
+
ref={(el) => {
|
|
162
|
+
if (el) {
|
|
163
|
+
fieldRefs.current[i] = el;
|
|
164
|
+
}
|
|
165
|
+
}}
|
|
166
|
+
type="text"
|
|
167
|
+
/>
|
|
168
|
+
))}
|
|
169
|
+
{error && error.message && showError && <ErrorMessage message={error.message} />}
|
|
170
|
+
{description && <Description description={description} inputName={name} />}
|
|
171
|
+
</InputContainer>
|
|
172
|
+
</Container>
|
|
173
|
+
);
|
|
174
|
+
};
|