@sanity/ui 4.0.0-beta.8 → 4.0.0-next.2
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/LICENSE +1 -1
- package/README.md +21 -7
- package/dist/_chunks/getScopedTheme.cjs +4043 -0
- package/dist/_chunks/getScopedTheme.cjs.map +1 -0
- package/dist/_chunks/getScopedTheme.js +3803 -0
- package/dist/_chunks/getScopedTheme.js.map +1 -0
- package/dist/_chunks/refractor.cjs +18 -0
- package/dist/_chunks/refractor.cjs.map +1 -0
- package/dist/_chunks/refractor.js +20 -0
- package/dist/_chunks/refractor.js.map +1 -0
- package/dist/_chunks/rgba.d.cts +929 -0
- package/dist/_chunks/rgba.d.cts.map +1 -0
- package/dist/_chunks/rgba.d.ts +929 -0
- package/dist/_chunks/rgba.d.ts.map +1 -0
- package/dist/index.cjs +6243 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2332 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1767 -1190
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6134 -4725
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs +54 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +278 -0
- package/dist/theme.d.cts.map +1 -0
- package/dist/theme.d.ts +278 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +53 -0
- package/dist/theme.js.map +1 -0
- package/package.json +55 -86
- package/dist/_chunks-es/Syntax.js +0 -23
- package/dist/_chunks-es/Syntax.js.map +0 -1
- package/dist/index.css +0 -1
- package/exports/index.css +0 -1
- package/exports/index.ts +0 -125
- package/src/components/autocomplete/Autocomplete.tsx +0 -665
- package/src/components/autocomplete/AutocompleteOption.tsx +0 -42
- package/src/components/autocomplete/__workshop__/Async.tsx +0 -162
- package/src/components/autocomplete/__workshop__/ConstrainedHeight.tsx +0 -121
- package/src/components/autocomplete/__workshop__/Custom.tsx +0 -91
- package/src/components/autocomplete/__workshop__/Example.tsx +0 -70
- package/src/components/autocomplete/__workshop__/FocusAndBlur.tsx +0 -39
- package/src/components/autocomplete/__workshop__/Fullscreen.tsx +0 -307
- package/src/components/autocomplete/__workshop__/index.ts +0 -41
- package/src/components/autocomplete/__workshop__/mock/apiStore.ts +0 -49
- package/src/components/autocomplete/__workshop__/mock/countries.ts +0 -245
- package/src/components/autocomplete/__workshop__/types.ts +0 -4
- package/src/components/autocomplete/autocompleteReducer.ts +0 -47
- package/src/components/autocomplete/constants.ts +0 -28
- package/src/components/autocomplete/types.ts +0 -103
- package/src/components/breadcrumbs/Breadcrumbs.tsx +0 -163
- package/src/components/breadcrumbs/__workshop__/Example.tsx +0 -48
- package/src/components/breadcrumbs/__workshop__/index.ts +0 -16
- package/src/components/dialog/Dialog.tsx +0 -230
- package/src/components/dialog/DialogCard.tsx +0 -233
- package/src/components/dialog/DialogContext.ts +0 -21
- package/src/components/dialog/DialogProvider.tsx +0 -34
- package/src/components/dialog/__workshop__/Activate.tsx +0 -141
- package/src/components/dialog/__workshop__/AutoFocus.tsx +0 -29
- package/src/components/dialog/__workshop__/Layering.tsx +0 -41
- package/src/components/dialog/__workshop__/Nested.tsx +0 -71
- package/src/components/dialog/__workshop__/OnScroll.tsx +0 -51
- package/src/components/dialog/__workshop__/Panes.tsx +0 -75
- package/src/components/dialog/__workshop__/Position.tsx +0 -30
- package/src/components/dialog/__workshop__/Props.tsx +0 -93
- package/src/components/dialog/__workshop__/Provider.tsx +0 -11
- package/src/components/dialog/__workshop__/Wrapped.tsx +0 -76
- package/src/components/dialog/__workshop__/index.ts +0 -21
- package/src/components/dialog/isTargetWithinScope.ts +0 -14
- package/src/components/dialog/types.ts +0 -2
- package/src/components/dialog/useDialog.ts +0 -11
- package/src/components/hotkeys/Hotkeys.tsx +0 -70
- package/src/components/hotkeys/__workshop__/Plain.tsx +0 -9
- package/src/components/hotkeys/__workshop__/index.ts +0 -16
- package/src/components/menu/Menu.test.tsx +0 -125
- package/src/components/menu/Menu.tsx +0 -174
- package/src/components/menu/MenuButton.tsx +0 -231
- package/src/components/menu/MenuContext.ts +0 -19
- package/src/components/menu/MenuDivider.tsx +0 -32
- package/src/components/menu/MenuGroup.tsx +0 -240
- package/src/components/menu/MenuItem.tsx +0 -153
- package/src/components/menu/__workshop__/AsComponent.tsx +0 -45
- package/src/components/menu/__workshop__/AvatarMenu.tsx +0 -36
- package/src/components/menu/__workshop__/ClosableMenuButton.tsx +0 -47
- package/src/components/menu/__workshop__/ConstrainedInBoundary.tsx +0 -133
- package/src/components/menu/__workshop__/CustomMenuItem.tsx +0 -47
- package/src/components/menu/__workshop__/CustomSelectedState.tsx +0 -35
- package/src/components/menu/__workshop__/DataProps.tsx +0 -27
- package/src/components/menu/__workshop__/DisableFocusOnClose.tsx +0 -40
- package/src/components/menu/__workshop__/Groups.tsx +0 -164
- package/src/components/menu/__workshop__/MenuButton.tsx +0 -79
- package/src/components/menu/__workshop__/MenuGroupRight.tsx +0 -73
- package/src/components/menu/__workshop__/NestedMenu.tsx +0 -22
- package/src/components/menu/__workshop__/OnCloseMenuButton.tsx +0 -50
- package/src/components/menu/__workshop__/SelectedItem.tsx +0 -69
- package/src/components/menu/__workshop__/ShouldFocus.tsx +0 -42
- package/src/components/menu/__workshop__/Tones.tsx +0 -19
- package/src/components/menu/__workshop__/index.ts +0 -91
- package/src/components/menu/helpers.ts +0 -82
- package/src/components/menu/useMenu.ts +0 -21
- package/src/components/menu/useMenuController.ts +0 -245
- package/src/components/tab/Tab.tsx +0 -135
- package/src/components/tab/TabList.tsx +0 -157
- package/src/components/tab/TabListContext.ts +0 -10
- package/src/components/tab/TabPanel.tsx +0 -94
- package/src/components/tab/__workshop__/Example.tsx +0 -135
- package/src/components/tab/__workshop__/index.ts +0 -16
- package/src/components/tab/types.ts +0 -11
- package/src/components/toast/Toast.test.tsx +0 -103
- package/src/components/toast/Toast.tsx +0 -191
- package/src/components/toast/ToastContext.ts +0 -7
- package/src/components/toast/ToastLayer.tsx +0 -54
- package/src/components/toast/ToastProvider.tsx +0 -127
- package/src/components/toast/__workshop__/Hook.tsx +0 -71
- package/src/components/toast/__workshop__/Toast.tsx +0 -26
- package/src/components/toast/__workshop__/index.ts +0 -21
- package/src/components/toast/toastState.ts +0 -6
- package/src/components/toast/types.ts +0 -24
- package/src/components/toast/useToast.ts +0 -23
- package/src/components/tree/Tree.tsx +0 -248
- package/src/components/tree/TreeContext.ts +0 -10
- package/src/components/tree/TreeGroup.tsx +0 -46
- package/src/components/tree/TreeItem.tsx +0 -236
- package/src/components/tree/__workshop__/Basic.tsx +0 -108
- package/src/components/tree/__workshop__/TabFromElement.tsx +0 -84
- package/src/components/tree/__workshop__/basic.perf.ts +0 -19
- package/src/components/tree/__workshop__/index.ts +0 -23
- package/src/components/tree/helpers.ts +0 -105
- package/src/components/tree/types.ts +0 -24
- package/src/components/tree/useTree.ts +0 -17
- package/src/components/virtualList/VirtualList.tsx +0 -254
- package/src/components/virtualList/__workshop__/ChangingProps.tsx +0 -41
- package/src/components/virtualList/__workshop__/ElementScroll.tsx +0 -43
- package/src/components/virtualList/__workshop__/InfiniteList.tsx +0 -40
- package/src/components/virtualList/__workshop__/WindowScrolll.tsx +0 -23
- package/src/components/virtualList/__workshop__/index.ts +0 -31
- package/src/core/_keys.ts +0 -26
- package/src/core/constants.ts +0 -67
- package/src/core/getElementRef.ts +0 -29
- package/src/core/helpers/animation.ts +0 -26
- package/src/core/helpers/element.ts +0 -55
- package/src/core/helpers/focus.ts +0 -92
- package/src/core/helpers/props.ts +0 -51
- package/src/core/helpers/scroll.ts +0 -15
- package/src/core/lib/createGlobalScopedContext.ts +0 -39
- package/src/core/lib/globalScope.ts +0 -19
- package/src/core/lib/isArray.ts +0 -3
- package/src/core/lib/isRecord.ts +0 -3
- package/src/core/types.ts +0 -57
- package/src/hooks/useClickOutsideEvent.test.tsx +0 -114
- package/src/hooks/useClickOutsideEvent.ts +0 -66
- package/src/hooks/useCustomValidity.ts +0 -13
- package/src/hooks/useElementSize.ts +0 -19
- package/src/hooks/useGlobalKeyDown.ts +0 -23
- package/src/hooks/useMatchMedia.ts +0 -28
- package/src/hooks/useMediaIndex/__workshop__/Test.tsx +0 -14
- package/src/hooks/useMediaIndex/__workshop__/index.ts +0 -16
- package/src/hooks/useMediaIndex/useMediaIndex.test.tsx +0 -21
- package/src/hooks/useMediaIndex/useMediaIndex.ts +0 -111
- package/src/hooks/useMounted.ts +0 -15
- package/src/hooks/usePrefersDark.hydration.test.tsx +0 -56
- package/src/hooks/usePrefersDark.test.tsx +0 -20
- package/src/hooks/usePrefersDark.ts +0 -16
- package/src/hooks/usePrefersReducedMotion.hydration.test.tsx +0 -56
- package/src/hooks/usePrefersReducedMotion.test.tsx +0 -20
- package/src/hooks/usePrefersReducedMotion.ts +0 -16
- package/src/hooks/useResponsiveProp.ts +0 -14
- package/src/hooks/useUnique.ts +0 -54
- package/src/middleware/origin.ts +0 -47
- package/src/observers/elementSize.ts +0 -114
- package/src/primitives/_syntax/LazySyntax.tsx +0 -4
- package/src/primitives/_syntax/Syntax.tsx +0 -26
- package/src/primitives/avatar/Avatar.tsx +0 -145
- package/src/primitives/avatar/AvatarCounter.tsx +0 -69
- package/src/primitives/avatar/AvatarStack.tsx +0 -77
- package/src/primitives/avatar/__workshop__/AsButton.tsx +0 -12
- package/src/primitives/avatar/__workshop__/PropsStory.tsx +0 -24
- package/src/primitives/avatar/__workshop__/Stack.tsx +0 -27
- package/src/primitives/avatar/__workshop__/WithinButton.tsx +0 -51
- package/src/primitives/avatar/__workshop__/WithinMenuItem.tsx +0 -52
- package/src/primitives/avatar/__workshop__/index.ts +0 -36
- package/src/primitives/avatar/types.ts +0 -2
- package/src/primitives/badge/Badge.test.tsx +0 -16
- package/src/primitives/badge/Badge.tsx +0 -53
- package/src/primitives/badge/__workshop__/Props.tsx +0 -27
- package/src/primitives/badge/__workshop__/Tones.tsx +0 -15
- package/src/primitives/badge/__workshop__/index.ts +0 -26
- package/src/primitives/badge/__workshop__/within-button.tsx +0 -36
- package/src/primitives/box/Box.tsx +0 -73
- package/src/primitives/box/__workshop__/Props.tsx +0 -26
- package/src/primitives/box/__workshop__/Responsive.tsx +0 -19
- package/src/primitives/box/__workshop__/index.ts +0 -21
- package/src/primitives/button/Button.test.tsx +0 -30
- package/src/primitives/button/Button.tsx +0 -148
- package/src/primitives/button/__workshop__/Custom.tsx +0 -39
- package/src/primitives/button/__workshop__/CustomIcons.tsx +0 -37
- package/src/primitives/button/__workshop__/DataProps.tsx +0 -18
- package/src/primitives/button/__workshop__/Disabled.tsx +0 -43
- package/src/primitives/button/__workshop__/MixedChildren.tsx +0 -12
- package/src/primitives/button/__workshop__/Props.tsx +0 -60
- package/src/primitives/button/__workshop__/Stacked.tsx +0 -60
- package/src/primitives/button/__workshop__/Styled1.css.ts +0 -7
- package/src/primitives/button/__workshop__/Styled1.tsx +0 -11
- package/src/primitives/button/__workshop__/TextOverflow.tsx +0 -17
- package/src/primitives/button/__workshop__/UploadButton.tsx +0 -28
- package/src/primitives/button/__workshop__/index.ts +0 -61
- package/src/primitives/button/types.ts +0 -2
- package/src/primitives/card/Card.tsx +0 -124
- package/src/primitives/card/CardContext.ts +0 -10
- package/src/primitives/card/CardInternalContext.ts +0 -10
- package/src/primitives/card/CardInternalProvider.tsx +0 -15
- package/src/primitives/card/CardProvider.tsx +0 -16
- package/src/primitives/card/__workshop__/AsButton.tsx +0 -103
- package/src/primitives/card/__workshop__/AsComponent.tsx +0 -25
- package/src/primitives/card/__workshop__/Checkered.tsx +0 -25
- package/src/primitives/card/__workshop__/DataProps.tsx +0 -25
- package/src/primitives/card/__workshop__/Interactive.tsx +0 -29
- package/src/primitives/card/__workshop__/ListNavigation.tsx +0 -78
- package/src/primitives/card/__workshop__/Props.tsx +0 -59
- package/src/primitives/card/__workshop__/Selected.tsx +0 -62
- package/src/primitives/card/__workshop__/Styled.tsx +0 -11
- package/src/primitives/card/__workshop__/Tones.tsx +0 -26
- package/src/primitives/card/__workshop__/index.ts +0 -21
- package/src/primitives/card/types.ts +0 -21
- package/src/primitives/card/useCard.ts +0 -20
- package/src/primitives/checkbox/Checkbox.tsx +0 -80
- package/src/primitives/checkbox/__workshop__/Example.tsx +0 -25
- package/src/primitives/checkbox/__workshop__/Props.tsx +0 -35
- package/src/primitives/checkbox/__workshop__/ReadOnly.tsx +0 -16
- package/src/primitives/checkbox/__workshop__/Tones.tsx +0 -26
- package/src/primitives/checkbox/__workshop__/index.ts +0 -15
- package/src/primitives/code/Code.tsx +0 -47
- package/src/primitives/code/__workshop__/OpticalAlignment.tsx +0 -25
- package/src/primitives/code/__workshop__/Props.tsx +0 -20
- package/src/primitives/code/__workshop__/index.ts +0 -21
- package/src/primitives/container/Container.tsx +0 -43
- package/src/primitives/container/__workshop__/Example.tsx +0 -16
- package/src/primitives/container/__workshop__/index.ts +0 -16
- package/src/primitives/container/types.ts +0 -6
- package/src/primitives/flex/Flex.tsx +0 -38
- package/src/primitives/flex/__workshop__/Example.tsx +0 -26
- package/src/primitives/flex/__workshop__/Gap.tsx +0 -25
- package/src/primitives/flex/__workshop__/index.ts +0 -13
- package/src/primitives/flex/__workshop__/styles.css.ts +0 -12
- package/src/primitives/grid/Grid.tsx +0 -38
- package/src/primitives/grid/__workshop__/Responsive.tsx +0 -54
- package/src/primitives/grid/__workshop__/index.ts +0 -12
- package/src/primitives/heading/Heading.tsx +0 -68
- package/src/primitives/heading/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/heading/__workshop__/Plain.tsx +0 -25
- package/src/primitives/heading/__workshop__/index.ts +0 -21
- package/src/primitives/inline/Inline.tsx +0 -37
- package/src/primitives/inline/__workshop__/Plain.tsx +0 -22
- package/src/primitives/inline/__workshop__/index.ts +0 -10
- package/src/primitives/kbd/Kbd.tsx +0 -36
- package/src/primitives/kbd/__workshop__/Plain.tsx +0 -9
- package/src/primitives/kbd/__workshop__/index.ts +0 -10
- package/src/primitives/label/Label.tsx +0 -67
- package/src/primitives/label/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/label/__workshop__/Plain.tsx +0 -27
- package/src/primitives/label/__workshop__/index.ts +0 -21
- package/src/primitives/layer/Layer.test.tsx +0 -110
- package/src/primitives/layer/Layer.tsx +0 -35
- package/src/primitives/layer/LayerCard.tsx +0 -90
- package/src/primitives/layer/LayerContext.ts +0 -7
- package/src/primitives/layer/LayerProvider.tsx +0 -106
- package/src/primitives/layer/__workshop__/MultipleRoots.tsx +0 -49
- package/src/primitives/layer/__workshop__/Nested.tsx +0 -107
- package/src/primitives/layer/__workshop__/ResponsiveZOffset.tsx +0 -17
- package/src/primitives/layer/__workshop__/_debug.tsx +0 -17
- package/src/primitives/layer/__workshop__/index.ts +0 -26
- package/src/primitives/layer/getLayerContext.test.ts +0 -32
- package/src/primitives/layer/getLayerContext.ts +0 -21
- package/src/primitives/layer/types.ts +0 -9
- package/src/primitives/layer/useLayer.ts +0 -24
- package/src/primitives/popover/Popover.tsx +0 -291
- package/src/primitives/popover/PopoverLayer.tsx +0 -101
- package/src/primitives/popover/__workshop__/AlignedStory.tsx +0 -75
- package/src/primitives/popover/__workshop__/MarginsStory.tsx +0 -31
- package/src/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +0 -32
- package/src/primitives/popover/__workshop__/OpenOnMountStory.tsx +0 -11
- package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -67
- package/src/primitives/popover/__workshop__/RecursiveStory.tsx +0 -71
- package/src/primitives/popover/__workshop__/SidePanelStory.tsx +0 -95
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -97
- package/src/primitives/popover/__workshop__/index.ts +0 -56
- package/src/primitives/popover/__workshop__/portal-inheritance.tsx +0 -15
- package/src/primitives/popover/constants.ts +0 -20
- package/src/primitives/popover/floating-ui/size.ts +0 -75
- package/src/primitives/popover/types.ts +0 -12
- package/src/primitives/popover/useMiddleware.ts +0 -126
- package/src/primitives/radio/Radio.tsx +0 -64
- package/src/primitives/radio/__workshop__/Example.tsx +0 -63
- package/src/primitives/radio/__workshop__/Plain.tsx +0 -28
- package/src/primitives/radio/__workshop__/index.ts +0 -13
- package/src/primitives/select/Select.tsx +0 -76
- package/src/primitives/select/__workshop__/Plain.tsx +0 -37
- package/src/primitives/select/__workshop__/ReadOnly.tsx +0 -23
- package/src/primitives/select/__workshop__/index.ts +0 -13
- package/src/primitives/selectable/Selectable.tsx +0 -48
- package/src/primitives/selectable/__workshop__/DataProps.tsx +0 -24
- package/src/primitives/selectable/__workshop__/as-link.tsx +0 -13
- package/src/primitives/selectable/__workshop__/index.ts +0 -19
- package/src/primitives/skeleton/CodeSkeleton.tsx +0 -49
- package/src/primitives/skeleton/HeadingSkeleton.tsx +0 -48
- package/src/primitives/skeleton/LabelSkeleton.tsx +0 -47
- package/src/primitives/skeleton/Skeleton.tsx +0 -70
- package/src/primitives/skeleton/TextSkeleton.tsx +0 -49
- package/src/primitives/skeleton/__workshop__/Delay.tsx +0 -69
- package/src/primitives/skeleton/__workshop__/Skeleton.tsx +0 -63
- package/src/primitives/skeleton/__workshop__/index.ts +0 -13
- package/src/primitives/spinner/Spinner.tsx +0 -45
- package/src/primitives/spinner/SpinnerAnimatedIcon.tsx +0 -14
- package/src/primitives/spinner/__workshop__/Props.tsx +0 -13
- package/src/primitives/spinner/__workshop__/index.ts +0 -16
- package/src/primitives/srOnly/SrOnly.tsx +0 -33
- package/src/primitives/stack/Stack.tsx +0 -38
- package/src/primitives/stack/__workshop__/Plain.tsx +0 -30
- package/src/primitives/stack/__workshop__/index.ts +0 -16
- package/src/primitives/switch/Switch.tsx +0 -76
- package/src/primitives/switch/__workshop__/Example.tsx +0 -25
- package/src/primitives/switch/__workshop__/Props.tsx +0 -23
- package/src/primitives/switch/__workshop__/index.ts +0 -13
- package/src/primitives/text/InlineCode.tsx +0 -25
- package/src/primitives/text/Text.tsx +0 -68
- package/src/primitives/text/__workshop__/Example.tsx +0 -26
- package/src/primitives/text/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/text/__workshop__/index.ts +0 -26
- package/src/primitives/text/__workshop__/inline-code.tsx +0 -13
- package/src/primitives/textArea/TextArea.tsx +0 -97
- package/src/primitives/textArea/__workshop__/Plain.tsx +0 -46
- package/src/primitives/textArea/__workshop__/index.ts +0 -16
- package/src/primitives/textInput/TextInput.tsx +0 -279
- package/src/primitives/textInput/__workshop__/ClearButton.tsx +0 -32
- package/src/primitives/textInput/__workshop__/CustomValidity.tsx +0 -17
- package/src/primitives/textInput/__workshop__/Plain.tsx +0 -102
- package/src/primitives/textInput/__workshop__/ReadOnly.tsx +0 -14
- package/src/primitives/textInput/__workshop__/States.tsx +0 -53
- package/src/primitives/textInput/__workshop__/Tones.tsx +0 -40
- package/src/primitives/textInput/__workshop__/Typed.tsx +0 -23
- package/src/primitives/textInput/__workshop__/index.ts +0 -46
- package/src/primitives/tooltip/Tooltip.test.tsx +0 -496
- package/src/primitives/tooltip/Tooltip.tsx +0 -546
- package/src/primitives/tooltip/TooltipLayer.tsx +0 -72
- package/src/primitives/tooltip/__workshop__/CustomPortal.tsx +0 -102
- package/src/primitives/tooltip/__workshop__/OverflowingBoundary.tsx +0 -74
- package/src/primitives/tooltip/__workshop__/Props.tsx +0 -107
- package/src/primitives/tooltip/__workshop__/ResizableBoundary.tsx +0 -91
- package/src/primitives/tooltip/__workshop__/index.ts +0 -31
- package/src/primitives/tooltip/constants.ts +0 -24
- package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupContext.tsx +0 -13
- package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupProvider.tsx +0 -96
- package/src/primitives/tooltip/tooltipDelayGroup/types.ts +0 -7
- package/src/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +0 -13
- package/src/root/Root.tsx +0 -93
- package/src/root/RootProvider.tsx +0 -37
- package/src/root/__workshop__/Boundary.tsx +0 -43
- package/src/root/__workshop__/index.ts +0 -24
- package/src/root/__workshop__/primitives.tsx +0 -49
- package/src/root/__workshop__/tone-inheritance.tsx +0 -65
- package/src/utils/ErrorBoundary.tsx +0 -50
- package/src/utils/boundaryElement/BoundaryElementContext.ts +0 -7
- package/src/utils/boundaryElement/BoundaryElementProvider.tsx +0 -16
- package/src/utils/boundaryElement/__workshop__/Plain.tsx +0 -49
- package/src/utils/boundaryElement/__workshop__/index.ts +0 -16
- package/src/utils/boundaryElement/types.ts +0 -2
- package/src/utils/boundaryElement/useBoundaryElement.ts +0 -12
- package/src/utils/elementQuery/ElementQuery.tsx +0 -75
- package/src/utils/elementQuery/__workshop__/CustomMedia.tsx +0 -19
- package/src/utils/elementQuery/__workshop__/index.ts +0 -16
- package/src/utils/elementQuery/__workshop__/styles.css.ts +0 -31
- package/src/utils/elementQuery/helpers.ts +0 -27
- package/src/utils/portal/Portal.test.tsx +0 -105
- package/src/utils/portal/Portal.tsx +0 -42
- package/src/utils/portal/PortalContext.ts +0 -37
- package/src/utils/portal/PortalProvider.tsx +0 -38
- package/src/utils/portal/__workshop__/Named.tsx +0 -69
- package/src/utils/portal/__workshop__/index.ts +0 -16
- package/src/utils/portal/types.ts +0 -7
- package/src/utils/portal/usePortal.ts +0 -30
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {use} from 'react'
|
|
2
|
-
|
|
3
|
-
import {isRecord} from '../../core/lib/isRecord'
|
|
4
|
-
import {MenuContext, type MenuContextValue} from './MenuContext'
|
|
5
|
-
|
|
6
|
-
export function useMenu(): MenuContextValue {
|
|
7
|
-
const value = use(MenuContext)
|
|
8
|
-
|
|
9
|
-
if (!value) {
|
|
10
|
-
throw new Error('useMenu(): missing context value')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// NOTE: This check is for future-compatiblity
|
|
14
|
-
// - If the value is not an object, it’s not compatible with the current version
|
|
15
|
-
// - If the value is an object, but doesn’t have `version: 2`, it’s not compatible with the current version
|
|
16
|
-
if (!isRecord(value) || value.version !== 2) {
|
|
17
|
-
throw new Error('useMenu(): the context value is not compatible')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return value
|
|
21
|
-
}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type KeyboardEvent,
|
|
3
|
-
type KeyboardEventHandler,
|
|
4
|
-
type MouseEvent,
|
|
5
|
-
type MutableRefObject,
|
|
6
|
-
useCallback,
|
|
7
|
-
useEffect,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
} from 'react'
|
|
11
|
-
|
|
12
|
-
import {_getFocusableElements, _sortElements} from './helpers'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export interface MenuController {
|
|
18
|
-
activeElement: HTMLElement | null
|
|
19
|
-
activeIndex: number
|
|
20
|
-
handleItemMouseEnter: (event: MouseEvent<HTMLElement>) => void
|
|
21
|
-
handleItemMouseLeave: () => void
|
|
22
|
-
handleKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void
|
|
23
|
-
mount: (element: HTMLElement | null, selected?: boolean) => () => void
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This controller is responsible for controlling UI menu state.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export function useMenuController(props: {
|
|
32
|
-
onKeyDown?: KeyboardEventHandler
|
|
33
|
-
originElement?: HTMLElement | null
|
|
34
|
-
shouldFocus: 'first' | 'last' | null
|
|
35
|
-
rootElementRef: MutableRefObject<HTMLDivElement | null>
|
|
36
|
-
}): MenuController {
|
|
37
|
-
const {onKeyDown, originElement, shouldFocus, rootElementRef} = props
|
|
38
|
-
const elementsRef = useRef<HTMLElement[]>([])
|
|
39
|
-
const [activeIndex, _setActiveIndex] = useState(-1)
|
|
40
|
-
const activeIndexRef = useRef(activeIndex)
|
|
41
|
-
const [activeElement, setActiveElement] = useState<HTMLElement | null>(null)
|
|
42
|
-
|
|
43
|
-
const setActiveIndex = useCallback((nextActiveIndex: number) => {
|
|
44
|
-
_setActiveIndex(nextActiveIndex)
|
|
45
|
-
activeIndexRef.current = nextActiveIndex
|
|
46
|
-
|
|
47
|
-
setActiveElement(elementsRef.current[nextActiveIndex] || null)
|
|
48
|
-
}, [])
|
|
49
|
-
|
|
50
|
-
const mount = useCallback(
|
|
51
|
-
(element: HTMLElement | null, selected?: boolean): (() => void) => {
|
|
52
|
-
if (!element) return () => undefined
|
|
53
|
-
|
|
54
|
-
if (elementsRef.current.indexOf(element) === -1) {
|
|
55
|
-
elementsRef.current.push(element)
|
|
56
|
-
_sortElements(rootElementRef.current, elementsRef.current)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (selected) {
|
|
60
|
-
const selectedIndex = elementsRef.current.indexOf(element)
|
|
61
|
-
|
|
62
|
-
setActiveIndex(selectedIndex)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return () => {
|
|
66
|
-
const idx = elementsRef.current.indexOf(element)
|
|
67
|
-
|
|
68
|
-
if (idx > -1) {
|
|
69
|
-
elementsRef.current.splice(idx, 1)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
[rootElementRef, setActiveIndex],
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
const handleKeyDown = useCallback(
|
|
77
|
-
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
78
|
-
// Move focus to the element that opened the menu before handling the `Tab` press
|
|
79
|
-
if (event.key === 'Tab') {
|
|
80
|
-
if (originElement) {
|
|
81
|
-
originElement.focus()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Move focus to the first focusable menuitem
|
|
88
|
-
if (event.key === 'Home') {
|
|
89
|
-
event.preventDefault()
|
|
90
|
-
event.stopPropagation()
|
|
91
|
-
|
|
92
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
93
|
-
const el = focusableElements[0]
|
|
94
|
-
|
|
95
|
-
if (!el) return
|
|
96
|
-
|
|
97
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
98
|
-
|
|
99
|
-
setActiveIndex(currentIndex)
|
|
100
|
-
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Move focus to the last focusable menuitem
|
|
105
|
-
if (event.key === 'End') {
|
|
106
|
-
event.preventDefault()
|
|
107
|
-
event.stopPropagation()
|
|
108
|
-
|
|
109
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
110
|
-
const el = focusableElements[focusableElements.length - 1]
|
|
111
|
-
|
|
112
|
-
if (!el) return
|
|
113
|
-
|
|
114
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
115
|
-
|
|
116
|
-
setActiveIndex(currentIndex)
|
|
117
|
-
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (event.key === 'ArrowUp') {
|
|
122
|
-
event.preventDefault()
|
|
123
|
-
event.stopPropagation()
|
|
124
|
-
|
|
125
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
126
|
-
const focusableLen = focusableElements.length
|
|
127
|
-
|
|
128
|
-
if (focusableLen === 0) return
|
|
129
|
-
|
|
130
|
-
const focusedElement = elementsRef.current[activeIndexRef.current]
|
|
131
|
-
|
|
132
|
-
let focusedIndex = focusableElements.indexOf(focusedElement)
|
|
133
|
-
|
|
134
|
-
focusedIndex = (focusedIndex - 1 + focusableLen) % focusableLen
|
|
135
|
-
|
|
136
|
-
const el = focusableElements[focusedIndex]
|
|
137
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
138
|
-
|
|
139
|
-
setActiveIndex(currentIndex)
|
|
140
|
-
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (event.key === 'ArrowDown') {
|
|
145
|
-
event.preventDefault()
|
|
146
|
-
event.stopPropagation()
|
|
147
|
-
|
|
148
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
149
|
-
const focusableLen = focusableElements.length
|
|
150
|
-
|
|
151
|
-
if (focusableLen === 0) return
|
|
152
|
-
|
|
153
|
-
const focusedElement = elementsRef.current[activeIndexRef.current]
|
|
154
|
-
|
|
155
|
-
let focusedIndex = focusableElements.indexOf(focusedElement)
|
|
156
|
-
|
|
157
|
-
focusedIndex = (focusedIndex + 1) % focusableLen
|
|
158
|
-
|
|
159
|
-
const el = focusableElements[focusedIndex]
|
|
160
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
161
|
-
|
|
162
|
-
setActiveIndex(currentIndex)
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (onKeyDown) {
|
|
168
|
-
onKeyDown(event)
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
[onKeyDown, originElement, setActiveIndex],
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
const handleItemMouseEnter = useCallback(
|
|
175
|
-
(event: MouseEvent<HTMLElement>) => {
|
|
176
|
-
const element = event.currentTarget
|
|
177
|
-
const currentIndex = elementsRef.current.indexOf(element)
|
|
178
|
-
|
|
179
|
-
setActiveIndex(currentIndex)
|
|
180
|
-
},
|
|
181
|
-
[setActiveIndex],
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
const handleItemMouseLeave = useCallback(() => {
|
|
185
|
-
// Set the active index to -2 to deactivate all menu items
|
|
186
|
-
// when the user moves the mouse away from the menu item.
|
|
187
|
-
// We avoid using -1 because it would focus the first menu item,
|
|
188
|
-
// which would be incorrect when the user hovers over a gap
|
|
189
|
-
// between two menu items or a menu divider.
|
|
190
|
-
setActiveIndex(-2)
|
|
191
|
-
rootElementRef.current?.focus()
|
|
192
|
-
}, [rootElementRef, setActiveIndex])
|
|
193
|
-
|
|
194
|
-
// Set focus on the currently active element
|
|
195
|
-
useEffect(() => {
|
|
196
|
-
if (!rootElementRef.current) return
|
|
197
|
-
|
|
198
|
-
const rafId = requestAnimationFrame(() => {
|
|
199
|
-
let i = activeIndex
|
|
200
|
-
|
|
201
|
-
if (i === -1) {
|
|
202
|
-
if (shouldFocus === 'first') {
|
|
203
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
204
|
-
const el = focusableElements[0]
|
|
205
|
-
|
|
206
|
-
if (el) {
|
|
207
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
208
|
-
|
|
209
|
-
setActiveIndex(currentIndex)
|
|
210
|
-
i = currentIndex
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (shouldFocus === 'last') {
|
|
215
|
-
const focusableElements = _getFocusableElements(elementsRef.current)
|
|
216
|
-
const el = focusableElements[focusableElements.length - 1]
|
|
217
|
-
|
|
218
|
-
if (el) {
|
|
219
|
-
const currentIndex = elementsRef.current.indexOf(el)
|
|
220
|
-
|
|
221
|
-
setActiveIndex(currentIndex)
|
|
222
|
-
i = currentIndex
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const element = elementsRef.current[i] || null
|
|
230
|
-
|
|
231
|
-
element?.focus()
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
return () => cancelAnimationFrame(rafId)
|
|
235
|
-
}, [activeIndex, rootElementRef, setActiveIndex, shouldFocus])
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
activeElement,
|
|
239
|
-
activeIndex,
|
|
240
|
-
handleItemMouseEnter,
|
|
241
|
-
handleItemMouseLeave,
|
|
242
|
-
handleKeyDown,
|
|
243
|
-
mount,
|
|
244
|
-
}
|
|
245
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {use, useCallback, useEffect, useImperativeHandle, useRef} from 'react'
|
|
2
|
-
|
|
3
|
-
import type {ComponentType, Props} from '../../core/types'
|
|
4
|
-
import {Button, type ButtonOwnProps} from '../../primitives/button/Button'
|
|
5
|
-
import {TabContext} from './TabListContext'
|
|
6
|
-
|
|
7
|
-
/** @public */
|
|
8
|
-
export const DEFAULT_TAB_ELEMENT = 'button'
|
|
9
|
-
|
|
10
|
-
/** @public */
|
|
11
|
-
export interface TabOwnProps extends ButtonOwnProps {
|
|
12
|
-
/**
|
|
13
|
-
* The `id` of the corresponding `TabPanel` component.
|
|
14
|
-
*/
|
|
15
|
-
'aria-controls': string
|
|
16
|
-
'id': string
|
|
17
|
-
'focused'?: boolean
|
|
18
|
-
'label'?: React.ReactNode
|
|
19
|
-
'onActivate'?: () => void
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** @public */
|
|
23
|
-
export type TabElementType = 'button' | ComponentType
|
|
24
|
-
|
|
25
|
-
/** @public */
|
|
26
|
-
export type TabProps<E extends TabElementType = TabElementType> = Props<TabOwnProps, E>
|
|
27
|
-
|
|
28
|
-
/** @public */
|
|
29
|
-
export function Tab<E extends TabElementType = typeof DEFAULT_TAB_ELEMENT>(
|
|
30
|
-
props: TabProps<E>,
|
|
31
|
-
): React.JSX.Element {
|
|
32
|
-
const {
|
|
33
|
-
as = DEFAULT_TAB_ELEMENT,
|
|
34
|
-
id,
|
|
35
|
-
fontSize = 1,
|
|
36
|
-
label,
|
|
37
|
-
onActivate,
|
|
38
|
-
onBlur,
|
|
39
|
-
onClick,
|
|
40
|
-
onFocus,
|
|
41
|
-
padding = 2,
|
|
42
|
-
ref: forwardedRef,
|
|
43
|
-
selected: selectedProp,
|
|
44
|
-
...rest
|
|
45
|
-
} = props as TabProps<typeof DEFAULT_TAB_ELEMENT>
|
|
46
|
-
|
|
47
|
-
const {focusTab, focusedId, activateTab, registerTab, activeId} = use(TabContext) ?? {}
|
|
48
|
-
const focused = Boolean(id && focusedId === id)
|
|
49
|
-
const active = Boolean(id && activeId === id)
|
|
50
|
-
const activeRef = useRef(active)
|
|
51
|
-
const selected = selectedProp ?? active
|
|
52
|
-
const ref = useRef<HTMLButtonElement | null>(null)
|
|
53
|
-
const focusedRef = useRef(false)
|
|
54
|
-
|
|
55
|
-
useImperativeHandle<HTMLButtonElement | null, HTMLButtonElement | null>(
|
|
56
|
-
forwardedRef,
|
|
57
|
-
() => ref.current,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
const handleClick = useCallback(
|
|
61
|
-
(event: React.MouseEvent<HTMLButtonElement>) => {
|
|
62
|
-
if (onClick) onClick(event)
|
|
63
|
-
activateTab?.(id)
|
|
64
|
-
},
|
|
65
|
-
[onClick, activateTab, id],
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const handleBlur = useCallback(
|
|
69
|
-
(event: React.FocusEvent<HTMLButtonElement>) => {
|
|
70
|
-
focusedRef.current = false
|
|
71
|
-
if (onBlur) onBlur(event)
|
|
72
|
-
focusTab?.(undefined)
|
|
73
|
-
},
|
|
74
|
-
[onBlur, focusTab],
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const handleFocus = useCallback(
|
|
78
|
-
(event: React.FocusEvent<HTMLButtonElement>) => {
|
|
79
|
-
focusedRef.current = true
|
|
80
|
-
if (onFocus) onFocus(event)
|
|
81
|
-
focusTab?.(id)
|
|
82
|
-
},
|
|
83
|
-
[onFocus, focusTab, id],
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
// register the tab with the list
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
const element = ref.current
|
|
89
|
-
|
|
90
|
-
if (registerTab && element) {
|
|
91
|
-
return registerTab(id, element, selectedProp)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return undefined
|
|
95
|
-
}, [registerTab, id, selected, selectedProp])
|
|
96
|
-
|
|
97
|
-
// focus the tab when using keyboard navigation
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (focused) {
|
|
100
|
-
ref.current?.focus()
|
|
101
|
-
}
|
|
102
|
-
}, [focused])
|
|
103
|
-
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
const wasActive = activeRef.current
|
|
106
|
-
|
|
107
|
-
activeRef.current = active
|
|
108
|
-
|
|
109
|
-
if (!wasActive && active) onActivate?.()
|
|
110
|
-
}, [active, selectedProp, onActivate])
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<Button
|
|
114
|
-
data-ui="Tab"
|
|
115
|
-
{...rest}
|
|
116
|
-
ref={ref}
|
|
117
|
-
aria-selected={selected ? 'true' : 'false'}
|
|
118
|
-
as={as}
|
|
119
|
-
flex="none"
|
|
120
|
-
fontSize={fontSize}
|
|
121
|
-
id={id}
|
|
122
|
-
maxWidth="fill"
|
|
123
|
-
mode="bleed"
|
|
124
|
-
padding={padding}
|
|
125
|
-
role="tab"
|
|
126
|
-
selected={selected}
|
|
127
|
-
tabIndex={selected ? 0 : -1}
|
|
128
|
-
text={label}
|
|
129
|
-
type="button"
|
|
130
|
-
onBlur={handleBlur}
|
|
131
|
-
onClick={handleClick}
|
|
132
|
-
onFocus={handleFocus}
|
|
133
|
-
/>
|
|
134
|
-
)
|
|
135
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import {type KeyboardEvent, useCallback, useEffect, useRef, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import type {ComponentType, Props} from '../../core/types'
|
|
4
|
-
import {Flex, type FlexOwnProps} from '../../primitives/flex/Flex'
|
|
5
|
-
import {TabContext} from './TabListContext'
|
|
6
|
-
import type {TabContextListValue} from './types'
|
|
7
|
-
|
|
8
|
-
/** @public */
|
|
9
|
-
export const DEFAULT_TAB_LIST_ELEMENT = 'div'
|
|
10
|
-
|
|
11
|
-
/** @public */
|
|
12
|
-
export interface TabListOwnProps extends FlexOwnProps {
|
|
13
|
-
autoActivate?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** @public */
|
|
17
|
-
export type TabListElementType = 'div' | 'span' | ComponentType
|
|
18
|
-
|
|
19
|
-
/** @public */
|
|
20
|
-
export type TabListProps<E extends TabListElementType = TabListElementType> = Omit<
|
|
21
|
-
Props<TabListOwnProps, E>,
|
|
22
|
-
'role'
|
|
23
|
-
>
|
|
24
|
-
|
|
25
|
-
/** @public */
|
|
26
|
-
export function TabList<E extends TabListElementType = typeof DEFAULT_TAB_LIST_ELEMENT>(
|
|
27
|
-
props: TabListProps<E>,
|
|
28
|
-
): React.JSX.Element {
|
|
29
|
-
const {
|
|
30
|
-
as = DEFAULT_TAB_LIST_ELEMENT,
|
|
31
|
-
autoActivate = false,
|
|
32
|
-
children,
|
|
33
|
-
gap = 2,
|
|
34
|
-
onKeyDown,
|
|
35
|
-
wrap = 'wrap',
|
|
36
|
-
...rest
|
|
37
|
-
} = props as TabListProps<typeof DEFAULT_TAB_LIST_ELEMENT>
|
|
38
|
-
|
|
39
|
-
const [focusedId, setFocusedId] = useState<string | undefined>(undefined)
|
|
40
|
-
const [activeId, setActiveId] = useState<string | undefined>(undefined)
|
|
41
|
-
const [tabs, setTabs] = useState<{id: string; element: HTMLElement}[]>(() => [])
|
|
42
|
-
|
|
43
|
-
const tabsRef = useRef(tabs)
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
tabsRef.current = tabs
|
|
47
|
-
}, [tabs])
|
|
48
|
-
|
|
49
|
-
const handleKeyDown = useCallback(
|
|
50
|
-
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
51
|
-
onKeyDown?.(event)
|
|
52
|
-
|
|
53
|
-
if (event.key === 'ArrowLeft') {
|
|
54
|
-
setFocusedId((prevId) => {
|
|
55
|
-
const numTabs = tabsRef.current.length
|
|
56
|
-
const prevIndex = prevId ? tabsRef.current.findIndex((tab) => tab.id === prevId) : -1
|
|
57
|
-
const nextIndex = (prevIndex + numTabs - 1) % numTabs
|
|
58
|
-
const nextId = tabsRef.current[nextIndex]?.id
|
|
59
|
-
|
|
60
|
-
if (autoActivate) setActiveId(nextId)
|
|
61
|
-
|
|
62
|
-
return nextId
|
|
63
|
-
})
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (event.key === 'ArrowRight') {
|
|
68
|
-
setFocusedId((prevId) => {
|
|
69
|
-
const numTabs = tabsRef.current.length
|
|
70
|
-
const prevIndex = prevId ? tabsRef.current.findIndex((tab) => tab.id === prevId) : -1
|
|
71
|
-
const nextIndex = (prevIndex + 1) % numTabs
|
|
72
|
-
|
|
73
|
-
const nextId = tabsRef.current[nextIndex]?.id
|
|
74
|
-
|
|
75
|
-
if (autoActivate) setActiveId(nextId)
|
|
76
|
-
|
|
77
|
-
return nextId
|
|
78
|
-
})
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Home (Optional): Moves focus to the first tab.
|
|
83
|
-
if (event.key === 'Home') {
|
|
84
|
-
const nextId = tabsRef.current[0]?.id
|
|
85
|
-
if (autoActivate) setActiveId(nextId)
|
|
86
|
-
setFocusedId(nextId)
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// End (Optional): Moves focus to the last tab.
|
|
91
|
-
if (event.key === 'End') {
|
|
92
|
-
const nextId = tabsRef.current[tabsRef.current.length - 1]?.id
|
|
93
|
-
if (autoActivate) setActiveId(nextId)
|
|
94
|
-
setFocusedId(nextId)
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
[autoActivate, onKeyDown],
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
const context: TabContextListValue = {
|
|
102
|
-
version: 0.0,
|
|
103
|
-
focusedId,
|
|
104
|
-
activeId: activeId,
|
|
105
|
-
registerTab: (id, element, selectedProp) => {
|
|
106
|
-
setTabs((prevTabs) => {
|
|
107
|
-
const newTabs = [...prevTabs]
|
|
108
|
-
newTabs.push({id, element})
|
|
109
|
-
newTabs.sort((a, b) => {
|
|
110
|
-
// sort by position in DOM
|
|
111
|
-
return a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
112
|
-
? -1
|
|
113
|
-
: 1
|
|
114
|
-
})
|
|
115
|
-
return newTabs
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
if (selectedProp) {
|
|
119
|
-
setActiveId(id)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return () => {
|
|
123
|
-
setTabs((prevTabs) => {
|
|
124
|
-
const newTabs = [...prevTabs]
|
|
125
|
-
|
|
126
|
-
newTabs.splice(
|
|
127
|
-
newTabs.findIndex((tab) => tab.id === id),
|
|
128
|
-
1,
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
return newTabs
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
focusTab: (id) => {
|
|
136
|
-
setFocusedId(id)
|
|
137
|
-
if (autoActivate) setActiveId(id)
|
|
138
|
-
},
|
|
139
|
-
activateTab: setActiveId,
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<TabContext.Provider value={context}>
|
|
144
|
-
<Flex
|
|
145
|
-
data-ui="TabList"
|
|
146
|
-
{...rest}
|
|
147
|
-
as={as}
|
|
148
|
-
gap={gap}
|
|
149
|
-
role="tablist"
|
|
150
|
-
wrap={wrap}
|
|
151
|
-
onKeyDown={handleKeyDown}
|
|
152
|
-
>
|
|
153
|
-
{children}
|
|
154
|
-
</Flex>
|
|
155
|
-
</TabContext.Provider>
|
|
156
|
-
)
|
|
157
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type {Context} from 'react'
|
|
2
|
-
|
|
3
|
-
import {createGlobalScopedContext} from '../../core/lib/createGlobalScopedContext'
|
|
4
|
-
import type {TabContextListValue} from './types'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const TabContext: Context<TabContextListValue | null> =
|
|
10
|
-
createGlobalScopedContext<TabContextListValue | null>('@sanity/ui/v4/tree', null)
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {tab_panel} from '@sanity/ui-css'
|
|
2
|
-
import {useEffect, useImperativeHandle, useRef, useState} from 'react'
|
|
3
|
-
|
|
4
|
-
import {isFocusable} from '../../core/helpers/focus'
|
|
5
|
-
import type {ComponentType, Props} from '../../core/types'
|
|
6
|
-
import {Box, type BoxOwnProps} from '../../primitives/box/Box'
|
|
7
|
-
|
|
8
|
-
/** @public */
|
|
9
|
-
export const DEFAULT_TAB_PANEL_ELEMENT = 'div'
|
|
10
|
-
|
|
11
|
-
/** @public */
|
|
12
|
-
export type TabPanelOwnProps = BoxOwnProps & {
|
|
13
|
-
/**
|
|
14
|
-
* The `id` of the corresponding `Tab` component.
|
|
15
|
-
*/
|
|
16
|
-
'aria-labelledby': string
|
|
17
|
-
'id': string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** @public */
|
|
21
|
-
export type TabPanelElementType = 'div' | 'span' | ComponentType
|
|
22
|
-
|
|
23
|
-
/** @public */
|
|
24
|
-
export type TabPanelProps<E extends TabPanelElementType = TabPanelElementType> = Props<
|
|
25
|
-
TabPanelOwnProps,
|
|
26
|
-
E
|
|
27
|
-
>
|
|
28
|
-
|
|
29
|
-
/** @public */
|
|
30
|
-
export function TabPanel<E extends TabPanelElementType = typeof DEFAULT_TAB_PANEL_ELEMENT>(
|
|
31
|
-
props: TabPanelProps<E>,
|
|
32
|
-
): React.JSX.Element {
|
|
33
|
-
const {
|
|
34
|
-
as = DEFAULT_TAB_PANEL_ELEMENT,
|
|
35
|
-
children,
|
|
36
|
-
className,
|
|
37
|
-
ref: forwardedRef,
|
|
38
|
-
...rest
|
|
39
|
-
} = props as TabPanelProps<typeof DEFAULT_TAB_PANEL_ELEMENT>
|
|
40
|
-
|
|
41
|
-
const ref = useRef<HTMLDivElement | null>(null)
|
|
42
|
-
|
|
43
|
-
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
44
|
-
|
|
45
|
-
const [hasFocusableChildren, setHasFocusableChildren] = useState(false)
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
const el = ref.current
|
|
49
|
-
|
|
50
|
-
if (!el) return undefined
|
|
51
|
-
|
|
52
|
-
const mo = new MutationObserver(() => {
|
|
53
|
-
setHasFocusableChildren(_hasFocusableChildren(el))
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
mo.observe(el, {
|
|
57
|
-
childList: true,
|
|
58
|
-
subtree: true,
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
return () => {
|
|
62
|
-
mo.disconnect()
|
|
63
|
-
}
|
|
64
|
-
}, [])
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<Box
|
|
68
|
-
data-ui="TabPanel"
|
|
69
|
-
{...rest}
|
|
70
|
-
ref={ref}
|
|
71
|
-
as={as}
|
|
72
|
-
className={tab_panel({className})}
|
|
73
|
-
role="tabpanel"
|
|
74
|
-
tabIndex={hasFocusableChildren ? undefined : 0}
|
|
75
|
-
>
|
|
76
|
-
{children}
|
|
77
|
-
</Box>
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// check if children has focusable elements
|
|
82
|
-
function _hasFocusableChildren(element: HTMLElement) {
|
|
83
|
-
for (let i = 0; i < element.childNodes.length; i++) {
|
|
84
|
-
const child = element.childNodes[i]
|
|
85
|
-
|
|
86
|
-
if (child instanceof HTMLElement) {
|
|
87
|
-
if (isFocusable(child) || _hasFocusableChildren(child)) {
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return false
|
|
94
|
-
}
|