@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,34 @@
|
|
|
1
|
+
import { styled } from '../../../styled';
|
|
2
|
+
|
|
3
|
+
export const Container = styled.div`
|
|
4
|
+
width: 100%;
|
|
5
|
+
position: relative;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const InputContainer = styled.div``;
|
|
9
|
+
|
|
10
|
+
export const ContentContainer = styled.div<{ hasError: boolean }>`
|
|
11
|
+
width: 100%;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
|
|
17
|
+
border: 1px solid ${({ theme, hasError }): string => (hasError ? theme.colors.error : theme.colors.backgroundAccent)};
|
|
18
|
+
padding: ${({ theme }) => `${theme.spacing['0_75']} ${theme.spacing[1]}`};
|
|
19
|
+
border-width: 0.1rem;
|
|
20
|
+
border-radius: ${({ theme }) => theme.borderRadius.medium};
|
|
21
|
+
font-size: ${({ theme }) => theme.fontSize.small};
|
|
22
|
+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
|
|
23
|
+
color: ${({ theme }) => theme.colors.textAlt};
|
|
24
|
+
|
|
25
|
+
&:focus {
|
|
26
|
+
border: 1px solid ${({ theme, hasError }): string => (hasError ? theme.colors.error : theme.colors.primary)};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
span {
|
|
30
|
+
text-overflow: ellipsis;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ChangeEventHandler, FocusEventHandler } from 'react';
|
|
2
|
+
import { Control, FieldValues } from 'react-hook-form';
|
|
3
|
+
import { Size } from '../../styled';
|
|
4
|
+
|
|
5
|
+
// Props that available on all fields (but no default value)
|
|
6
|
+
interface InputProps extends DefaultInputProps {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Props for generic input props
|
|
11
|
+
export interface GenericInputProps<V, T> extends InputProps {
|
|
12
|
+
value: V;
|
|
13
|
+
// Although name could be used as a unique field identifier, name is not retrievable in JsonSchemaForm/FieldTemplate
|
|
14
|
+
id: string;
|
|
15
|
+
hasDescription: boolean;
|
|
16
|
+
hasError: boolean;
|
|
17
|
+
onChange: ChangeEventHandler<T>;
|
|
18
|
+
onBlur?: FocusEventHandler<T>;
|
|
19
|
+
onFocus?: FocusEventHandler<T>;
|
|
20
|
+
}
|
|
21
|
+
export interface GenericInputPropsFunctionHandlers<V, D> extends InputProps {
|
|
22
|
+
value: V;
|
|
23
|
+
id: string;
|
|
24
|
+
hasError: boolean;
|
|
25
|
+
hasDescription: boolean;
|
|
26
|
+
onChange: (val: V) => void;
|
|
27
|
+
onBlur?: FocusEventHandler<D>;
|
|
28
|
+
onFocus?: FocusEventHandler<D>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ControlledInputProps extends InputProps {
|
|
32
|
+
control: Control<FieldValues> | Control<any>;
|
|
33
|
+
label?: string;
|
|
34
|
+
loading?: boolean;
|
|
35
|
+
hint?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// All input components have a set of props in common which all should have the same default values.
|
|
40
|
+
interface DefaultInputProps {
|
|
41
|
+
required?: boolean;
|
|
42
|
+
readOnly?: boolean;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
size?: Size;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Required<T> = {
|
|
48
|
+
[P in keyof T]-?: T[P];
|
|
49
|
+
};
|
|
50
|
+
export const defaultInputProps: Required<DefaultInputProps> = {
|
|
51
|
+
required: false,
|
|
52
|
+
readOnly: false,
|
|
53
|
+
disabled: false,
|
|
54
|
+
size: 'medium',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function defaultInputPropsFactory<T extends InputProps>(defaultValues: Required<DefaultInputProps>) {
|
|
58
|
+
return (values: T) => Object.assign({} as Required<DefaultInputProps> & T, defaultValues, values);
|
|
59
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { useController } from 'react-hook-form';
|
|
3
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
4
|
+
|
|
5
|
+
import { Container } from './style';
|
|
6
|
+
import { RadioItem } from './RadioItem';
|
|
7
|
+
import { InputWrapper, ErrorMessage, Description } from '../layout';
|
|
8
|
+
import { GenericRadioGroup, RadioGroupSubComponents } from './Generic';
|
|
9
|
+
|
|
10
|
+
export type ControlledRadioGroupProps = PropsWithChildren<ControlledInputProps>;
|
|
11
|
+
|
|
12
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledRadioGroupProps>(defaultInputProps);
|
|
13
|
+
|
|
14
|
+
export const ControlledRadioGroup: FC<ControlledRadioGroupProps> & RadioGroupSubComponents = (props) => {
|
|
15
|
+
const { name, control, description, children, disabled, readOnly, required } = defaultsApplier(props);
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
field,
|
|
19
|
+
fieldState: { error },
|
|
20
|
+
} = useController({ name, control });
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<InputWrapper>
|
|
24
|
+
<Container>
|
|
25
|
+
<GenericRadioGroup
|
|
26
|
+
id={name}
|
|
27
|
+
name={name}
|
|
28
|
+
onChange={field.onChange}
|
|
29
|
+
value={field.value}
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
readOnly={readOnly}
|
|
32
|
+
hasError={!!error}
|
|
33
|
+
required={required}
|
|
34
|
+
hasDescription={!!description}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
</GenericRadioGroup>
|
|
38
|
+
{error && error.message && <ErrorMessage message={error.message} />}
|
|
39
|
+
</Container>
|
|
40
|
+
{description && <Description description={description} inputName={name} />}
|
|
41
|
+
</InputWrapper>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
ControlledRadioGroup.Item = RadioItem;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ChangeEvent, FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { defaultInputProps, defaultInputPropsFactory, GenericInputProps } from '../InputProps';
|
|
3
|
+
import { RadioItem } from './RadioItem';
|
|
4
|
+
import { Container } from './style';
|
|
5
|
+
import { setAriaDescribedBy } from '../layout';
|
|
6
|
+
import { RadioGroupContext } from './context';
|
|
7
|
+
|
|
8
|
+
export interface RadioGroupSubComponents {
|
|
9
|
+
Item: typeof RadioItem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type RadioGroupProps = PropsWithChildren<GenericInputProps<string, HTMLInputElement>>;
|
|
13
|
+
const defaultsApplier = defaultInputPropsFactory<RadioGroupProps>(defaultInputProps);
|
|
14
|
+
|
|
15
|
+
export const GenericRadioGroup: FC<RadioGroupProps> & RadioGroupSubComponents = (props) => {
|
|
16
|
+
const { readOnly, value, name, onChange, hasDescription, disabled, children } = defaultsApplier(props);
|
|
17
|
+
|
|
18
|
+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
19
|
+
if (readOnly || disabled) return;
|
|
20
|
+
onChange(e);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Container role="radiogroup" aria-describedby={setAriaDescribedBy(name, hasDescription)}>
|
|
25
|
+
<RadioGroupContext.Provider
|
|
26
|
+
value={{ name, selectedValue: value, setSelectedValue: handleChange, readOnly, disabled }}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</RadioGroupContext.Provider>
|
|
30
|
+
</Container>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
GenericRadioGroup.Item = RadioItem;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, { ChangeEvent, useMemo, useState } from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { Button, RadioGroup, RadioGroupProps } from '../../../components';
|
|
4
|
+
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
7
|
+
import { GenericRadioGroup } from './Generic';
|
|
8
|
+
|
|
9
|
+
const options = [
|
|
10
|
+
{ value: 'm', label: 'male' },
|
|
11
|
+
{ value: 'f', label: 'female' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: 'Inputs/RadioGroup',
|
|
16
|
+
component: RadioGroup,
|
|
17
|
+
args: {
|
|
18
|
+
readOnly: false,
|
|
19
|
+
disabled: false,
|
|
20
|
+
loading: false,
|
|
21
|
+
hint: 'this is the hint',
|
|
22
|
+
label: 'Enter your gender',
|
|
23
|
+
description: 'this is the description',
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
} as Meta<RadioGroupProps>;
|
|
27
|
+
|
|
28
|
+
export const OnSubmit: StoryFn<RadioGroupProps> = (args) => {
|
|
29
|
+
type FormFields = {
|
|
30
|
+
gender: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const [result, setResult] = useState<string>('');
|
|
34
|
+
|
|
35
|
+
const validationSchema = useMemo(
|
|
36
|
+
() =>
|
|
37
|
+
z.object({
|
|
38
|
+
gender: z.enum(['m', 'f']),
|
|
39
|
+
}),
|
|
40
|
+
[],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const { control, handleSubmit } = useForm<FormFields>({
|
|
44
|
+
resolver: zodResolver(validationSchema),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const onSubmit: SubmitHandler<FormFields> = async ({ gender }) => {
|
|
48
|
+
setResult(gender);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
54
|
+
<RadioGroup
|
|
55
|
+
control={control}
|
|
56
|
+
loading={args.loading}
|
|
57
|
+
readOnly={args.readOnly}
|
|
58
|
+
label={args.label}
|
|
59
|
+
name="gender"
|
|
60
|
+
hint={args.hint}
|
|
61
|
+
disabled={args.disabled}
|
|
62
|
+
required={args.required}
|
|
63
|
+
description={args.description}
|
|
64
|
+
>
|
|
65
|
+
{options.map(({ value, label }) => (
|
|
66
|
+
<div
|
|
67
|
+
key={`gender-${value}`}
|
|
68
|
+
style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginBottom: '1rem' }}
|
|
69
|
+
>
|
|
70
|
+
<RadioGroup.Item value={value} id={value} />
|
|
71
|
+
<label htmlFor={value} style={{ cursor: !args.disabled && !args.readOnly ? 'pointer' : 'default' }}>
|
|
72
|
+
{label}
|
|
73
|
+
</label>
|
|
74
|
+
</div>
|
|
75
|
+
))}
|
|
76
|
+
</RadioGroup>
|
|
77
|
+
<Button type="submit">submit</Button>
|
|
78
|
+
</form>
|
|
79
|
+
<div>Result: {result}</div>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const Generic: StoryFn<RadioGroupProps> = (args) => {
|
|
85
|
+
const id = 'gender';
|
|
86
|
+
const [value, setValue] = useState<string>('m');
|
|
87
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
88
|
+
setValue(e.target.value);
|
|
89
|
+
};
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<GenericRadioGroup
|
|
93
|
+
id={id}
|
|
94
|
+
readOnly={args.readOnly}
|
|
95
|
+
name="gender"
|
|
96
|
+
required={args.required}
|
|
97
|
+
disabled={args.disabled}
|
|
98
|
+
hasDescription={!!args.description}
|
|
99
|
+
hasError={false}
|
|
100
|
+
value={value}
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
onChange={handleOnChange}
|
|
104
|
+
>
|
|
105
|
+
{options.map(({ value, label }) => (
|
|
106
|
+
<div
|
|
107
|
+
key={`${id}-${value}`}
|
|
108
|
+
style={{ display: 'flex', alignItems: 'center', gap: '1rem', marginBottom: '1rem' }}
|
|
109
|
+
>
|
|
110
|
+
<GenericRadioGroup.Item value={value} id={value} />
|
|
111
|
+
<label htmlFor={value}>{label}</label>
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</GenericRadioGroup>
|
|
115
|
+
<>{value}</>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { forwardRef, useRef } from 'react';
|
|
2
|
+
import { useRadioGroupContext } from './context';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { motion } from 'framer-motion';
|
|
5
|
+
import { AiOutlineCheck as CheckMarkIcon } from 'react-icons/ai';
|
|
6
|
+
import { shade } from 'polished';
|
|
7
|
+
|
|
8
|
+
const RadioItemContainer = styled.div<{ readOnly: boolean; isChecked: boolean; disabled: boolean }>`
|
|
9
|
+
display: grid;
|
|
10
|
+
place-items: center;
|
|
11
|
+
min-width: ${({ theme }) => theme.spacing['2_5']};
|
|
12
|
+
min-height: ${({ theme }) => theme.spacing['2_5']};
|
|
13
|
+
width: ${({ theme }) => theme.spacing['2_5']};
|
|
14
|
+
height: ${({ theme }) => theme.spacing['2_5']};
|
|
15
|
+
max-width: ${({ theme }) => theme.spacing['2_5']};
|
|
16
|
+
max-height: ${({ theme }) => theme.spacing['2_5']};
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
border: 0.1rem solid
|
|
20
|
+
${({ theme, readOnly, isChecked }): string => {
|
|
21
|
+
if (readOnly) return theme.colors.backgroundAccent;
|
|
22
|
+
if (isChecked) return theme.colors.primary;
|
|
23
|
+
return theme.colors.backgroundAccent;
|
|
24
|
+
}};
|
|
25
|
+
|
|
26
|
+
background-color: ${({ theme, readOnly, disabled }) =>
|
|
27
|
+
readOnly || disabled ? theme.colors.backgroundAccent : shade(0.5, theme.colors.background)};
|
|
28
|
+
border-radius: 100%;
|
|
29
|
+
cursor: ${({ readOnly, disabled }) => {
|
|
30
|
+
if (disabled) return 'not-allowed';
|
|
31
|
+
if (readOnly) return 'default';
|
|
32
|
+
return 'pointer';
|
|
33
|
+
}};
|
|
34
|
+
|
|
35
|
+
overflow: visible;
|
|
36
|
+
|
|
37
|
+
&.placeholder {
|
|
38
|
+
border: none;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
width: 2.2rem; /* 2.1rem + 1px shadow */
|
|
41
|
+
height: 2.2rem;
|
|
42
|
+
cursor: default;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const Inner = styled(motion.div)<{ $isChecked: boolean; $readOnly: boolean }>`
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
width: ${({ theme }) => theme.spacing['2_5']};
|
|
51
|
+
height: ${({ theme }) => theme.spacing['2_5']};
|
|
52
|
+
border-radius: 100%;
|
|
53
|
+
background-color: ${({ theme, $readOnly }) => {
|
|
54
|
+
if ($readOnly) return theme.colors.backgroundAlt;
|
|
55
|
+
return shade(0.5, theme.colors.primary);
|
|
56
|
+
}};
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
opacity: ${({ $isChecked }): number => ($isChecked ? 1 : 0)};
|
|
59
|
+
transition: 0.1s opacity linear cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
export interface RadioItemProps {
|
|
63
|
+
value: string;
|
|
64
|
+
id: string;
|
|
65
|
+
disabled?: boolean;
|
|
66
|
+
readOnly?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const variants = {
|
|
70
|
+
checked: { scale: 1 },
|
|
71
|
+
unchecked: { scale: 0 },
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const RadioItem = forwardRef<HTMLDivElement, RadioItemProps>(function RadioItem(
|
|
75
|
+
{ readOnly = false, disabled = false, value },
|
|
76
|
+
ref,
|
|
77
|
+
) {
|
|
78
|
+
const {
|
|
79
|
+
setSelectedValue,
|
|
80
|
+
selectedValue,
|
|
81
|
+
name,
|
|
82
|
+
disabled: groupDisabled,
|
|
83
|
+
readOnly: groupReadOnly,
|
|
84
|
+
} = useRadioGroupContext();
|
|
85
|
+
const checked = selectedValue === value;
|
|
86
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
87
|
+
|
|
88
|
+
const handleOnClick = () => {
|
|
89
|
+
if (readOnly || disabled || groupDisabled || groupReadOnly) return;
|
|
90
|
+
inputRef.current?.click();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
<input
|
|
96
|
+
id={value}
|
|
97
|
+
name={name}
|
|
98
|
+
type="radio"
|
|
99
|
+
style={{ position: 'absolute', opacity: 0, margin: 0, padding: 0, pointerEvents: 'none' }}
|
|
100
|
+
aria-hidden="true"
|
|
101
|
+
value={value}
|
|
102
|
+
tabIndex={-1}
|
|
103
|
+
checked={checked}
|
|
104
|
+
aria-readonly={readOnly || groupReadOnly}
|
|
105
|
+
aria-disabled={disabled || groupDisabled}
|
|
106
|
+
onChange={(e) => setSelectedValue(e)}
|
|
107
|
+
ref={inputRef}
|
|
108
|
+
/>
|
|
109
|
+
<RadioItemContainer
|
|
110
|
+
isChecked={checked}
|
|
111
|
+
readOnly={readOnly || groupReadOnly}
|
|
112
|
+
disabled={disabled || groupDisabled}
|
|
113
|
+
onClick={handleOnClick}
|
|
114
|
+
tabIndex={disabled ? -1 : 0}
|
|
115
|
+
role="radio"
|
|
116
|
+
ref={ref}
|
|
117
|
+
>
|
|
118
|
+
<Inner
|
|
119
|
+
initial={checked ? 'checked' : 'unchecked'}
|
|
120
|
+
animate={checked ? 'checked' : 'unchecked'}
|
|
121
|
+
$isChecked={checked}
|
|
122
|
+
$readOnly={readOnly || groupReadOnly}
|
|
123
|
+
variants={variants}
|
|
124
|
+
>
|
|
125
|
+
{checked && <CheckMarkIcon />}
|
|
126
|
+
</Inner>
|
|
127
|
+
</RadioItemContainer>
|
|
128
|
+
</>
|
|
129
|
+
);
|
|
130
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChangeEvent, createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ContextValue {
|
|
4
|
+
selectedValue: string;
|
|
5
|
+
setSelectedValue: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
6
|
+
name: string;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
readOnly: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const RadioGroupContext = createContext<ContextValue>({} as ContextValue);
|
|
12
|
+
|
|
13
|
+
export const useRadioGroupContext = () => {
|
|
14
|
+
const context = useContext(RadioGroupContext);
|
|
15
|
+
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('Component must be wrapped with RadioGroup');
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useController } from 'react-hook-form';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { GenericSwitch } from '.';
|
|
4
|
+
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
5
|
+
import { Label } from '../../../components';
|
|
6
|
+
import { Container } from './style';
|
|
7
|
+
import { InputWrapper, Description } from '../layout';
|
|
8
|
+
|
|
9
|
+
export type ControlledSwitchProps = ControlledInputProps;
|
|
10
|
+
|
|
11
|
+
const defaultsApplier = defaultInputPropsFactory<ControlledSwitchProps>(defaultInputProps);
|
|
12
|
+
|
|
13
|
+
export const ControlledSwitch: FC<ControlledSwitchProps> = (props) => {
|
|
14
|
+
const { readOnly, size, name, required, disabled, hint, label, control, description } = defaultsApplier(props);
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
field,
|
|
18
|
+
fieldState: { error },
|
|
19
|
+
} = useController({
|
|
20
|
+
name,
|
|
21
|
+
control,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<InputWrapper>
|
|
26
|
+
<Container>
|
|
27
|
+
{label && (
|
|
28
|
+
<Label
|
|
29
|
+
htmlFor={name}
|
|
30
|
+
text={label}
|
|
31
|
+
position="top"
|
|
32
|
+
error={!!error}
|
|
33
|
+
size={size}
|
|
34
|
+
required={required}
|
|
35
|
+
hint={hint}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
<GenericSwitch
|
|
40
|
+
id={name}
|
|
41
|
+
hasError={!!error}
|
|
42
|
+
hasDescription={!!description}
|
|
43
|
+
readOnly={readOnly}
|
|
44
|
+
required={required}
|
|
45
|
+
disabled={disabled}
|
|
46
|
+
name={name}
|
|
47
|
+
size={size}
|
|
48
|
+
onChange={field.onChange}
|
|
49
|
+
onBlur={field.onBlur}
|
|
50
|
+
value={field.value}
|
|
51
|
+
ref={field.ref}
|
|
52
|
+
/>
|
|
53
|
+
</Container>
|
|
54
|
+
{description && <Description description={description} inputName={name} style={{ marginTop: 0 }} />}
|
|
55
|
+
</InputWrapper>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ChangeEvent, forwardRef } from 'react';
|
|
2
|
+
import { Input } from './style';
|
|
3
|
+
import { defaultInputProps, defaultInputPropsFactory, GenericInputProps } from '../InputProps';
|
|
4
|
+
|
|
5
|
+
export type GenericSwitchProps = GenericInputProps<boolean, HTMLInputElement>;
|
|
6
|
+
|
|
7
|
+
const defaultsApplier = defaultInputPropsFactory<GenericSwitchProps>(defaultInputProps);
|
|
8
|
+
|
|
9
|
+
export const GenericSwitch = forwardRef<HTMLInputElement, GenericSwitchProps>(function Switch(props, ref) {
|
|
10
|
+
const {
|
|
11
|
+
readOnly,
|
|
12
|
+
onChange,
|
|
13
|
+
value: isChecked = false,
|
|
14
|
+
id,
|
|
15
|
+
hasDescription,
|
|
16
|
+
name,
|
|
17
|
+
disabled,
|
|
18
|
+
hasError,
|
|
19
|
+
} = defaultsApplier(props);
|
|
20
|
+
|
|
21
|
+
function handleOnChange(e: ChangeEvent<HTMLInputElement>) {
|
|
22
|
+
if (disabled || readOnly) return;
|
|
23
|
+
onChange(e);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Input
|
|
28
|
+
name={name}
|
|
29
|
+
hasError={hasError}
|
|
30
|
+
hasDescription={hasDescription}
|
|
31
|
+
readOnly={readOnly}
|
|
32
|
+
disabled={disabled}
|
|
33
|
+
type="checkbox"
|
|
34
|
+
checked={isChecked}
|
|
35
|
+
id={id}
|
|
36
|
+
onChange={handleOnChange}
|
|
37
|
+
ref={ref}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { styled } from '../../../styled';
|
|
4
|
+
import { Switch, SwitchProps, Button } from '../../../components';
|
|
5
|
+
import { useForm, SubmitHandler, useWatch } from 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
const Wrapper = styled.div`
|
|
8
|
+
padding: 5rem;
|
|
9
|
+
background: ${({ theme }) => theme.colors.background};
|
|
10
|
+
|
|
11
|
+
& > div {
|
|
12
|
+
margin: 0 auto;
|
|
13
|
+
padding: 0.2rem 1rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
form {
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
title: 'Inputs/Switch',
|
|
23
|
+
component: Switch,
|
|
24
|
+
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
25
|
+
args: {
|
|
26
|
+
label: 'Do you have a car?',
|
|
27
|
+
loading: false,
|
|
28
|
+
name: 'hasCar',
|
|
29
|
+
description: 'This is a description',
|
|
30
|
+
readOnly: false,
|
|
31
|
+
required: true,
|
|
32
|
+
disabled: false,
|
|
33
|
+
},
|
|
34
|
+
} as Meta<SwitchProps>;
|
|
35
|
+
|
|
36
|
+
type FormFields = {
|
|
37
|
+
hasCar: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const OnSubmit: StoryFn<SwitchProps> = (args) => {
|
|
41
|
+
const [value, setValue] = useState<boolean>();
|
|
42
|
+
const { control, handleSubmit } = useForm<FormFields>();
|
|
43
|
+
|
|
44
|
+
const onSubmit: SubmitHandler<FormFields> = ({ hasCar }) => {
|
|
45
|
+
setValue(hasCar);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
51
|
+
<Switch
|
|
52
|
+
name={args.name}
|
|
53
|
+
label={args.label}
|
|
54
|
+
control={control}
|
|
55
|
+
description={args.description}
|
|
56
|
+
hint={args.hint}
|
|
57
|
+
loading={args.loading}
|
|
58
|
+
disabled={args.disabled}
|
|
59
|
+
required={args.required}
|
|
60
|
+
readOnly={args.readOnly}
|
|
61
|
+
/>
|
|
62
|
+
<Button type="submit">submit</Button>
|
|
63
|
+
</form>
|
|
64
|
+
submitted value: {value ? 'true' : 'false'}
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const OnChange: StoryFn<SwitchProps> = (args) => {
|
|
70
|
+
const { control } = useForm({ mode: 'onChange' });
|
|
71
|
+
const switchValue = useWatch({ control, name: args.name });
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
<Switch
|
|
76
|
+
control={control}
|
|
77
|
+
name={args.name}
|
|
78
|
+
label={args.label}
|
|
79
|
+
description={args.description}
|
|
80
|
+
hint={args.hint}
|
|
81
|
+
loading={args.loading}
|
|
82
|
+
disabled={args.disabled}
|
|
83
|
+
required={args.required}
|
|
84
|
+
readOnly={args.readOnly}
|
|
85
|
+
/>
|
|
86
|
+
<pre>value: {switchValue ? 'true' : 'false'}</pre>
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
};
|