@lumx/react 3.20.1-alpha.20 → 3.20.1-alpha.21
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/_internal/Falsy.d.ts +7 -0
- package/_internal/index.js +236 -0
- package/_internal/index.js.map +1 -0
- package/index.d.ts +352 -7
- package/index.js +14486 -65
- package/index.js.map +1 -1
- package/package.json +11 -4
- package/src/components/alert-dialog/AlertDialog.stories.tsx +127 -0
- package/src/components/alert-dialog/AlertDialog.test.tsx +34 -0
- package/src/components/alert-dialog/AlertDialog.tsx +189 -0
- package/src/components/alert-dialog/index.ts +1 -0
- package/src/components/autocomplete/Autocomplete.stories.tsx +75 -0
- package/src/components/autocomplete/Autocomplete.test.tsx +99 -0
- package/src/components/autocomplete/Autocomplete.tsx +294 -0
- package/src/components/autocomplete/AutocompleteMultiple.stories.tsx +167 -0
- package/src/components/autocomplete/AutocompleteMultiple.test.tsx +61 -0
- package/src/components/autocomplete/AutocompleteMultiple.tsx +156 -0
- package/src/components/autocomplete/__mockData__/index.ts +39 -0
- package/src/components/autocomplete/index.ts +2 -0
- package/src/components/avatar/Avatar.stories.tsx +119 -0
- package/src/components/avatar/Avatar.test.tsx +32 -0
- package/src/components/avatar/Avatar.tsx +114 -0
- package/src/components/avatar/index.ts +1 -0
- package/src/components/badge/Badge.stories.tsx +69 -0
- package/src/components/badge/Badge.test.tsx +45 -0
- package/src/components/badge/Badge.tsx +58 -0
- package/src/components/badge/BadgeWrapper.stories.tsx +75 -0
- package/src/components/badge/BadgeWrapper.test.tsx +47 -0
- package/src/components/badge/BadgeWrapper.tsx +37 -0
- package/src/components/badge/index.ts +2 -0
- package/src/components/button/Button.stories.tsx +355 -0
- package/src/components/button/Button.test.tsx +125 -0
- package/src/components/button/Button.tsx +101 -0
- package/src/components/button/ButtonGroup.stories.tsx +52 -0
- package/src/components/button/ButtonGroup.test.tsx +41 -0
- package/src/components/button/ButtonGroup.tsx +50 -0
- package/src/components/button/ButtonRoot.tsx +163 -0
- package/src/components/button/IconButton.stories.tsx +52 -0
- package/src/components/button/IconButton.test.tsx +66 -0
- package/src/components/button/IconButton.tsx +91 -0
- package/src/components/button/index.ts +4 -0
- package/src/components/checkbox/Checkbox.stories.tsx +64 -0
- package/src/components/checkbox/Checkbox.test.tsx +154 -0
- package/src/components/checkbox/Checkbox.tsx +164 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/chip/Chip.stories.tsx +164 -0
- package/src/components/chip/Chip.test.tsx +243 -0
- package/src/components/chip/Chip.tsx +168 -0
- package/src/components/chip/ChipGroup.stories.tsx +47 -0
- package/src/components/chip/ChipGroup.test.tsx +37 -0
- package/src/components/chip/ChipGroup.tsx +60 -0
- package/src/components/chip/index.ts +2 -0
- package/src/components/comment-block/CommentBlock.stories.tsx +91 -0
- package/src/components/comment-block/CommentBlock.test.tsx +28 -0
- package/src/components/comment-block/CommentBlock.tsx +172 -0
- package/src/components/comment-block/index.ts +1 -0
- package/src/components/date-picker/DatePicker.stories.tsx +118 -0
- package/src/components/date-picker/DatePicker.test.tsx +34 -0
- package/src/components/date-picker/DatePicker.tsx +52 -0
- package/src/components/date-picker/DatePickerControlled.test.tsx +91 -0
- package/src/components/date-picker/DatePickerControlled.tsx +259 -0
- package/src/components/date-picker/DatePickerField.stories.tsx +100 -0
- package/src/components/date-picker/DatePickerField.test.tsx +70 -0
- package/src/components/date-picker/DatePickerField.tsx +135 -0
- package/src/components/date-picker/constants.ts +11 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/types.ts +28 -0
- package/src/components/dialog/Dialog.stories.tsx +318 -0
- package/src/components/dialog/Dialog.test.tsx +97 -0
- package/src/components/dialog/Dialog.tsx +288 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/divider/Divider.test.tsx +51 -0
- package/src/components/divider/Divider.tsx +50 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/drag-handle/DragHandle.test.tsx +36 -0
- package/src/components/drag-handle/DragHandle.tsx +51 -0
- package/src/components/drag-handle/index.ts +1 -0
- package/src/components/dropdown/Dropdown.stories.tsx +31 -0
- package/src/components/dropdown/Dropdown.test.tsx +66 -0
- package/src/components/dropdown/Dropdown.tsx +186 -0
- package/src/components/dropdown/index.ts +1 -0
- package/src/components/expansion-panel/ExpansionPanel.stories.tsx +91 -0
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +185 -0
- package/src/components/expansion-panel/ExpansionPanel.tsx +195 -0
- package/src/components/expansion-panel/index.ts +1 -0
- package/src/components/flag/Flag.stories.tsx +48 -0
- package/src/components/flag/Flag.test.tsx +62 -0
- package/src/components/flag/Flag.tsx +52 -0
- package/src/components/flag/index.ts +1 -0
- package/src/components/flex-box/FlexBox.stories.tsx +156 -0
- package/src/components/flex-box/FlexBox.test.tsx +24 -0
- package/src/components/flex-box/FlexBox.tsx +100 -0
- package/src/components/flex-box/index.ts +1 -0
- package/src/components/generic-block/GenericBlock.stories.jsx +128 -0
- package/src/components/generic-block/GenericBlock.test.tsx +156 -0
- package/src/components/generic-block/GenericBlock.tsx +225 -0
- package/src/components/generic-block/constants.ts +9 -0
- package/src/components/generic-block/index.ts +2 -0
- package/src/components/grid/Grid.tsx +83 -0
- package/src/components/grid/GridItem.tsx +55 -0
- package/src/components/grid/index.ts +2 -0
- package/src/components/grid-column/GridColumn.stories.tsx +45 -0
- package/src/components/grid-column/GridColumn.test.jsx +56 -0
- package/src/components/grid-column/GridColumn.tsx +83 -0
- package/src/components/grid-column/index.ts +1 -0
- package/src/components/heading/Heading.stories.tsx +69 -0
- package/src/components/heading/Heading.test.tsx +82 -0
- package/src/components/heading/Heading.tsx +65 -0
- package/src/components/heading/HeadingLevelProvider.tsx +30 -0
- package/src/components/heading/constants.ts +16 -0
- package/src/components/heading/context.tsx +13 -0
- package/src/components/heading/index.ts +3 -0
- package/src/components/heading/useHeadingLevel.tsx +8 -0
- package/src/components/icon/Icon.stories.tsx +73 -0
- package/src/components/icon/Icon.test.tsx +125 -0
- package/src/components/icon/Icon.tsx +133 -0
- package/src/components/icon/index.ts +1 -0
- package/src/components/image-block/ImageBlock.stories.tsx +117 -0
- package/src/components/image-block/ImageBlock.test.tsx +58 -0
- package/src/components/image-block/ImageBlock.tsx +142 -0
- package/src/components/image-block/ImageCaption.tsx +115 -0
- package/src/components/image-block/index.ts +1 -0
- package/src/components/image-lightbox/ImageLightbox.stories.tsx +160 -0
- package/src/components/image-lightbox/ImageLightbox.test.tsx +254 -0
- package/src/components/image-lightbox/ImageLightbox.tsx +90 -0
- package/src/components/image-lightbox/constants.ts +11 -0
- package/src/components/image-lightbox/index.ts +2 -0
- package/src/components/image-lightbox/internal/ImageSlide.tsx +107 -0
- package/src/components/image-lightbox/internal/ImageSlideshow.tsx +164 -0
- package/src/components/image-lightbox/internal/useAnimateScroll.ts +55 -0
- package/src/components/image-lightbox/internal/usePointerZoom.ts +148 -0
- package/src/components/image-lightbox/types.ts +48 -0
- package/src/components/image-lightbox/useImageLightbox.tsx +141 -0
- package/src/components/inline-list/InlineList.stories.tsx +77 -0
- package/src/components/inline-list/InlineList.test.tsx +52 -0
- package/src/components/inline-list/InlineList.tsx +96 -0
- package/src/components/inline-list/index.ts +1 -0
- package/src/components/input-helper/InputHelper.stories.tsx +35 -0
- package/src/components/input-helper/InputHelper.test.tsx +55 -0
- package/src/components/input-helper/InputHelper.tsx +65 -0
- package/src/components/input-helper/constants.ts +11 -0
- package/src/components/input-helper/index.ts +1 -0
- package/src/components/input-label/InputLabel.stories.tsx +45 -0
- package/src/components/input-label/InputLabel.test.tsx +59 -0
- package/src/components/input-label/InputLabel.tsx +69 -0
- package/src/components/input-label/index.ts +1 -0
- package/src/components/lightbox/Lightbox.stories.tsx +101 -0
- package/src/components/lightbox/Lightbox.test.tsx +53 -0
- package/src/components/lightbox/Lightbox.tsx +180 -0
- package/src/components/lightbox/index.ts +1 -0
- package/src/components/link/Link.stories.tsx +195 -0
- package/src/components/link/Link.test.tsx +127 -0
- package/src/components/link/Link.tsx +106 -0
- package/src/components/link/index.ts +1 -0
- package/src/components/link-preview/LinkPreview.stories.tsx +61 -0
- package/src/components/link-preview/LinkPreview.test.tsx +105 -0
- package/src/components/link-preview/LinkPreview.tsx +158 -0
- package/src/components/link-preview/index.ts +1 -0
- package/src/components/list/List.stories.tsx +116 -0
- package/src/components/list/List.test.tsx +18 -0
- package/src/components/list/List.tsx +104 -0
- package/src/components/list/ListDivider.stories.tsx +12 -0
- package/src/components/list/ListDivider.test.tsx +22 -0
- package/src/components/list/ListDivider.tsx +35 -0
- package/src/components/list/ListItem.stories.tsx +66 -0
- package/src/components/list/ListItem.test.tsx +93 -0
- package/src/components/list/ListItem.tsx +157 -0
- package/src/components/list/ListSubheader.stories.tsx +11 -0
- package/src/components/list/ListSubheader.test.tsx +21 -0
- package/src/components/list/ListSubheader.tsx +44 -0
- package/src/components/list/index.ts +4 -0
- package/src/components/list/useInteractiveList.tsx +202 -0
- package/src/components/message/Message.stories.tsx +72 -0
- package/src/components/message/Message.test.tsx +76 -0
- package/src/components/message/Message.tsx +100 -0
- package/src/components/message/index.ts +1 -0
- package/src/components/mosaic/Mosaic.stories.tsx +89 -0
- package/src/components/mosaic/Mosaic.test.tsx +77 -0
- package/src/components/mosaic/Mosaic.tsx +98 -0
- package/src/components/mosaic/index.ts +1 -0
- package/src/components/navigation/Navigation.stories.tsx +234 -0
- package/src/components/navigation/Navigation.test.tsx +65 -0
- package/src/components/navigation/Navigation.tsx +79 -0
- package/src/components/navigation/NavigationItem.test.tsx +35 -0
- package/src/components/navigation/NavigationItem.tsx +82 -0
- package/src/components/navigation/NavigationSection.test.tsx +137 -0
- package/src/components/navigation/NavigationSection.tsx +108 -0
- package/src/components/navigation/context.tsx +7 -0
- package/src/components/navigation/index.ts +1 -0
- package/src/components/notification/Notification.test.tsx +94 -0
- package/src/components/notification/Notification.tsx +138 -0
- package/src/components/notification/Notifications.stories.tsx +92 -0
- package/src/components/notification/constants.ts +28 -0
- package/src/components/notification/index.ts +1 -0
- package/src/components/popover/Popover.stories.tsx +264 -0
- package/src/components/popover/Popover.test.tsx +62 -0
- package/src/components/popover/Popover.tsx +201 -0
- package/src/components/popover/constants.ts +62 -0
- package/src/components/popover/index.ts +3 -0
- package/src/components/popover/usePopoverStyle.tsx +184 -0
- package/src/components/popover/useRestoreFocusOnClose.tsx +47 -0
- package/src/components/popover-dialog/PopoverDialog.stories.tsx +64 -0
- package/src/components/popover-dialog/PopoverDialog.test.tsx +139 -0
- package/src/components/popover-dialog/PopoverDialog.tsx +74 -0
- package/src/components/popover-dialog/index.tsx +1 -0
- package/src/components/post-block/PostBlock.test.tsx +27 -0
- package/src/components/post-block/PostBlock.tsx +122 -0
- package/src/components/post-block/index.ts +1 -0
- package/src/components/progress/Progress.tsx +68 -0
- package/src/components/progress/ProgressCircular.stories.tsx +43 -0
- package/src/components/progress/ProgressCircular.test.tsx +46 -0
- package/src/components/progress/ProgressCircular.tsx +82 -0
- package/src/components/progress/ProgressLinear.stories.tsx +12 -0
- package/src/components/progress/ProgressLinear.test.tsx +30 -0
- package/src/components/progress/ProgressLinear.tsx +50 -0
- package/src/components/progress/index.ts +3 -0
- package/src/components/progress-tracker/ProgressTracker.stories.tsx +145 -0
- package/src/components/progress-tracker/ProgressTracker.test.tsx +42 -0
- package/src/components/progress-tracker/ProgressTracker.tsx +87 -0
- package/src/components/progress-tracker/ProgressTrackerProvider.test.tsx +65 -0
- package/src/components/progress-tracker/ProgressTrackerProvider.tsx +67 -0
- package/src/components/progress-tracker/ProgressTrackerStep.test.tsx +36 -0
- package/src/components/progress-tracker/ProgressTrackerStep.tsx +159 -0
- package/src/components/progress-tracker/ProgressTrackerStepPanel.test.tsx +34 -0
- package/src/components/progress-tracker/ProgressTrackerStepPanel.tsx +67 -0
- package/src/components/progress-tracker/index.ts +4 -0
- package/src/components/radio-button/RadioButton.stories.tsx +71 -0
- package/src/components/radio-button/RadioButton.test.tsx +143 -0
- package/src/components/radio-button/RadioButton.tsx +143 -0
- package/src/components/radio-button/RadioGroup.stories.tsx +39 -0
- package/src/components/radio-button/RadioGroup.test.tsx +29 -0
- package/src/components/radio-button/RadioGroup.tsx +44 -0
- package/src/components/radio-button/index.ts +2 -0
- package/src/components/select/Select.stories.tsx +385 -0
- package/src/components/select/Select.test.tsx +199 -0
- package/src/components/select/Select.tsx +199 -0
- package/src/components/select/SelectMultiple.stories.tsx +315 -0
- package/src/components/select/SelectMultiple.test.tsx +213 -0
- package/src/components/select/SelectMultiple.tsx +206 -0
- package/src/components/select/WithSelectContext.tsx +147 -0
- package/src/components/select/constants.ts +55 -0
- package/src/components/select/index.ts +2 -0
- package/src/components/side-navigation/SideNavigation.stories.tsx +191 -0
- package/src/components/side-navigation/SideNavigation.test.tsx +37 -0
- package/src/components/side-navigation/SideNavigation.tsx +52 -0
- package/src/components/side-navigation/SideNavigationItem.stories.tsx +133 -0
- package/src/components/side-navigation/SideNavigationItem.test.tsx +136 -0
- package/src/components/side-navigation/SideNavigationItem.tsx +165 -0
- package/src/components/side-navigation/index.ts +2 -0
- package/src/components/skeleton/SkeletonCircle.stories.tsx +41 -0
- package/src/components/skeleton/SkeletonCircle.test.tsx +27 -0
- package/src/components/skeleton/SkeletonCircle.tsx +52 -0
- package/src/components/skeleton/SkeletonRectangle.stories.tsx +82 -0
- package/src/components/skeleton/SkeletonRectangle.test.tsx +27 -0
- package/src/components/skeleton/SkeletonRectangle.tsx +88 -0
- package/src/components/skeleton/SkeletonTypography.stories.tsx +19 -0
- package/src/components/skeleton/SkeletonTypography.test.tsx +27 -0
- package/src/components/skeleton/SkeletonTypography.tsx +59 -0
- package/src/components/skeleton/index.ts +3 -0
- package/src/components/slider/Slider.stories.tsx +45 -0
- package/src/components/slider/Slider.test.tsx +29 -0
- package/src/components/slider/Slider.tsx +299 -0
- package/src/components/slider/index.ts +2 -0
- package/src/components/slideshow/Slides.tsx +130 -0
- package/src/components/slideshow/Slideshow.stories.tsx +179 -0
- package/src/components/slideshow/Slideshow.test.tsx +35 -0
- package/src/components/slideshow/Slideshow.tsx +173 -0
- package/src/components/slideshow/SlideshowControls.stories.tsx +100 -0
- package/src/components/slideshow/SlideshowControls.tsx +243 -0
- package/src/components/slideshow/SlideshowItem.tsx +44 -0
- package/src/components/slideshow/SlideshowItemGroup.tsx +60 -0
- package/src/components/slideshow/constants.ts +24 -0
- package/src/components/slideshow/index.ts +4 -0
- package/src/components/slideshow/useKeyNavigate.ts +28 -0
- package/src/components/slideshow/usePaginationVisibleRange.ts +37 -0
- package/src/components/slideshow/useSlideFocusManagement.tsx +92 -0
- package/src/components/slideshow/useSwipeNavigate.ts +18 -0
- package/src/components/switch/Switch.stories.tsx +49 -0
- package/src/components/switch/Switch.test.tsx +144 -0
- package/src/components/switch/Switch.tsx +145 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.test.tsx +29 -0
- package/src/components/table/Table.tsx +59 -0
- package/src/components/table/TableBody.test.tsx +30 -0
- package/src/components/table/TableBody.tsx +42 -0
- package/src/components/table/TableCell.test.tsx +72 -0
- package/src/components/table/TableCell.tsx +130 -0
- package/src/components/table/TableHeader.test.tsx +30 -0
- package/src/components/table/TableHeader.tsx +48 -0
- package/src/components/table/TableRow.test.tsx +40 -0
- package/src/components/table/TableRow.tsx +71 -0
- package/src/components/table/index.ts +5 -0
- package/src/components/tabs/Tab.test.tsx +50 -0
- package/src/components/tabs/Tab.tsx +133 -0
- package/src/components/tabs/TabList.test.tsx +49 -0
- package/src/components/tabs/TabList.tsx +94 -0
- package/src/components/tabs/TabPanel.test.tsx +37 -0
- package/src/components/tabs/TabPanel.tsx +67 -0
- package/src/components/tabs/TabProvider.test.tsx +161 -0
- package/src/components/tabs/TabProvider.tsx +67 -0
- package/src/components/tabs/Tabs.stories.tsx +170 -0
- package/src/components/tabs/index.ts +4 -0
- package/src/components/tabs/state.ts +114 -0
- package/src/components/tabs/test-utils.ts +39 -0
- package/src/components/text/Text.stories.tsx +177 -0
- package/src/components/text/Text.test.tsx +92 -0
- package/src/components/text/Text.tsx +139 -0
- package/src/components/text/index.ts +1 -0
- package/src/components/text-field/TextField.stories.tsx +180 -0
- package/src/components/text-field/TextField.test.tsx +298 -0
- package/src/components/text-field/TextField.tsx +493 -0
- package/src/components/text-field/index.ts +1 -0
- package/src/components/thumbnail/Thumbnail.stories.tsx +448 -0
- package/src/components/thumbnail/Thumbnail.test.tsx +88 -0
- package/src/components/thumbnail/Thumbnail.tsx +248 -0
- package/src/components/thumbnail/index.ts +3 -0
- package/src/components/thumbnail/types.ts +48 -0
- package/src/components/thumbnail/useFocusPointStyle.test.ts +92 -0
- package/src/components/thumbnail/useFocusPointStyle.tsx +107 -0
- package/src/components/thumbnail/useImageLoad.ts +40 -0
- package/src/components/toolbar/Toolbar.tsx +68 -0
- package/src/components/toolbar/index.ts +1 -0
- package/src/components/tooltip/Tooltip.stories.tsx +118 -0
- package/src/components/tooltip/Tooltip.test.tsx +417 -0
- package/src/components/tooltip/Tooltip.tsx +165 -0
- package/src/components/tooltip/constants.ts +8 -0
- package/src/components/tooltip/context.tsx +17 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/useInjectTooltipRef.tsx +55 -0
- package/src/components/tooltip/useTooltipOpen.tsx +143 -0
- package/src/components/uploader/Uploader.stories.tsx +109 -0
- package/src/components/uploader/Uploader.test.tsx +146 -0
- package/src/components/uploader/Uploader.tsx +177 -0
- package/src/components/uploader/index.ts +1 -0
- package/src/components/user-block/UserBlock.stories.tsx +133 -0
- package/src/components/user-block/UserBlock.test.tsx +106 -0
- package/src/components/user-block/UserBlock.tsx +193 -0
- package/src/components/user-block/index.ts +1 -0
- package/src/constants.ts +27 -0
- package/src/hooks/useBooleanState.tsx +13 -0
- package/src/hooks/useCallbackOnEscape.ts +34 -0
- package/src/hooks/useChipGroupNavigation.tsx +75 -0
- package/src/hooks/useClickAway.tsx +48 -0
- package/src/hooks/useDisableBodyScroll.ts +28 -0
- package/src/hooks/useEventCallback.tsx +17 -0
- package/src/hooks/useFocus.tsx +21 -0
- package/src/hooks/useFocusTrap.ts +93 -0
- package/src/hooks/useFocusWithin.ts +33 -0
- package/src/hooks/useId.test.tsx +22 -0
- package/src/hooks/useId.ts +15 -0
- package/src/hooks/useImageSize.ts +17 -0
- package/src/hooks/useInfiniteScroll.tsx +60 -0
- package/src/hooks/useIntersectionObserver.tsx +43 -0
- package/src/hooks/useInterval.tsx +31 -0
- package/src/hooks/useKeyboardListNavigation.tsx +204 -0
- package/src/hooks/useListenFocus.tsx +26 -0
- package/src/hooks/useOverflowTooltipLabel.tsx +32 -0
- package/src/hooks/usePopper.ts +12 -0
- package/src/hooks/usePreviousValue.ts +12 -0
- package/src/hooks/useRovingTabIndex.tsx +90 -0
- package/src/hooks/useSizeOnWindowResize.ts +30 -0
- package/src/hooks/useSlideshowControls.ts +246 -0
- package/src/hooks/useStopPropagation.ts +21 -0
- package/src/hooks/useTransitionVisibility.ts +48 -0
- package/src/index.ts +63 -0
- package/src/stories/controls/color.ts +7 -0
- package/src/stories/controls/element.ts +6 -0
- package/src/stories/controls/focusPoint.ts +1 -0
- package/src/stories/controls/icons.ts +126 -0
- package/src/stories/controls/image.ts +84 -0
- package/src/stories/controls/selectArgType.ts +8 -0
- package/src/stories/controls/theme.ts +3 -0
- package/src/stories/controls/typography.ts +5 -0
- package/src/stories/controls/withUndefined.ts +1 -0
- package/src/stories/decorators/withChromaticForceScreenSize.tsx +7 -0
- package/src/stories/decorators/withCombinations.tsx +132 -0
- package/src/stories/decorators/withNestedProps.tsx +22 -0
- package/src/stories/decorators/withResizableBox.tsx +21 -0
- package/src/stories/decorators/withThemedBackground.tsx +16 -0
- package/src/stories/decorators/withValueOnChange.tsx +18 -0
- package/src/stories/decorators/withWrapper.tsx +19 -0
- package/src/stories/generated/Autocomplete/Demos.stories.tsx +7 -0
- package/src/stories/generated/Avatar/Demos.stories.tsx +7 -0
- package/src/stories/generated/Badge/Demos.stories.tsx +9 -0
- package/src/stories/generated/Button/Demos.stories.tsx +11 -0
- package/src/stories/generated/Checkbox/Demos.stories.tsx +6 -0
- package/src/stories/generated/Chip/Demos.stories.tsx +11 -0
- package/src/stories/generated/CommentBlock/Demos.stories.tsx +8 -0
- package/src/stories/generated/DatePicker/Demos.stories.tsx +8 -0
- package/src/stories/generated/Dialog/Demos.stories.tsx +10 -0
- package/src/stories/generated/Divider/Demos.stories.tsx +6 -0
- package/src/stories/generated/Dropdown/Demos.stories.tsx +8 -0
- package/src/stories/generated/ExpansionPanel/Demos.stories.tsx +9 -0
- package/src/stories/generated/Flag/Demos.stories.tsx +6 -0
- package/src/stories/generated/GenericBlock/Demos.stories.tsx +8 -0
- package/src/stories/generated/Heading/Demos.stories.tsx +6 -0
- package/src/stories/generated/Icon/Demos.stories.tsx +8 -0
- package/src/stories/generated/ImageBlock/Demos.stories.tsx +9 -0
- package/src/stories/generated/ImageLightbox/Demos.stories.tsx +6 -0
- package/src/stories/generated/Lightbox/Demos.stories.tsx +6 -0
- package/src/stories/generated/LinkPreview/Demos.stories.tsx +7 -0
- package/src/stories/generated/List/Demos.stories.tsx +11 -0
- package/src/stories/generated/Message/Demos.stories.tsx +11 -0
- package/src/stories/generated/Mosaic/Demos.stories.tsx +10 -0
- package/src/stories/generated/Notification/Demos.stories.tsx +6 -0
- package/src/stories/generated/Popover/Demos.stories.tsx +11 -0
- package/src/stories/generated/PopoverDialog/Demos.stories.tsx +6 -0
- package/src/stories/generated/PostBlock/Demos.stories.tsx +6 -0
- package/src/stories/generated/Progress/Demos.stories.tsx +7 -0
- package/src/stories/generated/ProgressTracker/Demos.stories.tsx +9 -0
- package/src/stories/generated/RadioButton/Demos.stories.tsx +6 -0
- package/src/stories/generated/Select/Demos.stories.tsx +14 -0
- package/src/stories/generated/SideNavigation/Demos.stories.tsx +10 -0
- package/src/stories/generated/Skeleton/Demos.stories.tsx +9 -0
- package/src/stories/generated/Slider/Demos.stories.tsx +9 -0
- package/src/stories/generated/Slideshow/Demos.stories.tsx +8 -0
- package/src/stories/generated/Switch/Demos.stories.tsx +6 -0
- package/src/stories/generated/Table/Demos.stories.tsx +7 -0
- package/src/stories/generated/Tabs/Demos.stories.tsx +8 -0
- package/src/stories/generated/TextField/Demos.stories.tsx +20 -0
- package/src/stories/generated/Thumbnail/Demos.stories.tsx +12 -0
- package/src/stories/generated/Toolbar/Demos.stories.tsx +10 -0
- package/src/stories/generated/Tooltip/Demos.stories.tsx +8 -0
- package/src/stories/generated/Uploader/Demos.stories.tsx +8 -0
- package/src/stories/generated/UserBlock/Demos.stories.tsx +11 -0
- package/src/stories/utils/CustomLink.tsx +12 -0
- package/src/stories/utils/concatPath.tsx +17 -0
- package/src/stories/utils/disableArgTypes.ts +3 -0
- package/src/stories/utils/initDemoShadowDOMPortal.ts +10 -0
- package/src/stories/utils/lorem.ts +59 -0
- package/src/stories/utils/theming.tsx +166 -0
- package/src/stories/utils/toFlattenProps.ts +28 -0
- package/src/stories/utils/withCategory.ts +12 -0
- package/src/testing/utils/ThemeSentinel.tsx +10 -0
- package/src/testing/utils/commonTestsSuiteRTL.tsx +193 -0
- package/src/testing/utils/index.ts +1 -0
- package/src/testing/utils/queries.ts +19 -0
- package/src/untypped-modules.d.ts +9 -0
- package/src/utils/ClickAwayProvider/ClickAwayProvider.stories.jsx +70 -0
- package/src/utils/ClickAwayProvider/ClickAwayProvider.tsx +69 -0
- package/src/utils/ClickAwayProvider/index.ts +1 -0
- package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +54 -0
- package/src/utils/MaterialThemeSwitcher/index.ts +1 -0
- package/src/utils/Portal/Portal.test.tsx +31 -0
- package/src/utils/Portal/Portal.tsx +33 -0
- package/src/utils/Portal/PortalProvider.stories.jsx +22 -0
- package/src/utils/Portal/PortalProvider.test.tsx +72 -0
- package/src/utils/Portal/PortalProvider.tsx +24 -0
- package/src/utils/Portal/index.tsx +2 -0
- package/src/utils/browser/DOM/findImage.tsx +3 -0
- package/src/utils/browser/DOM/startViewTransition.ts +68 -0
- package/src/utils/browser/focus/constants.ts +7 -0
- package/src/utils/browser/focus/getFirstAndLastFocusable.test.ts +134 -0
- package/src/utils/browser/focus/getFirstAndLastFocusable.ts +21 -0
- package/src/utils/browser/focus/getFocusableElements.test.ts +151 -0
- package/src/utils/browser/focus/getFocusableElements.ts +7 -0
- package/src/utils/browser/isFocusVisible.ts +9 -0
- package/src/utils/browser/isHoverNotSupported.test.js +24 -0
- package/src/utils/browser/isHoverNotSupported.ts +2 -0
- package/src/utils/browser/isReducedMotion.ts +6 -0
- package/src/utils/date/addMonthResetDay.test.ts +13 -0
- package/src/utils/date/addMonthResetDay.ts +9 -0
- package/src/utils/date/formatDayNumber.test.ts +12 -0
- package/src/utils/date/formatDayNumber.ts +5 -0
- package/src/utils/date/getFirstDayOfWeek.test.ts +20 -0
- package/src/utils/date/getFirstDayOfWeek.ts +59 -0
- package/src/utils/date/getMonthCalendar.test.ts +127 -0
- package/src/utils/date/getMonthCalendar.ts +69 -0
- package/src/utils/date/getWeekDays.test.ts +48 -0
- package/src/utils/date/getWeekDays.ts +34 -0
- package/src/utils/date/getYearDisplayName.test.ts +20 -0
- package/src/utils/date/getYearDisplayName.ts +12 -0
- package/src/utils/date/isDateValid.test.ts +15 -0
- package/src/utils/date/isDateValid.ts +4 -0
- package/src/utils/date/isSameDay.test.ts +37 -0
- package/src/utils/date/isSameDay.ts +11 -0
- package/src/utils/disabled/DisabledStateContext.tsx +29 -0
- package/src/utils/disabled/DisabledStateProvider.stories.tsx +92 -0
- package/src/utils/disabled/index.ts +2 -0
- package/src/utils/disabled/useDisableStateProps.test.tsx +74 -0
- package/src/utils/disabled/useDisableStateProps.tsx +37 -0
- package/src/utils/function/makeListenerTowerContext.ts +32 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/locale/getCurrentLocale.ts +4 -0
- package/src/utils/locale/parseLocale.test.ts +17 -0
- package/src/utils/locale/parseLocale.ts +23 -0
- package/src/utils/locale/types.ts +8 -0
- package/src/utils/number/clamp.ts +17 -0
- package/src/utils/object/isEqual.test.ts +25 -0
- package/src/utils/object/isEqual.ts +11 -0
- package/src/utils/partitionMulti.test.ts +27 -0
- package/{_internal/partitionMulti-4daccdd5.js → src/utils/partitionMulti.ts} +9 -5
- package/src/utils/react/OnBeforeUnmount.tsx +20 -0
- package/src/utils/react/RawClickable.test.tsx +153 -0
- package/src/utils/react/RawClickable.tsx +65 -0
- package/src/utils/react/flattenChildren.ts +32 -0
- package/src/utils/react/forwardRef.ts +11 -0
- package/src/utils/react/forwardRefPolymorphic.ts +9 -0
- package/src/utils/react/mergeRefs.ts +33 -0
- package/src/utils/react/renderLink.tsx +17 -0
- package/src/utils/react/skipRender.tsx +18 -0
- package/src/utils/react/unref.ts +7 -0
- package/src/utils/react/wrapChildrenIconWithSpaces.test.tsx +37 -0
- package/src/utils/react/wrapChildrenIconWithSpaces.tsx +22 -0
- package/src/utils/theme/ThemeContext.ts +16 -0
- package/src/utils/theme/invertTheme.ts +4 -0
- package/src/utils/type/Comp.ts +14 -0
- package/src/utils/type/ComponentRef.ts +16 -0
- package/src/utils/type/HasAriaDisabled.ts +6 -0
- package/src/utils/type/HasPolymorphicAs.ts +6 -0
- package/src/utils/type/HasRequiredLinkHref.ts +1 -0
- package/src/utils/type/MaybeElementOrRef.ts +6 -0
- package/src/utils/type/index.ts +9 -0
- package/src/utils/type/isComponent.ts +33 -0
- package/src/utils/type/isComponentType.ts +9 -0
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -3
- package/utils/index.js.map +1 -1
- package/_internal/Button-1f227024.js +0 -98
- package/_internal/Button-1f227024.js.map +0 -1
- package/_internal/ButtonRoot-823f3e9c.js +0 -117
- package/_internal/ButtonRoot-823f3e9c.js.map +0 -1
- package/_internal/Chip-a34f6905.js +0 -146
- package/_internal/Chip-a34f6905.js.map +0 -1
- package/_internal/ClickAwayProvider-7093ba23.js +0 -95
- package/_internal/ClickAwayProvider-7093ba23.js.map +0 -1
- package/_internal/DisabledStateContext-ea04260d.js +0 -29
- package/_internal/DisabledStateContext-ea04260d.js.map +0 -1
- package/_internal/HeadingLevelProvider-ebdcb0c7.js +0 -61
- package/_internal/HeadingLevelProvider-ebdcb0c7.js.map +0 -1
- package/_internal/IconButton-f4df224c.js +0 -77
- package/_internal/IconButton-f4df224c.js.map +0 -1
- package/_internal/ImageCaption-8134a3aa.js +0 -75
- package/_internal/ImageCaption-8134a3aa.js.map +0 -1
- package/_internal/List-54237e0e.js +0 -793
- package/_internal/List-54237e0e.js.map +0 -1
- package/_internal/PopoverDialog-e0967e5f.js +0 -655
- package/_internal/PopoverDialog-e0967e5f.js.map +0 -1
- package/_internal/Portal-3f86608e.js +0 -45
- package/_internal/Portal-3f86608e.js.map +0 -1
- package/_internal/RawClickable-2c2b6a89.js +0 -52
- package/_internal/RawClickable-2c2b6a89.js.map +0 -1
- package/_internal/Slides-b7a67f32.js +0 -678
- package/_internal/Slides-b7a67f32.js.map +0 -1
- package/_internal/ThemeContext-3181f000.js +0 -14
- package/_internal/ThemeContext-3181f000.js.map +0 -1
- package/_internal/Thumbnail-b5dea0af.js +0 -313
- package/_internal/Thumbnail-b5dea0af.js.map +0 -1
- package/_internal/components/alert-dialog-b284b191.js +0 -162
- package/_internal/components/alert-dialog-b284b191.js.map +0 -1
- package/_internal/components/autocomplete-8d3f37ea.js +0 -261
- package/_internal/components/autocomplete-8d3f37ea.js.map +0 -1
- package/_internal/components/avatar-5fc70e00.js +0 -83
- package/_internal/components/avatar-5fc70e00.js.map +0 -1
- package/_internal/components/badge-8390e590.js +0 -81
- package/_internal/components/badge-8390e590.js.map +0 -1
- package/_internal/components/button-e3c7f2eb.js +0 -47
- package/_internal/components/button-e3c7f2eb.js.map +0 -1
- package/_internal/components/checkbox-d1ca9748.js +0 -140
- package/_internal/components/checkbox-d1ca9748.js.map +0 -1
- package/_internal/components/chip-e40c5521.js +0 -102
- package/_internal/components/chip-e40c5521.js.map +0 -1
- package/_internal/components/comment-block-a3cf7b9b.js +0 -138
- package/_internal/components/comment-block-a3cf7b9b.js.map +0 -1
- package/_internal/components/date-picker-6c1b14e4.js +0 -2
- package/_internal/components/date-picker-6c1b14e4.js.map +0 -1
- package/_internal/components/dialog-ebdb9500.js +0 -238
- package/_internal/components/dialog-ebdb9500.js.map +0 -1
- package/_internal/components/divider-116af6b9.js +0 -50
- package/_internal/components/divider-116af6b9.js.map +0 -1
- package/_internal/components/drag-handle-5215cd21.js +0 -51
- package/_internal/components/drag-handle-5215cd21.js.map +0 -1
- package/_internal/components/dropdown-0baed51b.js +0 -147
- package/_internal/components/dropdown-0baed51b.js.map +0 -1
- package/_internal/components/expansion-panel-5533a680.js +0 -167
- package/_internal/components/expansion-panel-5533a680.js.map +0 -1
- package/_internal/components/flag-8d4a7e72.js +0 -59
- package/_internal/components/flag-8d4a7e72.js.map +0 -1
- package/_internal/components/flex-box-55144e5f.js +0 -56
- package/_internal/components/flex-box-55144e5f.js.map +0 -1
- package/_internal/components/generic-block-ff0509ee.js +0 -124
- package/_internal/components/generic-block-ff0509ee.js.map +0 -1
- package/_internal/components/grid-6f1b5a41.js +0 -104
- package/_internal/components/grid-6f1b5a41.js.map +0 -1
- package/_internal/components/grid-column-f01df853.js +0 -59
- package/_internal/components/grid-column-f01df853.js.map +0 -1
- package/_internal/components/heading-89239843.js +0 -53
- package/_internal/components/heading-89239843.js.map +0 -1
- package/_internal/components/icon-b708cca4.js +0 -102
- package/_internal/components/icon-b708cca4.js.map +0 -1
- package/_internal/components/image-block-7938422d.js +0 -110
- package/_internal/components/image-block-7938422d.js.map +0 -1
- package/_internal/components/image-lightbox-58331704.js +0 -756
- package/_internal/components/image-lightbox-58331704.js.map +0 -1
- package/_internal/components/inline-list-e6f19a98.js +0 -74
- package/_internal/components/inline-list-e6f19a98.js.map +0 -1
- package/_internal/components/input-helper-64153099.js +0 -71
- package/_internal/components/input-helper-64153099.js.map +0 -1
- package/_internal/components/input-label-2feb0bb0.js +0 -59
- package/_internal/components/input-label-2feb0bb0.js.map +0 -1
- package/_internal/components/lightbox-570ad9e5.js +0 -155
- package/_internal/components/lightbox-570ad9e5.js.map +0 -1
- package/_internal/components/link-91f76477.js +0 -72
- package/_internal/components/link-91f76477.js.map +0 -1
- package/_internal/components/link-preview-fdd8d738.js +0 -117
- package/_internal/components/link-preview-fdd8d738.js.map +0 -1
- package/_internal/components/list-b08d8423.js +0 -71
- package/_internal/components/list-b08d8423.js.map +0 -1
- package/_internal/components/message-29cb9181.js +0 -96
- package/_internal/components/message-29cb9181.js.map +0 -1
- package/_internal/components/mosaic-cdb9f563.js +0 -95
- package/_internal/components/mosaic-cdb9f563.js.map +0 -1
- package/_internal/components/navigation-8b7d9bd8.js +0 -225
- package/_internal/components/navigation-8b7d9bd8.js.map +0 -1
- package/_internal/components/notification-a45fda96.js +0 -145
- package/_internal/components/notification-a45fda96.js.map +0 -1
- package/_internal/components/popover-65bfbc57.js +0 -3
- package/_internal/components/popover-65bfbc57.js.map +0 -1
- package/_internal/components/post-block-52e58dd5.js +0 -109
- package/_internal/components/post-block-52e58dd5.js.map +0 -1
- package/_internal/components/progress-f39c3fa2.js +0 -182
- package/_internal/components/progress-f39c3fa2.js.map +0 -1
- package/_internal/components/progress-tracker-512d7a08.js +0 -305
- package/_internal/components/progress-tracker-512d7a08.js.map +0 -1
- package/_internal/components/radio-button-559a4863.js +0 -149
- package/_internal/components/radio-button-559a4863.js.map +0 -1
- package/_internal/components/select-48d4fa8c.js +0 -454
- package/_internal/components/select-48d4fa8c.js.map +0 -1
- package/_internal/components/side-navigation-f9bc5b4e.js +0 -165
- package/_internal/components/side-navigation-f9bc5b4e.js.map +0 -1
- package/_internal/components/skeleton-c66516ee.js +0 -166
- package/_internal/components/skeleton-c66516ee.js.map +0 -1
- package/_internal/components/slider-efbfbc45.js +0 -311
- package/_internal/components/slider-efbfbc45.js.map +0 -1
- package/_internal/components/slideshow-dd312470.js +0 -151
- package/_internal/components/slideshow-dd312470.js.map +0 -1
- package/_internal/components/switch-769a2a04.js +0 -122
- package/_internal/components/switch-769a2a04.js.map +0 -1
- package/_internal/components/table-8617b1ba.js +0 -294
- package/_internal/components/table-8617b1ba.js.map +0 -1
- package/_internal/components/tabs-884c57b6.js +0 -298
- package/_internal/components/tabs-884c57b6.js.map +0 -1
- package/_internal/components/text-c7b1e079.js +0 -2
- package/_internal/components/text-c7b1e079.js.map +0 -1
- package/_internal/components/text-field-478acd86.js +0 -359
- package/_internal/components/text-field-478acd86.js.map +0 -1
- package/_internal/components/thumbnail-310a4c4b.js +0 -42
- package/_internal/components/thumbnail-310a4c4b.js.map +0 -1
- package/_internal/components/toolbar-a43533a2.js +0 -61
- package/_internal/components/toolbar-a43533a2.js.map +0 -1
- package/_internal/components/tooltip-2885ab2e.js +0 -327
- package/_internal/components/tooltip-2885ab2e.js.map +0 -1
- package/_internal/components/uploader-1e7f5bbb.js +0 -153
- package/_internal/components/uploader-1e7f5bbb.js.map +0 -1
- package/_internal/components/user-block-68a51ed0.js +0 -145
- package/_internal/components/user-block-68a51ed0.js.map +0 -1
- package/_internal/constants-b9e57936.js +0 -2155
- package/_internal/constants-b9e57936.js.map +0 -1
- package/_internal/constants-d0e3f49e.js +0 -24
- package/_internal/constants-d0e3f49e.js.map +0 -1
- package/_internal/context-9d1336a1.js +0 -19
- package/_internal/context-9d1336a1.js.map +0 -1
- package/_internal/forwardRef-15f62847.js +0 -70
- package/_internal/forwardRef-15f62847.js.map +0 -1
- package/_internal/getFocusableElements-230173a8.js +0 -13
- package/_internal/getFocusableElements-230173a8.js.map +0 -1
- package/_internal/index-9df37c0d.js +0 -436
- package/_internal/index-9df37c0d.js.map +0 -1
- package/_internal/index-a9c5cd69.js +0 -117
- package/_internal/index-a9c5cd69.js.map +0 -1
- package/_internal/isComponent-78df9309.js +0 -20
- package/_internal/isComponent-78df9309.js.map +0 -1
- package/_internal/isComponentType-e806b848.js +0 -9
- package/_internal/isComponentType-e806b848.js.map +0 -1
- package/_internal/mergeRefs-f0d7d6ea.js +0 -30
- package/_internal/mergeRefs-f0d7d6ea.js.map +0 -1
- package/_internal/partitionMulti-4daccdd5.js.map +0 -1
- package/_internal/state-db358714.js +0 -130
- package/_internal/state-db358714.js.map +0 -1
- package/_internal/useBooleanState-2a3d237c.js +0 -12
- package/_internal/useBooleanState-2a3d237c.js.map +0 -1
- package/_internal/useCallbackOnEscape-ea4d9eb4.js +0 -62
- package/_internal/useCallbackOnEscape-ea4d9eb4.js.map +0 -1
- package/_internal/useDisableBodyScroll-36bd7352.js +0 -219
- package/_internal/useDisableBodyScroll-36bd7352.js.map +0 -1
- package/_internal/useDisableStateProps-69e16b7c.js +0 -36
- package/_internal/useDisableStateProps-69e16b7c.js.map +0 -1
- package/_internal/useFocusTrap-c3c6378b.js +0 -112
- package/_internal/useFocusTrap-c3c6378b.js.map +0 -1
- package/_internal/useId-3a1facc0.js +0 -18
- package/_internal/useId-3a1facc0.js.map +0 -1
- package/_internal/useRovingTabIndex-7daf0f24.js +0 -77
- package/_internal/useRovingTabIndex-7daf0f24.js.map +0 -1
- package/_internal/useTransitionVisibility-321fdbfa.js +0 -50
- package/_internal/useTransitionVisibility-321fdbfa.js.map +0 -1
- package/_internal/wrapChildrenIconWithSpaces-c1faaae4.js +0 -20
- package/_internal/wrapChildrenIconWithSpaces-c1faaae4.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { PortalContext } from './PortalProvider';
|
|
4
|
+
|
|
5
|
+
export interface PortalProps {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Render children in a portal outside the current DOM position
|
|
12
|
+
* (defaults to `document.body` but can be customized with the PortalContextProvider)
|
|
13
|
+
*/
|
|
14
|
+
export const Portal: React.FC<PortalProps> = ({ children, enabled = true }) => {
|
|
15
|
+
const init = React.useContext(PortalContext);
|
|
16
|
+
const context = React.useMemo(
|
|
17
|
+
() => {
|
|
18
|
+
return enabled ? init() : null;
|
|
19
|
+
},
|
|
20
|
+
// Only update on 'enabled'
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
[enabled],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
React.useLayoutEffect(() => {
|
|
26
|
+
return context?.teardown;
|
|
27
|
+
}, [context?.teardown, enabled]);
|
|
28
|
+
|
|
29
|
+
if (!context?.container) {
|
|
30
|
+
return <>{children}</>;
|
|
31
|
+
}
|
|
32
|
+
return createPortal(children, context.container);
|
|
33
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Button } from '@lumx/react';
|
|
2
|
+
import { initDemoShadowDOMPortal } from '@lumx/react/stories/utils/initDemoShadowDOMPortal';
|
|
3
|
+
import { PortalProvider } from './PortalProvider';
|
|
4
|
+
import { Portal } from './Portal';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'LumX components/PortalProvider',
|
|
8
|
+
component: PortalProvider,
|
|
9
|
+
args: { enabled: true },
|
|
10
|
+
parameters: { chromatic: { disable: true } },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Demonstrate how to customize portals to render into a custom shadow root
|
|
15
|
+
*/
|
|
16
|
+
export const RenderInShadowDOM = ({ enabled }) => (
|
|
17
|
+
<PortalProvider value={initDemoShadowDOMPortal}>
|
|
18
|
+
<Portal enabled={enabled}>
|
|
19
|
+
<Button>My button {!enabled && 'not'} in a shadow DOM portal</Button>
|
|
20
|
+
</Portal>
|
|
21
|
+
</PortalProvider>
|
|
22
|
+
);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { PortalInit, PortalProvider } from './PortalProvider';
|
|
3
|
+
import { Portal } from './Portal';
|
|
4
|
+
|
|
5
|
+
const TEST_ID = 'portal-child';
|
|
6
|
+
const PORTAL_CONTAINER_ID = 'portal-container';
|
|
7
|
+
|
|
8
|
+
const PortalChild = () => <div data-testid={TEST_ID}>Hello from portal</div>;
|
|
9
|
+
|
|
10
|
+
describe('PortalProvider', () => {
|
|
11
|
+
it('should render portal content in the provided container', () => {
|
|
12
|
+
const portalContainer = document.createElement('div');
|
|
13
|
+
portalContainer.id = PORTAL_CONTAINER_ID;
|
|
14
|
+
document.body.appendChild(portalContainer);
|
|
15
|
+
|
|
16
|
+
const getContainer: PortalInit = () => ({ container: portalContainer });
|
|
17
|
+
|
|
18
|
+
render(
|
|
19
|
+
<PortalProvider value={getContainer}>
|
|
20
|
+
<Portal>
|
|
21
|
+
<PortalChild />
|
|
22
|
+
</Portal>
|
|
23
|
+
</PortalProvider>,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const child = screen.getByTestId(TEST_ID);
|
|
27
|
+
expect(child.parentElement).toBe(portalContainer);
|
|
28
|
+
portalContainer.remove();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should call teardown on unmount', () => {
|
|
32
|
+
const teardownMock = vi.fn();
|
|
33
|
+
const portalContainer = document.createElement('div');
|
|
34
|
+
portalContainer.id = PORTAL_CONTAINER_ID;
|
|
35
|
+
document.body.appendChild(portalContainer);
|
|
36
|
+
|
|
37
|
+
const getContainer: PortalInit = () => ({
|
|
38
|
+
container: portalContainer,
|
|
39
|
+
teardown: teardownMock,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const { unmount } = render(
|
|
43
|
+
<PortalProvider value={getContainer}>
|
|
44
|
+
<Portal>
|
|
45
|
+
<PortalChild />
|
|
46
|
+
</Portal>
|
|
47
|
+
</PortalProvider>,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(teardownMock).not.toHaveBeenCalled();
|
|
51
|
+
unmount();
|
|
52
|
+
expect(teardownMock).toHaveBeenCalledTimes(1);
|
|
53
|
+
portalContainer.remove();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should render inline if provider does not return a container', () => {
|
|
57
|
+
const getContainer: PortalInit = () => ({}); // No container
|
|
58
|
+
|
|
59
|
+
const { container } = render(
|
|
60
|
+
<div id="wrapper">
|
|
61
|
+
<PortalProvider value={getContainer}>
|
|
62
|
+
<Portal>
|
|
63
|
+
<PortalChild />
|
|
64
|
+
</Portal>
|
|
65
|
+
</PortalProvider>
|
|
66
|
+
</div>,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const child = screen.getByTestId(TEST_ID);
|
|
70
|
+
expect(child.parentElement).toBe(container.querySelector('#wrapper'));
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type Container = DocumentFragment | Element;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Portal initializing function.
|
|
7
|
+
* If it does not provide a container, the Portal children will render in classic React tree and not in a portal.
|
|
8
|
+
*/
|
|
9
|
+
export type PortalInit = () => {
|
|
10
|
+
container?: Container;
|
|
11
|
+
teardown?: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const PortalContext = React.createContext<PortalInit>(() => ({ container: document.body }));
|
|
15
|
+
|
|
16
|
+
export interface PortalProviderProps {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
value: PortalInit;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)
|
|
23
|
+
*/
|
|
24
|
+
export const PortalProvider: React.FC<PortalProviderProps> = PortalContext.Provider;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import ReactDOM from 'react-dom';
|
|
2
|
+
|
|
3
|
+
import { MaybeElementOrRef } from '@lumx/react/utils/type';
|
|
4
|
+
|
|
5
|
+
import { unref } from '../../react/unref';
|
|
6
|
+
import { isReducedMotion } from '../isReducedMotion';
|
|
7
|
+
|
|
8
|
+
function setupViewTransitionName(elementRef: MaybeElementOrRef<HTMLElement>, name: string) {
|
|
9
|
+
let originalName: string | null = null;
|
|
10
|
+
return {
|
|
11
|
+
set() {
|
|
12
|
+
const element = unref(elementRef);
|
|
13
|
+
if (!element) return;
|
|
14
|
+
originalName = element.style.viewTransitionName;
|
|
15
|
+
element.style.viewTransitionName = name;
|
|
16
|
+
},
|
|
17
|
+
unset() {
|
|
18
|
+
const element = unref(elementRef);
|
|
19
|
+
if (!element || originalName === null) return;
|
|
20
|
+
element.style.viewTransitionName = originalName;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Wrapper around the `document.startViewTransition` handling browser incompatibilities, react DOM flush and
|
|
27
|
+
* user preference.
|
|
28
|
+
*
|
|
29
|
+
* @param changes callback containing the changes to apply within the view transition.
|
|
30
|
+
* @param setViewTransitionName set the `viewTransitionName` style on a `source` & `target` to morph these elements.
|
|
31
|
+
*/
|
|
32
|
+
export async function startViewTransition({
|
|
33
|
+
changes,
|
|
34
|
+
viewTransitionName,
|
|
35
|
+
}: {
|
|
36
|
+
changes: () => void;
|
|
37
|
+
viewTransitionName: {
|
|
38
|
+
source: MaybeElementOrRef<HTMLElement>;
|
|
39
|
+
target: MaybeElementOrRef<HTMLElement>;
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
}) {
|
|
43
|
+
const start = (document as any)?.startViewTransition?.bind(document);
|
|
44
|
+
const prefersReducedMotion = isReducedMotion();
|
|
45
|
+
const { flushSync } = ReactDOM as any;
|
|
46
|
+
if (prefersReducedMotion || !start || !flushSync || !viewTransitionName?.source || !viewTransitionName?.target) {
|
|
47
|
+
// Skip, apply changes without a transition
|
|
48
|
+
changes();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Setup set/unset transition name on source & target
|
|
53
|
+
const sourceTransitionName = setupViewTransitionName(viewTransitionName.source, viewTransitionName.name);
|
|
54
|
+
const targetTransitionName = setupViewTransitionName(viewTransitionName.target, viewTransitionName.name);
|
|
55
|
+
|
|
56
|
+
sourceTransitionName.set();
|
|
57
|
+
|
|
58
|
+
// Start view transition, apply changes & flush to DOM
|
|
59
|
+
await start(() => {
|
|
60
|
+
sourceTransitionName.unset();
|
|
61
|
+
|
|
62
|
+
flushSync(changes);
|
|
63
|
+
|
|
64
|
+
targetTransitionName.set();
|
|
65
|
+
}).updateCallbackDone;
|
|
66
|
+
|
|
67
|
+
targetTransitionName.unset();
|
|
68
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** CSS selector listing all tabbable elements. */
|
|
2
|
+
export const TABBABLE_ELEMENTS_SELECTOR =
|
|
3
|
+
'a[href], button, textarea, input:not([type="hidden"]):not([hidden]), [tabindex]';
|
|
4
|
+
|
|
5
|
+
/** CSS selector matching element that are disabled (should not receive focus). */
|
|
6
|
+
export const DISABLED_SELECTOR =
|
|
7
|
+
'[hidden], [tabindex="-1"], [disabled]:not([disabled="false"]), [aria-disabled]:not([aria-disabled="false"])';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { getFirstAndLastFocusable } from './getFirstAndLastFocusable';
|
|
2
|
+
|
|
3
|
+
function htmlToElement(html: string): any {
|
|
4
|
+
const template = document.createElement('template');
|
|
5
|
+
template.innerHTML = html.trim();
|
|
6
|
+
return template.content.firstChild;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe(getFirstAndLastFocusable.name, () => {
|
|
10
|
+
it('should get empty', () => {
|
|
11
|
+
const element = htmlToElement('<div></div>');
|
|
12
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
13
|
+
expect(focusable).toEqual({});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should get single item', () => {
|
|
17
|
+
const element = htmlToElement('<div><button /></div>');
|
|
18
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
19
|
+
expect(focusable.last).toBe(focusable.first);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should get first and last', () => {
|
|
23
|
+
const element = htmlToElement(`
|
|
24
|
+
<div>
|
|
25
|
+
<div>Non focusable div</div>
|
|
26
|
+
<button>Simple button</button>
|
|
27
|
+
<div>Non focusable div</div>
|
|
28
|
+
<input />
|
|
29
|
+
<div>Non focusable div</div>
|
|
30
|
+
</div>
|
|
31
|
+
`);
|
|
32
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
33
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
34
|
+
<button>
|
|
35
|
+
Simple button
|
|
36
|
+
</button>
|
|
37
|
+
`);
|
|
38
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
39
|
+
<button>
|
|
40
|
+
Simple button
|
|
41
|
+
</button>
|
|
42
|
+
`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('match focusable elements', () => {
|
|
46
|
+
it('should match input element', () => {
|
|
47
|
+
const element = htmlToElement('<div><input /></div>');
|
|
48
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
49
|
+
expect(focusable.first).toMatchInlineSnapshot('<input />');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should match link element', () => {
|
|
53
|
+
const element = htmlToElement('<div><a href="#" /></div>');
|
|
54
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
55
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
56
|
+
<a
|
|
57
|
+
href="#"
|
|
58
|
+
/>
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should match textarea element', () => {
|
|
63
|
+
const element = htmlToElement('<div><textarea /></div>');
|
|
64
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
65
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
66
|
+
<textarea>
|
|
67
|
+
</div>
|
|
68
|
+
</textarea>
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should match element with tabindex', () => {
|
|
73
|
+
const element = htmlToElement('<div><span tabindex="0" /></div>');
|
|
74
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
75
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
76
|
+
<span
|
|
77
|
+
tabindex="0"
|
|
78
|
+
/>
|
|
79
|
+
`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should keep disabled=false', () => {
|
|
83
|
+
const element = htmlToElement('<div><button disabled="false" /><button /></div>');
|
|
84
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
85
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
86
|
+
<button
|
|
87
|
+
disabled="false"
|
|
88
|
+
/>
|
|
89
|
+
`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should keep aria-disabled=false', () => {
|
|
93
|
+
const element = htmlToElement('<div><button aria-disabled="false" /><button /></div>');
|
|
94
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
95
|
+
expect(focusable.first).toMatchInlineSnapshot(`
|
|
96
|
+
<button
|
|
97
|
+
aria-disabled="false"
|
|
98
|
+
/>
|
|
99
|
+
`);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('skip disabled elements', () => {
|
|
104
|
+
it('should skip disabled', () => {
|
|
105
|
+
const element = htmlToElement('<div><button disabled /><button /></div>');
|
|
106
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
107
|
+
expect(focusable.first).toMatchInlineSnapshot('<button />');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should skip aria-disabled', () => {
|
|
111
|
+
const element = htmlToElement('<div><button aria-disabled /><button /></div>');
|
|
112
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
113
|
+
expect(focusable.first).toMatchInlineSnapshot('<button />');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should skip tabindex=-1', () => {
|
|
117
|
+
const element = htmlToElement('<div><button tabindex="-1" /><button /></div>');
|
|
118
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
119
|
+
expect(focusable.first).toMatchInlineSnapshot('<button />');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should skip input type hidden', () => {
|
|
123
|
+
const element = htmlToElement('<div><input type="hidden" /><button /></div>');
|
|
124
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
125
|
+
expect(focusable.first).toMatchInlineSnapshot('<button />');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should skip hidden input', () => {
|
|
129
|
+
const element = htmlToElement('<div><input hidden /><button /></div>');
|
|
130
|
+
const focusable = getFirstAndLastFocusable(element);
|
|
131
|
+
expect(focusable.first).toMatchInlineSnapshot('<button />');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getFocusableElements } from './getFocusableElements';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get first and last elements focusable in an element.
|
|
5
|
+
*
|
|
6
|
+
* @param parentElement The element in which to search focusable elements.
|
|
7
|
+
* @return first and last focusable elements
|
|
8
|
+
*/
|
|
9
|
+
export function getFirstAndLastFocusable(parentElement: HTMLElement | ShadowRoot) {
|
|
10
|
+
const focusableElements = getFocusableElements(parentElement);
|
|
11
|
+
|
|
12
|
+
// First non disabled element.
|
|
13
|
+
const first = focusableElements[0];
|
|
14
|
+
// Last non disabled element.
|
|
15
|
+
const last = focusableElements[focusableElements.length - 1];
|
|
16
|
+
|
|
17
|
+
if (last && first) {
|
|
18
|
+
return { first, last };
|
|
19
|
+
}
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { getFocusableElements } from './getFocusableElements';
|
|
2
|
+
|
|
3
|
+
function htmlToElement(html: string): any {
|
|
4
|
+
const template = document.createElement('template');
|
|
5
|
+
template.innerHTML = html.trim();
|
|
6
|
+
return template.content.firstChild;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe(getFocusableElements.name, () => {
|
|
10
|
+
it('should get empty', () => {
|
|
11
|
+
const element = htmlToElement('<div></div>');
|
|
12
|
+
const focusable = getFocusableElements(element);
|
|
13
|
+
expect(focusable).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should get single item', () => {
|
|
17
|
+
const element = htmlToElement('<div><button /></div>');
|
|
18
|
+
const focusable = getFocusableElements(element);
|
|
19
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
20
|
+
[
|
|
21
|
+
<button />,
|
|
22
|
+
]
|
|
23
|
+
`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('match focusable elements', () => {
|
|
27
|
+
it('should match input element', () => {
|
|
28
|
+
const element = htmlToElement('<div><input /></div>');
|
|
29
|
+
const focusable = getFocusableElements(element);
|
|
30
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
31
|
+
[
|
|
32
|
+
<input />,
|
|
33
|
+
]
|
|
34
|
+
`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should match link element', () => {
|
|
38
|
+
const element = htmlToElement('<div><a href="#" /></div>');
|
|
39
|
+
const focusable = getFocusableElements(element);
|
|
40
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
41
|
+
[
|
|
42
|
+
<a
|
|
43
|
+
href="#"
|
|
44
|
+
/>,
|
|
45
|
+
]
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should match textarea element', () => {
|
|
50
|
+
const element = htmlToElement('<div><textarea /></div>');
|
|
51
|
+
const focusable = getFocusableElements(element);
|
|
52
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
53
|
+
[
|
|
54
|
+
<textarea>
|
|
55
|
+
</div>
|
|
56
|
+
</textarea>,
|
|
57
|
+
]
|
|
58
|
+
`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should match element with tabindex', () => {
|
|
62
|
+
const element = htmlToElement('<div><span tabindex="0" /></div>');
|
|
63
|
+
const focusable = getFocusableElements(element);
|
|
64
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
65
|
+
[
|
|
66
|
+
<span
|
|
67
|
+
tabindex="0"
|
|
68
|
+
/>,
|
|
69
|
+
]
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should keep disabled=false', () => {
|
|
74
|
+
const element = htmlToElement('<div><button disabled="false" /><button /></div>');
|
|
75
|
+
const focusable = getFocusableElements(element);
|
|
76
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
77
|
+
[
|
|
78
|
+
<button
|
|
79
|
+
disabled="false"
|
|
80
|
+
/>,
|
|
81
|
+
<button />,
|
|
82
|
+
]
|
|
83
|
+
`);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should keep aria-disabled=false', () => {
|
|
87
|
+
const element = htmlToElement('<div><button aria-disabled="false" /><button /></div>');
|
|
88
|
+
const focusable = getFocusableElements(element);
|
|
89
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
90
|
+
[
|
|
91
|
+
<button
|
|
92
|
+
aria-disabled="false"
|
|
93
|
+
/>,
|
|
94
|
+
<button />,
|
|
95
|
+
]
|
|
96
|
+
`);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('skip disabled elements', () => {
|
|
101
|
+
it('should skip disabled', () => {
|
|
102
|
+
const element = htmlToElement('<div><button disabled /><button /></div>');
|
|
103
|
+
const focusable = getFocusableElements(element);
|
|
104
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
105
|
+
[
|
|
106
|
+
<button />,
|
|
107
|
+
]
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should skip aria-disabled', () => {
|
|
112
|
+
const element = htmlToElement('<div><button aria-disabled /><button /></div>');
|
|
113
|
+
const focusable = getFocusableElements(element);
|
|
114
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
115
|
+
[
|
|
116
|
+
<button />,
|
|
117
|
+
]
|
|
118
|
+
`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should skip tabindex=-1', () => {
|
|
122
|
+
const element = htmlToElement('<div><button tabindex="-1" /><button /></div>');
|
|
123
|
+
const focusable = getFocusableElements(element);
|
|
124
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
125
|
+
[
|
|
126
|
+
<button />,
|
|
127
|
+
]
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should skip input type hidden', () => {
|
|
132
|
+
const element = htmlToElement('<div><input type="hidden" /><button /></div>');
|
|
133
|
+
const focusable = getFocusableElements(element);
|
|
134
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
135
|
+
[
|
|
136
|
+
<button />,
|
|
137
|
+
]
|
|
138
|
+
`);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should skip hidden input', () => {
|
|
142
|
+
const element = htmlToElement('<div><input hidden /><button /></div>');
|
|
143
|
+
const focusable = getFocusableElements(element);
|
|
144
|
+
expect(focusable).toMatchInlineSnapshot(`
|
|
145
|
+
[
|
|
146
|
+
<button />,
|
|
147
|
+
]
|
|
148
|
+
`);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DISABLED_SELECTOR, TABBABLE_ELEMENTS_SELECTOR } from './constants';
|
|
2
|
+
|
|
3
|
+
const isNotDisabled = (element: HTMLElement) => !element.matches(DISABLED_SELECTOR);
|
|
4
|
+
|
|
5
|
+
export function getFocusableElements(element: HTMLElement | ShadowRoot): HTMLElement[] {
|
|
6
|
+
return Array.from(element.querySelectorAll<HTMLElement>(TABBABLE_ELEMENTS_SELECTOR)).filter(isNotDisabled);
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Check if the focus is visible on the given element */
|
|
2
|
+
export const isFocusVisible = (element?: HTMLElement) => {
|
|
3
|
+
try {
|
|
4
|
+
return element?.matches?.(':focus-visible, [data-focus-visible-added]');
|
|
5
|
+
} catch (_ignored) {
|
|
6
|
+
// Can fail on non browser env
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isHoverNotSupported } from './isHoverNotSupported';
|
|
2
|
+
|
|
3
|
+
const originalMatchMedia = global.matchMedia;
|
|
4
|
+
|
|
5
|
+
describe('isHoverNotSupported', () => {
|
|
6
|
+
afterAll(() => {
|
|
7
|
+
global.matchMedia = originalMatchMedia;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should return `false` on browsers that do not support matchMedia', () => {
|
|
11
|
+
global.matchMedia = undefined;
|
|
12
|
+
expect(isHoverNotSupported()).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return `false` on browsers that support matchMedia and does support hover', () => {
|
|
16
|
+
global.matchMedia = () => ({ matches: false });
|
|
17
|
+
expect(isHoverNotSupported()).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return `true` on browsers that support matchMedia and does not support hover', () => {
|
|
21
|
+
global.matchMedia = () => ({ matches: true });
|
|
22
|
+
expect(isHoverNotSupported()).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { addMonthResetDay } from '@lumx/react/utils/date/addMonthResetDay';
|
|
2
|
+
|
|
3
|
+
describe(addMonthResetDay.name, () => {
|
|
4
|
+
it('should add month to date', () => {
|
|
5
|
+
const actual = addMonthResetDay(new Date('2017-01-30'), 1);
|
|
6
|
+
expect(actual).toEqual(new Date('2017-02-01'));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should remove months to date', () => {
|
|
10
|
+
const actual = addMonthResetDay(new Date('2017-01-30'), -2);
|
|
11
|
+
expect(actual).toEqual(new Date('2016-11-01'));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add a number of months from a date while resetting the day to prevent month length mismatches.
|
|
3
|
+
*/
|
|
4
|
+
export function addMonthResetDay(date: Date, monthOffset: number) {
|
|
5
|
+
const newDate = new Date(date.getTime());
|
|
6
|
+
newDate.setDate(1);
|
|
7
|
+
newDate.setMonth(date.getMonth() + monthOffset);
|
|
8
|
+
return newDate;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { formatDayNumber } from '@lumx/react/utils/date/formatDayNumber';
|
|
2
|
+
|
|
3
|
+
describe(formatDayNumber, () => {
|
|
4
|
+
it('should format ', () => {
|
|
5
|
+
// Standard numerical formatting.
|
|
6
|
+
expect(formatDayNumber('en', new Date('2024-05-11'))).toEqual('11');
|
|
7
|
+
// Keep only the numerical part (if any). Raw formatted day number here is '11日'.
|
|
8
|
+
expect(formatDayNumber('ja', new Date('2024-05-11'))).toEqual('11');
|
|
9
|
+
// Else Keep the non-numerical formatting
|
|
10
|
+
expect(formatDayNumber('ar-eg', new Date('2024-05-11'))).toEqual('١١');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Locale } from '@lumx/react/utils/locale/types';
|
|
2
|
+
import { parseLocale } from '../locale/parseLocale';
|
|
3
|
+
import { getFirstDayOfWeek } from './getFirstDayOfWeek';
|
|
4
|
+
|
|
5
|
+
describe(getFirstDayOfWeek.name, () => {
|
|
6
|
+
it('should return for a valid locales', () => {
|
|
7
|
+
expect(getFirstDayOfWeek(parseLocale('fa-ir') as Locale)).toBe(6);
|
|
8
|
+
expect(getFirstDayOfWeek(parseLocale('ar-ma') as Locale)).toBe(1);
|
|
9
|
+
expect(getFirstDayOfWeek(parseLocale('ar') as Locale)).toBe(6);
|
|
10
|
+
expect(getFirstDayOfWeek(parseLocale('en') as Locale)).toBe(0);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return for the lang locale if available', () => {
|
|
14
|
+
// Test for a specific locale and its root locale
|
|
15
|
+
const localeWithRoot = parseLocale('es-ES') as Locale; // Spanish (Spain) with root locale es
|
|
16
|
+
const expectedFirstDay = getFirstDayOfWeek(parseLocale('es') as Locale); // First day for root locale 'es'
|
|
17
|
+
|
|
18
|
+
expect(getFirstDayOfWeek(localeWithRoot)).toBe(expectedFirstDay);
|
|
19
|
+
});
|
|
20
|
+
});
|