@sanity/ui 3.3.0 → 3.3.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/README.md +12 -0
- package/dist/_visual-editing.d.mts +2 -1126
- package/dist/_visual-editing.d.ts +2 -1126
- package/dist/_visual-editing.js +3 -31
- package/dist/_visual-editing.mjs +2 -31
- package/dist/index.d.mts +555 -2769
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +555 -2769
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2982 -1934
- package/dist/index.mjs +2950 -1903
- package/dist/index.mjs.map +1 -1
- package/dist/refractor.js +16 -0
- package/dist/refractor.mjs +21 -0
- package/dist/refractor.mjs.map +1 -0
- package/dist/tabList.js +3804 -0
- package/dist/tabList.mjs +3355 -0
- package/dist/tabList.mjs.map +1 -0
- package/dist/theme.d.mts +927 -1227
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.d.ts +927 -1227
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +3 -4127
- package/dist/theme.mjs +2 -4127
- package/dist/theme2.d.mts +2 -0
- package/dist/theme2.d.ts +2 -0
- package/dist/theme2.js +4104 -0
- package/dist/theme2.mjs +3851 -0
- package/dist/theme2.mjs.map +1 -0
- package/dist/useTheme.d.mts +1451 -0
- package/dist/useTheme.d.mts.map +1 -0
- package/dist/useTheme.d.ts +1451 -0
- package/dist/useTheme.d.ts.map +1 -0
- package/exports/_visual-editing.ts +1 -0
- package/package.json +52 -168
- package/src/core/_compat.ts +30 -0
- package/src/core/components/autocomplete/autocomplete.tsx +8 -0
- package/src/core/components/autocomplete/autocompleteOption.tsx +1 -0
- package/src/core/components/breadcrumbs/breadcrumbs.test.tsx +8 -5
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +3 -0
- package/src/core/components/dialog/dialog.tsx +5 -2
- package/src/core/components/hotkeys/hotkeys.test.tsx +10 -5
- package/src/core/components/hotkeys/hotkeys.tsx +2 -0
- package/src/core/components/menu/menu.spacing.test.tsx +12 -7
- package/src/core/components/menu/menu.test.tsx +9 -6
- package/src/core/components/menu/menu.tsx +4 -2
- package/src/core/components/menu/menuButton.tsx +8 -0
- package/src/core/components/menu/menuDivider.ts +1 -0
- package/src/core/components/menu/menuGroup.spacing.test.tsx +9 -6
- package/src/core/components/menu/menuGroup.tsx +6 -2
- package/src/core/components/menu/menuItem.spacing.test.tsx +8 -5
- package/src/core/components/menu/menuItem.tsx +4 -0
- package/src/core/components/menu/useMenuController.ts +2 -0
- package/src/core/components/skeleton/skeleton.tsx +1 -0
- package/src/core/components/tab/tab.tsx +1 -0
- package/src/core/components/tab/tabList.test.tsx +7 -5
- package/src/core/components/tab/tabList.tsx +1 -0
- package/src/core/components/toast/toast.test.tsx +9 -4
- package/src/core/components/toast/toast.tsx +1 -0
- package/src/core/components/toast/toastLayer.tsx +1 -0
- package/src/core/components/tree/tree.test.tsx +10 -5
- package/src/core/components/tree/tree.tsx +2 -0
- package/src/core/components/tree/treeGroup.tsx +1 -0
- package/src/core/components/tree/treeItem.test.tsx +10 -5
- package/src/core/components/tree/treeItem.tsx +1 -0
- package/src/core/hooks/index.ts +1 -0
- package/src/core/hooks/useClickOutside.test.tsx +43 -15
- package/src/core/hooks/useClickOutside.ts +1 -1
- package/src/core/hooks/useClickOutsideEvent.test.tsx +8 -4
- package/src/core/hooks/useDelayed.test.ts +9 -8
- package/src/core/hooks/useElementRect/useElementRect.ts +1 -0
- package/src/core/hooks/useForwardedRef.ts +1 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +2 -1
- package/src/core/hooks/usePrefersDark.hydration.test.tsx +7 -5
- package/src/core/hooks/usePrefersDark.test.tsx +3 -1
- package/src/core/hooks/usePrefersReducedMotion.hydration.test.tsx +7 -5
- package/src/core/hooks/usePrefersReducedMotion.test.tsx +3 -1
- package/src/core/lib/createGlobalScopedContext.ts +1 -0
- package/src/core/lib/globalScope.ts +1 -0
- package/src/core/observers/elementSizeObserver.ts +1 -0
- package/src/core/primitives/avatar/avatar.tsx +2 -2
- package/src/core/primitives/avatar/avatarStack.tsx +1 -0
- package/src/core/primitives/badge/badge.test.tsx +3 -2
- package/src/core/primitives/badge/badge.tsx +3 -1
- package/src/core/primitives/box/box.test.tsx +18 -5
- package/src/core/primitives/box/box.tsx +9 -1
- package/src/core/primitives/button/button.test.tsx +10 -6
- package/src/core/primitives/button/button.tsx +4 -0
- package/src/core/primitives/button/styles.ts +1 -0
- package/src/core/primitives/card/card.tsx +2 -5
- package/src/core/primitives/card/types.ts +1 -0
- package/src/core/primitives/code/code.tsx +1 -0
- package/src/core/primitives/code/refractor.tsx +2 -0
- package/src/core/primitives/container/container.tsx +1 -0
- package/src/core/primitives/flex/flex.tsx +2 -3
- package/src/core/primitives/grid/grid.test.tsx +11 -5
- package/src/core/primitives/grid/grid.tsx +3 -0
- package/src/core/primitives/heading/heading.tsx +1 -0
- package/src/core/primitives/inline/inline.test.tsx +9 -5
- package/src/core/primitives/inline/inline.tsx +3 -0
- package/src/core/primitives/kbd/kbd.tsx +5 -1
- package/src/core/primitives/label/label.tsx +1 -0
- package/src/core/primitives/popover/popover.tsx +5 -4
- package/src/core/primitives/popover/popoverCard.tsx +1 -0
- package/src/core/primitives/popover/types.ts +0 -1
- package/src/core/primitives/select/select.test.tsx +9 -5
- package/src/core/primitives/select/select.tsx +1 -0
- package/src/core/primitives/stack/stack.test.tsx +9 -5
- package/src/core/primitives/stack/stack.tsx +2 -0
- package/src/core/primitives/stack/styles.ts +1 -0
- package/src/core/primitives/text/text.tsx +1 -0
- package/src/core/primitives/textInput/textInput.test.tsx +9 -5
- package/src/core/primitives/textInput/textInput.tsx +3 -0
- package/src/core/primitives/tooltip/tooltip.test.tsx +82 -49
- package/src/core/primitives/tooltip/tooltip.tsx +3 -1
- package/src/core/primitives/tooltip/tooltipCard.tsx +1 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/types.ts +2 -0
- package/src/core/styles/flex/types.ts +0 -1
- package/src/core/styles/font/responsiveFont.ts +0 -3
- package/src/core/styles/font/types.ts +1 -3
- package/src/core/styles/grid/gridStyle.ts +1 -0
- package/src/core/styles/margin/marginStyle.ts +1 -0
- package/src/core/styles/margin/marginsStyle.test.ts +2 -1
- package/src/core/styles/padding/paddingStyle.test.ts +2 -1
- package/src/core/styles/padding/paddingStyle.ts +1 -0
- package/src/core/theme/theme.test.tsx +7 -3
- package/src/core/theme/useRootTheme.ts +1 -0
- package/src/core/theme/useTheme.ts +2 -0
- package/src/core/utils/arrow/arrow.tsx +1 -0
- package/src/core/utils/boundaryElement/boundaryElement.test.tsx +9 -4
- package/src/core/utils/conditionalWrapper/conditionalWrapper.tsx +1 -0
- package/src/core/utils/getElementRef.ts +5 -0
- package/src/core/utils/layer/getLayerContext.test.ts +2 -0
- package/src/core/utils/layer/layer.test.tsx +9 -4
- package/src/core/utils/layer/layer.tsx +1 -0
- package/src/core/utils/layer/useLayer.ts +2 -0
- package/src/core/utils/portal/portal.test.tsx +9 -4
- package/src/core/utils/portal/portalProvider.tsx +1 -0
- package/src/core/utils/virtualList/virtualList.tsx +2 -1
- package/src/theme/build/_deprecated/color/_selectable/createSelectableTones.ts +10 -0
- package/src/theme/build/_deprecated/color/_solid/createSolidTones.ts +4 -0
- package/src/theme/build/_deprecated/color/button/createButtonModes.ts +5 -0
- package/src/theme/build/_deprecated/color/button/createButtonTones.ts +5 -0
- package/src/theme/build/_deprecated/color/card/createCardStates.ts +6 -0
- package/src/theme/build/_deprecated/color/color.test.ts +5 -1
- package/src/theme/build/_deprecated/color/defaults.ts +1 -0
- package/src/theme/build/_deprecated/color/factory.ts +36 -0
- package/src/theme/build/_deprecated/color/input/createInputModes.ts +5 -0
- package/src/theme/build/_deprecated/color/muted/createMuted.ts +4 -0
- package/src/theme/build/_deprecated/color/spot/createSpot.ts +3 -0
- package/src/theme/build/buildColorTheme.test.ts +2 -0
- package/src/theme/build/buildColorTheme.ts +8 -0
- package/src/theme/build/buildTheme.test.ts +2 -0
- package/src/theme/build/lib/color-fns/color-fns.test.ts +3 -1
- package/src/theme/build/merge.ts +5 -0
- package/src/theme/build/mixThemeColor.test.ts +2 -0
- package/src/theme/build/renderColorTheme.ts +6 -0
- package/src/theme/build/renderColorValue.ts +0 -2
- package/src/theme/build/resolveColorTokens.ts +6 -0
- package/src/theme/build/theme.test.ts +2 -0
- package/src/theme/config/helpers.ts +5 -0
- package/src/theme/config/system.ts +2 -0
- package/src/theme/config/tokens/color/types.ts +6 -4
- package/src/theme/config/tokens/parseTokenKey.test.ts +2 -0
- package/src/theme/config/tokens/parseTokenValue.test.ts +2 -0
- package/src/theme/config/tokens/parseTokenValue.ts +1 -0
- package/src/theme/getScopedTheme.ts +6 -1
- package/src/theme/system/color/_helpers.ts +4 -0
- package/src/theme/system/theme.ts +4 -0
- package/src/theme/system/v0/color/_system.ts +1 -0
- package/src/theme/system/v0/color/button.ts +14 -0
- package/src/theme/system/v0/color/card.ts +6 -0
- package/src/theme/system/v0/color/color.ts +11 -0
- package/src/theme/system/v0/color/input.ts +6 -0
- package/src/theme/system/v0/color/muted.ts +11 -0
- package/src/theme/system/v0/color/selectable.ts +11 -0
- package/src/theme/system/v0/color/solid.ts +11 -0
- package/src/theme/system/v0/color/spot.ts +1 -0
- package/src/theme/versioning/getTheme_v2.ts +15 -0
- package/src/theme/versioning/themeColor_v0_v2.ts +7 -0
- package/src/theme/versioning/themeColor_v2_v2_9.ts +1 -0
- package/src/theme/versioning/v0_v2.ts +13 -1
- package/src/theme/versioning/v2_v0.ts +18 -0
- package/dist/_chunks-cjs/_visual-editing.js +0 -5899
- package/dist/_chunks-cjs/_visual-editing.js.map +0 -1
- package/dist/_chunks-cjs/refractor.js +0 -23
- package/dist/_chunks-cjs/refractor.js.map +0 -1
- package/dist/_chunks-es/_visual-editing.mjs +0 -5905
- package/dist/_chunks-es/_visual-editing.mjs.map +0 -1
- package/dist/_chunks-es/refractor.mjs +0 -26
- package/dist/_chunks-es/refractor.mjs.map +0 -1
- package/dist/_visual-editing.js.map +0 -1
- package/dist/_visual-editing.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/theme.js.map +0 -1
- package/dist/theme.mjs.map +0 -1
- package/src/core/__workshop__/constants.ts +0 -293
- package/src/core/components/autocomplete/__mocks__/apiStore.ts +0 -49
- package/src/core/components/autocomplete/__mocks__/countries.ts +0 -245
- package/src/core/components/autocomplete/__workshop__/async.tsx +0 -156
- package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +0 -137
- package/src/core/components/autocomplete/__workshop__/custom.tsx +0 -89
- package/src/core/components/autocomplete/__workshop__/example.tsx +0 -79
- package/src/core/components/autocomplete/__workshop__/focusAndBlur.tsx +0 -36
- package/src/core/components/autocomplete/__workshop__/fullscreen.tsx +0 -294
- package/src/core/components/autocomplete/__workshop__/index.ts +0 -39
- package/src/core/components/autocomplete/__workshop__/types.ts +0 -4
- package/src/core/components/breadcrumbs/__workshop__/example.tsx +0 -62
- package/src/core/components/breadcrumbs/__workshop__/index.ts +0 -14
- package/src/core/components/dialog/__workshop__/activate.tsx +0 -134
- package/src/core/components/dialog/__workshop__/autoFocus.tsx +0 -29
- package/src/core/components/dialog/__workshop__/index.ts +0 -19
- package/src/core/components/dialog/__workshop__/layering.tsx +0 -41
- package/src/core/components/dialog/__workshop__/nested.tsx +0 -72
- package/src/core/components/dialog/__workshop__/onScroll.tsx +0 -39
- package/src/core/components/dialog/__workshop__/panes.tsx +0 -82
- package/src/core/components/dialog/__workshop__/position.tsx +0 -30
- package/src/core/components/dialog/__workshop__/props.tsx +0 -75
- package/src/core/components/dialog/__workshop__/provider.tsx +0 -11
- package/src/core/components/dialog/__workshop__/wrapped.tsx +0 -76
- package/src/core/components/hotkeys/__workshop__/index.ts +0 -14
- package/src/core/components/hotkeys/__workshop__/plain.tsx +0 -9
- package/src/core/components/menu/__workshop__/asComponent.tsx +0 -45
- package/src/core/components/menu/__workshop__/avatarMenu.tsx +0 -51
- package/src/core/components/menu/__workshop__/closableMenuButton.tsx +0 -46
- package/src/core/components/menu/__workshop__/constrainedInBoundary.tsx +0 -134
- package/src/core/components/menu/__workshop__/customMenuItem.tsx +0 -45
- package/src/core/components/menu/__workshop__/customSelectedState.tsx +0 -39
- package/src/core/components/menu/__workshop__/disableFocusOnClose.tsx +0 -40
- package/src/core/components/menu/__workshop__/groups.tsx +0 -156
- package/src/core/components/menu/__workshop__/index.ts +0 -89
- package/src/core/components/menu/__workshop__/menuButton.tsx +0 -80
- package/src/core/components/menu/__workshop__/menuGroupRight.tsx +0 -65
- package/src/core/components/menu/__workshop__/nestedMenu.tsx +0 -22
- package/src/core/components/menu/__workshop__/onCloseMenuButton.tsx +0 -41
- package/src/core/components/menu/__workshop__/selectedItem.tsx +0 -69
- package/src/core/components/menu/__workshop__/shouldFocus.tsx +0 -47
- package/src/core/components/menu/__workshop__/tones.tsx +0 -25
- package/src/core/components/menu/__workshop__/withoutArrow.tsx +0 -32
- package/src/core/components/skeleton/__workshop__/delay.tsx +0 -70
- package/src/core/components/skeleton/__workshop__/index.ts +0 -11
- package/src/core/components/skeleton/__workshop__/skeleton.tsx +0 -64
- package/src/core/components/tab/__workshop__/example.tsx +0 -79
- package/src/core/components/tab/__workshop__/index.ts +0 -14
- package/src/core/components/toast/__workshop__/hook.tsx +0 -71
- package/src/core/components/toast/__workshop__/index.ts +0 -19
- package/src/core/components/toast/__workshop__/toast.tsx +0 -26
- package/src/core/components/tree/__workshop__/basic.perf.ts +0 -19
- package/src/core/components/tree/__workshop__/basic.tsx +0 -105
- package/src/core/components/tree/__workshop__/index.ts +0 -21
- package/src/core/components/tree/__workshop__/tabFromElement.tsx +0 -84
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +0 -32
- package/src/core/hooks/useElementRect/__workshop__/index.ts +0 -14
- package/src/core/hooks/useMediaIndex/__workshop__/index.ts +0 -14
- package/src/core/hooks/useMediaIndex/__workshop__/test.tsx +0 -14
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +0 -14
- package/src/core/primitives/avatar/__workshop__/index.ts +0 -29
- package/src/core/primitives/avatar/__workshop__/stack.tsx +0 -25
- package/src/core/primitives/avatar/__workshop__/withinButton.tsx +0 -63
- package/src/core/primitives/avatar/__workshop__/withinMenuItem.tsx +0 -70
- package/src/core/primitives/badge/__workshop__/index.ts +0 -19
- package/src/core/primitives/badge/__workshop__/props.tsx +0 -30
- package/src/core/primitives/badge/__workshop__/tones.tsx +0 -21
- package/src/core/primitives/box/__workshop__/asComponent.tsx +0 -31
- package/src/core/primitives/box/__workshop__/index.ts +0 -24
- package/src/core/primitives/box/__workshop__/props.tsx +0 -20
- package/src/core/primitives/box/__workshop__/responsive.tsx +0 -20
- package/src/core/primitives/button/__workshop__/custom.tsx +0 -51
- package/src/core/primitives/button/__workshop__/customIcons.tsx +0 -30
- package/src/core/primitives/button/__workshop__/disabled.tsx +0 -74
- package/src/core/primitives/button/__workshop__/index.ts +0 -59
- package/src/core/primitives/button/__workshop__/mixedChildren.tsx +0 -12
- package/src/core/primitives/button/__workshop__/props.tsx +0 -55
- package/src/core/primitives/button/__workshop__/sanityUploadButton.tsx +0 -36
- package/src/core/primitives/button/__workshop__/stacked.tsx +0 -58
- package/src/core/primitives/button/__workshop__/styled1.tsx +0 -17
- package/src/core/primitives/button/__workshop__/styled2.tsx +0 -19
- package/src/core/primitives/button/__workshop__/uploadButton.tsx +0 -28
- package/src/core/primitives/card/__workshop__/allTones.tsx +0 -25
- package/src/core/primitives/card/__workshop__/asButton.tsx +0 -107
- package/src/core/primitives/card/__workshop__/asComponent.tsx +0 -27
- package/src/core/primitives/card/__workshop__/checkered.tsx +0 -26
- package/src/core/primitives/card/__workshop__/index.ts +0 -18
- package/src/core/primitives/card/__workshop__/interactive.tsx +0 -30
- package/src/core/primitives/card/__workshop__/listNavigation.tsx +0 -80
- package/src/core/primitives/card/__workshop__/props.tsx +0 -53
- package/src/core/primitives/card/__workshop__/selected.tsx +0 -94
- package/src/core/primitives/card/__workshop__/styled.tsx +0 -14
- package/src/core/primitives/checkbox/__workshop__/example.tsx +0 -25
- package/src/core/primitives/checkbox/__workshop__/index.ts +0 -13
- package/src/core/primitives/checkbox/__workshop__/props.tsx +0 -33
- package/src/core/primitives/checkbox/__workshop__/readOnly.tsx +0 -16
- package/src/core/primitives/checkbox/__workshop__/tones.tsx +0 -28
- package/src/core/primitives/code/__workshop__/index.ts +0 -19
- package/src/core/primitives/code/__workshop__/opticalAlignment.tsx +0 -48
- package/src/core/primitives/code/__workshop__/props.tsx +0 -21
- package/src/core/primitives/container/__workshop__/example.tsx +0 -20
- package/src/core/primitives/container/__workshop__/index.ts +0 -8
- package/src/core/primitives/flex/__workshop__/example.tsx +0 -34
- package/src/core/primitives/flex/__workshop__/gap.tsx +0 -25
- package/src/core/primitives/flex/__workshop__/index.ts +0 -11
- package/src/core/primitives/grid/__workshop__/index.ts +0 -10
- package/src/core/primitives/grid/__workshop__/responsive.tsx +0 -54
- package/src/core/primitives/heading/__workshop__/index.ts +0 -19
- package/src/core/primitives/heading/__workshop__/opticalAlignment.tsx +0 -54
- package/src/core/primitives/heading/__workshop__/plain.tsx +0 -32
- package/src/core/primitives/inline/__workshop__/index.ts +0 -8
- package/src/core/primitives/inline/__workshop__/plain.tsx +0 -27
- package/src/core/primitives/kbd/__workshop__/index.ts +0 -8
- package/src/core/primitives/kbd/__workshop__/plain.tsx +0 -9
- package/src/core/primitives/label/__workshop__/index.ts +0 -19
- package/src/core/primitives/label/__workshop__/opticalAlignment.tsx +0 -48
- package/src/core/primitives/label/__workshop__/plain.tsx +0 -24
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +0 -77
- package/src/core/primitives/popover/__workshop__/MarginsStory.tsx +0 -31
- package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +0 -32
- package/src/core/primitives/popover/__workshop__/OpenOnMountStory.tsx +0 -11
- package/src/core/primitives/popover/__workshop__/PlainStory.tsx +0 -71
- package/src/core/primitives/popover/__workshop__/RecursiveStory.tsx +0 -71
- package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +0 -89
- package/src/core/primitives/popover/__workshop__/TestStory.tsx +0 -97
- package/src/core/primitives/popover/__workshop__/index.ts +0 -49
- package/src/core/primitives/radio/__workshop__/example.tsx +0 -63
- package/src/core/primitives/radio/__workshop__/index.ts +0 -11
- package/src/core/primitives/radio/__workshop__/plain.tsx +0 -28
- package/src/core/primitives/select/__workshop__/index.ts +0 -11
- package/src/core/primitives/select/__workshop__/plain.tsx +0 -27
- package/src/core/primitives/select/__workshop__/readOnly.tsx +0 -23
- package/src/core/primitives/spinner/__workshop__/Props.tsx +0 -15
- package/src/core/primitives/spinner/__workshop__/index.ts +0 -14
- package/src/core/primitives/stack/__workshop__/index.ts +0 -14
- package/src/core/primitives/stack/__workshop__/plain.tsx +0 -32
- package/src/core/primitives/switch/__workshop__/example.tsx +0 -23
- package/src/core/primitives/switch/__workshop__/index.ts +0 -11
- package/src/core/primitives/switch/__workshop__/props.tsx +0 -21
- package/src/core/primitives/text/__workshop__/colored.tsx +0 -30
- package/src/core/primitives/text/__workshop__/example.tsx +0 -39
- package/src/core/primitives/text/__workshop__/index.ts +0 -24
- package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +0 -48
- package/src/core/primitives/textArea/__workshop__/index.ts +0 -14
- package/src/core/primitives/textArea/__workshop__/plain.tsx +0 -50
- package/src/core/primitives/textInput/__workshop__/clearButton.tsx +0 -30
- package/src/core/primitives/textInput/__workshop__/customValidity.tsx +0 -17
- package/src/core/primitives/textInput/__workshop__/index.ts +0 -44
- package/src/core/primitives/textInput/__workshop__/plain.tsx +0 -98
- package/src/core/primitives/textInput/__workshop__/readOnly.tsx +0 -9
- package/src/core/primitives/textInput/__workshop__/states.tsx +0 -53
- package/src/core/primitives/textInput/__workshop__/tones.tsx +0 -277
- package/src/core/primitives/textInput/__workshop__/typed.tsx +0 -23
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +0 -102
- package/src/core/primitives/tooltip/__workshop__/index.ts +0 -29
- package/src/core/primitives/tooltip/__workshop__/overflowingBoundary.tsx +0 -74
- package/src/core/primitives/tooltip/__workshop__/props.tsx +0 -107
- package/src/core/primitives/tooltip/__workshop__/resizableBoundary.tsx +0 -86
- package/src/core/theme/__workshop__/build/Root.tsx +0 -367
- package/src/core/theme/__workshop__/build/helpers.ts +0 -46
- package/src/core/theme/__workshop__/build/story.tsx +0 -465
- package/src/core/theme/__workshop__/canvas.tsx +0 -352
- package/src/core/theme/__workshop__/color.tsx +0 -62
- package/src/core/theme/__workshop__/debug/story.tsx +0 -408
- package/src/core/theme/__workshop__/index.ts +0 -39
- package/src/core/theme/__workshop__/layer.tsx +0 -78
- package/src/core/theme/__workshop__/nestedProvider.tsx +0 -15
- package/src/core/utils/boundaryElement/__workshop__/index.ts +0 -14
- package/src/core/utils/boundaryElement/__workshop__/plain.tsx +0 -19
- package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +0 -30
- package/src/core/utils/elementQuery/__workshop__/index.ts +0 -14
- package/src/core/utils/layer/__workshop__/_debug.tsx +0 -17
- package/src/core/utils/layer/__workshop__/index.ts +0 -24
- package/src/core/utils/layer/__workshop__/multipleRoots.tsx +0 -49
- package/src/core/utils/layer/__workshop__/nested.tsx +0 -98
- package/src/core/utils/layer/__workshop__/responsiveZOffset.tsx +0 -13
- package/src/core/utils/portal/__workshop__/index.ts +0 -14
- package/src/core/utils/portal/__workshop__/named.tsx +0 -63
- package/src/core/utils/virtualList/__workshop__/changingProps.tsx +0 -36
- package/src/core/utils/virtualList/__workshop__/elementScroll.tsx +0 -24
- package/src/core/utils/virtualList/__workshop__/index.ts +0 -29
- package/src/core/utils/virtualList/__workshop__/infiniteList.tsx +0 -48
- package/src/core/utils/virtualList/__workshop__/windowScrolll.tsx +0 -22
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
2
|
|
|
3
3
|
import {render, screen} from '@testing-library/react'
|
|
4
4
|
import userEvent from '@testing-library/user-event'
|
|
5
5
|
import {useEffect, useRef, useState} from 'react'
|
|
6
|
+
import {describe, expect, it, vi} from 'vitest'
|
|
6
7
|
|
|
7
8
|
import {useClickOutside} from './useClickOutside'
|
|
8
9
|
|
|
@@ -16,16 +17,18 @@ describe('useClickOutside', () => {
|
|
|
16
17
|
*/
|
|
17
18
|
it('calls the handler when clicking outside of the array of elements', async () => {
|
|
18
19
|
const user = userEvent.setup()
|
|
19
|
-
const handler =
|
|
20
|
+
const handler = vi.fn()
|
|
20
21
|
|
|
21
22
|
const TestComponent = () => {
|
|
22
23
|
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
23
24
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
24
25
|
|
|
26
|
+
// oxlint-disable-next-line no-deprecated
|
|
25
27
|
useClickOutside(handler, [buttonElement, popoverElement])
|
|
26
28
|
|
|
27
29
|
return (
|
|
28
30
|
<>
|
|
31
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
29
32
|
<button data-testid="button" ref={setButtonElement} />
|
|
30
33
|
<div data-testid="popover" ref={setPopoverElement} />
|
|
31
34
|
<div data-testid="outside" />
|
|
@@ -45,16 +48,18 @@ describe('useClickOutside', () => {
|
|
|
45
48
|
|
|
46
49
|
it('the elements array flattens nested arrays one level deep', async () => {
|
|
47
50
|
const user = userEvent.setup()
|
|
48
|
-
const handler =
|
|
51
|
+
const handler = vi.fn()
|
|
49
52
|
|
|
50
53
|
const TestComponent = () => {
|
|
51
54
|
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
52
55
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
53
56
|
|
|
57
|
+
// oxlint-disable-next-line no-deprecated
|
|
54
58
|
useClickOutside(handler, [null, [null, buttonElement], [popoverElement, null], null])
|
|
55
59
|
|
|
56
60
|
return (
|
|
57
61
|
<>
|
|
62
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
58
63
|
<button data-testid="button" ref={setButtonElement} />
|
|
59
64
|
<div data-testid="popover" ref={setPopoverElement} />
|
|
60
65
|
<div data-testid="outside" />
|
|
@@ -74,18 +79,20 @@ describe('useClickOutside', () => {
|
|
|
74
79
|
|
|
75
80
|
it('it can set a boundary to scope outside click events', async () => {
|
|
76
81
|
const user = userEvent.setup()
|
|
77
|
-
const handler =
|
|
82
|
+
const handler = vi.fn()
|
|
78
83
|
|
|
79
84
|
const TestComponent = () => {
|
|
80
85
|
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
81
86
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
82
87
|
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
|
|
83
88
|
|
|
89
|
+
// oxlint-disable-next-line no-deprecated
|
|
84
90
|
useClickOutside(handler, [buttonElement, popoverElement], boundaryElement)
|
|
85
91
|
|
|
86
92
|
return (
|
|
87
93
|
<>
|
|
88
94
|
<div ref={setBoundaryElement}>
|
|
95
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
89
96
|
<button data-testid="button" ref={setButtonElement} />
|
|
90
97
|
<div data-testid="popover" ref={setPopoverElement} />
|
|
91
98
|
<div data-testid="inside" />
|
|
@@ -114,16 +121,18 @@ describe('useClickOutside', () => {
|
|
|
114
121
|
* Thus it makes sense to unit test it to ensure it works as expected and we don't accidentally break backwards compatibility.
|
|
115
122
|
*/
|
|
116
123
|
const user = userEvent.setup()
|
|
117
|
-
const handler =
|
|
124
|
+
const handler = vi.fn()
|
|
118
125
|
|
|
119
126
|
const TestComponent = (props: {open?: true}) => {
|
|
120
127
|
const {open = false} = props
|
|
121
128
|
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
122
129
|
|
|
130
|
+
// oxlint-disable-next-line no-deprecated
|
|
123
131
|
const setElement = useClickOutside(handler, [buttonElement])
|
|
124
132
|
|
|
125
133
|
return (
|
|
126
134
|
<>
|
|
135
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
127
136
|
<button data-testid="button" ref={setButtonElement} />
|
|
128
137
|
{open && <div data-testid="popover" ref={setElement} />}
|
|
129
138
|
<div data-testid="outside" />
|
|
@@ -155,17 +164,19 @@ describe('useClickOutside', () => {
|
|
|
155
164
|
* Since we don't want people to use the `setElement` pattern, test that userland can handle dynamically changing elements arrays
|
|
156
165
|
*/
|
|
157
166
|
const user = userEvent.setup()
|
|
158
|
-
const handler =
|
|
167
|
+
const handler = vi.fn()
|
|
159
168
|
|
|
160
169
|
const TestComponent = (props: {open?: true}) => {
|
|
161
170
|
const {open = false} = props
|
|
162
171
|
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
163
172
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
164
173
|
|
|
174
|
+
// oxlint-disable-next-line no-deprecated
|
|
165
175
|
useClickOutside(handler, [buttonElement, popoverElement])
|
|
166
176
|
|
|
167
177
|
return (
|
|
168
178
|
<>
|
|
179
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
169
180
|
<button data-testid="button" ref={setButtonElement} />
|
|
170
181
|
{open && <div data-testid="popover" ref={setPopoverElement} />}
|
|
171
182
|
<div data-testid="outside" />
|
|
@@ -199,7 +210,7 @@ describe('useClickOutside', () => {
|
|
|
199
210
|
*/
|
|
200
211
|
|
|
201
212
|
const user = userEvent.setup()
|
|
202
|
-
let handler =
|
|
213
|
+
let handler = vi.fn()
|
|
203
214
|
|
|
204
215
|
/**
|
|
205
216
|
* Using refs in the `useClickOutside` elements array is dangerous,
|
|
@@ -210,10 +221,12 @@ describe('useClickOutside', () => {
|
|
|
210
221
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
211
222
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
212
223
|
|
|
224
|
+
// oxlint-disable-next-line no-deprecated
|
|
213
225
|
useClickOutside(handler, [buttonRef.current, popoverRef.current])
|
|
214
226
|
|
|
215
227
|
return (
|
|
216
228
|
<>
|
|
229
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
217
230
|
<button data-testid="button" ref={buttonRef} />
|
|
218
231
|
<div data-testid="popover" ref={popoverRef} />
|
|
219
232
|
</>
|
|
@@ -229,15 +242,17 @@ describe('useClickOutside', () => {
|
|
|
229
242
|
* If a mixture of refs and state is used it can appear like it's working correctly,
|
|
230
243
|
* but this is a side-effect, not an indication it's safe.
|
|
231
244
|
*/
|
|
232
|
-
handler =
|
|
245
|
+
handler = vi.fn()
|
|
233
246
|
TestComponent = () => {
|
|
234
247
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
235
248
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
236
249
|
|
|
250
|
+
// oxlint-disable-next-line no-deprecated
|
|
237
251
|
useClickOutside(handler, [buttonRef.current, popoverElement])
|
|
238
252
|
|
|
239
253
|
return (
|
|
240
254
|
<>
|
|
255
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
241
256
|
<button data-testid="button" ref={buttonRef} />
|
|
242
257
|
<div data-testid="popover" ref={setPopoverElement} />
|
|
243
258
|
<div data-testid="outside" />
|
|
@@ -254,11 +269,12 @@ describe('useClickOutside', () => {
|
|
|
254
269
|
/**
|
|
255
270
|
* Unrelated state updates can create the same false impression of safety.
|
|
256
271
|
*/
|
|
257
|
-
handler =
|
|
272
|
+
handler = vi.fn()
|
|
258
273
|
TestComponent = () => {
|
|
259
274
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
260
275
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
261
276
|
|
|
277
|
+
// oxlint-disable-next-line no-deprecated
|
|
262
278
|
useClickOutside(handler, [buttonRef.current, popoverRef.current])
|
|
263
279
|
|
|
264
280
|
const [, tick] = useState(0)
|
|
@@ -272,6 +288,7 @@ describe('useClickOutside', () => {
|
|
|
272
288
|
|
|
273
289
|
return (
|
|
274
290
|
<>
|
|
291
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
275
292
|
<button data-testid="button" ref={buttonRef} />
|
|
276
293
|
<div data-testid="popover" ref={popoverRef} />
|
|
277
294
|
<div data-testid="outside" />
|
|
@@ -289,6 +306,7 @@ describe('useClickOutside', () => {
|
|
|
289
306
|
* When using the legacy version of the `useClickOutside` API it's necessary to synchronize mutable ref values
|
|
290
307
|
* with a effect and state loop to ensure they're not stale
|
|
291
308
|
*/
|
|
309
|
+
// oxlint-disable-next-line no-deprecated
|
|
292
310
|
const useElementsFromRefs = (refs: React.MutableRefObject<HTMLElement | null>[]) => {
|
|
293
311
|
const [elements, setElements] = useState(() => refs.map((ref) => ref.current))
|
|
294
312
|
|
|
@@ -306,16 +324,18 @@ describe('useClickOutside', () => {
|
|
|
306
324
|
|
|
307
325
|
return elements
|
|
308
326
|
}
|
|
309
|
-
handler =
|
|
327
|
+
handler = vi.fn()
|
|
310
328
|
TestComponent = () => {
|
|
311
329
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
312
330
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
313
331
|
|
|
314
332
|
const elements = useElementsFromRefs([buttonRef, popoverRef])
|
|
333
|
+
// oxlint-disable-next-line no-deprecated
|
|
315
334
|
useClickOutside(handler, elements)
|
|
316
335
|
|
|
317
336
|
return (
|
|
318
337
|
<>
|
|
338
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
319
339
|
<button data-testid="button" ref={buttonRef} />
|
|
320
340
|
<div data-testid="popover" ref={popoverRef} />
|
|
321
341
|
<div data-testid="outside" />
|
|
@@ -337,7 +357,7 @@ describe('useClickOutside', () => {
|
|
|
337
357
|
*/
|
|
338
358
|
|
|
339
359
|
const user = userEvent.setup()
|
|
340
|
-
let handler =
|
|
360
|
+
let handler = vi.fn()
|
|
341
361
|
|
|
342
362
|
/**
|
|
343
363
|
* Using refs in the `useClickOutside` elements array is dangerous,
|
|
@@ -347,6 +367,7 @@ describe('useClickOutside', () => {
|
|
|
347
367
|
let TestComponent = () => {
|
|
348
368
|
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
349
369
|
|
|
370
|
+
// oxlint-disable-next-line no-deprecated
|
|
350
371
|
useClickOutside(handler, [], boundaryRef.current)
|
|
351
372
|
|
|
352
373
|
return (
|
|
@@ -368,17 +389,19 @@ describe('useClickOutside', () => {
|
|
|
368
389
|
* If a mixture of refs and state is used it can appear like it's working correctly,
|
|
369
390
|
* but this is a side-effect, not an indication it's safe.
|
|
370
391
|
*/
|
|
371
|
-
handler =
|
|
392
|
+
handler = vi.fn()
|
|
372
393
|
TestComponent = () => {
|
|
373
394
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
374
395
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
375
396
|
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
376
397
|
|
|
398
|
+
// oxlint-disable-next-line no-deprecated
|
|
377
399
|
useClickOutside(handler, [buttonRef.current, popoverElement], boundaryRef.current)
|
|
378
400
|
|
|
379
401
|
return (
|
|
380
402
|
<>
|
|
381
403
|
<div ref={boundaryRef}>
|
|
404
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
382
405
|
<button data-testid="button" ref={buttonRef} />
|
|
383
406
|
<div data-testid="popover" ref={setPopoverElement} />
|
|
384
407
|
<div data-testid="inside" />
|
|
@@ -398,12 +421,13 @@ describe('useClickOutside', () => {
|
|
|
398
421
|
/**
|
|
399
422
|
* Unrelated state updates can create the same false impression of safety.
|
|
400
423
|
*/
|
|
401
|
-
handler =
|
|
424
|
+
handler = vi.fn()
|
|
402
425
|
TestComponent = () => {
|
|
403
426
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
404
427
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
405
428
|
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
406
429
|
|
|
430
|
+
// oxlint-disable-next-line no-deprecated
|
|
407
431
|
useClickOutside(handler, [buttonRef.current, popoverRef.current], boundaryRef.current)
|
|
408
432
|
|
|
409
433
|
const [, tick] = useState(0)
|
|
@@ -418,6 +442,7 @@ describe('useClickOutside', () => {
|
|
|
418
442
|
return (
|
|
419
443
|
<>
|
|
420
444
|
<div ref={boundaryRef}>
|
|
445
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
421
446
|
<button data-testid="button" ref={buttonRef} />
|
|
422
447
|
<div data-testid="popover" ref={popoverRef} />
|
|
423
448
|
<div data-testid="inside" />
|
|
@@ -438,10 +463,11 @@ describe('useClickOutside', () => {
|
|
|
438
463
|
* When using the legacy version of the `useClickOutside` API it's necessary to synchronize mutable ref values
|
|
439
464
|
* with a effect and state loop to ensure they're not stale
|
|
440
465
|
*/
|
|
466
|
+
// oxlint-disable-next-line no-deprecated
|
|
441
467
|
const useBoundaryElementFromRef = (ref: React.MutableRefObject<HTMLElement | null>) => {
|
|
442
468
|
const [element, setElement] = useState(() => ref.current)
|
|
443
469
|
|
|
444
|
-
//
|
|
470
|
+
// oxlint-disable-next-line exhaustive-deps
|
|
445
471
|
useEffect(() => {
|
|
446
472
|
// If the ref has mutated since the last render, update the state and schedule a re-render
|
|
447
473
|
if (ref.current !== element) {
|
|
@@ -451,18 +477,20 @@ describe('useClickOutside', () => {
|
|
|
451
477
|
|
|
452
478
|
return element
|
|
453
479
|
}
|
|
454
|
-
handler =
|
|
480
|
+
handler = vi.fn()
|
|
455
481
|
TestComponent = () => {
|
|
456
482
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
457
483
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
458
484
|
const boundaryRef = useRef<HTMLDivElement | null>(null)
|
|
459
485
|
|
|
460
486
|
const boundaryElement = useBoundaryElementFromRef(boundaryRef)
|
|
487
|
+
// oxlint-disable-next-line no-deprecated
|
|
461
488
|
useClickOutside(handler, [buttonRef.current, popoverRef.current], boundaryElement)
|
|
462
489
|
|
|
463
490
|
return (
|
|
464
491
|
<>
|
|
465
492
|
<div ref={boundaryRef}>
|
|
493
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
466
494
|
<button data-testid="button" ref={buttonRef} />
|
|
467
495
|
<div data-testid="popover" ref={popoverRef} />
|
|
468
496
|
<div data-testid="inside" />
|
|
@@ -26,6 +26,7 @@ function _getElements(
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
29
30
|
return ret.filter(Boolean) as HTMLElement[]
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -58,7 +59,6 @@ export function useClickOutside(
|
|
|
58
59
|
const nextElements = _getElements(element, elementsArg)
|
|
59
60
|
|
|
60
61
|
if (prevElements.length !== nextElements.length) {
|
|
61
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
62
62
|
setElements(nextElements)
|
|
63
63
|
elementsRef.current = nextElements
|
|
64
64
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
2
|
|
|
3
3
|
import {render, screen} from '@testing-library/react'
|
|
4
4
|
import userEvent from '@testing-library/user-event'
|
|
5
5
|
import {useRef} from 'react'
|
|
6
|
+
import {describe, expect, it, vi} from 'vitest'
|
|
6
7
|
|
|
7
8
|
import {useClickOutsideEvent} from './useClickOutsideEvent'
|
|
8
9
|
|
|
@@ -13,7 +14,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
13
14
|
|
|
14
15
|
it('calls the handler when clicking outside of the array of elements', async () => {
|
|
15
16
|
const user = userEvent.setup()
|
|
16
|
-
const handler =
|
|
17
|
+
const handler = vi.fn()
|
|
17
18
|
|
|
18
19
|
const TestComponent = () => {
|
|
19
20
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
@@ -23,6 +24,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
23
24
|
|
|
24
25
|
return (
|
|
25
26
|
<>
|
|
27
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
26
28
|
<button data-testid="button" ref={buttonRef} />
|
|
27
29
|
<div data-testid="popover" ref={popoverRef} />
|
|
28
30
|
<div data-testid="outside" />
|
|
@@ -42,7 +44,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
42
44
|
|
|
43
45
|
it('the elements array flattens nested arrays one level deep', async () => {
|
|
44
46
|
const user = userEvent.setup()
|
|
45
|
-
const handler =
|
|
47
|
+
const handler = vi.fn()
|
|
46
48
|
|
|
47
49
|
const TestComponent = () => {
|
|
48
50
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
@@ -57,6 +59,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
57
59
|
|
|
58
60
|
return (
|
|
59
61
|
<>
|
|
62
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
60
63
|
<button data-testid="button" ref={buttonRef} />
|
|
61
64
|
<div data-testid="popover" ref={popoverRef} />
|
|
62
65
|
<div data-testid="outside" />
|
|
@@ -76,7 +79,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
76
79
|
|
|
77
80
|
it('it can set a boundary to scope outside click events', async () => {
|
|
78
81
|
const user = userEvent.setup()
|
|
79
|
-
const handler =
|
|
82
|
+
const handler = vi.fn()
|
|
80
83
|
|
|
81
84
|
const TestComponent = () => {
|
|
82
85
|
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
@@ -92,6 +95,7 @@ describe('useClickOutsideEvent', () => {
|
|
|
92
95
|
return (
|
|
93
96
|
<>
|
|
94
97
|
<div ref={boundaryRef}>
|
|
98
|
+
{/* oxlint-disable-next-line control-has-associated-label */}
|
|
95
99
|
<button data-testid="button" ref={buttonRef} />
|
|
96
100
|
<div data-testid="popover" ref={popoverRef} />
|
|
97
101
|
<div data-testid="inside" />
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
2
|
|
|
3
3
|
import {act, renderHook} from '@testing-library/react'
|
|
4
|
+
import {describe, expect, it, vi} from 'vitest'
|
|
4
5
|
|
|
5
6
|
import {useDelayedState} from './useDelayedState'
|
|
6
7
|
|
|
@@ -16,7 +17,7 @@ describe('useDelayedState', () => {
|
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
it('should update state after delay if delay is provided', async () => {
|
|
19
|
-
|
|
20
|
+
vi.useFakeTimers()
|
|
20
21
|
const {result} = renderHook(() => useDelayedState(false))
|
|
21
22
|
const [, setState] = result.current
|
|
22
23
|
|
|
@@ -25,12 +26,12 @@ describe('useDelayedState', () => {
|
|
|
25
26
|
})
|
|
26
27
|
expect(result.current[0]).toBe(false)
|
|
27
28
|
act(() => {
|
|
28
|
-
|
|
29
|
+
vi.advanceTimersByTime(500)
|
|
29
30
|
})
|
|
30
31
|
expect(result.current[0]).toBe(false)
|
|
31
32
|
|
|
32
33
|
act(() => {
|
|
33
|
-
|
|
34
|
+
vi.advanceTimersByTime(500)
|
|
34
35
|
})
|
|
35
36
|
|
|
36
37
|
expect(result.current[0]).toBe(true)
|
|
@@ -48,8 +49,8 @@ describe('useDelayedState', () => {
|
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
it('should clear pending timeout on unmount', () => {
|
|
51
|
-
|
|
52
|
-
const clearTimeoutSpy =
|
|
52
|
+
vi.useFakeTimers()
|
|
53
|
+
const clearTimeoutSpy = vi.spyOn(global, 'clearTimeout')
|
|
53
54
|
const {result, unmount} = renderHook(() => useDelayedState(false))
|
|
54
55
|
const [, setState] = result.current
|
|
55
56
|
|
|
@@ -76,12 +77,12 @@ describe('useDelayedState', () => {
|
|
|
76
77
|
})
|
|
77
78
|
expect(result.current[0]).toBe(false)
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
vi.advanceTimersByTime(500)
|
|
80
81
|
|
|
81
82
|
act(() => {
|
|
82
83
|
setState(false)
|
|
83
84
|
})
|
|
84
|
-
|
|
85
|
+
vi.advanceTimersByTime(600)
|
|
85
86
|
// Even after 1.1 seconds, the state should continue being false, because it was cancelled by a next setState call
|
|
86
87
|
expect(result.current[0]).toBe(false)
|
|
87
88
|
})
|
|
@@ -9,5 +9,6 @@ import {useElementSize} from '../useElementSize'
|
|
|
9
9
|
export function useElementRect(element: HTMLElement | null): DOMRectReadOnly | null {
|
|
10
10
|
const elementSize = useElementSize(element)
|
|
11
11
|
|
|
12
|
+
// oxlint-disable-next-line no-deprecated
|
|
12
13
|
return elementSize?._contentRect || null
|
|
13
14
|
}
|
|
@@ -10,6 +10,7 @@ import {useImperativeHandle, useRef} from 'react'
|
|
|
10
10
|
* +useImperativeHandle(forwardedRef, () => ref.current)
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
+
// oxlint-disable-next-line no-deprecated
|
|
13
14
|
export function useForwardedRef<T>(ref: React.ForwardedRef<T>): React.MutableRefObject<T | null> {
|
|
14
15
|
const innerRef = useRef<T | null>(null)
|
|
15
16
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment node */
|
|
2
2
|
|
|
3
3
|
import {buildTheme} from '@sanity/ui/theme'
|
|
4
4
|
import {renderToStaticMarkup, renderToString} from 'react-dom/server'
|
|
5
|
+
import {describe, expect, it} from 'vitest'
|
|
5
6
|
|
|
6
7
|
import {ThemeProvider} from '../../theme'
|
|
7
8
|
import {useMediaIndex} from './useMediaIndex'
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* As this hook is used for top-level theming it's likely to be called while server-rendering
|
|
4
5
|
* and that's why it's worth it to have a testing suite for hydration
|
|
5
6
|
*/
|
|
6
7
|
import {waitFor} from '@testing-library/dom'
|
|
7
8
|
import {hydrateRoot} from 'react-dom/client'
|
|
9
|
+
import {afterAll, beforeAll, describe, expect, it, vi} from 'vitest'
|
|
8
10
|
|
|
9
11
|
import {usePrefersDark} from './usePrefersDark'
|
|
10
12
|
|
|
@@ -19,9 +21,10 @@ const originalMatchMedia = window.matchMedia
|
|
|
19
21
|
describe('usePrefersDark SSR hydration', () => {
|
|
20
22
|
beforeAll(() => {
|
|
21
23
|
window.matchMedia = () =>
|
|
24
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
22
25
|
({
|
|
23
|
-
addEventListener:
|
|
24
|
-
removeEventListener:
|
|
26
|
+
addEventListener: vi.fn(),
|
|
27
|
+
removeEventListener: vi.fn(),
|
|
25
28
|
matches: true,
|
|
26
29
|
}) as any
|
|
27
30
|
})
|
|
@@ -31,7 +34,7 @@ describe('usePrefersDark SSR hydration', () => {
|
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
it(`hydrates without any warnings`, async () => {
|
|
34
|
-
const spy =
|
|
37
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
35
38
|
|
|
36
39
|
const node = document.createElement('div')
|
|
37
40
|
|
|
@@ -47,7 +50,6 @@ describe('usePrefersDark SSR hydration', () => {
|
|
|
47
50
|
// After hydration it should switch to true
|
|
48
51
|
await waitFor(() => expect(node.innerHTML).toBe('dark: <!-- -->true'))
|
|
49
52
|
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
53
|
expect(console.error).not.toHaveBeenCalled()
|
|
52
54
|
|
|
53
55
|
spy.mockReset()
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* As this hook is used for top-level theming it's likely to be called while server-rendering
|
|
4
5
|
* and that's why it's worth it to have a testing suite for hydration
|
|
5
6
|
*/
|
|
6
7
|
import {waitFor} from '@testing-library/dom'
|
|
7
8
|
import {hydrateRoot} from 'react-dom/client'
|
|
9
|
+
import {afterAll, beforeAll, describe, expect, it, vi} from 'vitest'
|
|
8
10
|
|
|
9
11
|
import {usePrefersReducedMotion} from './usePrefersReducedMotion'
|
|
10
12
|
|
|
@@ -19,9 +21,10 @@ const originalMatchMedia = window.matchMedia
|
|
|
19
21
|
describe('usePrefersReducedMotion SSR hydration', () => {
|
|
20
22
|
beforeAll(() => {
|
|
21
23
|
window.matchMedia = () =>
|
|
24
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
22
25
|
({
|
|
23
|
-
addEventListener:
|
|
24
|
-
removeEventListener:
|
|
26
|
+
addEventListener: vi.fn(),
|
|
27
|
+
removeEventListener: vi.fn(),
|
|
25
28
|
matches: true,
|
|
26
29
|
}) as any
|
|
27
30
|
})
|
|
@@ -31,7 +34,7 @@ describe('usePrefersReducedMotion SSR hydration', () => {
|
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
it(`hydrates without any warnings`, async () => {
|
|
34
|
-
const spy =
|
|
37
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
35
38
|
|
|
36
39
|
const node = document.createElement('div')
|
|
37
40
|
|
|
@@ -47,7 +50,6 @@ describe('usePrefersReducedMotion SSR hydration', () => {
|
|
|
47
50
|
// After hydration it should switch to true
|
|
48
51
|
await waitFor(() => expect(node.innerHTML).toBe('prefers-motion: <!-- -->true'))
|
|
49
52
|
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
53
|
expect(console.error).not.toHaveBeenCalled()
|
|
52
54
|
|
|
53
55
|
spy.mockReset()
|
|
@@ -12,6 +12,7 @@ import {type Context, createContext} from 'react'
|
|
|
12
12
|
|
|
13
13
|
import {globalScope} from './globalScope'
|
|
14
14
|
|
|
15
|
+
// oxlint-disable-next-line no-unnecessary-type-parameters
|
|
15
16
|
export function createGlobalScopedContext<ContextType, const T extends ContextType = ContextType>(
|
|
16
17
|
/**
|
|
17
18
|
* Enforce that all Symbol.for keys used for globally scoped contexts have a predictable prefix
|
|
@@ -50,6 +50,7 @@ function _createElementRectValueListener(): _ElementSizeListener {
|
|
|
50
50
|
subscribe(element, subscriber) {
|
|
51
51
|
const resizeObserver = new _ResizeObserver(([entry]) => {
|
|
52
52
|
subscriber({
|
|
53
|
+
// oxlint-disable-next-line no-deprecated
|
|
53
54
|
_contentRect: entry.contentRect,
|
|
54
55
|
border: {
|
|
55
56
|
width: entry.borderBoxSize[0].inlineSize,
|
|
@@ -76,7 +76,6 @@ const AvatarComponent = forwardRef(function Avatar(
|
|
|
76
76
|
const as = ReactIs.isValidElementType(asProp) ? asProp : 'div'
|
|
77
77
|
const size = _getArrayProp(sizeProp)
|
|
78
78
|
|
|
79
|
-
// eslint-disable-next-line no-warning-comments
|
|
80
79
|
// @todo: remove this
|
|
81
80
|
const avatarSize = avatar.sizes[size[0]] || avatar.sizes[0]
|
|
82
81
|
const _sizeRem = avatarSize.size
|
|
@@ -101,7 +100,7 @@ const AvatarComponent = forwardRef(function Avatar(
|
|
|
101
100
|
}, [arrowPosition, arrowPositionProp])
|
|
102
101
|
|
|
103
102
|
useEffect(() => {
|
|
104
|
-
//
|
|
103
|
+
// oxlint-disable-next-line react-compiler
|
|
105
104
|
if (src) setImageFailed(false)
|
|
106
105
|
}, [src])
|
|
107
106
|
|
|
@@ -195,6 +194,7 @@ AvatarComponent.displayName = 'ForwardRef(Avatar)'
|
|
|
195
194
|
*
|
|
196
195
|
* @public
|
|
197
196
|
*/
|
|
197
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
198
198
|
export const Avatar = AvatarComponent as unknown as <E extends ElementType = 'div'>(
|
|
199
199
|
props: AvatarProps<E>,
|
|
200
200
|
) => React.JSX.Element
|
|
@@ -92,6 +92,7 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
92
92
|
)}
|
|
93
93
|
|
|
94
94
|
{visibleChildren.map((child, childIndex) => (
|
|
95
|
+
// oxlint-disable-next-line no-array-index-key
|
|
95
96
|
<div key={String(childIndex)}>{cloneElement(child, {size})}</div>
|
|
96
97
|
))}
|
|
97
98
|
</StyledAvatarStack>
|
|
@@ -16,6 +16,7 @@ import {BadgeStyleProps} from './types'
|
|
|
16
16
|
export interface BadgeOwnProps extends BoxOwnProps, ResponsiveRadiusProps {
|
|
17
17
|
fontSize?: number | number[]
|
|
18
18
|
/** @deprecated No longer used. */
|
|
19
|
+
// oxlint-disable-next-line no-deprecated
|
|
19
20
|
mode?: BadgeMode
|
|
20
21
|
tone?: BadgeTone
|
|
21
22
|
}
|
|
@@ -37,7 +38,7 @@ const BadgeComponent = forwardRef(function Badge(
|
|
|
37
38
|
const {
|
|
38
39
|
children,
|
|
39
40
|
fontSize = 1,
|
|
40
|
-
//
|
|
41
|
+
// oxlint-disable-next-line no-deprecated
|
|
41
42
|
mode: _deprecated_mode,
|
|
42
43
|
padding = 1,
|
|
43
44
|
radius = 'full',
|
|
@@ -65,6 +66,7 @@ BadgeComponent.displayName = 'ForwardRef(Badge)'
|
|
|
65
66
|
*
|
|
66
67
|
* @public
|
|
67
68
|
*/
|
|
69
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
68
70
|
export const Badge = BadgeComponent as unknown as <E extends ElementType = 'div'>(
|
|
69
71
|
props: BadgeProps<E>,
|
|
70
72
|
) => React.JSX.Element
|