@strapi/design-system 1.2.7 → 1.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +3 -0
- package/.eslintrc.js +38 -0
- package/.prettierrc.js +7 -0
- package/.storybook/components/Theme.js +28 -0
- package/.storybook/main.js +13 -0
- package/.storybook/manager.js +12 -0
- package/.storybook/preview.js +42 -0
- package/.storybook/utils/createCustomTheme.js +26 -0
- package/LICENSE +20 -0
- package/__mocks__/fileMock.js +1 -0
- package/__mocks__/styleMock.js +1 -0
- package/babel.config.js +5 -0
- package/createIndexFiles.js +34 -0
- package/global-setup.js +4 -0
- package/jest.config.js +17 -0
- package/package.json +3 -3
- package/playwright.config.js +39 -0
- package/src/Accordion/Accordion.js +148 -0
- package/src/Accordion/Accordion.stories.mdx +327 -0
- package/src/Accordion/AccordionContent.js +26 -0
- package/src/Accordion/AccordionContext.js +5 -0
- package/src/Accordion/AccordionGroup.js +114 -0
- package/src/Accordion/AccordionToggle.js +192 -0
- package/src/Accordion/__tests__/Accordion.e2e.js +32 -0
- package/src/Accordion/__tests__/AccordionKeyboard.e2e.js +73 -0
- package/src/Accordion/index.js +4 -0
- package/src/Accordion/utils.js +15 -0
- package/src/Alert/Alert.js +144 -0
- package/src/Alert/Alert.stories.mdx +135 -0
- package/src/Alert/__tests__/Alert.e2e.js +39 -0
- package/src/Alert/index.js +1 -0
- package/src/Alert/utils.js +35 -0
- package/src/Avatar/Avatar.js +110 -0
- package/src/Avatar/Avatar.stories.mdx +67 -0
- package/src/Avatar/AvatarGroup.js +9 -0
- package/src/Avatar/__tests__/Avatar.e2e.js +23 -0
- package/src/Avatar/__tests__/Avatar.spec.js +153 -0
- package/src/Avatar/constants.js +2 -0
- package/src/Avatar/index.js +2 -0
- package/src/Badge/Badge.js +41 -0
- package/src/Badge/Badge.stories.mdx +57 -0
- package/src/Badge/__tests__/Badge.e2e.js +23 -0
- package/src/Badge/index.js +1 -0
- package/src/BaseButton/BaseButton.js +46 -0
- package/src/BaseButton/BaseButton.stories.mdx +32 -0
- package/src/BaseButton/__tests__/BaseButton.e2e.js +23 -0
- package/src/BaseButton/index.js +1 -0
- package/src/BaseCheckbox/BaseCheckbox.js +133 -0
- package/src/BaseCheckbox/BaseCheckbox.stories.mdx +107 -0
- package/src/BaseCheckbox/__tests__/BaseCheckbox.e2e.js +94 -0
- package/src/BaseCheckbox/assets/checkmark-black.svg +6 -0
- package/src/BaseCheckbox/assets/checkmark.svg +6 -0
- package/src/BaseCheckbox/index.js +1 -0
- package/src/BaseCheckbox/utils.js +7 -0
- package/src/BaseLink/BaseLink.js +38 -0
- package/src/BaseLink/BaseLink.stories.mdx +34 -0
- package/src/BaseLink/__tests__/BaseLink.e2e.js +23 -0
- package/src/BaseLink/__tests__/BaseLink.spec.js +26 -0
- package/src/BaseLink/index.js +1 -0
- package/src/BaseRadio/BaseRadio.js +69 -0
- package/src/BaseRadio/BaseRadio.stories.mdx +110 -0
- package/src/BaseRadio/RadioGroup.js +36 -0
- package/src/BaseRadio/__tests__/BaseRadio.e2e.js +90 -0
- package/src/BaseRadio/context.js +3 -0
- package/src/BaseRadio/index.js +2 -0
- package/src/BaseRadio/utils.js +30 -0
- package/src/Box/Box.js +104 -0
- package/src/Box/Box.stories.mdx +57 -0
- package/src/Box/BoxProps.js +99 -0
- package/src/Box/__tests__/Box.e2e.js +23 -0
- package/src/Box/__tests__/Box.spec.js +36 -0
- package/src/Box/index.js +1 -0
- package/src/Breadcrumbs/Breadcrumbs.js +58 -0
- package/src/Breadcrumbs/Breadcrumbs.stories.mdx +47 -0
- package/src/Breadcrumbs/__tests__/Breadcrumbs.e2e.js +23 -0
- package/src/Breadcrumbs/index.js +1 -0
- package/src/Button/Button.js +138 -0
- package/src/Button/Button.stories.mdx +216 -0
- package/src/Button/__tests__/Button.e2e.js +89 -0
- package/src/Button/__tests__/utils.spec.js +19 -0
- package/src/Button/constants.js +12 -0
- package/src/Button/index.js +1 -0
- package/src/Button/utils.js +170 -0
- package/src/Card/Card.js +35 -0
- package/src/Card/Card.stories.mdx +202 -0
- package/src/Card/CardAction.js +13 -0
- package/src/Card/CardAsset.js +49 -0
- package/src/Card/CardBadge.js +18 -0
- package/src/Card/CardBody.js +11 -0
- package/src/Card/CardCheckbox.js +14 -0
- package/src/Card/CardContent.js +16 -0
- package/src/Card/CardContext.js +5 -0
- package/src/Card/CardHeader.js +12 -0
- package/src/Card/CardTimer.js +23 -0
- package/src/Card/CardTitle.js +12 -0
- package/src/Card/__tests__/Card.e2e.js +164 -0
- package/src/Card/index.js +10 -0
- package/src/Card/story-assets/first.jpg +0 -0
- package/src/CarouselInput/Carousel.js +138 -0
- package/src/CarouselInput/Carousel.stories.mdx +149 -0
- package/src/CarouselInput/CarouselActions.js +6 -0
- package/src/CarouselInput/CarouselImage.js +39 -0
- package/src/CarouselInput/CarouselInput.js +80 -0
- package/src/CarouselInput/CarouselSlide.js +32 -0
- package/src/CarouselInput/__tests__/CarouselImage.e2e.js +15 -0
- package/src/CarouselInput/__tests__/CarouselInput.e2e.js +48 -0
- package/src/CarouselInput/index.js +5 -0
- package/src/CarouselInput/story-assets/first.jpg +0 -0
- package/src/Checkbox/Checkbox.js +63 -0
- package/src/Checkbox/Checkbox.stories.mdx +190 -0
- package/src/Checkbox/__tests__/Checkbox.e2e.js +96 -0
- package/src/Checkbox/index.js +1 -0
- package/src/Combobox/Combobox.js +421 -0
- package/src/Combobox/Combobox.stories.mdx +191 -0
- package/src/Combobox/ComboboxList.js +22 -0
- package/src/Combobox/ComboboxOption.js +36 -0
- package/src/Combobox/__tests__/Combobox.e2e.js +133 -0
- package/src/Combobox/__tests__/utils.spec.js +94 -0
- package/src/Combobox/components.js +69 -0
- package/src/Combobox/index.js +2 -0
- package/src/Combobox/utils.js +97 -0
- package/src/DatePicker/DatePicker.js +132 -0
- package/src/DatePicker/DatePicker.stories.mdx +172 -0
- package/src/DatePicker/DatePickerCalendar.js +134 -0
- package/src/DatePicker/DatePickerTd.js +51 -0
- package/src/DatePicker/DatePickerTh.js +39 -0
- package/src/DatePicker/__tests__/DatePicker.e2e.js +94 -0
- package/src/DatePicker/__tests__/DatePicker.spec.js +40 -0
- package/src/DatePicker/compareDates.js +9 -0
- package/src/DatePicker/components.js +45 -0
- package/src/DatePicker/index.js +1 -0
- package/src/DatePicker/utils/formatDate.js +5 -0
- package/src/DatePicker/utils/generateWeeks.js +58 -0
- package/src/DatePicker/utils/getDayOfWeek.js +24 -0
- package/src/DatePicker/utils/getMonths.js +10 -0
- package/src/DatePicker/utils/getYears.js +19 -0
- package/src/DatePicker/utils/index.js +5 -0
- package/src/DatePicker/utils/tests/generateWeeks.spec.js +136 -0
- package/src/DatePicker/utils/tests/getMonths.spec.js +21 -0
- package/src/DatePicker/utils/tests/getYears.spec.js +21 -0
- package/src/DateTimePicker/DateTimePicker.js +151 -0
- package/src/DateTimePicker/DateTimePicker.stories.mdx +114 -0
- package/src/DateTimePicker/DateTimePickerProps.js +85 -0
- package/src/DateTimePicker/__tests__/DateTimePicker.e2e.js +103 -0
- package/src/DateTimePicker/__tests__/DateTimePicker.spec.js +89 -0
- package/src/DateTimePicker/__tests__/__snapshots__/DateTimePicker.spec.js.snap +448 -0
- package/src/DateTimePicker/__tests__/parseDate.test.js +10 -0
- package/src/DateTimePicker/index.js +1 -0
- package/src/DateTimePicker/parseDate.js +11 -0
- package/src/Dialog/Dialog.js +86 -0
- package/src/Dialog/Dialog.stories.mdx +78 -0
- package/src/Dialog/DialogBody.js +36 -0
- package/src/Dialog/DialogFooter.js +38 -0
- package/src/Dialog/__tests__/Dialog.e2e.js +20 -0
- package/src/Dialog/__tests__/Dialog.spec.js +28 -0
- package/src/Dialog/index.js +3 -0
- package/src/DismissibleLayer/DismissibleLayer.js +87 -0
- package/src/DismissibleLayer/DismissibleLayer.stories.mdx +50 -0
- package/src/DismissibleLayer/__test__/DimissibleLayer.spec.js +44 -0
- package/src/DismissibleLayer/index.js +1 -0
- package/src/Divider/Divider.js +26 -0
- package/src/Divider/Divider.stories.mdx +55 -0
- package/src/Divider/__tests__/Divider.e2e.js +23 -0
- package/src/Divider/index.js +1 -0
- package/src/EmptyStateLayout/EmptyStateLayout.js +48 -0
- package/src/EmptyStateLayout/EmptyStateLayout.stories.mdx +87 -0
- package/src/EmptyStateLayout/__tests__/EmptyStateLayout.e2e.js +31 -0
- package/src/EmptyStateLayout/index.js +1 -0
- package/src/EmptyStateLayout/story-assets/Illo.js +51 -0
- package/src/Field/Field.js +29 -0
- package/src/Field/Field.stories.mdx +237 -0
- package/src/Field/FieldAction.js +25 -0
- package/src/Field/FieldContext.js +4 -0
- package/src/Field/FieldError.js +17 -0
- package/src/Field/FieldHint.js +17 -0
- package/src/Field/FieldInput.js +129 -0
- package/src/Field/FieldLabel.js +50 -0
- package/src/Field/__tests__/Field.e2e.js +61 -0
- package/src/Field/index.js +7 -0
- package/src/Flex/Flex.js +26 -0
- package/src/Flex/Flex.stories.mdx +45 -0
- package/src/Flex/FlexProps.js +41 -0
- package/src/Flex/__tests__/Flex.e2e.js +23 -0
- package/src/Flex/index.js +1 -0
- package/src/FocusTrap/ExampleComponent.js +71 -0
- package/src/FocusTrap/FocusTrap.js +83 -0
- package/src/FocusTrap/FocusTrap.stories.mdx +32 -0
- package/src/FocusTrap/__tests__/FocusTrap.e2e.js +126 -0
- package/src/FocusTrap/index.js +1 -0
- package/src/Grid/Grid.js +30 -0
- package/src/Grid/Grid.stories.mdx +112 -0
- package/src/Grid/GridContext.js +5 -0
- package/src/Grid/GridItem.js +40 -0
- package/src/Grid/__tests__/Grid.e2e.js +23 -0
- package/src/Grid/index.js +2 -0
- package/src/Icon/Icon.js +27 -0
- package/src/Icon/Icon.stories.mdx +41 -0
- package/src/Icon/__tests__/Icon.e2e.js +21 -0
- package/src/Icon/index.js +1 -0
- package/src/IconButton/IconButton.js +175 -0
- package/src/IconButton/IconButton.stories.mdx +153 -0
- package/src/IconButton/__tests__/IconButton.e2e.js +57 -0
- package/src/IconButton/index.js +1 -0
- package/src/KeyboardNavigable/KeyboardNavigable.js +96 -0
- package/src/KeyboardNavigable/index.js +1 -0
- package/src/Layout/ActionLayout.js +40 -0
- package/src/Layout/ContentLayout.js +15 -0
- package/src/Layout/GridLayout.js +12 -0
- package/src/Layout/GridLayout.stories.mdx +36 -0
- package/src/Layout/HeaderLayout.js +170 -0
- package/src/Layout/HeaderLayout.stories.mdx +175 -0
- package/src/Layout/Layout.js +31 -0
- package/src/Layout/Layout.stories.mdx +240 -0
- package/src/Layout/TwoColsLayout.js +26 -0
- package/src/Layout/TwoColsLayout.stories.mdx +46 -0
- package/src/Layout/__tests__/GridLayout.e2e.js +23 -0
- package/src/Layout/__tests__/HeaderLayout.e2e.js +83 -0
- package/src/Layout/__tests__/Layout.e2e.js +23 -0
- package/src/Layout/__tests__/TwoColsLayout.e2e.js +23 -0
- package/src/Layout/index.js +6 -0
- package/src/Link/Link.js +105 -0
- package/src/Link/Link.stories.mdx +57 -0
- package/src/Link/__tests__/Link.e2e.js +23 -0
- package/src/Link/index.js +1 -0
- package/src/LinkButton/LinkButton.js +113 -0
- package/src/LinkButton/LinkButton.stories.mdx +153 -0
- package/src/LinkButton/__tests__/LinkButton.e2e.js +89 -0
- package/src/LinkButton/index.js +1 -0
- package/src/LiveRegions/LiveRegions.js +13 -0
- package/src/LiveRegions/LiveRegions.stories.mdx +76 -0
- package/src/LiveRegions/StoryComponent.js +26 -0
- package/src/LiveRegions/__tests__/LiveRegions.spec.js +200 -0
- package/src/LiveRegions/constants.js +5 -0
- package/src/LiveRegions/index.js +1 -0
- package/src/LiveRegions/useNotifyAT.js +39 -0
- package/src/Loader/Loader.js +40 -0
- package/src/Loader/Loader.stories.mdx +48 -0
- package/src/Loader/__tests__/Loader.e2e.js +23 -0
- package/src/Loader/assets/loader.svg +3 -0
- package/src/Loader/index.js +1 -0
- package/src/Main/Main.js +24 -0
- package/src/Main/SkipToContent.js +29 -0
- package/src/Main/index.js +2 -0
- package/src/MainNav/MainNav.js +31 -0
- package/src/MainNav/MainNav.stories.mdx +197 -0
- package/src/MainNav/MainNavContext.js +5 -0
- package/src/MainNav/NavBrand.js +76 -0
- package/src/MainNav/NavCondense.js +44 -0
- package/src/MainNav/NavLink.js +143 -0
- package/src/MainNav/NavSection.js +53 -0
- package/src/MainNav/NavSections.js +20 -0
- package/src/MainNav/NavUser.js +53 -0
- package/src/MainNav/__tests__/MainNav.e2e.js +23 -0
- package/src/MainNav/index.js +7 -0
- package/src/MainNav/strapi-img.png +0 -0
- package/src/ModalLayout/ModalBody.js +12 -0
- package/src/ModalLayout/ModalContext.js +4 -0
- package/src/ModalLayout/ModalFooter.js +37 -0
- package/src/ModalLayout/ModalHeader.js +35 -0
- package/src/ModalLayout/ModalLayout.js +58 -0
- package/src/ModalLayout/ModalLayout.stories.mdx +100 -0
- package/src/ModalLayout/__tests__/ModalLayout.e2e.js +19 -0
- package/src/ModalLayout/__tests__/ModalLayout.spec.js +596 -0
- package/src/ModalLayout/index.js +4 -0
- package/src/NumberInput/NumberInput.js +253 -0
- package/src/NumberInput/NumberInput.stories.mdx +319 -0
- package/src/NumberInput/__tests__/NumberInput.e2e.js +194 -0
- package/src/NumberInput/index.js +1 -0
- package/src/Pagination/Pagination.js +37 -0
- package/src/Pagination/Pagination.stories.mdx +97 -0
- package/src/Pagination/PaginationContext.js +4 -0
- package/src/Pagination/__tests__/Pagination.e2e.js +23 -0
- package/src/Pagination/assets/next.svg +3 -0
- package/src/Pagination/assets/previous.svg +3 -0
- package/src/Pagination/components.js +147 -0
- package/src/Pagination/index.js +2 -0
- package/src/Popover/Popover.js +167 -0
- package/src/Popover/Popover.stories.mdx +167 -0
- package/src/Popover/__tests__/Popover.e2e.js +48 -0
- package/src/Popover/__tests__/Popover.spec.js +153 -0
- package/src/Popover/index.js +1 -0
- package/src/Portal/Portal.js +25 -0
- package/src/Portal/Portal.stories.mdx +33 -0
- package/src/Portal/__tests__/Portal.e2e.js +23 -0
- package/src/Portal/index.js +1 -0
- package/src/ProgressBar/ProgressBar.js +57 -0
- package/src/ProgressBar/ProgressBar.stories.mdx +47 -0
- package/src/ProgressBar/__tests__/ProgressBar.e2e.js +41 -0
- package/src/ProgressBar/index.js +1 -0
- package/src/Radio/Radio.js +25 -0
- package/src/Radio/Radio.stories.mdx +66 -0
- package/src/Radio/__tests__/Radio.e2e.js +66 -0
- package/src/Radio/__tests__/Radio.spec.js +56 -0
- package/src/Radio/index.js +2 -0
- package/src/RawTable/RawCell.js +182 -0
- package/src/RawTable/RawTable.js +123 -0
- package/src/RawTable/RawTable.stories.mdx +258 -0
- package/src/RawTable/RawTableContext.js +10 -0
- package/src/RawTable/RawTbody.js +18 -0
- package/src/RawTable/RawThead.js +15 -0
- package/src/RawTable/RawTr.js +20 -0
- package/src/RawTable/__tests__/RawTable.e2e.js +344 -0
- package/src/RawTable/focusFocusable.js +7 -0
- package/src/RawTable/index.js +5 -0
- package/src/Searchbar/SearchForm.js +3 -0
- package/src/Searchbar/Searchbar.js +103 -0
- package/src/Searchbar/Searchbar.stories.mdx +115 -0
- package/src/Searchbar/__tests__/Searchbar.e2e.js +52 -0
- package/src/Searchbar/index.js +2 -0
- package/src/Select/MultiSelectNested.js +31 -0
- package/src/Select/OptGroup.js +27 -0
- package/src/Select/Option.js +123 -0
- package/src/Select/Select.js +318 -0
- package/src/Select/Select.stories.mdx +362 -0
- package/src/Select/SelectButton.js +77 -0
- package/src/Select/SelectList.js +113 -0
- package/src/Select/SelectTags.js +50 -0
- package/src/Select/__tests__/Select.e2e.js +238 -0
- package/src/Select/__tests__/Select.spec.js +1020 -0
- package/src/Select/components.js +51 -0
- package/src/Select/constants.js +6 -0
- package/src/Select/hooks/useButtonRef.js +31 -0
- package/src/Select/hooks/useListRef.js +35 -0
- package/src/Select/index.js +5 -0
- package/src/Select/utils.js +27 -0
- package/src/SimpleMenu/SimpleMenu.js +252 -0
- package/src/SimpleMenu/SimpleMenu.stories.mdx +220 -0
- package/src/SimpleMenu/__tests__/SimpleMenu.e2e.js +98 -0
- package/src/SimpleMenu/__tests__/SimpleMenu.spec.js +48 -0
- package/src/SimpleMenu/index.js +1 -0
- package/src/SimpleMenu/utils.js +12 -0
- package/src/Stack/Stack.js +75 -0
- package/src/Stack/Stack.stories.mdx +66 -0
- package/src/Stack/__tests__/Stack.e2e.js +43 -0
- package/src/Stack/index.js +1 -0
- package/src/Status/Status.js +76 -0
- package/src/Status/Status.stories.mdx +80 -0
- package/src/Status/__tests__/Status.e2e.js +23 -0
- package/src/Status/__tests__/Status.spec.js +48 -0
- package/src/Status/index.js +1 -0
- package/src/SubNav/SubNav.js +25 -0
- package/src/SubNav/SubNav.stories.mdx +234 -0
- package/src/SubNav/SubNavHeader.js +122 -0
- package/src/SubNav/SubNavLink.js +92 -0
- package/src/SubNav/SubNavLinkSection.js +75 -0
- package/src/SubNav/SubNavSection.js +75 -0
- package/src/SubNav/SubNavSectionLabel.js +67 -0
- package/src/SubNav/SubNavSections.js +20 -0
- package/src/SubNav/__tests__/SubNav.e2e.js +23 -0
- package/src/SubNav/index.js +6 -0
- package/src/Switch/Switch.js +97 -0
- package/src/Switch/Switch.stories.mdx +76 -0
- package/src/Switch/__tests__/Switch.e2e.js +33 -0
- package/src/Switch/index.js +1 -0
- package/src/Table/Cell.js +49 -0
- package/src/Table/TFooter.js +58 -0
- package/src/Table/Table.js +96 -0
- package/src/Table/Table.stories.mdx +330 -0
- package/src/Table/Tbody.js +13 -0
- package/src/Table/Thead.js +11 -0
- package/src/Table/Tr.js +28 -0
- package/src/Table/__tests__/Table.e2e.js +41 -0
- package/src/Table/index.js +6 -0
- package/src/Tabs/TabGroup.js +46 -0
- package/src/Tabs/TabPanels.js +32 -0
- package/src/Tabs/Tabs.js +227 -0
- package/src/Tabs/Tabs.stories.mdx +211 -0
- package/src/Tabs/TabsContext.js +5 -0
- package/src/Tabs/__tests__/Tabs.e2e.js +253 -0
- package/src/Tabs/components.js +66 -0
- package/src/Tabs/index.js +3 -0
- package/src/Tabs/useTabsFocus.js +28 -0
- package/src/Tag/Tag.js +72 -0
- package/src/Tag/Tag.stories.mdx +47 -0
- package/src/Tag/__tests__/Tag.e2e.js +37 -0
- package/src/Tag/index.js +1 -0
- package/src/TextButton/TextButton.js +102 -0
- package/src/TextButton/TextButton.stories.mdx +71 -0
- package/src/TextButton/__tests__/TextButton.e2e.js +23 -0
- package/src/TextButton/index.js +1 -0
- package/src/TextInput/TextInput.js +67 -0
- package/src/TextInput/TextInput.stories.mdx +228 -0
- package/src/TextInput/__tests__/TextInput.e2e.js +73 -0
- package/src/TextInput/index.js +1 -0
- package/src/Textarea/Textarea.js +74 -0
- package/src/Textarea/Textarea.stories.mdx +105 -0
- package/src/Textarea/TextareaInput.js +77 -0
- package/src/Textarea/__tests__/Textarea.e2e.js +37 -0
- package/src/Textarea/index.js +1 -0
- package/src/ThemeProvider/ThemeProvider.js +193 -0
- package/src/ThemeProvider/hooks.js +5 -0
- package/src/ThemeProvider/index.js +2 -0
- package/src/TimePicker/TimePicker.js +128 -0
- package/src/TimePicker/TimePicker.stories.mdx +171 -0
- package/src/TimePicker/__tests__/TimePicker.e2e.js +37 -0
- package/src/TimePicker/__tests__/TimePicker.spec.js +2099 -0
- package/src/TimePicker/index.js +1 -0
- package/src/ToggleCheckbox/ToggleCheckbox.js +169 -0
- package/src/ToggleCheckbox/ToggleCheckbox.stories.mdx +96 -0
- package/src/ToggleCheckbox/__tests__/ToggleCheckbox.e2e.js +59 -0
- package/src/ToggleCheckbox/index.js +1 -0
- package/src/ToggleInput/ToggleInput.js +89 -0
- package/src/ToggleInput/ToggleInput.stories.mdx +171 -0
- package/src/ToggleInput/__tests__/ToggleInput.e2e.js +109 -0
- package/src/ToggleInput/index.js +1 -0
- package/src/Tooltip/Tooltip.js +72 -0
- package/src/Tooltip/Tooltip.stories.mdx +127 -0
- package/src/Tooltip/__tests__/Tooltip.e2e.js +33 -0
- package/src/Tooltip/__tests__/Tooltip.spec.js +306 -0
- package/src/Tooltip/hooks/useTooltipHandlers.js +39 -0
- package/src/Tooltip/hooks/useTooltipLayout.js +21 -0
- package/src/Tooltip/index.js +1 -0
- package/src/Tooltip/utils/__tests__/positionTooltip.spec.js +114 -0
- package/src/Tooltip/utils/positionTooltip.js +83 -0
- package/src/Typography/Typography.js +24 -0
- package/src/Typography/Typography.stories.mdx +86 -0
- package/src/Typography/TypographyProps.js +30 -0
- package/src/Typography/__tests__/Typography.e2e.js +25 -0
- package/src/Typography/__tests__/Typography.spec.js +32 -0
- package/src/Typography/__tests__/__snapshots__/Typography.spec.js.snap +103 -0
- package/src/Typography/constants.js +9 -0
- package/src/Typography/index.js +1 -0
- package/src/Typography/utils.js +69 -0
- package/src/VisuallyHidden/VisuallyHidden.js +12 -0
- package/src/VisuallyHidden/index.js +1 -0
- package/src/helpers/__tests__/useId.spec.js +39 -0
- package/src/helpers/escapeSelector.js +1 -0
- package/src/helpers/genId.js +2 -0
- package/src/helpers/getDefaultLocale.js +33 -0
- package/src/helpers/getFocusableNodes.js +35 -0
- package/src/helpers/handleResponsiveValues.js +34 -0
- package/src/helpers/keyboardKeys.js +17 -0
- package/src/helpers/setOpacity.js +4 -0
- package/src/helpers/setTabIndexOnFirstItem.js +7 -0
- package/src/helpers/useElementOnScreen.js +27 -0
- package/src/helpers/useId.js +8 -0
- package/src/helpers/useIntersection.js +31 -0
- package/src/helpers/useLockScroll.js +14 -0
- package/src/helpers/usePrevious.js +9 -0
- package/src/helpers/useResizeObserver.js +22 -0
- package/src/index.js +65 -0
- package/src/themes/ColorButton.js +24 -0
- package/src/themes/Theme.stories.mdx +227 -0
- package/src/themes/__tests__/extendTheme.spec.js +119 -0
- package/src/themes/colors.js +46 -0
- package/src/themes/common-theme.js +19 -0
- package/src/themes/darkTheme/dark-colors.js +49 -0
- package/src/themes/darkTheme/dark-shadows.js +10 -0
- package/src/themes/darkTheme/index.js +9 -0
- package/src/themes/extendTheme.js +60 -0
- package/src/themes/index.js +4 -0
- package/src/themes/lightTheme/index.js +9 -0
- package/src/themes/lightTheme/light-colors.js +49 -0
- package/src/themes/lightTheme/light-shadows.js +10 -0
- package/src/themes/sizes.js +10 -0
- package/src/themes/utils.js +50 -0
- package/src/v2/Breadcrumbs/Breadcrumbs.js +45 -0
- package/src/v2/Breadcrumbs/Breadcrumbs.stories.mdx +129 -0
- package/src/v2/Breadcrumbs/Crumb.js +30 -0
- package/src/v2/Breadcrumbs/CrumbLink.js +33 -0
- package/src/v2/Breadcrumbs/CrumbSimpleMenu.js +30 -0
- package/src/v2/Breadcrumbs/Divider.js +16 -0
- package/src/v2/Breadcrumbs/__tests__/Breadcrumbs.e2e.js +47 -0
- package/src/v2/Breadcrumbs/__tests__/Breadcrumbs.spec.js +47 -0
- package/src/v2/Breadcrumbs/index.js +4 -0
- package/src/v2/Link/Link.js +79 -0
- package/src/v2/Link/Link.stories.mdx +113 -0
- package/src/v2/Link/__tests__/Link.e2e.js +23 -0
- package/src/v2/Link/index.js +1 -0
- package/src/v2/LinkButton/LinkButton.js +105 -0
- package/src/v2/LinkButton/LinkButton.stories.mdx +153 -0
- package/src/v2/LinkButton/__tests__/LinkButton.e2e.js +89 -0
- package/src/v2/LinkButton/index.js +1 -0
- package/src/v2/MainNav/MainNav.js +31 -0
- package/src/v2/MainNav/MainNav.stories.mdx +197 -0
- package/src/v2/MainNav/MainNavContext.js +5 -0
- package/src/v2/MainNav/NavBrand.js +79 -0
- package/src/v2/MainNav/NavCondense.js +44 -0
- package/src/v2/MainNav/NavLink.js +143 -0
- package/src/v2/MainNav/NavSection.js +53 -0
- package/src/v2/MainNav/NavSections.js +20 -0
- package/src/v2/MainNav/NavUser.js +53 -0
- package/src/v2/MainNav/__tests__/MainNav.e2e.js +23 -0
- package/src/v2/MainNav/index.js +7 -0
- package/src/v2/MainNav/strapi-img.png +0 -0
- package/src/v2/Pagination/Pagination.js +37 -0
- package/src/v2/Pagination/Pagination.stories.mdx +97 -0
- package/src/v2/Pagination/PaginationContext.js +4 -0
- package/src/v2/Pagination/__tests__/Pagination.e2e.js +23 -0
- package/src/v2/Pagination/assets/next.svg +3 -0
- package/src/v2/Pagination/assets/previous.svg +3 -0
- package/src/v2/Pagination/components.js +136 -0
- package/src/v2/Pagination/index.js +2 -0
- package/src/v2/SimpleMenu/SimpleMenu.js +252 -0
- package/src/v2/SimpleMenu/SimpleMenu.stories.mdx +220 -0
- package/src/v2/SimpleMenu/__tests__/SimpleMenu.e2e.js +100 -0
- package/src/v2/SimpleMenu/__tests__/SimpleMenu.spec.js +48 -0
- package/src/v2/SimpleMenu/index.js +1 -0
- package/src/v2/SimpleMenu/utils.js +12 -0
- package/src/v2/SubNav/SubNav.js +25 -0
- package/src/v2/SubNav/SubNav.stories.mdx +234 -0
- package/src/v2/SubNav/SubNavHeader.js +122 -0
- package/src/v2/SubNav/SubNavLink.js +95 -0
- package/src/v2/SubNav/SubNavLinkSection.js +75 -0
- package/src/v2/SubNav/SubNavSection.js +75 -0
- package/src/v2/SubNav/SubNavSectionLabel.js +67 -0
- package/src/v2/SubNav/SubNavSections.js +20 -0
- package/src/v2/SubNav/__tests__/SubNav.e2e.js +23 -0
- package/src/v2/SubNav/index.js +6 -0
- package/src/v2/index.js +7 -0
- package/test-bundler.js +35 -0
- package/tests/check-exports.spec.js +36 -0
- package/webpack.config.js +84 -0
- package/Accordion.development.js +0 -775
- package/Accordion.js +0 -9
- package/Accordion.production.js +0 -1
- package/Alert.development.js +0 -562
- package/Alert.js +0 -9
- package/Alert.production.js +0 -1
- package/Avatar.development.js +0 -485
- package/Avatar.js +0 -9
- package/Avatar.production.js +0 -1
- package/Badge.development.js +0 -494
- package/Badge.js +0 -9
- package/Badge.production.js +0 -1
- package/BaseButton.development.js +0 -285
- package/BaseButton.js +0 -9
- package/BaseButton.production.js +0 -1
- package/BaseCheckbox.development.js +0 -309
- package/BaseCheckbox.js +0 -9
- package/BaseCheckbox.production.js +0 -1
- package/BaseLink.development.js +0 -273
- package/BaseLink.js +0 -9
- package/BaseLink.production.js +0 -1
- package/BaseRadio.development.js +0 -321
- package/BaseRadio.js +0 -9
- package/BaseRadio.production.js +0 -1
- package/Box.development.js +0 -341
- package/Box.js +0 -9
- package/Box.production.js +0 -1
- package/Breadcrumbs.development.js +0 -518
- package/Breadcrumbs.js +0 -9
- package/Breadcrumbs.production.js +0 -1
- package/Button.development.js +0 -573
- package/Button.js +0 -9
- package/Button.production.js +0 -1
- package/Card.development.js +0 -746
- package/Card.js +0 -9
- package/Card.production.js +0 -1
- package/CarouselInput.development.js +0 -898
- package/CarouselInput.js +0 -9
- package/CarouselInput.production.js +0 -1
- package/Checkbox.development.js +0 -722
- package/Checkbox.js +0 -9
- package/Checkbox.production.js +0 -1
- package/Combobox.development.js +0 -934
- package/Combobox.js +0 -9
- package/Combobox.production.js +0 -1
- package/DatePicker.development.js +0 -1323
- package/DatePicker.js +0 -9
- package/DatePicker.production.js +0 -1
- package/Dialog.development.js +0 -741
- package/Dialog.js +0 -9
- package/Dialog.production.js +0 -1
- package/DismissibleLayer.development.js +0 -218
- package/DismissibleLayer.js +0 -9
- package/DismissibleLayer.production.js +0 -1
- package/Divider.development.js +0 -398
- package/Divider.js +0 -9
- package/Divider.production.js +0 -1
- package/EmptyStateLayout.development.js +0 -425
- package/EmptyStateLayout.js +0 -9
- package/EmptyStateLayout.production.js +0 -1
- package/Field.development.js +0 -614
- package/Field.js +0 -9
- package/Field.production.js +0 -1
- package/Flex.development.js +0 -377
- package/Flex.js +0 -9
- package/Flex.production.js +0 -1
- package/FocusTrap.development.js +0 -341
- package/FocusTrap.js +0 -9
- package/FocusTrap.production.js +0 -1
- package/Grid.development.js +0 -422
- package/Grid.js +0 -9
- package/Grid.production.js +0 -1
- package/Icon.development.js +0 -376
- package/Icon.js +0 -9
- package/Icon.production.js +0 -1
- package/IconButton.development.js +0 -684
- package/IconButton.js +0 -9
- package/IconButton.production.js +0 -1
- package/KeyboardNavigable.development.js +0 -454
- package/KeyboardNavigable.js +0 -9
- package/KeyboardNavigable.production.js +0 -1
- package/Layout.development.js +0 -626
- package/Layout.js +0 -9
- package/Layout.production.js +0 -1
- package/Link.development.js +0 -492
- package/Link.js +0 -9
- package/Link.production.js +0 -1
- package/LinkButton.development.js +0 -573
- package/LinkButton.js +0 -9
- package/LinkButton.production.js +0 -1
- package/LiveRegions.development.js +0 -147
- package/LiveRegions.js +0 -9
- package/LiveRegions.production.js +0 -1
- package/Loader.development.js +0 -309
- package/Loader.js +0 -9
- package/Loader.production.js +0 -1
- package/Main.development.js +0 -410
- package/Main.js +0 -9
- package/Main.production.js +0 -1
- package/MainNav.development.js +0 -957
- package/MainNav.js +0 -9
- package/MainNav.production.js +0 -1
- package/ModalLayout.development.js +0 -895
- package/ModalLayout.js +0 -9
- package/ModalLayout.production.js +0 -1
- package/NumberInput.development.js +0 -733
- package/NumberInput.js +0 -9
- package/NumberInput.production.js +0 -1
- package/Pagination.development.js +0 -587
- package/Pagination.js +0 -9
- package/Pagination.production.js +0 -1
- package/Popover.development.js +0 -481
- package/Popover.js +0 -9
- package/Popover.production.js +0 -1
- package/Portal.development.js +0 -212
- package/Portal.js +0 -9
- package/Portal.production.js +0 -1
- package/ProgressBar.development.js +0 -273
- package/ProgressBar.js +0 -9
- package/ProgressBar.production.js +0 -1
- package/Radio.development.js +0 -518
- package/Radio.js +0 -9
- package/Radio.production.js +0 -1
- package/RawTable.development.js +0 -549
- package/RawTable.js +0 -9
- package/RawTable.production.js +0 -1
- package/Searchbar.development.js +0 -696
- package/Searchbar.js +0 -9
- package/Searchbar.production.js +0 -1
- package/Select.development.js +0 -1063
- package/Select.js +0 -9
- package/Select.production.js +0 -1
- package/SimpleMenu.development.js +0 -821
- package/SimpleMenu.js +0 -9
- package/SimpleMenu.production.js +0 -1
- package/Stack.development.js +0 -434
- package/Stack.js +0 -9
- package/Stack.production.js +0 -1
- package/Status.development.js +0 -494
- package/Status.js +0 -9
- package/Status.production.js +0 -1
- package/SubNav.development.js +0 -1123
- package/SubNav.js +0 -9
- package/SubNav.production.js +0 -1
- package/Switch.development.js +0 -434
- package/Switch.js +0 -9
- package/Switch.production.js +0 -1
- package/Table.development.js +0 -741
- package/Table.js +0 -9
- package/Table.production.js +0 -1
- package/Tabs.development.js +0 -590
- package/Tabs.js +0 -9
- package/Tabs.production.js +0 -1
- package/Tag.development.js +0 -494
- package/Tag.js +0 -9
- package/Tag.production.js +0 -1
- package/TextButton.development.js +0 -517
- package/TextButton.js +0 -9
- package/TextButton.production.js +0 -1
- package/TextInput.development.js +0 -662
- package/TextInput.js +0 -9
- package/TextInput.production.js +0 -1
- package/Textarea.development.js +0 -674
- package/Textarea.js +0 -9
- package/Textarea.production.js +0 -1
- package/ThemeProvider.development.js +0 -300
- package/ThemeProvider.js +0 -9
- package/ThemeProvider.production.js +0 -1
- package/TimePicker.development.js +0 -1098
- package/TimePicker.js +0 -9
- package/TimePicker.production.js +0 -1
- package/ToggleCheckbox.development.js +0 -542
- package/ToggleCheckbox.js +0 -9
- package/ToggleCheckbox.production.js +0 -1
- package/ToggleInput.development.js +0 -745
- package/ToggleInput.js +0 -9
- package/ToggleInput.production.js +0 -1
- package/Tooltip.development.js +0 -588
- package/Tooltip.js +0 -9
- package/Tooltip.production.js +0 -1
- package/Typography.development.js +0 -276
- package/Typography.js +0 -9
- package/Typography.production.js +0 -1
- package/VisuallyHidden.development.js +0 -146
- package/VisuallyHidden.js +0 -9
- package/VisuallyHidden.production.js +0 -1
- package/index.development.js +0 -4290
- package/index.js +0 -9
- package/index.production.js +0 -1
- package/themes.development.js +0 -254
- package/themes.js +0 -9
- package/themes.production.js +0 -1
- package/v2/Breadcrumbs.development.js +0 -906
- package/v2/Breadcrumbs.js +0 -9
- package/v2/Breadcrumbs.production.js +0 -1
- package/v2/Link.development.js +0 -505
- package/v2/Link.js +0 -9
- package/v2/Link.production.js +0 -1
- package/v2/LinkButton.development.js +0 -586
- package/v2/LinkButton.js +0 -9
- package/v2/LinkButton.production.js +0 -1
- package/v2/MainNav.development.js +0 -970
- package/v2/MainNav.js +0 -9
- package/v2/MainNav.production.js +0 -1
- package/v2/Pagination.development.js +0 -600
- package/v2/Pagination.js +0 -9
- package/v2/Pagination.production.js +0 -1
- package/v2/SimpleMenu.development.js +0 -834
- package/v2/SimpleMenu.js +0 -9
- package/v2/SimpleMenu.production.js +0 -1
- package/v2/SubNav.development.js +0 -1136
- package/v2/SubNav.js +0 -9
- package/v2/SubNav.production.js +0 -1
- package/v2/index.development.js +0 -1740
- package/v2/index.js +0 -9
- package/v2/index.production.js +0 -1
- package/v2/package.json +0 -81
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<!--- Radio.stories.mdx --->
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Meta, Story, Canvas } from '@storybook/addon-docs';
|
|
5
|
+
import { ArgsTable } from '@storybook/addon-docs';
|
|
6
|
+
import { Radio, RadioGroup } from './';
|
|
7
|
+
import { Typography } from '../Typography';
|
|
8
|
+
|
|
9
|
+
<Meta title="Design System/Components/Radio" component={Radio} />
|
|
10
|
+
|
|
11
|
+
# Radio
|
|
12
|
+
|
|
13
|
+
Radio buttons allow users to choose a single value from a range of options.
|
|
14
|
+
|
|
15
|
+
**Best practices**
|
|
16
|
+
|
|
17
|
+
- When a user picks an option, the previous one is automatically deselected.
|
|
18
|
+
- Radio buttons should be used when there is at least two options.
|
|
19
|
+
- Label of the Radio button should be concise and straightforward.
|
|
20
|
+
- Use the Checkbox component if the user could select one or several values.
|
|
21
|
+
- Start all Radio button labels with a capital letter.
|
|
22
|
+
- There is no need to include Radio buttons in a Select component when only a single value can be selected.
|
|
23
|
+
- Radio buttons should be used sparingly in the interface.
|
|
24
|
+
- Radio buttons should be used only when it is not obvious enough that a choice is required.
|
|
25
|
+
- Radio buttons should not be used in Table components.
|
|
26
|
+
- Use Switch or Toggle component to make binary choices.
|
|
27
|
+
|
|
28
|
+
[View source](https://github.com/strapi/design-system/tree/main/packages/strapi-design-system/src/Radio)
|
|
29
|
+
|
|
30
|
+
## Imports
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { Radio, RadioGroup } from '@strapi/design-system/Radio';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Radio buttons allow users to choose a single value from a range of at least two options.
|
|
39
|
+
|
|
40
|
+
<Canvas>
|
|
41
|
+
<Story name="base">
|
|
42
|
+
{() => {
|
|
43
|
+
const [selected, setSelected] = useState();
|
|
44
|
+
return (
|
|
45
|
+
<div>
|
|
46
|
+
<Typography variant="beta" id="trophy-champions">
|
|
47
|
+
Make a choice
|
|
48
|
+
</Typography>
|
|
49
|
+
<RadioGroup
|
|
50
|
+
labelledBy="trophy-champions"
|
|
51
|
+
onChange={(e) => setSelected(e.target.value)}
|
|
52
|
+
value={selected}
|
|
53
|
+
name="meal"
|
|
54
|
+
>
|
|
55
|
+
<Radio value="pizza">Pizza</Radio>
|
|
56
|
+
<Radio value="bagel">Bagel</Radio>
|
|
57
|
+
</RadioGroup>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}}
|
|
61
|
+
</Story>
|
|
62
|
+
</Canvas>
|
|
63
|
+
|
|
64
|
+
## Props
|
|
65
|
+
|
|
66
|
+
<ArgsTable of={Radio} />
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { injectAxe, checkA11y } from 'axe-playwright';
|
|
2
|
+
|
|
3
|
+
import { test, expect } from '@playwright/test';
|
|
4
|
+
|
|
5
|
+
test.describe.parallel('Radio', () => {
|
|
6
|
+
test.describe('light mode', () => {
|
|
7
|
+
test.beforeEach(async ({ page }) => {
|
|
8
|
+
// This is the URL of the Storybook Iframe
|
|
9
|
+
await page.goto('/iframe.html?id=design-system-components-radio--base&viewMode=story');
|
|
10
|
+
await injectAxe(page);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('triggers axe on the document', async ({ page }) => {
|
|
14
|
+
await checkA11y(page);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('moves to the next element when pressing ArrowDown', async ({ page }) => {
|
|
18
|
+
await page.focus('[value="pizza"]');
|
|
19
|
+
await page.keyboard.press('ArrowDown');
|
|
20
|
+
|
|
21
|
+
const secondBox = await page.$('[value="bagel"]');
|
|
22
|
+
if (secondBox) {
|
|
23
|
+
expect(await secondBox.isChecked()).toBe(true);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('moves to the next element when pressing ArrowRight', async ({ page }) => {
|
|
28
|
+
await page.focus('[value="pizza"]');
|
|
29
|
+
await page.keyboard.press('ArrowRight');
|
|
30
|
+
|
|
31
|
+
const secondBox = await page.$('[value="bagel"]');
|
|
32
|
+
if (secondBox) {
|
|
33
|
+
expect(await secondBox.isChecked()).toBe(true);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('moves to the previous element when pressing ArrowUp', async ({ page }) => {
|
|
38
|
+
await page.focus('[value="bagel"]');
|
|
39
|
+
await page.keyboard.press('ArrowUp');
|
|
40
|
+
|
|
41
|
+
const pizzaRadio = await page.$('[value="pizza"]');
|
|
42
|
+
if (pizzaRadio) {
|
|
43
|
+
expect(await pizzaRadio.isChecked()).toBe(true);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('moves to the previous element when pressing ArrowLeft', async ({ page }) => {
|
|
48
|
+
await page.focus('[value="bagel"]');
|
|
49
|
+
await page.keyboard.press('ArrowLeft');
|
|
50
|
+
|
|
51
|
+
const pizzaRadio = await page.$('[value="pizza"]');
|
|
52
|
+
if (pizzaRadio) {
|
|
53
|
+
expect(await pizzaRadio.isChecked()).toBe(true);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test.describe('dark mode', () => {
|
|
59
|
+
test('triggers axe on the document', async ({ page }) => {
|
|
60
|
+
// This is the URL of the Storybook Iframe
|
|
61
|
+
await page.goto('/iframe.html?id=design-system-components-radio--base&viewMode=story&theme=dark');
|
|
62
|
+
await injectAxe(page);
|
|
63
|
+
await checkA11y(page);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { RadioGroup, Radio } from '../';
|
|
4
|
+
import { ThemeProvider } from '../../ThemeProvider';
|
|
5
|
+
import { lightTheme } from '../../themes';
|
|
6
|
+
|
|
7
|
+
describe('Radio/RadioGroup', () => {
|
|
8
|
+
it('selects a Radio button when a value is passed in to RadioGroup', () => {
|
|
9
|
+
const onChangeMock = jest.fn();
|
|
10
|
+
const { getByRole } = render(
|
|
11
|
+
<ThemeProvider theme={lightTheme}>
|
|
12
|
+
<p id="food">Food choices</p>
|
|
13
|
+
<RadioGroup labelledBy="food" onChange={onChangeMock} value="pizza" name="meal">
|
|
14
|
+
<Radio value="pizza">Pizza</Radio>
|
|
15
|
+
<Radio value="bagel">Bagel</Radio>
|
|
16
|
+
</RadioGroup>
|
|
17
|
+
</ThemeProvider>,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(getByRole('radio', { name: 'Bagel' })).not.toBeChecked();
|
|
21
|
+
expect(getByRole('radio', { name: 'Pizza' })).toBeChecked();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('keeps all radio buttons unselected when value passed into RadioGroup is empty', () => {
|
|
25
|
+
const onChangeMock = jest.fn();
|
|
26
|
+
const { getByRole } = render(
|
|
27
|
+
<ThemeProvider theme={lightTheme}>
|
|
28
|
+
<p id="food">Food choices</p>
|
|
29
|
+
<RadioGroup labelledBy="food" onChange={onChangeMock} value="" name="meal">
|
|
30
|
+
<Radio value="pizza">Pizza</Radio>
|
|
31
|
+
<Radio value="bagel">Bagel</Radio>
|
|
32
|
+
</RadioGroup>
|
|
33
|
+
</ThemeProvider>,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(getByRole('radio', { name: 'Bagel' })).not.toBeChecked();
|
|
37
|
+
expect(getByRole('radio', { name: 'Pizza' })).not.toBeChecked();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('calls onChange prop when Radio button is clicked', () => {
|
|
41
|
+
const onChangeMock = jest.fn();
|
|
42
|
+
const { getByRole } = render(
|
|
43
|
+
<ThemeProvider theme={lightTheme}>
|
|
44
|
+
<p id="food">Food choices</p>
|
|
45
|
+
<RadioGroup labelledBy="food" onChange={onChangeMock} value="" name="meal">
|
|
46
|
+
<Radio value="pizza">Pizza</Radio>
|
|
47
|
+
<Radio value="bagel">Bagel</Radio>
|
|
48
|
+
</RadioGroup>
|
|
49
|
+
</ThemeProvider>,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
fireEvent.click(getByRole('radio', { name: 'Pizza' }));
|
|
53
|
+
|
|
54
|
+
expect(onChangeMock.mock.calls[0][0].target.value).toBe('pizza');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import { Box } from '../Box';
|
|
5
|
+
import { getFocusableNodes, getFocusableNodesWithKeyboardNav } from '../helpers/getFocusableNodes';
|
|
6
|
+
import { KeyboardKeys } from '../helpers/keyboardKeys';
|
|
7
|
+
|
|
8
|
+
import { useTable } from './RawTableContext';
|
|
9
|
+
|
|
10
|
+
export const RawTh = (props) => <RawTd {...props} as="th" />;
|
|
11
|
+
|
|
12
|
+
export const RawTd = ({ coords, as, ...props }) => {
|
|
13
|
+
const tdRef = useRef(null);
|
|
14
|
+
const { rowIndex, colIndex, setTableValues } = useTable();
|
|
15
|
+
const [isActive, setIsActive] = useState(false);
|
|
16
|
+
|
|
17
|
+
/** @type {import("react").KeyboardEventHandler<HTMLTableCellElement> } */
|
|
18
|
+
const handleKeyDown = (e) => {
|
|
19
|
+
const focusableNodes = getFocusableNodes(tdRef.current, true);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* If the cell does not have focusable children or if it has focusable children
|
|
23
|
+
* without keyboard navigation, we should not run the handler.
|
|
24
|
+
*/
|
|
25
|
+
if (
|
|
26
|
+
focusableNodes.length === 0 ||
|
|
27
|
+
(focusableNodes.length === 1 && getFocusableNodesWithKeyboardNav(focusableNodes).length === 0)
|
|
28
|
+
) {
|
|
29
|
+
return;
|
|
30
|
+
/**
|
|
31
|
+
* This allows cells that **only** have buttons in them to still be
|
|
32
|
+
* navigable with the keyboard arrow keys (left / right) as if they were grid cells.
|
|
33
|
+
*
|
|
34
|
+
* If there are nextNodes (next child node) then we stop the table's keyboard navigation
|
|
35
|
+
* handlers from happening.
|
|
36
|
+
*/
|
|
37
|
+
} else if (focusableNodes.length > 1 && !Boolean(focusableNodes.find((node) => node.tagName !== 'BUTTON'))) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
const focussedButtonIndex = focusableNodes.findIndex((node) => node === document.activeElement);
|
|
40
|
+
if (e.key === KeyboardKeys.RIGHT) {
|
|
41
|
+
const nextNode = focusableNodes[focussedButtonIndex + 1];
|
|
42
|
+
if (nextNode) {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
nextNode.focus();
|
|
45
|
+
}
|
|
46
|
+
} else if (e.key === KeyboardKeys.LEFT) {
|
|
47
|
+
const nextNode = focusableNodes[focussedButtonIndex - 1];
|
|
48
|
+
if (nextNode) {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
nextNode.focus();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (e.key === KeyboardKeys.ENTER && !isActive) {
|
|
57
|
+
setIsActive(true);
|
|
58
|
+
/**
|
|
59
|
+
* Cells should be "escapeable" with the escape key or enter key
|
|
60
|
+
*/
|
|
61
|
+
} else if ((e.key === KeyboardKeys.ESCAPE || e.key === KeyboardKeys.ENTER) && isActive) {
|
|
62
|
+
setIsActive(false);
|
|
63
|
+
tdRef.current.focus();
|
|
64
|
+
} else if (isActive) {
|
|
65
|
+
/**
|
|
66
|
+
* This stops the table navigation from working
|
|
67
|
+
*/
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const isFocused = rowIndex === coords.row - 1 && colIndex === coords.col - 1;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Handles tabindex of the rendered cell element
|
|
76
|
+
*/
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
const focusableNodes = getFocusableNodes(tdRef.current, true);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* We should focus the cell if there are no focussable children inside
|
|
82
|
+
* If there is only one focusable child and it has it's own keyboard navigation
|
|
83
|
+
* Or if there is more than one focusable child unless those children
|
|
84
|
+
* are exclusively buttons.
|
|
85
|
+
*/
|
|
86
|
+
if (
|
|
87
|
+
focusableNodes.length === 0 ||
|
|
88
|
+
(focusableNodes.length === 1 && getFocusableNodesWithKeyboardNav(focusableNodes).length !== 0) ||
|
|
89
|
+
(focusableNodes.length > 1 && Boolean(focusableNodes.find((node) => node.tagName !== 'BUTTON')))
|
|
90
|
+
) {
|
|
91
|
+
tdRef.current.setAttribute('tabIndex', !isActive && isFocused ? 0 : -1);
|
|
92
|
+
|
|
93
|
+
focusableNodes.forEach((node, index) => {
|
|
94
|
+
node.setAttribute('tabIndex', isActive ? 0 : -1);
|
|
95
|
+
/**
|
|
96
|
+
* When a cell is active we want to focus the
|
|
97
|
+
* first focusable element simulating a focus trap
|
|
98
|
+
*/
|
|
99
|
+
if (isActive && index === 0) {
|
|
100
|
+
node.focus();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
focusableNodes.forEach((node) => {
|
|
105
|
+
node.setAttribute('tabIndex', isFocused ? 0 : -1);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, [isActive, isFocused]);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* This handles the case where you click on a focusable
|
|
112
|
+
* node that has it's own keyboard nav (e.g. Input)
|
|
113
|
+
*/
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
const focusableNodes = getFocusableNodes(tdRef.current, true);
|
|
116
|
+
|
|
117
|
+
const handleFocusableNodeFocus = () => {
|
|
118
|
+
/**
|
|
119
|
+
* If there's 1 or more focusable children and at least one has keyboard navigation
|
|
120
|
+
* or the children are exclusively button elements the cell should be using the "active" system
|
|
121
|
+
*/
|
|
122
|
+
if (
|
|
123
|
+
focusableNodes.length >= 1 &&
|
|
124
|
+
(getFocusableNodesWithKeyboardNav(focusableNodes).length !== 0 ||
|
|
125
|
+
!Boolean(focusableNodes.find((node) => node.tagName !== 'BUTTON')))
|
|
126
|
+
) {
|
|
127
|
+
setIsActive(true);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* This function is wrapped in `useCallback` so we can safely
|
|
131
|
+
* assume that the reference will not change
|
|
132
|
+
*/
|
|
133
|
+
setTableValues({ rowIndex: coords.row - 1, colIndex: coords.col - 1 });
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
focusableNodes.forEach((node) => {
|
|
137
|
+
node.addEventListener('focus', handleFocusableNodeFocus);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
const focusableNodes = getFocusableNodes(tdRef.current, true);
|
|
142
|
+
focusableNodes.forEach((node) => {
|
|
143
|
+
node.removeEventListener('focus', handleFocusableNodeFocus);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
}, []);
|
|
147
|
+
|
|
148
|
+
return <Box as={as ? as : 'td'} ref={tdRef} onKeyDown={handleKeyDown} {...props} />;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
RawTh.defaultProps = {
|
|
152
|
+
coords: {},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
RawTh.propTypes = {
|
|
156
|
+
['aria-colindex']: PropTypes.number.isRequired,
|
|
157
|
+
children: PropTypes.node,
|
|
158
|
+
/**
|
|
159
|
+
* Position of the cell in the table
|
|
160
|
+
*/
|
|
161
|
+
coords: PropTypes.shape({
|
|
162
|
+
col: PropTypes.number,
|
|
163
|
+
row: PropTypes.number,
|
|
164
|
+
}),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
RawTd.defaultProps = {
|
|
168
|
+
coords: {},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
RawTd.propTypes = {
|
|
172
|
+
['aria-colindex']: PropTypes.number.isRequired,
|
|
173
|
+
as: PropTypes.oneOf(['td', 'th']),
|
|
174
|
+
children: PropTypes.node,
|
|
175
|
+
/**
|
|
176
|
+
* Position of the cell in the table
|
|
177
|
+
*/
|
|
178
|
+
coords: PropTypes.shape({
|
|
179
|
+
col: PropTypes.number,
|
|
180
|
+
row: PropTypes.number,
|
|
181
|
+
}),
|
|
182
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { RawTableContext } from './RawTableContext';
|
|
4
|
+
import { KeyboardKeys } from '../helpers/keyboardKeys';
|
|
5
|
+
import { focusFocusable } from './focusFocusable';
|
|
6
|
+
|
|
7
|
+
export const RawTable = ({ colCount, rowCount, jumpStep, initialCol, initialRow, ...props }) => {
|
|
8
|
+
const tableRef = useRef(null);
|
|
9
|
+
const mountedRef = useRef(false);
|
|
10
|
+
/**
|
|
11
|
+
* Rows will always have n+1 line because of the <tr><th></th></tr> elements
|
|
12
|
+
*/
|
|
13
|
+
const [rowIndex, setRowIndex] = useState(initialRow);
|
|
14
|
+
const [colIndex, setColIndex] = useState(initialCol);
|
|
15
|
+
|
|
16
|
+
const setTableValues = useCallback(({ colIndex, rowIndex }) => {
|
|
17
|
+
setColIndex(colIndex);
|
|
18
|
+
setRowIndex(rowIndex);
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (mountedRef.current) {
|
|
23
|
+
focusFocusable(tableRef.current);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!mountedRef.current) {
|
|
27
|
+
mountedRef.current = true;
|
|
28
|
+
}
|
|
29
|
+
}, [colIndex, rowIndex]);
|
|
30
|
+
|
|
31
|
+
const handleKeyDown = (e) => {
|
|
32
|
+
switch (e.key) {
|
|
33
|
+
case KeyboardKeys.RIGHT: {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
setColIndex((prevColIndex) => (prevColIndex < colCount - 1 ? prevColIndex + 1 : prevColIndex));
|
|
36
|
+
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
case KeyboardKeys.LEFT: {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
setColIndex((prevColIndex) => (prevColIndex > 0 ? prevColIndex - 1 : prevColIndex));
|
|
43
|
+
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
case KeyboardKeys.UP: {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
setRowIndex((prevRowIndex) => (prevRowIndex > 0 ? prevRowIndex - 1 : prevRowIndex));
|
|
50
|
+
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
case KeyboardKeys.DOWN: {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setRowIndex((prevRowIndex) => (prevRowIndex < rowCount - 1 ? prevRowIndex + 1 : prevRowIndex));
|
|
57
|
+
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
case KeyboardKeys.HOME: {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
if (e.ctrlKey) {
|
|
64
|
+
setRowIndex(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setColIndex(0);
|
|
68
|
+
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
case KeyboardKeys.END: {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
if (e.ctrlKey) {
|
|
75
|
+
setRowIndex(rowCount - 1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setColIndex(colCount - 1);
|
|
79
|
+
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
case KeyboardKeys.PAGE_DOWN: {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
|
|
86
|
+
setRowIndex((prevRowIndex) => (prevRowIndex + jumpStep < rowCount ? prevRowIndex + jumpStep : rowCount - 1));
|
|
87
|
+
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case KeyboardKeys.PAGE_UP: {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
|
|
94
|
+
setRowIndex((prevRowIndex) => (prevRowIndex - jumpStep > 0 ? prevRowIndex - jumpStep : 0));
|
|
95
|
+
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<RawTableContext.Provider value={{ rowIndex, colIndex, setTableValues }}>
|
|
106
|
+
<table ref={tableRef} aria-rowcount={rowCount} aria-colcount={colCount} onKeyDown={handleKeyDown} {...props} />
|
|
107
|
+
</RawTableContext.Provider>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
RawTable.defaultProps = {
|
|
112
|
+
jumpStep: 3,
|
|
113
|
+
initialCol: 0,
|
|
114
|
+
initialRow: 0,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
RawTable.propTypes = {
|
|
118
|
+
colCount: PropTypes.number.isRequired,
|
|
119
|
+
initialCol: PropTypes.number,
|
|
120
|
+
initialRow: PropTypes.number,
|
|
121
|
+
jumpStep: PropTypes.number,
|
|
122
|
+
rowCount: PropTypes.number.isRequired,
|
|
123
|
+
};
|