@sanity/ui 3.0.0-static.33 → 3.0.0-static.34
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/README.md +1 -1
- package/dist/_chunks-cjs/_visual-editing.cjs +263 -375
- package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
- package/dist/_chunks-cjs/refractor.cjs.map +1 -1
- package/dist/_chunks-es/_visual-editing.js +263 -377
- package/dist/_chunks-es/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/refractor.js.map +1 -1
- package/dist/_visual-editing.cjs +0 -2
- package/dist/_visual-editing.cjs.map +1 -1
- package/dist/_visual-editing.d.cts +2 -904
- package/dist/_visual-editing.d.ts +2 -904
- package/dist/_visual-editing.js +2 -4
- package/dist/css/index.cjs +12 -12
- package/dist/css/index.cjs.map +1 -1
- package/dist/css/index.css +1 -1
- package/dist/css/index.d.cts +805 -14697
- package/dist/css/index.d.ts +805 -14697
- package/dist/css/index.js +12 -12
- package/dist/css/index.js.map +1 -1
- package/dist/index.cjs +241 -366
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +990 -3095
- package/dist/index.d.ts +990 -3095
- package/dist/index.js +243 -360
- package/dist/index.js.map +1 -1
- package/dist/portalProvider-DgNIVviV.d.ts +575 -0
- package/dist/theme.cjs +367 -4288
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.d.cts +272 -1806
- package/dist/theme.d.ts +272 -1806
- package/dist/theme.js +371 -4292
- package/dist/theme.js.map +1 -1
- package/exports/_visual-editing.ts +0 -2
- package/package.json +3 -4
- package/src/core/Root.tsx +4 -2
- package/src/core/RootProvider.tsx +4 -4
- package/src/core/__workshop__/boundary.tsx +1 -1
- package/src/core/__workshop__/index.ts +5 -3
- package/src/core/components/autocomplete/__workshop__/async.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/custom.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/example.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/focusAndBlur.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/fullscreen.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/index.ts +5 -3
- package/src/core/components/autocomplete/__workshop__/mock/apiStore.ts +1 -1
- package/src/core/components/autocomplete/__workshop__/mock/countries.ts +1 -1
- package/src/core/components/autocomplete/autocomplete.tsx +2 -2
- package/src/core/components/autocomplete/autocompleteOption.tsx +2 -2
- package/src/core/components/autocomplete/constants.ts +2 -2
- package/src/core/components/breadcrumbs/__workshop__/example.tsx +1 -1
- package/src/core/components/breadcrumbs/__workshop__/index.ts +5 -3
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +6 -11
- package/src/core/components/dialog/__workshop__/activate.tsx +1 -1
- package/src/core/components/dialog/__workshop__/autoFocus.tsx +1 -1
- package/src/core/components/dialog/__workshop__/index.ts +5 -3
- package/src/core/components/dialog/__workshop__/layering.tsx +1 -1
- package/src/core/components/dialog/__workshop__/nested.tsx +2 -3
- package/src/core/components/dialog/__workshop__/onScroll.tsx +1 -1
- package/src/core/components/dialog/__workshop__/panes.tsx +1 -1
- package/src/core/components/dialog/__workshop__/position.tsx +1 -1
- package/src/core/components/dialog/__workshop__/props.tsx +1 -1
- package/src/core/components/dialog/__workshop__/provider.tsx +1 -1
- package/src/core/components/dialog/__workshop__/wrapped.tsx +1 -1
- package/src/core/components/dialog/dialog.tsx +5 -6
- package/src/core/components/dialog/dialogCard.tsx +2 -2
- package/src/core/components/dialog/dialogContext.ts +3 -4
- package/src/core/components/dialog/dialogProvider.tsx +2 -2
- package/src/core/components/hotkeys/__workshop__/index.ts +5 -3
- package/src/core/components/hotkeys/__workshop__/plain.tsx +1 -1
- package/src/core/components/hotkeys/hotkeys.tsx +4 -15
- package/src/core/components/menu/__workshop__/asComponent.tsx +1 -1
- package/src/core/components/menu/__workshop__/avatarMenu.tsx +1 -1
- package/src/core/components/menu/__workshop__/closableMenuButton.tsx +1 -1
- package/src/core/components/menu/__workshop__/constrainedInBoundary.tsx +3 -3
- package/src/core/components/menu/__workshop__/customMenuItem.tsx +1 -1
- package/src/core/components/menu/__workshop__/customSelectedState.tsx +1 -1
- package/src/core/components/menu/__workshop__/disableFocusOnClose.tsx +1 -1
- package/src/core/components/menu/__workshop__/groups.tsx +1 -1
- package/src/core/components/menu/__workshop__/index.ts +5 -3
- package/src/core/components/menu/__workshop__/menuButton.tsx +2 -2
- package/src/core/components/menu/__workshop__/menuGroupRight.tsx +1 -1
- package/src/core/components/menu/__workshop__/nestedMenu.tsx +1 -1
- package/src/core/components/menu/__workshop__/onCloseMenuButton.tsx +1 -1
- package/src/core/components/menu/__workshop__/selectedItem.tsx +1 -1
- package/src/core/components/menu/__workshop__/shouldFocus.tsx +1 -1
- package/src/core/components/menu/__workshop__/tones.tsx +3 -3
- package/src/core/components/menu/__workshop__/withoutArrow.tsx +1 -1
- package/src/core/components/menu/menu.test.tsx +2 -1
- package/src/core/components/menu/menu.tsx +7 -22
- package/src/core/components/menu/menuButton.tsx +4 -50
- package/src/core/components/menu/menuContext.ts +3 -15
- package/src/core/components/menu/menuDivider.tsx +2 -2
- package/src/core/components/menu/menuGroup.tsx +10 -15
- package/src/core/components/menu/menuItem.tsx +7 -18
- package/src/core/components/tab/__workshop__/example.tsx +1 -1
- package/src/core/components/tab/__workshop__/index.ts +5 -3
- package/src/core/components/tab/tab.tsx +6 -4
- package/src/core/components/tab/tabList.tsx +3 -8
- package/src/core/components/tab/tabPanel.tsx +2 -2
- package/src/core/components/toast/__workshop__/hook.tsx +1 -1
- package/src/core/components/toast/__workshop__/index.ts +5 -3
- package/src/core/components/toast/__workshop__/toast.tsx +1 -1
- package/src/core/components/toast/toast.test.tsx +2 -1
- package/src/core/components/toast/toast.tsx +2 -2
- package/src/core/components/toast/toastContext.ts +4 -4
- package/src/core/components/toast/toastLayer.tsx +3 -3
- package/src/core/components/tree/__workshop__/basic.perf.ts +1 -1
- package/src/core/components/tree/__workshop__/basic.tsx +1 -1
- package/src/core/components/tree/__workshop__/index.ts +5 -3
- package/src/core/components/tree/__workshop__/tabFromElement.tsx +1 -1
- package/src/core/components/tree/tree.tsx +8 -9
- package/src/core/components/tree/treeContext.ts +4 -4
- package/src/core/components/tree/treeGroup.tsx +6 -8
- package/src/core/components/tree/treeItem.tsx +4 -4
- package/src/core/components/tree/types.ts +1 -1
- package/src/core/components/virtualList/__workshop__/changingProps.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/elementScroll.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/index.ts +5 -3
- package/src/core/components/virtualList/__workshop__/infiniteList.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/windowScrolll.tsx +1 -1
- package/src/core/components/virtualList/virtualList.tsx +2 -2
- package/src/core/constants.ts +0 -18
- package/src/core/hooks/useMediaIndex/__workshop__/index.ts +5 -3
- package/src/core/hooks/useMediaIndex/__workshop__/test.tsx +1 -1
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +6 -1
- package/src/core/index.ts +1 -24
- package/src/core/lib/createGlobalScopedContext.ts +1 -1
- package/src/core/lib/globalScope.ts +1 -1
- package/src/core/observers/elementSize.ts +1 -1
- package/src/core/primitives/arrow/arrow.tsx +2 -2
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/index.ts +5 -3
- package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/withinButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/withinMenuItem.tsx +1 -1
- package/src/core/primitives/avatar/avatar.tsx +3 -10
- package/src/core/primitives/avatar/avatarCounter.tsx +2 -2
- package/src/core/primitives/avatar/avatarStack.tsx +2 -4
- package/src/core/primitives/avatar/types.ts +0 -32
- package/src/core/primitives/badge/__workshop__/index.ts +5 -3
- package/src/core/primitives/badge/__workshop__/props.tsx +1 -1
- package/src/core/primitives/badge/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/badge/badge.test.tsx +2 -1
- package/src/core/primitives/badge/badge.tsx +12 -11
- package/src/core/primitives/box/__workshop__/index.ts +5 -3
- package/src/core/primitives/box/__workshop__/props.tsx +1 -1
- package/src/core/primitives/box/__workshop__/responsive.tsx +1 -1
- package/src/core/primitives/box/box.tsx +28 -32
- package/src/core/primitives/button/__workshop__/custom.tsx +5 -5
- package/src/core/primitives/button/__workshop__/customIcons.tsx +1 -1
- package/src/core/primitives/button/__workshop__/disabled.tsx +3 -3
- package/src/core/primitives/button/__workshop__/index.ts +5 -3
- package/src/core/primitives/button/__workshop__/mixedChildren.tsx +1 -1
- package/src/core/primitives/button/__workshop__/props.tsx +1 -1
- package/src/core/primitives/button/__workshop__/sanityUploadButton.tsx +1 -1
- package/src/core/primitives/button/__workshop__/stacked.tsx +1 -1
- package/src/core/primitives/button/__workshop__/styled1.tsx +1 -1
- package/src/core/primitives/button/__workshop__/styled2.tsx +1 -1
- package/src/core/primitives/button/__workshop__/textOverflow.tsx +1 -1
- package/src/core/primitives/button/__workshop__/uploadButton.tsx +1 -1
- package/src/core/primitives/button/button.test.tsx +2 -1
- package/src/core/primitives/button/button.tsx +4 -7
- package/src/core/primitives/button/types.ts +0 -20
- package/src/core/primitives/card/__workshop__/asButton.tsx +2 -2
- package/src/core/primitives/card/__workshop__/asComponent.tsx +1 -1
- package/src/core/primitives/card/__workshop__/checkered.tsx +3 -3
- package/src/core/primitives/card/__workshop__/index.ts +5 -3
- package/src/core/primitives/card/__workshop__/interactive.tsx +1 -1
- package/src/core/primitives/card/__workshop__/listNavigation.tsx +1 -1
- package/src/core/primitives/card/__workshop__/props.tsx +1 -1
- package/src/core/primitives/card/__workshop__/selected.tsx +1 -1
- package/src/core/primitives/card/__workshop__/styled.tsx +1 -1
- package/src/core/primitives/card/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/card/card.tsx +4 -2
- package/src/core/primitives/card/cardContext.ts +1 -1
- package/src/core/primitives/card/cardProvider.tsx +4 -4
- package/src/core/primitives/card/types.ts +5 -19
- package/src/core/primitives/checkbox/__workshop__/example.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/index.ts +5 -3
- package/src/core/primitives/checkbox/__workshop__/props.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/checkbox/checkbox.tsx +2 -2
- package/src/core/primitives/code/__workshop__/index.ts +5 -3
- package/src/core/primitives/code/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/code/__workshop__/props.tsx +1 -1
- package/src/core/primitives/code/code.tsx +4 -2
- package/src/core/primitives/code/refractor.tsx +1 -1
- package/src/core/primitives/container/__workshop__/example.tsx +1 -1
- package/src/core/primitives/container/__workshop__/index.ts +5 -3
- package/src/core/primitives/container/container.tsx +2 -2
- package/src/core/primitives/flex/__workshop__/example.tsx +1 -1
- package/src/core/primitives/flex/__workshop__/gap.tsx +1 -1
- package/src/core/primitives/flex/__workshop__/index.ts +5 -3
- package/src/core/primitives/flex/flex.tsx +4 -2
- package/src/core/primitives/grid/__workshop__/index.ts +5 -3
- package/src/core/primitives/grid/__workshop__/responsive.tsx +3 -3
- package/src/core/primitives/grid/grid.tsx +4 -2
- package/src/core/primitives/heading/__workshop__/index.ts +5 -3
- package/src/core/primitives/heading/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/heading/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/heading/heading.tsx +2 -4
- package/src/core/primitives/inline/__workshop__/index.ts +5 -3
- package/src/core/primitives/inline/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/inline/inline.tsx +4 -11
- package/src/core/primitives/kbd/__workshop__/index.ts +5 -3
- package/src/core/primitives/kbd/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/kbd/kbd.tsx +4 -2
- package/src/core/primitives/label/__workshop__/index.ts +5 -3
- package/src/core/primitives/label/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/label/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/label/label.tsx +2 -4
- package/src/core/primitives/layer/__workshop__/_debug.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/index.ts +5 -3
- package/src/core/primitives/layer/__workshop__/multipleRoots.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/nested.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/responsiveZOffset.tsx +1 -1
- package/src/core/primitives/layer/layer.test.tsx +2 -1
- package/src/core/primitives/layer/layer.tsx +2 -2
- package/src/core/primitives/layer/layerCard.tsx +2 -2
- package/src/core/primitives/layer/layerContext.ts +4 -4
- package/src/core/primitives/layer/layerProvider.tsx +2 -10
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +2 -2
- package/src/core/primitives/popover/__workshop__/MarginsStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/OpenOnMountStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/PlainStory.tsx +2 -2
- package/src/core/primitives/popover/__workshop__/RecursiveStory.tsx +3 -3
- package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +3 -3
- package/src/core/primitives/popover/__workshop__/index.ts +5 -3
- package/src/core/primitives/popover/popover.tsx +4 -9
- package/src/core/primitives/popover/popoverLayer.tsx +2 -2
- package/src/core/primitives/radio/__workshop__/example.tsx +1 -1
- package/src/core/primitives/radio/__workshop__/index.ts +5 -3
- package/src/core/primitives/radio/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/radio/radio.tsx +2 -2
- package/src/core/primitives/select/__workshop__/index.ts +5 -3
- package/src/core/primitives/select/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/select/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/select/select.tsx +5 -15
- package/src/core/primitives/selectable/selectable.tsx +4 -4
- package/src/core/primitives/skeleton/__workshop__/delay.tsx +1 -1
- package/src/core/primitives/skeleton/__workshop__/index.ts +5 -3
- package/src/core/primitives/skeleton/__workshop__/skeleton.tsx +2 -2
- package/src/core/primitives/skeleton/codeSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/headingSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/labelSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/skeleton.tsx +2 -2
- package/src/core/primitives/skeleton/textSkeleton.tsx +2 -2
- package/src/core/primitives/spinner/__workshop__/Props.tsx +1 -1
- package/src/core/primitives/spinner/__workshop__/index.ts +5 -3
- package/src/core/primitives/spinner/animatedSpinnerIcon.tsx +2 -2
- package/src/core/primitives/spinner/spinner.tsx +2 -2
- package/src/core/primitives/srOnly/srOnly.tsx +2 -2
- package/src/core/primitives/stack/__workshop__/index.ts +5 -3
- package/src/core/primitives/stack/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/stack/stack.tsx +5 -10
- package/src/core/primitives/switch/__workshop__/example.tsx +1 -1
- package/src/core/primitives/switch/__workshop__/index.ts +5 -3
- package/src/core/primitives/switch/__workshop__/props.tsx +1 -1
- package/src/core/primitives/switch/switch.tsx +2 -2
- package/src/core/primitives/text/__workshop__/colored.tsx +1 -1
- package/src/core/primitives/text/__workshop__/example.tsx +1 -1
- package/src/core/primitives/text/__workshop__/index.ts +5 -3
- package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/text/text.tsx +4 -4
- package/src/core/primitives/textArea/__workshop__/index.ts +5 -3
- package/src/core/primitives/textArea/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textArea/textArea.tsx +5 -15
- package/src/core/primitives/textInput/__workshop__/clearButton.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/customValidity.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/index.ts +5 -3
- package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/states.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/tones.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/typed.tsx +1 -1
- package/src/core/primitives/textInput/textInput.tsx +6 -9
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/index.ts +5 -3
- package/src/core/primitives/tooltip/__workshop__/overflowingBoundary.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/props.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/resizableBoundary.tsx +1 -1
- package/src/core/primitives/tooltip/constants.ts +1 -1
- package/src/core/primitives/tooltip/tooltip.test.tsx +2 -4
- package/src/core/primitives/tooltip/tooltip.tsx +5 -9
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +4 -2
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +5 -3
- package/src/core/primitives/tooltip/tooltipLayer.tsx +2 -2
- package/src/core/{types/props.ts → types.ts} +27 -0
- package/src/core/utils/boundaryElement/__workshop__/index.ts +5 -3
- package/src/core/utils/boundaryElement/__workshop__/plain.tsx +1 -1
- package/src/core/utils/boundaryElement/boundaryElement.test.tsx +2 -1
- package/src/core/utils/boundaryElement/boundaryElementContext.ts +7 -4
- package/src/core/utils/boundaryElement/boundaryElementProvider.tsx +2 -2
- package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +1 -1
- package/src/core/utils/elementQuery/__workshop__/index.ts +5 -3
- package/src/core/utils/elementQuery/elementQuery.tsx +2 -2
- package/src/core/utils/getElementRef.ts +1 -1
- package/src/core/utils/portal/__workshop__/index.ts +5 -3
- package/src/core/utils/portal/__workshop__/named.tsx +1 -1
- package/src/core/utils/portal/portal.test.tsx +2 -1
- package/src/core/utils/portal/portalContext.ts +5 -2
- package/src/core/utils/portal/portalProvider.tsx +5 -9
- package/src/css/_responsiveClassName.ts +2 -2
- package/src/css/_style.css.ts +1 -1
- package/src/css/components/breadcrumbs/breadcrumbs.css.ts +1 -1
- package/src/css/components/dialog/dialog.css.ts +9 -17
- package/src/css/components/menu/menu.css.ts +2 -2
- package/src/css/components/menu/menu.ts +2 -2
- package/src/css/components/skeleton/skeleton.css.ts +2 -6
- package/src/css/components/toast/toast.css.ts +2 -2
- package/src/css/components/toast/toast.ts +2 -2
- package/src/css/components/tree/tree.css.ts +1 -1
- package/src/css/components/tree/tree.ts +1 -1
- package/src/css/defaultTheme.css.ts +59 -60
- package/src/css/layers.css.ts +4 -1
- package/src/css/primitives/_arrow/_arrow.css.ts +5 -5
- package/src/css/primitives/_input/_input.css.ts +4 -4
- package/src/css/primitives/_selectable/_selectable.css.ts +4 -4
- package/src/css/primitives/_selectable/types.ts +2 -2
- package/src/css/primitives/avatar/avatar.css.ts +10 -10
- package/src/css/primitives/badge/badge.css.ts +4 -4
- package/src/css/primitives/badge/types.ts +8 -2
- package/src/css/primitives/box/box.css.ts +2 -2
- package/src/css/primitives/button/button.css.ts +6 -6
- package/src/css/primitives/button/button.ts +2 -2
- package/src/css/primitives/button/types.ts +3 -3
- package/src/css/primitives/card/__workshop__/color.tsx +9 -9
- package/src/css/primitives/card/__workshop__/index.ts +5 -3
- package/src/css/primitives/card/card.css.ts +12 -18
- package/src/css/primitives/card/types.ts +3 -3
- package/src/css/primitives/checkbox/checkbox.css.ts +3 -3
- package/src/css/primitives/checkbox/checkbox.ts +3 -3
- package/src/css/primitives/code/code.css.ts +4 -3
- package/src/css/primitives/code/types.ts +3 -4
- package/src/css/primitives/container/container.css.ts +1 -1
- package/src/css/primitives/heading/heading.css.ts +5 -4
- package/src/css/primitives/heading/types.ts +3 -6
- package/src/css/primitives/kbd/kbd.css.ts +1 -1
- package/src/css/primitives/label/label.css.ts +5 -4
- package/src/css/primitives/label/types.ts +0 -8
- package/src/css/primitives/popover/popover.css.ts +2 -2
- package/src/css/primitives/popover/popover.ts +2 -2
- package/src/css/primitives/radio/radio.css.ts +3 -3
- package/src/css/primitives/radio/radio.ts +3 -3
- package/src/css/primitives/root/root.css.ts +1 -1
- package/src/css/primitives/root/root.ts +1 -1
- package/src/css/primitives/root/types.ts +3 -3
- package/src/css/primitives/select/select.css.ts +3 -3
- package/src/css/primitives/spinner/spinner.css.ts +2 -6
- package/src/css/primitives/spinner/spinner.ts +2 -2
- package/src/css/primitives/srOnly/srOnly.css.ts +1 -1
- package/src/css/primitives/srOnly/srOnly.ts +1 -1
- package/src/css/primitives/stack/stack.css.ts +1 -1
- package/src/css/primitives/stack/stack.ts +1 -1
- package/src/css/primitives/switch/switch.css.ts +5 -5
- package/src/css/primitives/text/text.css.ts +5 -4
- package/src/css/primitives/text/types.ts +3 -5
- package/src/css/primitives/textArea/textArea.css.ts +1 -1
- package/src/css/primitives/textInput/textInput.css.ts +4 -4
- package/src/css/primitives/tooltip/tooltip.css.ts +1 -1
- package/src/css/props/alignItems/alignItems.ts +1 -1
- package/src/css/props/border/border.ts +1 -16
- package/src/css/props/boxSizing/boxSizing.css.ts +2 -1
- package/src/css/props/boxSizing/boxSizing.ts +0 -3
- package/src/css/props/display/display.ts +1 -10
- package/src/css/props/flex/flex.ts +1 -1
- package/src/css/props/flexDirection/flexDirection.ts +1 -1
- package/src/css/props/flexWrap/flexWrap.ts +1 -1
- package/src/css/props/font/font.css.ts +3 -2
- package/src/css/props/font/font.ts +1 -1
- package/src/css/props/gap/gap.ts +1 -1
- package/src/css/props/gridAutoColumns/gridAutoColumns.css.ts +2 -2
- package/src/css/props/gridAutoColumns/gridAutoColumns.ts +2 -2
- package/src/css/props/gridAutoColumns/types.ts +0 -10
- package/src/css/props/gridAutoFlow/gridAutoFlow.ts +2 -2
- package/src/css/props/gridAutoFlow/types.ts +0 -4
- package/src/css/props/gridAutoRows/gridAutoRows.ts +2 -2
- package/src/css/props/gridAutoRows/types.ts +0 -4
- package/src/css/props/gridColumn/gridColumn.ts +3 -3
- package/src/css/props/gridColumn/types.ts +0 -10
- package/src/css/props/gridColumnEnd/gridColumnEnd.ts +3 -3
- package/src/css/props/gridColumnEnd/types.ts +0 -10
- package/src/css/props/gridColumnStart/gridColumnStart.ts +3 -6
- package/src/css/props/gridColumnStart/types.ts +0 -10
- package/src/css/props/gridRow/gridRow.ts +3 -3
- package/src/css/props/gridRow/types.ts +0 -10
- package/src/css/props/gridRowEnd/gridRowEnd.ts +3 -3
- package/src/css/props/gridRowEnd/types.ts +0 -10
- package/src/css/props/gridRowStart/gridRowStart.ts +3 -3
- package/src/css/props/gridRowStart/types.ts +0 -10
- package/src/css/props/gridTemplateColumns/gridTemplateColumns.ts +2 -2
- package/src/css/props/gridTemplateColumns/types.ts +0 -10
- package/src/css/props/gridTemplateRows/gridTemplateRows.ts +2 -2
- package/src/css/props/gridTemplateRows/types.ts +0 -10
- package/src/css/props/height/height.ts +1 -1
- package/src/css/props/height/types.ts +0 -6
- package/src/css/props/inset/inset.ts +1 -1
- package/src/css/props/justifyContent/justifyContent.ts +1 -1
- package/src/css/props/margin/margin.ts +1 -1
- package/src/css/props/maxWidth/maxWidth.ts +1 -1
- package/src/css/props/minHeight/minHeight.ts +1 -1
- package/src/css/props/minWidth/minWidth.ts +1 -1
- package/src/css/props/outline/outline.ts +1 -1
- package/src/css/props/overflow/overflow.ts +1 -1
- package/src/css/props/overflow/types.ts +0 -6
- package/src/css/props/padding/padding.ts +1 -1
- package/src/css/props/pointerEvents/pointerEvents.ts +1 -1
- package/src/css/props/position/position.ts +1 -1
- package/src/css/props/radius/radius.ts +1 -1
- package/src/css/props/shadow/shadow.ts +1 -1
- package/src/css/props/textAlign/textAlign.ts +1 -1
- package/src/css/props/textOverflow/textOverflow.ts +1 -1
- package/src/css/props/width/width.ts +1 -1
- package/src/css/types.ts +225 -53
- package/src/css/util.ts +2 -2
- package/src/css/vars.css.ts +33 -36
- package/src/theme/{v3/_parseColorToken.ts → _parseColorToken.ts} +2 -2
- package/src/theme/buildTheme.ts +33 -0
- package/src/theme/constants.ts +90 -0
- package/src/theme/defaults/color.ts +197 -0
- package/src/theme/{v2/defaults/config.ts → defaults/common.ts} +3 -16
- package/src/theme/{v3/defaultFonts.ts → defaults/fonts.ts} +2 -2
- package/src/theme/index.ts +4 -5
- package/src/theme/{v3/resolveTokens.ts → resolveTokens.ts} +15 -15
- package/src/theme/types.ts +355 -15
- package/src/core/__DEV__.ts +0 -5
- package/src/core/_compat/helpers.ts +0 -72
- package/src/core/_compat/styles/_responsive.ts +0 -19
- package/src/core/_compat/theme/theme.test.tsx +0 -73
- package/src/core/_compat/theme/themeColorProvider.tsx +0 -24
- package/src/core/_compat/theme/themeContext.ts +0 -10
- package/src/core/_compat/theme/themeProvider.tsx +0 -68
- package/src/core/_compat/theme/types.ts +0 -10
- package/src/core/_compat/theme/useRootTheme.ts +0 -15
- package/src/core/_compat/theme/useTheme.ts +0 -12
- package/src/core/_compat/types.ts +0 -191
- package/src/core/hooks/useArrayProp.ts +0 -26
- package/src/core/hooks/useClickOutside.test.tsx +0 -481
- package/src/core/hooks/useClickOutside.ts +0 -113
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +0 -30
- package/src/core/hooks/useElementRect/__workshop__/index.ts +0 -14
- package/src/core/hooks/useElementRect/useElementRect.ts +0 -13
- package/src/core/hooks/useForwardedRef.ts +0 -19
- package/src/core/hooks/useIsomorphicEffect.ts +0 -7
- package/src/core/primitives/badge/types.ts +0 -18
- package/src/core/primitives/box/types.ts +0 -22
- package/src/core/primitives/flex/types.ts +0 -27
- package/src/core/primitives/grid/types.ts +0 -17
- package/src/core/primitives/selectable/types.ts +0 -7
- package/src/core/primitives/types.ts +0 -153
- package/src/core/types/gridItem.ts +0 -32
- package/src/core/types/placement.ts +0 -18
- package/src/core/types/radius.ts +0 -7
- package/src/core/types/textAlign.ts +0 -7
- package/src/core/utils/spanWithTextOverflow.tsx +0 -10
- package/src/theme/getScopedTheme.ts +0 -88
- package/src/theme/v0/avatar.ts +0 -10
- package/src/theme/v0/color/_generic.ts +0 -35
- package/src/theme/v0/color/_system.ts +0 -17
- package/src/theme/v0/color/base.ts +0 -21
- package/src/theme/v0/color/button.ts +0 -42
- package/src/theme/v0/color/card.ts +0 -19
- package/src/theme/v0/color/color.ts +0 -40
- package/src/theme/v0/color/index.ts +0 -11
- package/src/theme/v0/color/input.ts +0 -34
- package/src/theme/v0/color/muted.ts +0 -26
- package/src/theme/v0/color/selectable.ts +0 -31
- package/src/theme/v0/color/solid.ts +0 -26
- package/src/theme/v0/color/spot.ts +0 -13
- package/src/theme/v0/css.ts +0 -10
- package/src/theme/v0/focusRing.ts +0 -5
- package/src/theme/v0/font.ts +0 -40
- package/src/theme/v0/index.ts +0 -10
- package/src/theme/v0/input.ts +0 -23
- package/src/theme/v0/layer.ts +0 -6
- package/src/theme/v0/shadow.ts +0 -15
- package/src/theme/v0/styles.ts +0 -13
- package/src/theme/v0/theme.ts +0 -72
- package/src/theme/v2/avatar.ts +0 -12
- package/src/theme/v2/build/_deprecated/color/_selectable/createSelectableTones.ts +0 -76
- package/src/theme/v2/build/_deprecated/color/_solid/createSolidTones.ts +0 -54
- package/src/theme/v2/build/_deprecated/color/button/createButtonModes.ts +0 -22
- package/src/theme/v2/build/_deprecated/color/button/createButtonTones.ts +0 -55
- package/src/theme/v2/build/_deprecated/color/card/createCardStates.ts +0 -60
- package/src/theme/v2/build/_deprecated/color/color.test.ts +0 -63
- package/src/theme/v2/build/_deprecated/color/defaults.ts +0 -390
- package/src/theme/v2/build/_deprecated/color/factory.ts +0 -141
- package/src/theme/v2/build/_deprecated/color/index.ts +0 -1
- package/src/theme/v2/build/_deprecated/color/input/createInputModes.ts +0 -86
- package/src/theme/v2/build/_deprecated/color/muted/createMuted.ts +0 -54
- package/src/theme/v2/build/_deprecated/color/spot/createSpot.ts +0 -20
- package/src/theme/v2/build/buildColorTheme.test.ts +0 -185
- package/src/theme/v2/build/buildColorTheme.ts +0 -494
- package/src/theme/v2/build/buildTheme.test.ts +0 -89
- package/src/theme/v2/build/buildTheme.ts +0 -37
- package/src/theme/v2/build/colorToken/colorToken.ts +0 -19
- package/src/theme/v2/build/colorToken/compileColorToken.ts +0 -21
- package/src/theme/v2/build/colorToken/index.ts +0 -2
- package/src/theme/v2/build/colorToken/types.ts +0 -6
- package/src/theme/v2/build/index.ts +0 -3
- package/src/theme/v2/build/lib/color-fns/blend/index.ts +0 -3
- package/src/theme/v2/build/lib/color-fns/blend/mix.ts +0 -21
- package/src/theme/v2/build/lib/color-fns/blend/multiply.ts +0 -18
- package/src/theme/v2/build/lib/color-fns/blend/screen.ts +0 -18
- package/src/theme/v2/build/lib/color-fns/color-fns.test.ts +0 -68
- package/src/theme/v2/build/lib/color-fns/contrastRatio.ts +0 -34
- package/src/theme/v2/build/lib/color-fns/convert.ts +0 -150
- package/src/theme/v2/build/lib/color-fns/index.ts +0 -6
- package/src/theme/v2/build/lib/color-fns/parse.ts +0 -60
- package/src/theme/v2/build/lib/color-fns/rgba.ts +0 -14
- package/src/theme/v2/build/lib/color-fns/types.ts +0 -28
- package/src/theme/v2/build/lib/isRecord.ts +0 -3
- package/src/theme/v2/build/lib/utils.ts +0 -19
- package/src/theme/v2/build/merge.ts +0 -28
- package/src/theme/v2/build/mixThemeColor.test.ts +0 -23
- package/src/theme/v2/build/mixThemeColor.ts +0 -53
- package/src/theme/v2/build/renderColorTheme.ts +0 -532
- package/src/theme/v2/build/renderColorValue.ts +0 -85
- package/src/theme/v2/build/resolveColorTokens.ts +0 -268
- package/src/theme/v2/color/_constants.ts +0 -45
- package/src/theme/v2/color/_helpers.ts +0 -24
- package/src/theme/v2/color/_system.ts +0 -38
- package/src/theme/v2/color/avatar.ts +0 -11
- package/src/theme/v2/color/badge.ts +0 -12
- package/src/theme/v2/color/button.ts +0 -11
- package/src/theme/v2/color/color.ts +0 -28
- package/src/theme/v2/color/index.ts +0 -13
- package/src/theme/v2/color/input.ts +0 -23
- package/src/theme/v2/color/kbd.ts +0 -6
- package/src/theme/v2/color/selectable.ts +0 -8
- package/src/theme/v2/color/shadow.ts +0 -7
- package/src/theme/v2/color/state.ts +0 -41
- package/src/theme/v2/color/syntax.ts +0 -39
- package/src/theme/v2/config/helpers.ts +0 -48
- package/src/theme/v2/config/index.ts +0 -4
- package/src/theme/v2/config/system.ts +0 -114
- package/src/theme/v2/config/tokens/color/index.ts +0 -1
- package/src/theme/v2/config/tokens/color/types.ts +0 -137
- package/src/theme/v2/config/tokens/index.ts +0 -3
- package/src/theme/v2/config/tokens/parseTokenValue.test.ts +0 -44
- package/src/theme/v2/config/tokens/parseTokenValue.ts +0 -133
- package/src/theme/v2/config/tokens/types.ts +0 -53
- package/src/theme/v2/config/types.ts +0 -47
- package/src/theme/v2/defaults/colorPalette.ts +0 -5
- package/src/theme/v2/defaults/colorTokens.ts +0 -648
- package/src/theme/v2/defaults/fonts.ts +0 -227
- package/src/theme/v2/index.ts +0 -6
- package/src/theme/v2/input.ts +0 -31
- package/src/theme/v2/theme.ts +0 -45
- package/src/theme/v3/_constants.ts +0 -29
- package/src/theme/v3/buildTheme_v3.ts +0 -39
- package/src/theme/v3/color/_constants.ts +0 -15
- package/src/theme/v3/color/avatar.ts +0 -14
- package/src/theme/v3/color/card.ts +0 -79
- package/src/theme/v3/color/color.ts +0 -98
- package/src/theme/v3/color/element.ts +0 -19
- package/src/theme/v3/color/index.ts +0 -7
- package/src/theme/v3/color/token.ts +0 -32
- package/src/theme/v3/color/tokens.ts +0 -5
- package/src/theme/v3/defaultTokens.ts +0 -199
- package/src/theme/v3/index.ts +0 -9
- package/src/theme/v3/palette/constants.ts +0 -15
- package/src/theme/v3/palette/index.ts +0 -2
- package/src/theme/v3/palette/types.ts +0 -7
- package/src/theme/v3/tokens.ts +0 -16
- package/src/theme/v3/types.ts +0 -133
- package/src/theme/versioning/getTheme_v2.ts +0 -58
- package/src/theme/versioning/index.ts +0 -1
- package/src/theme/versioning/is_v0.ts +0 -7
- package/src/theme/versioning/is_v2.ts +0 -7
- package/src/theme/versioning/themeColor_v0_v2.ts +0 -245
- package/src/theme/versioning/themeColor_v2_v2_9.ts +0 -49
- package/src/theme/versioning/themeColor_v3_v2.ts +0 -383
- package/src/theme/versioning/v0_v2.ts +0 -95
- package/src/theme/versioning/v2_v0.ts +0 -127
- package/src/theme/versioning/v3_v2.ts +0 -130
- /package/src/theme/{v3/merge.ts → merge.ts} +0 -0
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
// This file re-exports API members which existed in the `@sanity/ui` export in v1.
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type BaseTheme as _BaseTheme,
|
|
5
|
-
type HSL as _HSL,
|
|
6
|
-
type PartialThemeColorBuilderOpts,
|
|
7
|
-
type RGB as _RGB,
|
|
8
|
-
type RootTheme as _RootTheme,
|
|
9
|
-
type Theme as _Theme,
|
|
10
|
-
type ThemeAvatar,
|
|
11
|
-
type ThemeBoxShadow,
|
|
12
|
-
type ThemeColor,
|
|
13
|
-
type ThemeColorBase,
|
|
14
|
-
type ThemeColorBuilderOpts,
|
|
15
|
-
type ThemeColorButton,
|
|
16
|
-
type ThemeColorButtonModeKey as _ThemeColorButtonModeKey,
|
|
17
|
-
type ThemeColorButtonState,
|
|
18
|
-
type ThemeColorButtonStates,
|
|
19
|
-
type ThemeColorButtonTones,
|
|
20
|
-
type ThemeColorCard,
|
|
21
|
-
type ThemeColorCardState,
|
|
22
|
-
type ThemeColorGenericState,
|
|
23
|
-
type ThemeColorInput,
|
|
24
|
-
type ThemeColorInputState,
|
|
25
|
-
type ThemeColorInputStates,
|
|
26
|
-
type ThemeColorMuted,
|
|
27
|
-
type ThemeColorMutedTone,
|
|
28
|
-
type ThemeColorName,
|
|
29
|
-
type ThemeColorScheme,
|
|
30
|
-
type ThemeColorSchemeKey as _ThemeColorSchemeKey,
|
|
31
|
-
type ThemeColorSchemes,
|
|
32
|
-
type ThemeColorSelectable,
|
|
33
|
-
type ThemeColorSelectableState,
|
|
34
|
-
type ThemeColorSelectableStates,
|
|
35
|
-
type ThemeColorSolid,
|
|
36
|
-
type ThemeColorSolidTone,
|
|
37
|
-
type ThemeColorSpot,
|
|
38
|
-
type ThemeColorSpotKey,
|
|
39
|
-
type ThemeColorSyntax as _ThemeColorSyntax,
|
|
40
|
-
type ThemeColorToneKey,
|
|
41
|
-
type ThemeFont as _ThemeFont,
|
|
42
|
-
type ThemeFontKey as _ThemeFontKey,
|
|
43
|
-
type ThemeFonts as _ThemeFonts,
|
|
44
|
-
type ThemeFontSize as _ThemeFontSize,
|
|
45
|
-
type ThemeFontWeight as _ThemeFontWeight,
|
|
46
|
-
type ThemeFontWeightKey as _ThemeFontWeightKey,
|
|
47
|
-
type ThemeInput,
|
|
48
|
-
type ThemeLayer as _ThemeLayer,
|
|
49
|
-
type ThemeShadow as _ThemeShadow,
|
|
50
|
-
type ThemeStyles,
|
|
51
|
-
} from '@sanity/ui/theme'
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @public
|
|
55
|
-
* @deprecated Use `BaseTheme` from `@sanity/ui/theme` instead.
|
|
56
|
-
*/
|
|
57
|
-
export type BaseTheme = _BaseTheme
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @public
|
|
61
|
-
* @deprecated Use `ThemeBoxShadow` from `@sanity/ui/theme` instead.
|
|
62
|
-
*/
|
|
63
|
-
export type BoxShadow = ThemeBoxShadow
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @public
|
|
67
|
-
* @deprecated Use `HSL` from `@sanity/ui/theme` instead.
|
|
68
|
-
*/
|
|
69
|
-
export type HSL = _HSL
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @public
|
|
73
|
-
* @deprecated Use `RGB` from `@sanity/ui/theme` instead.
|
|
74
|
-
*/
|
|
75
|
-
export type RGB = _RGB
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @public
|
|
79
|
-
* @deprecated Use `RootTheme` from `@sanity/ui/theme` instead.
|
|
80
|
-
*/
|
|
81
|
-
export type RootTheme = _RootTheme
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @public
|
|
85
|
-
* @deprecated Use `ThemeStyles` from `@sanity/ui/theme` instead.
|
|
86
|
-
*/
|
|
87
|
-
export type Styles = ThemeStyles
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @public
|
|
91
|
-
* @deprecated Use `Theme` from `@sanity/ui/theme` instead.
|
|
92
|
-
*/
|
|
93
|
-
export type Theme = _Theme
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @public
|
|
97
|
-
* @deprecated Use `ThemeColorButtonModeKey` from `@sanity/ui/theme` instead.
|
|
98
|
-
*/
|
|
99
|
-
export type ThemeColorButtonModeKey = _ThemeColorButtonModeKey
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @public
|
|
103
|
-
* @deprecated Use `ThemeColorSchemeKey` from `@sanity/ui/theme` instead.
|
|
104
|
-
*/
|
|
105
|
-
export type ThemeColorSchemeKey = _ThemeColorSchemeKey
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @public
|
|
109
|
-
* @deprecated Use `ThemeColorSyntax` from `@sanity/ui/theme` instead.
|
|
110
|
-
*/
|
|
111
|
-
export type ThemeColorSyntax = _ThemeColorSyntax
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @public
|
|
115
|
-
* @deprecated Use `ThemeFont` from `@sanity/ui/theme` instead.
|
|
116
|
-
*/
|
|
117
|
-
export type ThemeFont = _ThemeFont
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @public
|
|
121
|
-
* @deprecated Use `ThemeFontKey` from `@sanity/ui/theme` instead.
|
|
122
|
-
*/
|
|
123
|
-
export type ThemeFontKey = _ThemeFontKey
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @public
|
|
127
|
-
* @deprecated Use `ThemeFontSize` from `@sanity/ui/theme` instead.
|
|
128
|
-
*/
|
|
129
|
-
export type ThemeFontSize = _ThemeFontSize
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @public
|
|
133
|
-
* @deprecated Use `ThemeFontWeight` from `@sanity/ui/theme` instead.
|
|
134
|
-
*/
|
|
135
|
-
export type ThemeFontWeight = _ThemeFontWeight
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @public
|
|
139
|
-
* @deprecated Use `ThemeFontWeightKey` from `@sanity/ui/theme` instead.
|
|
140
|
-
*/
|
|
141
|
-
export type ThemeFontWeightKey = _ThemeFontWeightKey
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @public
|
|
145
|
-
* @deprecated Use `ThemeFonts` from `@sanity/ui/theme` instead.
|
|
146
|
-
*/
|
|
147
|
-
export type ThemeFonts = _ThemeFonts
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @public
|
|
151
|
-
* @deprecated Use `ThemeLayer` from `@sanity/ui/theme` instead.
|
|
152
|
-
*/
|
|
153
|
-
export type ThemeLayer = _ThemeLayer
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @public
|
|
157
|
-
* @deprecated Use `ThemeShadow` from `@sanity/ui/theme` instead.
|
|
158
|
-
*/
|
|
159
|
-
export type ThemeShadow = _ThemeShadow
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
type PartialThemeColorBuilderOpts,
|
|
163
|
-
type ThemeAvatar,
|
|
164
|
-
type ThemeColor,
|
|
165
|
-
type ThemeColorBase,
|
|
166
|
-
type ThemeColorBuilderOpts,
|
|
167
|
-
type ThemeColorButton,
|
|
168
|
-
type ThemeColorButtonState,
|
|
169
|
-
type ThemeColorButtonStates,
|
|
170
|
-
type ThemeColorButtonTones,
|
|
171
|
-
type ThemeColorCard,
|
|
172
|
-
type ThemeColorCardState,
|
|
173
|
-
type ThemeColorGenericState,
|
|
174
|
-
type ThemeColorInput,
|
|
175
|
-
type ThemeColorInputState,
|
|
176
|
-
type ThemeColorInputStates,
|
|
177
|
-
type ThemeColorMuted,
|
|
178
|
-
type ThemeColorMutedTone,
|
|
179
|
-
type ThemeColorName,
|
|
180
|
-
type ThemeColorScheme,
|
|
181
|
-
type ThemeColorSchemes,
|
|
182
|
-
type ThemeColorSelectable,
|
|
183
|
-
type ThemeColorSelectableState,
|
|
184
|
-
type ThemeColorSelectableStates,
|
|
185
|
-
type ThemeColorSolid,
|
|
186
|
-
type ThemeColorSolidTone,
|
|
187
|
-
type ThemeColorSpot,
|
|
188
|
-
type ThemeColorSpotKey,
|
|
189
|
-
type ThemeColorToneKey,
|
|
190
|
-
type ThemeInput,
|
|
191
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import {_getArrayProp} from '../helpers/props'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This API might change. DO NOT USE IN PRODUCTION.
|
|
7
|
-
* @beta
|
|
8
|
-
* @deprecated Use `useResponsiveProp` instead.
|
|
9
|
-
*/
|
|
10
|
-
export function useArrayProp<T>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
|
|
11
|
-
const [[cachedVal, cachedHash], setCache] = useState<[T[], string]>(() => [
|
|
12
|
-
_getArrayProp(val, defaultVal),
|
|
13
|
-
JSON.stringify(val ?? defaultVal),
|
|
14
|
-
])
|
|
15
|
-
|
|
16
|
-
const hash = JSON.stringify(val ?? defaultVal)
|
|
17
|
-
|
|
18
|
-
if (hash !== cachedHash) {
|
|
19
|
-
// If the cached hash has changed, update the cache right away.
|
|
20
|
-
// Calling setState during render is fine in this case, and preferred over a useEffect loop
|
|
21
|
-
// https://19.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
|
|
22
|
-
setCache([_getArrayProp(val, defaultVal), hash])
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return cachedVal
|
|
26
|
-
}
|
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import {render, screen} from '@testing-library/react'
|
|
2
|
-
import userEvent from '@testing-library/user-event'
|
|
3
|
-
import {type MutableRefObject, useEffect, useRef, useState} from 'react'
|
|
4
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
5
|
-
|
|
6
|
-
import {useClickOutside} from './useClickOutside'
|
|
7
|
-
|
|
8
|
-
describe('useClickOutside', () => {
|
|
9
|
-
/**
|
|
10
|
-
* Specifying the elements array directly:
|
|
11
|
-
* useClickOutside(handler, [buttonElement, popoverElement])
|
|
12
|
-
* instead of in a callback:
|
|
13
|
-
* useClickOutside(handler, () => [buttonElement, popoverElement])
|
|
14
|
-
* is still supported, but deprecated and discouraged. The same is true for the `setElement` callback pattern
|
|
15
|
-
*/
|
|
16
|
-
it('calls the handler when clicking outside of the array of elements', async () => {
|
|
17
|
-
const user = userEvent.setup()
|
|
18
|
-
const handler = vi.fn()
|
|
19
|
-
|
|
20
|
-
const TestComponent = () => {
|
|
21
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
22
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
23
|
-
|
|
24
|
-
useClickOutside(handler, [buttonElement, popoverElement])
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<>
|
|
28
|
-
<button data-testid="button" ref={setButtonElement} />
|
|
29
|
-
<div data-testid="popover" ref={setPopoverElement} />
|
|
30
|
-
<div data-testid="outside" />
|
|
31
|
-
</>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
render(<TestComponent />)
|
|
36
|
-
|
|
37
|
-
await user.click(screen.getByTestId('button'))
|
|
38
|
-
await user.click(screen.getByTestId('popover'))
|
|
39
|
-
expect(handler).not.toHaveBeenCalled()
|
|
40
|
-
|
|
41
|
-
await user.click(screen.getByTestId('outside'))
|
|
42
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('the elements array flattens nested arrays one level deep', async () => {
|
|
46
|
-
const user = userEvent.setup()
|
|
47
|
-
const handler = vi.fn()
|
|
48
|
-
|
|
49
|
-
const TestComponent = () => {
|
|
50
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
51
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
52
|
-
|
|
53
|
-
useClickOutside(handler, [null, [null, buttonElement], [popoverElement, null], null])
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<>
|
|
57
|
-
<button data-testid="button" ref={setButtonElement} />
|
|
58
|
-
<div data-testid="popover" ref={setPopoverElement} />
|
|
59
|
-
<div data-testid="outside" />
|
|
60
|
-
</>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
render(<TestComponent />)
|
|
65
|
-
|
|
66
|
-
await user.click(screen.getByTestId('button'))
|
|
67
|
-
await user.click(screen.getByTestId('popover'))
|
|
68
|
-
expect(handler).not.toHaveBeenCalled()
|
|
69
|
-
|
|
70
|
-
await user.click(screen.getByTestId('outside'))
|
|
71
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('it can set a boundary to scope outside click events', async () => {
|
|
75
|
-
const user = userEvent.setup()
|
|
76
|
-
const handler = vi.fn()
|
|
77
|
-
|
|
78
|
-
const TestComponent = () => {
|
|
79
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
80
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
81
|
-
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
|
|
82
|
-
|
|
83
|
-
useClickOutside(handler, [buttonElement, popoverElement], boundaryElement)
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<>
|
|
87
|
-
<div ref={setBoundaryElement}>
|
|
88
|
-
<button data-testid="button" ref={setButtonElement} />
|
|
89
|
-
<div data-testid="popover" ref={setPopoverElement} />
|
|
90
|
-
<div data-testid="inside" />
|
|
91
|
-
</div>
|
|
92
|
-
<div data-testid="outside" />
|
|
93
|
-
</>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
render(<TestComponent />)
|
|
98
|
-
|
|
99
|
-
await user.click(screen.getByTestId('button'))
|
|
100
|
-
await user.click(screen.getByTestId('popover'))
|
|
101
|
-
// Since it's outside the boundary it should be ignored
|
|
102
|
-
await user.click(screen.getByTestId('outside'))
|
|
103
|
-
expect(handler).not.toHaveBeenCalled()
|
|
104
|
-
|
|
105
|
-
await user.click(screen.getByTestId('inside'))
|
|
106
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('it returns a `setElement` callback', async () => {
|
|
110
|
-
/**
|
|
111
|
-
* We don't use this pattern in the studio codebase anymore, and we don't recommend using it moving forward.
|
|
112
|
-
* But since it's part of the public API we can't remove it without a major version bump.
|
|
113
|
-
* Thus it makes sense to unit test it to ensure it works as expected and we don't accidentally break backwards compatibility.
|
|
114
|
-
*/
|
|
115
|
-
const user = userEvent.setup()
|
|
116
|
-
const handler = vi.fn()
|
|
117
|
-
|
|
118
|
-
const TestComponent = (props: {open?: true}) => {
|
|
119
|
-
const {open = false} = props
|
|
120
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
121
|
-
|
|
122
|
-
const setElement = useClickOutside(handler, [buttonElement])
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<>
|
|
126
|
-
<button data-testid="button" ref={setButtonElement} />
|
|
127
|
-
{open && <div data-testid="popover" ref={setElement} />}
|
|
128
|
-
<div data-testid="outside" />
|
|
129
|
-
</>
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const {rerender} = render(<TestComponent />)
|
|
134
|
-
|
|
135
|
-
await user.click(screen.getByTestId('button'))
|
|
136
|
-
expect(handler).not.toHaveBeenCalled()
|
|
137
|
-
|
|
138
|
-
await user.click(screen.getByTestId('outside'))
|
|
139
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
140
|
-
|
|
141
|
-
// The popover isn't rendered yet
|
|
142
|
-
expect(screen.queryByTestId('popover')).toBeNull()
|
|
143
|
-
|
|
144
|
-
// Rerender the component with the popover open
|
|
145
|
-
rerender(<TestComponent open />)
|
|
146
|
-
|
|
147
|
-
// Clicking the popover should not trigger the handler
|
|
148
|
-
await user.click(screen.getByTestId('popover'))
|
|
149
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('instead of `setElement`, update the `elements` array', async () => {
|
|
153
|
-
/**
|
|
154
|
-
* Since we don't want people to use the `setElement` pattern, test that userland can handle dynamically changing elements arrays
|
|
155
|
-
*/
|
|
156
|
-
const user = userEvent.setup()
|
|
157
|
-
const handler = vi.fn()
|
|
158
|
-
|
|
159
|
-
const TestComponent = (props: {open?: true}) => {
|
|
160
|
-
const {open = false} = props
|
|
161
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
162
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
163
|
-
|
|
164
|
-
useClickOutside(handler, [buttonElement, popoverElement])
|
|
165
|
-
|
|
166
|
-
return (
|
|
167
|
-
<>
|
|
168
|
-
<button data-testid="button" ref={setButtonElement} />
|
|
169
|
-
{open && <div data-testid="popover" ref={setPopoverElement} />}
|
|
170
|
-
<div data-testid="outside" />
|
|
171
|
-
</>
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const {rerender} = render(<TestComponent />)
|
|
176
|
-
|
|
177
|
-
await user.click(screen.getByTestId('button'))
|
|
178
|
-
expect(handler).not.toHaveBeenCalled()
|
|
179
|
-
|
|
180
|
-
await user.click(screen.getByTestId('outside'))
|
|
181
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
182
|
-
|
|
183
|
-
// The popover isn't rendered yet
|
|
184
|
-
expect(screen.queryByTestId('popover')).toBeNull()
|
|
185
|
-
|
|
186
|
-
// Rerender the component with the popover open
|
|
187
|
-
rerender(<TestComponent open />)
|
|
188
|
-
|
|
189
|
-
// Clicking the popover should not trigger the handler
|
|
190
|
-
await user.click(screen.getByTestId('popover'))
|
|
191
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('returning the current value of refs in the elements array is dangerous', async () => {
|
|
195
|
-
/**
|
|
196
|
-
* This test demonstrates why it's dangerous to return ref values in the elements array.
|
|
197
|
-
* When using refs, pass a function returning the elements array, instead of defining the array directly during render
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
const user = userEvent.setup()
|
|
201
|
-
let handler = vi.fn()
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Using refs in the `useClickOutside` elements array is dangerous,
|
|
205
|
-
* the below example demonstrates how `useClickOutside` doesn't "see" the current values of refs,
|
|
206
|
-
* it can only "see" whatever the value of the ref was when the hook was rendered.
|
|
207
|
-
*/
|
|
208
|
-
let TestComponent = () => {
|
|
209
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
210
|
-
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
211
|
-
|
|
212
|
-
useClickOutside(handler, [buttonRef.current, popoverRef.current])
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<>
|
|
216
|
-
<button data-testid="button" ref={buttonRef} />
|
|
217
|
-
<div data-testid="popover" ref={popoverRef} />
|
|
218
|
-
</>
|
|
219
|
-
)
|
|
220
|
-
}
|
|
221
|
-
const {rerender} = render(<TestComponent />)
|
|
222
|
-
await user.click(screen.getByTestId('button'))
|
|
223
|
-
await user.click(screen.getByTestId('popover'))
|
|
224
|
-
// Because the ref values are stale, the handler is called
|
|
225
|
-
expect(handler).toHaveBeenCalledTimes(2)
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* If a mixture of refs and state is used it can appear like it's working correctly,
|
|
229
|
-
* but this is a side-effect, not an indication it's safe.
|
|
230
|
-
*/
|
|
231
|
-
handler = vi.fn()
|
|
232
|
-
TestComponent = () => {
|
|
233
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
234
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
235
|
-
|
|
236
|
-
useClickOutside(handler, [buttonRef.current, popoverElement])
|
|
237
|
-
|
|
238
|
-
return (
|
|
239
|
-
<>
|
|
240
|
-
<button data-testid="button" ref={buttonRef} />
|
|
241
|
-
<div data-testid="popover" ref={setPopoverElement} />
|
|
242
|
-
<div data-testid="outside" />
|
|
243
|
-
</>
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
rerender(<TestComponent />)
|
|
247
|
-
await user.click(screen.getByTestId('button'))
|
|
248
|
-
await user.click(screen.getByTestId('popover'))
|
|
249
|
-
expect(handler).not.toHaveBeenCalled()
|
|
250
|
-
await user.click(screen.getByTestId('outside'))
|
|
251
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Unrelated state updates can create the same false impression of safety.
|
|
255
|
-
*/
|
|
256
|
-
handler = vi.fn()
|
|
257
|
-
TestComponent = () => {
|
|
258
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
259
|
-
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
260
|
-
|
|
261
|
-
useClickOutside(handler, [buttonRef.current, popoverRef.current])
|
|
262
|
-
|
|
263
|
-
const [, tick] = useState(0)
|
|
264
|
-
useEffect(() => {
|
|
265
|
-
/**
|
|
266
|
-
* This effect schedules a re-render, which will lead to `useClickOutsideHandler` "seeing"
|
|
267
|
-
* the current value of the refs after they got assigned dom nodes when the React ref callbacks executed.
|
|
268
|
-
*/
|
|
269
|
-
tick((prev) => ++prev)
|
|
270
|
-
}, [])
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<>
|
|
274
|
-
<button data-testid="button" ref={buttonRef} />
|
|
275
|
-
<div data-testid="popover" ref={popoverRef} />
|
|
276
|
-
<div data-testid="outside" />
|
|
277
|
-
</>
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
rerender(<TestComponent />)
|
|
281
|
-
await user.click(screen.getByTestId('button'))
|
|
282
|
-
await user.click(screen.getByTestId('popover'))
|
|
283
|
-
expect(handler).not.toHaveBeenCalled()
|
|
284
|
-
await user.click(screen.getByTestId('outside'))
|
|
285
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* When using the legacy version of the `useClickOutside` API it's necessary to synchronize mutable ref values
|
|
289
|
-
* with a effect and state loop to ensure they're not stale
|
|
290
|
-
*/
|
|
291
|
-
const useElementsFromRefs = (refs: MutableRefObject<HTMLElement | null>[]) => {
|
|
292
|
-
const [elements, setElements] = useState(() => refs.map((ref) => ref.current))
|
|
293
|
-
|
|
294
|
-
useEffect(() => {
|
|
295
|
-
if (refs.length !== elements.length) {
|
|
296
|
-
setElements(refs.map((ref) => ref.current))
|
|
297
|
-
}
|
|
298
|
-
for (const ref of refs) {
|
|
299
|
-
if (!elements.includes(ref.current)) {
|
|
300
|
-
setElements(refs.map((ref) => ref.current))
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}, [elements, refs])
|
|
305
|
-
|
|
306
|
-
return elements
|
|
307
|
-
}
|
|
308
|
-
handler = vi.fn()
|
|
309
|
-
TestComponent = () => {
|
|
310
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
311
|
-
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
312
|
-
|
|
313
|
-
const elements = useElementsFromRefs([buttonRef, popoverRef])
|
|
314
|
-
useClickOutside(handler, elements)
|
|
315
|
-
|
|
316
|
-
return (
|
|
317
|
-
<>
|
|
318
|
-
<button data-testid="button" ref={buttonRef} />
|
|
319
|
-
<div data-testid="popover" ref={popoverRef} />
|
|
320
|
-
<div data-testid="outside" />
|
|
321
|
-
</>
|
|
322
|
-
)
|
|
323
|
-
}
|
|
324
|
-
rerender(<TestComponent />)
|
|
325
|
-
await user.click(screen.getByTestId('button'))
|
|
326
|
-
await user.click(screen.getByTestId('popover'))
|
|
327
|
-
expect(handler).not.toHaveBeenCalled()
|
|
328
|
-
await user.click(screen.getByTestId('outside'))
|
|
329
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
it('using the current value of a react ref as the `boundaryElement` is dangerous', async () => {
|
|
333
|
-
/**
|
|
334
|
-
* This test demonstrates why it's dangerous to return a ref value as the boundaryElement,
|
|
335
|
-
* for the same reasons it's dangerous for the elements array.
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
const user = userEvent.setup()
|
|
339
|
-
let handler = vi.fn()
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Using refs in the `useClickOutside` elements array is dangerous,
|
|
343
|
-
* the below example demonstrates how `useClickOutside` doesn't "see" the current values of refs,
|
|
344
|
-
* it can only "see" whatever the value of the ref was when the hook was rendered.
|
|
345
|
-
*/
|
|
346
|
-
let TestComponent = () => {
|
|
347
|
-
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
348
|
-
|
|
349
|
-
useClickOutside(handler, [], boundaryRef.current)
|
|
350
|
-
|
|
351
|
-
return (
|
|
352
|
-
<>
|
|
353
|
-
<div ref={boundaryRef}>
|
|
354
|
-
<div data-testid="inside" />
|
|
355
|
-
</div>
|
|
356
|
-
<div data-testid="outside" />
|
|
357
|
-
</>
|
|
358
|
-
)
|
|
359
|
-
}
|
|
360
|
-
const {rerender} = render(<TestComponent />)
|
|
361
|
-
await user.click(screen.getByTestId('inside'))
|
|
362
|
-
await user.click(screen.getByTestId('outside'))
|
|
363
|
-
// Because the ref values are stale, the handler is called
|
|
364
|
-
expect(handler).toHaveBeenCalledTimes(2)
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* If a mixture of refs and state is used it can appear like it's working correctly,
|
|
368
|
-
* but this is a side-effect, not an indication it's safe.
|
|
369
|
-
*/
|
|
370
|
-
handler = vi.fn()
|
|
371
|
-
TestComponent = () => {
|
|
372
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
373
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
374
|
-
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
375
|
-
|
|
376
|
-
useClickOutside(handler, [buttonRef.current, popoverElement], boundaryRef.current)
|
|
377
|
-
|
|
378
|
-
return (
|
|
379
|
-
<>
|
|
380
|
-
<div ref={boundaryRef}>
|
|
381
|
-
<button data-testid="button" ref={buttonRef} />
|
|
382
|
-
<div data-testid="popover" ref={setPopoverElement} />
|
|
383
|
-
<div data-testid="inside" />
|
|
384
|
-
</div>
|
|
385
|
-
<div data-testid="outside" />
|
|
386
|
-
</>
|
|
387
|
-
)
|
|
388
|
-
}
|
|
389
|
-
rerender(<TestComponent />)
|
|
390
|
-
await user.click(screen.getByTestId('button'))
|
|
391
|
-
await user.click(screen.getByTestId('popover'))
|
|
392
|
-
await user.click(screen.getByTestId('outside'))
|
|
393
|
-
expect(handler).not.toHaveBeenCalled()
|
|
394
|
-
await user.click(screen.getByTestId('inside'))
|
|
395
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Unrelated state updates can create the same false impression of safety.
|
|
399
|
-
*/
|
|
400
|
-
handler = vi.fn()
|
|
401
|
-
TestComponent = () => {
|
|
402
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
403
|
-
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
404
|
-
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
405
|
-
|
|
406
|
-
useClickOutside(handler, [buttonRef.current, popoverRef.current], boundaryRef.current)
|
|
407
|
-
|
|
408
|
-
const [, tick] = useState(0)
|
|
409
|
-
useEffect(() => {
|
|
410
|
-
/**
|
|
411
|
-
* This effect schedules a re-render, which will lead to `useClickOutsideHandler` "seeing"
|
|
412
|
-
* the current value of the refs after they got assigned dom nodes when the React ref callbacks executed.
|
|
413
|
-
*/
|
|
414
|
-
tick((prev) => ++prev)
|
|
415
|
-
}, [])
|
|
416
|
-
|
|
417
|
-
return (
|
|
418
|
-
<>
|
|
419
|
-
<div ref={boundaryRef}>
|
|
420
|
-
<button data-testid="button" ref={buttonRef} />
|
|
421
|
-
<div data-testid="popover" ref={popoverRef} />
|
|
422
|
-
<div data-testid="inside" />
|
|
423
|
-
</div>
|
|
424
|
-
<div data-testid="outside" />
|
|
425
|
-
</>
|
|
426
|
-
)
|
|
427
|
-
}
|
|
428
|
-
rerender(<TestComponent />)
|
|
429
|
-
await user.click(screen.getByTestId('button'))
|
|
430
|
-
await user.click(screen.getByTestId('popover'))
|
|
431
|
-
await user.click(screen.getByTestId('outside'))
|
|
432
|
-
expect(handler).not.toHaveBeenCalled()
|
|
433
|
-
await user.click(screen.getByTestId('inside'))
|
|
434
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* When using the legacy version of the `useClickOutside` API it's necessary to synchronize mutable ref values
|
|
438
|
-
* with a effect and state loop to ensure they're not stale
|
|
439
|
-
*/
|
|
440
|
-
const useBoundaryElementFromRef = (ref: MutableRefObject<HTMLElement | null>) => {
|
|
441
|
-
const [element, setElement] = useState(() => ref.current)
|
|
442
|
-
|
|
443
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
444
|
-
useEffect(() => {
|
|
445
|
-
// If the ref has mutated since the last render, update the state and schedule a re-render
|
|
446
|
-
if (ref.current !== element) {
|
|
447
|
-
setElement(ref.current)
|
|
448
|
-
}
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
return element
|
|
452
|
-
}
|
|
453
|
-
handler = vi.fn()
|
|
454
|
-
TestComponent = () => {
|
|
455
|
-
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
456
|
-
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
457
|
-
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
458
|
-
|
|
459
|
-
const boundaryElement = useBoundaryElementFromRef(boundaryRef)
|
|
460
|
-
useClickOutside(handler, [buttonRef.current, popoverRef.current], boundaryElement)
|
|
461
|
-
|
|
462
|
-
return (
|
|
463
|
-
<>
|
|
464
|
-
<div ref={boundaryRef}>
|
|
465
|
-
<button data-testid="button" ref={buttonRef} />
|
|
466
|
-
<div data-testid="popover" ref={popoverRef} />
|
|
467
|
-
<div data-testid="inside" />
|
|
468
|
-
</div>
|
|
469
|
-
<div data-testid="outside" />
|
|
470
|
-
</>
|
|
471
|
-
)
|
|
472
|
-
}
|
|
473
|
-
rerender(<TestComponent />)
|
|
474
|
-
await user.click(screen.getByTestId('button'))
|
|
475
|
-
await user.click(screen.getByTestId('popover'))
|
|
476
|
-
await user.click(screen.getByTestId('outside'))
|
|
477
|
-
expect(handler).not.toHaveBeenCalled()
|
|
478
|
-
await user.click(screen.getByTestId('inside'))
|
|
479
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
480
|
-
})
|
|
481
|
-
})
|