@sanity/ui 4.0.0-beta.8 → 4.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +21 -7
- package/dist/_chunks/getScopedTheme.cjs +4043 -0
- package/dist/_chunks/getScopedTheme.cjs.map +1 -0
- package/dist/_chunks/getScopedTheme.js +3803 -0
- package/dist/_chunks/getScopedTheme.js.map +1 -0
- package/dist/_chunks/refractor.cjs +18 -0
- package/dist/_chunks/refractor.cjs.map +1 -0
- package/dist/_chunks/refractor.js +20 -0
- package/dist/_chunks/refractor.js.map +1 -0
- package/dist/_chunks/rgba.d.cts +929 -0
- package/dist/_chunks/rgba.d.cts.map +1 -0
- package/dist/_chunks/rgba.d.ts +929 -0
- package/dist/_chunks/rgba.d.ts.map +1 -0
- package/dist/index.cjs +6243 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2332 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1767 -1190
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6134 -4725
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs +54 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +278 -0
- package/dist/theme.d.cts.map +1 -0
- package/dist/theme.d.ts +278 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +53 -0
- package/dist/theme.js.map +1 -0
- package/package.json +55 -86
- package/dist/_chunks-es/Syntax.js +0 -23
- package/dist/_chunks-es/Syntax.js.map +0 -1
- package/dist/index.css +0 -1
- package/exports/index.css +0 -1
- package/exports/index.ts +0 -125
- package/src/components/autocomplete/Autocomplete.tsx +0 -665
- package/src/components/autocomplete/AutocompleteOption.tsx +0 -42
- package/src/components/autocomplete/__workshop__/Async.tsx +0 -162
- package/src/components/autocomplete/__workshop__/ConstrainedHeight.tsx +0 -121
- package/src/components/autocomplete/__workshop__/Custom.tsx +0 -91
- package/src/components/autocomplete/__workshop__/Example.tsx +0 -70
- package/src/components/autocomplete/__workshop__/FocusAndBlur.tsx +0 -39
- package/src/components/autocomplete/__workshop__/Fullscreen.tsx +0 -307
- package/src/components/autocomplete/__workshop__/index.ts +0 -41
- package/src/components/autocomplete/__workshop__/mock/apiStore.ts +0 -49
- package/src/components/autocomplete/__workshop__/mock/countries.ts +0 -245
- package/src/components/autocomplete/__workshop__/types.ts +0 -4
- package/src/components/autocomplete/autocompleteReducer.ts +0 -47
- package/src/components/autocomplete/constants.ts +0 -28
- package/src/components/autocomplete/types.ts +0 -103
- package/src/components/breadcrumbs/Breadcrumbs.tsx +0 -163
- package/src/components/breadcrumbs/__workshop__/Example.tsx +0 -48
- package/src/components/breadcrumbs/__workshop__/index.ts +0 -16
- package/src/components/dialog/Dialog.tsx +0 -230
- package/src/components/dialog/DialogCard.tsx +0 -233
- package/src/components/dialog/DialogContext.ts +0 -21
- package/src/components/dialog/DialogProvider.tsx +0 -34
- package/src/components/dialog/__workshop__/Activate.tsx +0 -141
- package/src/components/dialog/__workshop__/AutoFocus.tsx +0 -29
- package/src/components/dialog/__workshop__/Layering.tsx +0 -41
- package/src/components/dialog/__workshop__/Nested.tsx +0 -71
- package/src/components/dialog/__workshop__/OnScroll.tsx +0 -51
- package/src/components/dialog/__workshop__/Panes.tsx +0 -75
- package/src/components/dialog/__workshop__/Position.tsx +0 -30
- package/src/components/dialog/__workshop__/Props.tsx +0 -93
- package/src/components/dialog/__workshop__/Provider.tsx +0 -11
- package/src/components/dialog/__workshop__/Wrapped.tsx +0 -76
- package/src/components/dialog/__workshop__/index.ts +0 -21
- package/src/components/dialog/isTargetWithinScope.ts +0 -14
- package/src/components/dialog/types.ts +0 -2
- package/src/components/dialog/useDialog.ts +0 -11
- package/src/components/hotkeys/Hotkeys.tsx +0 -70
- package/src/components/hotkeys/__workshop__/Plain.tsx +0 -9
- package/src/components/hotkeys/__workshop__/index.ts +0 -16
- package/src/components/menu/Menu.test.tsx +0 -125
- package/src/components/menu/Menu.tsx +0 -174
- package/src/components/menu/MenuButton.tsx +0 -231
- package/src/components/menu/MenuContext.ts +0 -19
- package/src/components/menu/MenuDivider.tsx +0 -32
- package/src/components/menu/MenuGroup.tsx +0 -240
- package/src/components/menu/MenuItem.tsx +0 -153
- package/src/components/menu/__workshop__/AsComponent.tsx +0 -45
- package/src/components/menu/__workshop__/AvatarMenu.tsx +0 -36
- package/src/components/menu/__workshop__/ClosableMenuButton.tsx +0 -47
- package/src/components/menu/__workshop__/ConstrainedInBoundary.tsx +0 -133
- package/src/components/menu/__workshop__/CustomMenuItem.tsx +0 -47
- package/src/components/menu/__workshop__/CustomSelectedState.tsx +0 -35
- package/src/components/menu/__workshop__/DataProps.tsx +0 -27
- package/src/components/menu/__workshop__/DisableFocusOnClose.tsx +0 -40
- package/src/components/menu/__workshop__/Groups.tsx +0 -164
- package/src/components/menu/__workshop__/MenuButton.tsx +0 -79
- package/src/components/menu/__workshop__/MenuGroupRight.tsx +0 -73
- package/src/components/menu/__workshop__/NestedMenu.tsx +0 -22
- package/src/components/menu/__workshop__/OnCloseMenuButton.tsx +0 -50
- package/src/components/menu/__workshop__/SelectedItem.tsx +0 -69
- package/src/components/menu/__workshop__/ShouldFocus.tsx +0 -42
- package/src/components/menu/__workshop__/Tones.tsx +0 -19
- package/src/components/menu/__workshop__/index.ts +0 -91
- package/src/components/menu/helpers.ts +0 -82
- package/src/components/menu/useMenu.ts +0 -21
- package/src/components/menu/useMenuController.ts +0 -245
- package/src/components/tab/Tab.tsx +0 -135
- package/src/components/tab/TabList.tsx +0 -157
- package/src/components/tab/TabListContext.ts +0 -10
- package/src/components/tab/TabPanel.tsx +0 -94
- package/src/components/tab/__workshop__/Example.tsx +0 -135
- package/src/components/tab/__workshop__/index.ts +0 -16
- package/src/components/tab/types.ts +0 -11
- package/src/components/toast/Toast.test.tsx +0 -103
- package/src/components/toast/Toast.tsx +0 -191
- package/src/components/toast/ToastContext.ts +0 -7
- package/src/components/toast/ToastLayer.tsx +0 -54
- package/src/components/toast/ToastProvider.tsx +0 -127
- package/src/components/toast/__workshop__/Hook.tsx +0 -71
- package/src/components/toast/__workshop__/Toast.tsx +0 -26
- package/src/components/toast/__workshop__/index.ts +0 -21
- package/src/components/toast/toastState.ts +0 -6
- package/src/components/toast/types.ts +0 -24
- package/src/components/toast/useToast.ts +0 -23
- package/src/components/tree/Tree.tsx +0 -248
- package/src/components/tree/TreeContext.ts +0 -10
- package/src/components/tree/TreeGroup.tsx +0 -46
- package/src/components/tree/TreeItem.tsx +0 -236
- package/src/components/tree/__workshop__/Basic.tsx +0 -108
- package/src/components/tree/__workshop__/TabFromElement.tsx +0 -84
- package/src/components/tree/__workshop__/basic.perf.ts +0 -19
- package/src/components/tree/__workshop__/index.ts +0 -23
- package/src/components/tree/helpers.ts +0 -105
- package/src/components/tree/types.ts +0 -24
- package/src/components/tree/useTree.ts +0 -17
- package/src/components/virtualList/VirtualList.tsx +0 -254
- package/src/components/virtualList/__workshop__/ChangingProps.tsx +0 -41
- package/src/components/virtualList/__workshop__/ElementScroll.tsx +0 -43
- package/src/components/virtualList/__workshop__/InfiniteList.tsx +0 -40
- package/src/components/virtualList/__workshop__/WindowScrolll.tsx +0 -23
- package/src/components/virtualList/__workshop__/index.ts +0 -31
- package/src/core/_keys.ts +0 -26
- package/src/core/constants.ts +0 -67
- package/src/core/getElementRef.ts +0 -29
- package/src/core/helpers/animation.ts +0 -26
- package/src/core/helpers/element.ts +0 -55
- package/src/core/helpers/focus.ts +0 -92
- package/src/core/helpers/props.ts +0 -51
- package/src/core/helpers/scroll.ts +0 -15
- package/src/core/lib/createGlobalScopedContext.ts +0 -39
- package/src/core/lib/globalScope.ts +0 -19
- package/src/core/lib/isArray.ts +0 -3
- package/src/core/lib/isRecord.ts +0 -3
- package/src/core/types.ts +0 -57
- package/src/hooks/useClickOutsideEvent.test.tsx +0 -114
- package/src/hooks/useClickOutsideEvent.ts +0 -66
- package/src/hooks/useCustomValidity.ts +0 -13
- package/src/hooks/useElementSize.ts +0 -19
- package/src/hooks/useGlobalKeyDown.ts +0 -23
- package/src/hooks/useMatchMedia.ts +0 -28
- package/src/hooks/useMediaIndex/__workshop__/Test.tsx +0 -14
- package/src/hooks/useMediaIndex/__workshop__/index.ts +0 -16
- package/src/hooks/useMediaIndex/useMediaIndex.test.tsx +0 -21
- package/src/hooks/useMediaIndex/useMediaIndex.ts +0 -111
- package/src/hooks/useMounted.ts +0 -15
- package/src/hooks/usePrefersDark.hydration.test.tsx +0 -56
- package/src/hooks/usePrefersDark.test.tsx +0 -20
- package/src/hooks/usePrefersDark.ts +0 -16
- package/src/hooks/usePrefersReducedMotion.hydration.test.tsx +0 -56
- package/src/hooks/usePrefersReducedMotion.test.tsx +0 -20
- package/src/hooks/usePrefersReducedMotion.ts +0 -16
- package/src/hooks/useResponsiveProp.ts +0 -14
- package/src/hooks/useUnique.ts +0 -54
- package/src/middleware/origin.ts +0 -47
- package/src/observers/elementSize.ts +0 -114
- package/src/primitives/_syntax/LazySyntax.tsx +0 -4
- package/src/primitives/_syntax/Syntax.tsx +0 -26
- package/src/primitives/avatar/Avatar.tsx +0 -145
- package/src/primitives/avatar/AvatarCounter.tsx +0 -69
- package/src/primitives/avatar/AvatarStack.tsx +0 -77
- package/src/primitives/avatar/__workshop__/AsButton.tsx +0 -12
- package/src/primitives/avatar/__workshop__/PropsStory.tsx +0 -24
- package/src/primitives/avatar/__workshop__/Stack.tsx +0 -27
- package/src/primitives/avatar/__workshop__/WithinButton.tsx +0 -51
- package/src/primitives/avatar/__workshop__/WithinMenuItem.tsx +0 -52
- package/src/primitives/avatar/__workshop__/index.ts +0 -36
- package/src/primitives/avatar/types.ts +0 -2
- package/src/primitives/badge/Badge.test.tsx +0 -16
- package/src/primitives/badge/Badge.tsx +0 -53
- package/src/primitives/badge/__workshop__/Props.tsx +0 -27
- package/src/primitives/badge/__workshop__/Tones.tsx +0 -15
- package/src/primitives/badge/__workshop__/index.ts +0 -26
- package/src/primitives/badge/__workshop__/within-button.tsx +0 -36
- package/src/primitives/box/Box.tsx +0 -73
- package/src/primitives/box/__workshop__/Props.tsx +0 -26
- package/src/primitives/box/__workshop__/Responsive.tsx +0 -19
- package/src/primitives/box/__workshop__/index.ts +0 -21
- package/src/primitives/button/Button.test.tsx +0 -30
- package/src/primitives/button/Button.tsx +0 -148
- package/src/primitives/button/__workshop__/Custom.tsx +0 -39
- package/src/primitives/button/__workshop__/CustomIcons.tsx +0 -37
- package/src/primitives/button/__workshop__/DataProps.tsx +0 -18
- package/src/primitives/button/__workshop__/Disabled.tsx +0 -43
- package/src/primitives/button/__workshop__/MixedChildren.tsx +0 -12
- package/src/primitives/button/__workshop__/Props.tsx +0 -60
- package/src/primitives/button/__workshop__/Stacked.tsx +0 -60
- package/src/primitives/button/__workshop__/Styled1.css.ts +0 -7
- package/src/primitives/button/__workshop__/Styled1.tsx +0 -11
- package/src/primitives/button/__workshop__/TextOverflow.tsx +0 -17
- package/src/primitives/button/__workshop__/UploadButton.tsx +0 -28
- package/src/primitives/button/__workshop__/index.ts +0 -61
- package/src/primitives/button/types.ts +0 -2
- package/src/primitives/card/Card.tsx +0 -124
- package/src/primitives/card/CardContext.ts +0 -10
- package/src/primitives/card/CardInternalContext.ts +0 -10
- package/src/primitives/card/CardInternalProvider.tsx +0 -15
- package/src/primitives/card/CardProvider.tsx +0 -16
- package/src/primitives/card/__workshop__/AsButton.tsx +0 -103
- package/src/primitives/card/__workshop__/AsComponent.tsx +0 -25
- package/src/primitives/card/__workshop__/Checkered.tsx +0 -25
- package/src/primitives/card/__workshop__/DataProps.tsx +0 -25
- package/src/primitives/card/__workshop__/Interactive.tsx +0 -29
- package/src/primitives/card/__workshop__/ListNavigation.tsx +0 -78
- package/src/primitives/card/__workshop__/Props.tsx +0 -59
- package/src/primitives/card/__workshop__/Selected.tsx +0 -62
- package/src/primitives/card/__workshop__/Styled.tsx +0 -11
- package/src/primitives/card/__workshop__/Tones.tsx +0 -26
- package/src/primitives/card/__workshop__/index.ts +0 -21
- package/src/primitives/card/types.ts +0 -21
- package/src/primitives/card/useCard.ts +0 -20
- package/src/primitives/checkbox/Checkbox.tsx +0 -80
- package/src/primitives/checkbox/__workshop__/Example.tsx +0 -25
- package/src/primitives/checkbox/__workshop__/Props.tsx +0 -35
- package/src/primitives/checkbox/__workshop__/ReadOnly.tsx +0 -16
- package/src/primitives/checkbox/__workshop__/Tones.tsx +0 -26
- package/src/primitives/checkbox/__workshop__/index.ts +0 -15
- package/src/primitives/code/Code.tsx +0 -47
- package/src/primitives/code/__workshop__/OpticalAlignment.tsx +0 -25
- package/src/primitives/code/__workshop__/Props.tsx +0 -20
- package/src/primitives/code/__workshop__/index.ts +0 -21
- package/src/primitives/container/Container.tsx +0 -43
- package/src/primitives/container/__workshop__/Example.tsx +0 -16
- package/src/primitives/container/__workshop__/index.ts +0 -16
- package/src/primitives/container/types.ts +0 -6
- package/src/primitives/flex/Flex.tsx +0 -38
- package/src/primitives/flex/__workshop__/Example.tsx +0 -26
- package/src/primitives/flex/__workshop__/Gap.tsx +0 -25
- package/src/primitives/flex/__workshop__/index.ts +0 -13
- package/src/primitives/flex/__workshop__/styles.css.ts +0 -12
- package/src/primitives/grid/Grid.tsx +0 -38
- package/src/primitives/grid/__workshop__/Responsive.tsx +0 -54
- package/src/primitives/grid/__workshop__/index.ts +0 -12
- package/src/primitives/heading/Heading.tsx +0 -68
- package/src/primitives/heading/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/heading/__workshop__/Plain.tsx +0 -25
- package/src/primitives/heading/__workshop__/index.ts +0 -21
- package/src/primitives/inline/Inline.tsx +0 -37
- package/src/primitives/inline/__workshop__/Plain.tsx +0 -22
- package/src/primitives/inline/__workshop__/index.ts +0 -10
- package/src/primitives/kbd/Kbd.tsx +0 -36
- package/src/primitives/kbd/__workshop__/Plain.tsx +0 -9
- package/src/primitives/kbd/__workshop__/index.ts +0 -10
- package/src/primitives/label/Label.tsx +0 -67
- package/src/primitives/label/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/label/__workshop__/Plain.tsx +0 -27
- package/src/primitives/label/__workshop__/index.ts +0 -21
- package/src/primitives/layer/Layer.test.tsx +0 -110
- package/src/primitives/layer/Layer.tsx +0 -35
- package/src/primitives/layer/LayerCard.tsx +0 -90
- package/src/primitives/layer/LayerContext.ts +0 -7
- package/src/primitives/layer/LayerProvider.tsx +0 -106
- package/src/primitives/layer/__workshop__/MultipleRoots.tsx +0 -49
- package/src/primitives/layer/__workshop__/Nested.tsx +0 -107
- package/src/primitives/layer/__workshop__/ResponsiveZOffset.tsx +0 -17
- package/src/primitives/layer/__workshop__/_debug.tsx +0 -17
- package/src/primitives/layer/__workshop__/index.ts +0 -26
- package/src/primitives/layer/getLayerContext.test.ts +0 -32
- package/src/primitives/layer/getLayerContext.ts +0 -21
- package/src/primitives/layer/types.ts +0 -9
- package/src/primitives/layer/useLayer.ts +0 -24
- package/src/primitives/popover/Popover.tsx +0 -291
- package/src/primitives/popover/PopoverLayer.tsx +0 -101
- package/src/primitives/popover/__workshop__/AlignedStory.tsx +0 -75
- package/src/primitives/popover/__workshop__/MarginsStory.tsx +0 -31
- package/src/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +0 -32
- package/src/primitives/popover/__workshop__/OpenOnMountStory.tsx +0 -11
- package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -67
- package/src/primitives/popover/__workshop__/RecursiveStory.tsx +0 -71
- package/src/primitives/popover/__workshop__/SidePanelStory.tsx +0 -95
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -97
- package/src/primitives/popover/__workshop__/index.ts +0 -56
- package/src/primitives/popover/__workshop__/portal-inheritance.tsx +0 -15
- package/src/primitives/popover/constants.ts +0 -20
- package/src/primitives/popover/floating-ui/size.ts +0 -75
- package/src/primitives/popover/types.ts +0 -12
- package/src/primitives/popover/useMiddleware.ts +0 -126
- package/src/primitives/radio/Radio.tsx +0 -64
- package/src/primitives/radio/__workshop__/Example.tsx +0 -63
- package/src/primitives/radio/__workshop__/Plain.tsx +0 -28
- package/src/primitives/radio/__workshop__/index.ts +0 -13
- package/src/primitives/select/Select.tsx +0 -76
- package/src/primitives/select/__workshop__/Plain.tsx +0 -37
- package/src/primitives/select/__workshop__/ReadOnly.tsx +0 -23
- package/src/primitives/select/__workshop__/index.ts +0 -13
- package/src/primitives/selectable/Selectable.tsx +0 -48
- package/src/primitives/selectable/__workshop__/DataProps.tsx +0 -24
- package/src/primitives/selectable/__workshop__/as-link.tsx +0 -13
- package/src/primitives/selectable/__workshop__/index.ts +0 -19
- package/src/primitives/skeleton/CodeSkeleton.tsx +0 -49
- package/src/primitives/skeleton/HeadingSkeleton.tsx +0 -48
- package/src/primitives/skeleton/LabelSkeleton.tsx +0 -47
- package/src/primitives/skeleton/Skeleton.tsx +0 -70
- package/src/primitives/skeleton/TextSkeleton.tsx +0 -49
- package/src/primitives/skeleton/__workshop__/Delay.tsx +0 -69
- package/src/primitives/skeleton/__workshop__/Skeleton.tsx +0 -63
- package/src/primitives/skeleton/__workshop__/index.ts +0 -13
- package/src/primitives/spinner/Spinner.tsx +0 -45
- package/src/primitives/spinner/SpinnerAnimatedIcon.tsx +0 -14
- package/src/primitives/spinner/__workshop__/Props.tsx +0 -13
- package/src/primitives/spinner/__workshop__/index.ts +0 -16
- package/src/primitives/srOnly/SrOnly.tsx +0 -33
- package/src/primitives/stack/Stack.tsx +0 -38
- package/src/primitives/stack/__workshop__/Plain.tsx +0 -30
- package/src/primitives/stack/__workshop__/index.ts +0 -16
- package/src/primitives/switch/Switch.tsx +0 -76
- package/src/primitives/switch/__workshop__/Example.tsx +0 -25
- package/src/primitives/switch/__workshop__/Props.tsx +0 -23
- package/src/primitives/switch/__workshop__/index.ts +0 -13
- package/src/primitives/text/InlineCode.tsx +0 -25
- package/src/primitives/text/Text.tsx +0 -68
- package/src/primitives/text/__workshop__/Example.tsx +0 -26
- package/src/primitives/text/__workshop__/OpticalAlignment.tsx +0 -27
- package/src/primitives/text/__workshop__/index.ts +0 -26
- package/src/primitives/text/__workshop__/inline-code.tsx +0 -13
- package/src/primitives/textArea/TextArea.tsx +0 -97
- package/src/primitives/textArea/__workshop__/Plain.tsx +0 -46
- package/src/primitives/textArea/__workshop__/index.ts +0 -16
- package/src/primitives/textInput/TextInput.tsx +0 -279
- package/src/primitives/textInput/__workshop__/ClearButton.tsx +0 -32
- package/src/primitives/textInput/__workshop__/CustomValidity.tsx +0 -17
- package/src/primitives/textInput/__workshop__/Plain.tsx +0 -102
- package/src/primitives/textInput/__workshop__/ReadOnly.tsx +0 -14
- package/src/primitives/textInput/__workshop__/States.tsx +0 -53
- package/src/primitives/textInput/__workshop__/Tones.tsx +0 -40
- package/src/primitives/textInput/__workshop__/Typed.tsx +0 -23
- package/src/primitives/textInput/__workshop__/index.ts +0 -46
- package/src/primitives/tooltip/Tooltip.test.tsx +0 -496
- package/src/primitives/tooltip/Tooltip.tsx +0 -546
- package/src/primitives/tooltip/TooltipLayer.tsx +0 -72
- package/src/primitives/tooltip/__workshop__/CustomPortal.tsx +0 -102
- package/src/primitives/tooltip/__workshop__/OverflowingBoundary.tsx +0 -74
- package/src/primitives/tooltip/__workshop__/Props.tsx +0 -107
- package/src/primitives/tooltip/__workshop__/ResizableBoundary.tsx +0 -91
- package/src/primitives/tooltip/__workshop__/index.ts +0 -31
- package/src/primitives/tooltip/constants.ts +0 -24
- package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupContext.tsx +0 -13
- package/src/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupProvider.tsx +0 -96
- package/src/primitives/tooltip/tooltipDelayGroup/types.ts +0 -7
- package/src/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +0 -13
- package/src/root/Root.tsx +0 -93
- package/src/root/RootProvider.tsx +0 -37
- package/src/root/__workshop__/Boundary.tsx +0 -43
- package/src/root/__workshop__/index.ts +0 -24
- package/src/root/__workshop__/primitives.tsx +0 -49
- package/src/root/__workshop__/tone-inheritance.tsx +0 -65
- package/src/utils/ErrorBoundary.tsx +0 -50
- package/src/utils/boundaryElement/BoundaryElementContext.ts +0 -7
- package/src/utils/boundaryElement/BoundaryElementProvider.tsx +0 -16
- package/src/utils/boundaryElement/__workshop__/Plain.tsx +0 -49
- package/src/utils/boundaryElement/__workshop__/index.ts +0 -16
- package/src/utils/boundaryElement/types.ts +0 -2
- package/src/utils/boundaryElement/useBoundaryElement.ts +0 -12
- package/src/utils/elementQuery/ElementQuery.tsx +0 -75
- package/src/utils/elementQuery/__workshop__/CustomMedia.tsx +0 -19
- package/src/utils/elementQuery/__workshop__/index.ts +0 -16
- package/src/utils/elementQuery/__workshop__/styles.css.ts +0 -31
- package/src/utils/elementQuery/helpers.ts +0 -27
- package/src/utils/portal/Portal.test.tsx +0 -105
- package/src/utils/portal/Portal.tsx +0 -42
- package/src/utils/portal/PortalContext.ts +0 -37
- package/src/utils/portal/PortalProvider.tsx +0 -38
- package/src/utils/portal/__workshop__/Named.tsx +0 -69
- package/src/utils/portal/__workshop__/index.ts +0 -16
- package/src/utils/portal/types.ts +0 -7
- package/src/utils/portal/usePortal.ts +0 -30
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import {ToggleArrowRightIcon} from '@sanity/icons'
|
|
2
|
-
import {type ResponsiveProp, tree_item, vars} from '@sanity/ui-css'
|
|
3
|
-
import type {FontTextSize, FontWeight, Space} from '@sanity/ui-tokens'
|
|
4
|
-
import {
|
|
5
|
-
type ElementType,
|
|
6
|
-
type KeyboardEvent,
|
|
7
|
-
type MouseEvent,
|
|
8
|
-
type MouseEventHandler,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
useCallback,
|
|
11
|
-
useEffect,
|
|
12
|
-
useId,
|
|
13
|
-
useMemo,
|
|
14
|
-
useRef,
|
|
15
|
-
useState,
|
|
16
|
-
} from 'react'
|
|
17
|
-
|
|
18
|
-
import type {ComponentType, Props} from '../../core/types'
|
|
19
|
-
import {Box, type BoxProps} from '../../primitives/box/Box'
|
|
20
|
-
import {
|
|
21
|
-
Selectable,
|
|
22
|
-
type SelectableElementType,
|
|
23
|
-
type SelectableOwnProps,
|
|
24
|
-
} from '../../primitives/selectable/Selectable'
|
|
25
|
-
import {Text} from '../../primitives/text/Text'
|
|
26
|
-
import {TreeContext} from './TreeContext'
|
|
27
|
-
import {TreeGroup} from './TreeGroup'
|
|
28
|
-
import {useTree} from './useTree'
|
|
29
|
-
|
|
30
|
-
/** @beta */
|
|
31
|
-
export const DEFAULT_TREE_ITEM_ELEMENT = 'a'
|
|
32
|
-
|
|
33
|
-
/** @beta */
|
|
34
|
-
export type TreeItemOwnProps = SelectableOwnProps & {
|
|
35
|
-
expanded?: boolean
|
|
36
|
-
fontSize?: ResponsiveProp<FontTextSize>
|
|
37
|
-
icon?: ElementType
|
|
38
|
-
/**
|
|
39
|
-
* Allows passing a custom element type to the link component
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
linkAs?: SelectableElementType
|
|
43
|
-
onClick?: MouseEventHandler<HTMLAnchorElement | HTMLLIElement>
|
|
44
|
-
padding?: ResponsiveProp<Space>
|
|
45
|
-
gap?: ResponsiveProp<Space>
|
|
46
|
-
/** @deprecated Use `gap` instead */
|
|
47
|
-
space?: never
|
|
48
|
-
text?: ReactNode
|
|
49
|
-
weight?: FontWeight
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @beta */
|
|
53
|
-
export type TreeItemElementType = 'a' | 'li' | ComponentType
|
|
54
|
-
|
|
55
|
-
/** @beta */
|
|
56
|
-
export type TreeItemProps<E extends TreeItemElementType = TreeItemElementType> = Props<
|
|
57
|
-
TreeItemOwnProps,
|
|
58
|
-
E
|
|
59
|
-
>
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* This API might change. DO NOT USE IN PRODUCTION.
|
|
63
|
-
* @beta
|
|
64
|
-
*/
|
|
65
|
-
export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITEM_ELEMENT>(
|
|
66
|
-
props: TreeItemProps<E>,
|
|
67
|
-
): React.JSX.Element {
|
|
68
|
-
const {
|
|
69
|
-
children,
|
|
70
|
-
className,
|
|
71
|
-
expanded: expandedProp = false,
|
|
72
|
-
fontSize = 1,
|
|
73
|
-
gap: gapProp,
|
|
74
|
-
href,
|
|
75
|
-
icon: IconComponent,
|
|
76
|
-
id: idProp,
|
|
77
|
-
linkAs = 'a',
|
|
78
|
-
muted,
|
|
79
|
-
onClick,
|
|
80
|
-
padding = 2,
|
|
81
|
-
radius = 2,
|
|
82
|
-
selected = false,
|
|
83
|
-
text,
|
|
84
|
-
weight,
|
|
85
|
-
...rest
|
|
86
|
-
} = props as TreeItemProps<typeof DEFAULT_TREE_ITEM_ELEMENT>
|
|
87
|
-
const gap = gapProp ?? padding
|
|
88
|
-
|
|
89
|
-
const [rootElement, setRootElement] = useState<HTMLElement | null>(null)
|
|
90
|
-
const treeitemRef = useRef<HTMLDivElement | null>(null)
|
|
91
|
-
const tree = useTree()
|
|
92
|
-
const {path, registerItem, setExpanded, setFocusedElement} = tree
|
|
93
|
-
const _id = useId()
|
|
94
|
-
const id = idProp || _id
|
|
95
|
-
const [itemPath, itemKey] = useMemo(() => {
|
|
96
|
-
const itemPath = path.concat([id || ''])
|
|
97
|
-
return [itemPath, itemPath.join('/')]
|
|
98
|
-
}, [id, path])
|
|
99
|
-
const itemState = tree.state[itemKey]
|
|
100
|
-
const expanded = itemState?.expanded === undefined ? expandedProp : itemState?.expanded || false
|
|
101
|
-
const focused = tree.focusedElement && tree.focusedElement === rootElement
|
|
102
|
-
const tabIndex = focused ? 0 : -1
|
|
103
|
-
const contextValue = useMemo(
|
|
104
|
-
() => ({...tree, level: tree.level + 1, path: itemPath}),
|
|
105
|
-
[itemPath, tree],
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
const handleClick = useCallback(
|
|
109
|
-
(event: MouseEvent<HTMLAnchorElement> | MouseEvent<HTMLLIElement>) => {
|
|
110
|
-
if (onClick) onClick(event)
|
|
111
|
-
|
|
112
|
-
const target = event.target
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
target instanceof HTMLElement &&
|
|
116
|
-
(target.getAttribute('data-ui') === 'TreeItem' ||
|
|
117
|
-
target.closest('[data-ui="TreeItem__box"]'))
|
|
118
|
-
) {
|
|
119
|
-
event.stopPropagation()
|
|
120
|
-
setExpanded(itemKey, !expanded)
|
|
121
|
-
setFocusedElement(rootElement)
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
[expanded, itemKey, onClick, rootElement, setExpanded, setFocusedElement],
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
const handleKeyDown = useCallback(
|
|
128
|
-
(event: KeyboardEvent<HTMLElement>) => {
|
|
129
|
-
if (focused && event.key === 'Enter') {
|
|
130
|
-
const el = treeitemRef.current || rootElement
|
|
131
|
-
|
|
132
|
-
el?.click()
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
[focused, rootElement],
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (!rootElement) return
|
|
140
|
-
|
|
141
|
-
return registerItem(rootElement, itemKey, expanded, selected)
|
|
142
|
-
}, [expanded, itemKey, registerItem, rootElement, selected])
|
|
143
|
-
|
|
144
|
-
const content = (
|
|
145
|
-
<Box display="flex" gap={gap} padding={padding}>
|
|
146
|
-
<Text
|
|
147
|
-
flex="none"
|
|
148
|
-
muted={muted}
|
|
149
|
-
size={fontSize}
|
|
150
|
-
style={{
|
|
151
|
-
visibility: IconComponent || children ? 'visible' : 'hidden',
|
|
152
|
-
pointerEvents: 'none',
|
|
153
|
-
}}
|
|
154
|
-
weight={weight}
|
|
155
|
-
>
|
|
156
|
-
{IconComponent ? (
|
|
157
|
-
<IconComponent />
|
|
158
|
-
) : (
|
|
159
|
-
<ToggleArrowRightIcon style={{transform: expanded ? 'rotate(90deg)' : undefined}} />
|
|
160
|
-
)}
|
|
161
|
-
</Text>
|
|
162
|
-
|
|
163
|
-
<Text flex={1} muted={muted} size={fontSize} textOverflow="ellipsis" weight={weight}>
|
|
164
|
-
{text}
|
|
165
|
-
</Text>
|
|
166
|
-
</Box>
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
if (href) {
|
|
170
|
-
return (
|
|
171
|
-
<Box
|
|
172
|
-
data-selected={selected ? '' : undefined}
|
|
173
|
-
data-tree-id={id}
|
|
174
|
-
data-tree-key={itemKey}
|
|
175
|
-
data-ui="TreeItem"
|
|
176
|
-
{...(rest as BoxProps<'li'>)}
|
|
177
|
-
ref={setRootElement}
|
|
178
|
-
as="li"
|
|
179
|
-
className={tree_item({className})}
|
|
180
|
-
role="none"
|
|
181
|
-
onClick={handleClick}
|
|
182
|
-
>
|
|
183
|
-
<Selectable
|
|
184
|
-
ref={treeitemRef}
|
|
185
|
-
aria-expanded={expanded}
|
|
186
|
-
as={linkAs}
|
|
187
|
-
data-ui="TreeItem__box"
|
|
188
|
-
href={href}
|
|
189
|
-
radius={radius}
|
|
190
|
-
role="treeitem"
|
|
191
|
-
selected={selected}
|
|
192
|
-
style={{paddingLeft: `calc(${vars.space[2]} * ${tree.level})`}}
|
|
193
|
-
tabIndex={tabIndex}
|
|
194
|
-
>
|
|
195
|
-
{content}
|
|
196
|
-
</Selectable>
|
|
197
|
-
|
|
198
|
-
<TreeContext value={contextValue}>
|
|
199
|
-
{children && <TreeGroup hidden={!expanded}>{children}</TreeGroup>}
|
|
200
|
-
</TreeContext>
|
|
201
|
-
</Box>
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<Box
|
|
207
|
-
data-pressed={selected ? '' : undefined}
|
|
208
|
-
data-tree-id={id}
|
|
209
|
-
data-tree-key={itemKey}
|
|
210
|
-
data-ui="TreeItem"
|
|
211
|
-
{...rest}
|
|
212
|
-
ref={setRootElement}
|
|
213
|
-
aria-expanded={expanded}
|
|
214
|
-
className={tree_item({className})}
|
|
215
|
-
role="treeitem"
|
|
216
|
-
tabIndex={tabIndex}
|
|
217
|
-
onClick={handleClick}
|
|
218
|
-
onKeyDown={handleKeyDown}
|
|
219
|
-
>
|
|
220
|
-
<Selectable
|
|
221
|
-
data-focused={focused ? '' : undefined}
|
|
222
|
-
data-ui="TreeItem__box"
|
|
223
|
-
radius={radius}
|
|
224
|
-
selected={selected}
|
|
225
|
-
style={{paddingLeft: `calc(${vars.space[2]} * ${tree.level})`}}
|
|
226
|
-
tabIndex={tabIndex}
|
|
227
|
-
>
|
|
228
|
-
{content}
|
|
229
|
-
</Selectable>
|
|
230
|
-
|
|
231
|
-
<TreeContext value={contextValue}>
|
|
232
|
-
{children && <TreeGroup expanded={expanded}>{children}</TreeGroup>}
|
|
233
|
-
</TreeContext>
|
|
234
|
-
</Box>
|
|
235
|
-
)
|
|
236
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {LinkIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, SPACE, Tree, TreeItem} from '@sanity/ui'
|
|
3
|
-
import {useSelect} from '@sanity/ui-workshop'
|
|
4
|
-
import {usePerfTest} from '@sanity/ui-workshop/plugin-perf'
|
|
5
|
-
import {useCallback, useState} from 'react'
|
|
6
|
-
|
|
7
|
-
import {perfTests} from './basic.perf'
|
|
8
|
-
|
|
9
|
-
export default function BasicStory(): React.JSX.Element {
|
|
10
|
-
const {ref, Wrapper} = usePerfTest(perfTests[0])
|
|
11
|
-
|
|
12
|
-
const padding = useSelect('Padding', SPACE)
|
|
13
|
-
|
|
14
|
-
const [id, setId] = useState('')
|
|
15
|
-
|
|
16
|
-
const handleClick = useCallback((event: React.MouseEvent) => {
|
|
17
|
-
event.preventDefault()
|
|
18
|
-
|
|
19
|
-
const testid = event.currentTarget.getAttribute('data-testid')
|
|
20
|
-
|
|
21
|
-
if (testid) setId(testid)
|
|
22
|
-
}, [])
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Box padding={[4, 5, 6]}>
|
|
26
|
-
<Wrapper>
|
|
27
|
-
<Tree ref={ref} gap={1} padding={padding} radius={3}>
|
|
28
|
-
<TreeItem expanded text="Fruit" onClick={handleClick}>
|
|
29
|
-
<TreeItem
|
|
30
|
-
data-testid="oranges"
|
|
31
|
-
selected={id === 'oranges'}
|
|
32
|
-
text="Oranges"
|
|
33
|
-
onClick={handleClick}
|
|
34
|
-
/>
|
|
35
|
-
<TreeItem
|
|
36
|
-
data-testid="pineapples"
|
|
37
|
-
selected={id === 'pineapples'}
|
|
38
|
-
text="Pineapples"
|
|
39
|
-
onClick={handleClick}
|
|
40
|
-
/>
|
|
41
|
-
<TreeItem data-testid="apples" text="Apples" onClick={handleClick}>
|
|
42
|
-
<TreeItem
|
|
43
|
-
data-testid="apples/macintosh"
|
|
44
|
-
href="/apples/macintosh"
|
|
45
|
-
icon={LinkIcon}
|
|
46
|
-
text="Macintosh"
|
|
47
|
-
onClick={handleClick}
|
|
48
|
-
/>
|
|
49
|
-
<TreeItem
|
|
50
|
-
data-testid="apples/granny-smith"
|
|
51
|
-
text="Granny Smith"
|
|
52
|
-
onClick={handleClick}
|
|
53
|
-
/>
|
|
54
|
-
<TreeItem data-testid="apples/fuji" text="Fuji" onClick={handleClick} />
|
|
55
|
-
</TreeItem>
|
|
56
|
-
<TreeItem muted text="Bananas" onClick={handleClick} />
|
|
57
|
-
<TreeItem text="Pears" onClick={handleClick}>
|
|
58
|
-
<TreeItem muted text="Anjou" onClick={handleClick} />
|
|
59
|
-
<TreeItem muted text="Bartlett" onClick={handleClick} />
|
|
60
|
-
<TreeItem muted text="Bosc" onClick={handleClick} />
|
|
61
|
-
<TreeItem muted text="Concorde" onClick={handleClick} />
|
|
62
|
-
<TreeItem muted text="Seckel" onClick={handleClick} />
|
|
63
|
-
<TreeItem muted text="Starkrimson" onClick={handleClick} />
|
|
64
|
-
</TreeItem>
|
|
65
|
-
</TreeItem>
|
|
66
|
-
<TreeItem text="Vegetables" onClick={handleClick}>
|
|
67
|
-
<TreeItem text="Podded vegetables" onClick={handleClick}>
|
|
68
|
-
<TreeItem muted text="Lentil" onClick={handleClick} />
|
|
69
|
-
<TreeItem muted text="Pea" onClick={handleClick} />
|
|
70
|
-
<TreeItem muted text="Peanut" onClick={handleClick} />
|
|
71
|
-
</TreeItem>
|
|
72
|
-
<TreeItem text="Bulb and stem vegetables" onClick={handleClick}>
|
|
73
|
-
<TreeItem muted text="Asparagus" onClick={handleClick} />
|
|
74
|
-
<TreeItem muted text="Celery" onClick={handleClick} />
|
|
75
|
-
<TreeItem muted text="Leek" onClick={handleClick} />
|
|
76
|
-
<TreeItem muted text="Onion" onClick={handleClick} />
|
|
77
|
-
</TreeItem>
|
|
78
|
-
<TreeItem text="Root and tuberous vegetables" onClick={handleClick}>
|
|
79
|
-
<TreeItem muted text="Carrot" onClick={handleClick} />
|
|
80
|
-
<TreeItem muted text="Ginger" onClick={handleClick} />
|
|
81
|
-
<TreeItem muted text="Parsnip" onClick={handleClick} />
|
|
82
|
-
<TreeItem muted text="Potato" onClick={handleClick} />
|
|
83
|
-
</TreeItem>
|
|
84
|
-
</TreeItem>
|
|
85
|
-
<TreeItem text="Grains" onClick={handleClick}>
|
|
86
|
-
<TreeItem text="Cereal grains" onClick={handleClick}>
|
|
87
|
-
<TreeItem muted text="Barley" onClick={handleClick} />
|
|
88
|
-
<TreeItem muted text="Oats" onClick={handleClick} />
|
|
89
|
-
<TreeItem muted text="Rice" onClick={handleClick} />
|
|
90
|
-
</TreeItem>
|
|
91
|
-
<TreeItem text="Pseudocereal grains" onClick={handleClick}>
|
|
92
|
-
<TreeItem muted text="Amaranth" onClick={handleClick} />
|
|
93
|
-
<TreeItem muted text="Buckwheat" onClick={handleClick} />
|
|
94
|
-
<TreeItem muted text="Chia" onClick={handleClick} />
|
|
95
|
-
<TreeItem muted text="Quinoa" onClick={handleClick} />
|
|
96
|
-
</TreeItem>
|
|
97
|
-
<TreeItem text="Oilseeds" onClick={handleClick}>
|
|
98
|
-
<TreeItem muted text="India mustard" onClick={handleClick} />
|
|
99
|
-
<TreeItem muted text="Safflower" onClick={handleClick} />
|
|
100
|
-
<TreeItem muted text="Flax seed" onClick={handleClick} />
|
|
101
|
-
<TreeItem muted text="Poppy seed" onClick={handleClick} />
|
|
102
|
-
</TreeItem>
|
|
103
|
-
</TreeItem>
|
|
104
|
-
</Tree>
|
|
105
|
-
</Wrapper>
|
|
106
|
-
</Box>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {LinkIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Text, TextInput, Tree, TreeItem} from '@sanity/ui'
|
|
3
|
-
import {usePerfTest} from '@sanity/ui-workshop/plugin-perf'
|
|
4
|
-
import {useCallback, useState} from 'react'
|
|
5
|
-
|
|
6
|
-
import {perfTests} from './basic.perf'
|
|
7
|
-
|
|
8
|
-
export default function BasicStory(): React.JSX.Element {
|
|
9
|
-
const {ref, Wrapper} = usePerfTest(perfTests[0])
|
|
10
|
-
|
|
11
|
-
const [id, setId] = useState('')
|
|
12
|
-
const [focus, setFocus] = useState('')
|
|
13
|
-
|
|
14
|
-
const handleClick = useCallback((event: React.MouseEvent) => {
|
|
15
|
-
event.preventDefault()
|
|
16
|
-
|
|
17
|
-
const testid = event.currentTarget.getAttribute('data-testid')
|
|
18
|
-
|
|
19
|
-
if (testid) setId(testid)
|
|
20
|
-
}, [])
|
|
21
|
-
|
|
22
|
-
const handleFocus = useCallback((event: React.FocusEvent<HTMLDivElement>) => {
|
|
23
|
-
const elementFocus = event.target.getAttribute('data-testid')
|
|
24
|
-
if (elementFocus) setFocus(elementFocus)
|
|
25
|
-
}, [])
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Box padding={[4, 5, 6]}>
|
|
29
|
-
<Box paddingY={3}>
|
|
30
|
-
<Text muted size={1}>
|
|
31
|
-
This example is to demonstrate that when you tab from an outside element (using the
|
|
32
|
-
keyboard to navigate), you can still access the tree and tree item. Press the input
|
|
33
|
-
beneath and start tabbing / using the arrow.
|
|
34
|
-
</Text>
|
|
35
|
-
</Box>
|
|
36
|
-
<Box paddingY={3}>
|
|
37
|
-
<Text>Focus: {focus}</Text>
|
|
38
|
-
</Box>
|
|
39
|
-
<Wrapper>
|
|
40
|
-
<TextInput />
|
|
41
|
-
<Tree ref={ref} gap={1} onFocus={handleFocus}>
|
|
42
|
-
<TreeItem data-testid="fruit" expanded text="Fruit" onClick={handleClick}>
|
|
43
|
-
<TreeItem
|
|
44
|
-
data-testid="oranges"
|
|
45
|
-
selected={id === 'oranges'}
|
|
46
|
-
text="Oranges"
|
|
47
|
-
onClick={handleClick}
|
|
48
|
-
/>
|
|
49
|
-
<TreeItem
|
|
50
|
-
data-testid="pineapples"
|
|
51
|
-
selected={id === 'pineapples'}
|
|
52
|
-
text="Pineapples"
|
|
53
|
-
onClick={handleClick}
|
|
54
|
-
/>
|
|
55
|
-
<TreeItem data-testid="apples" text="Apples" onClick={handleClick}>
|
|
56
|
-
<TreeItem
|
|
57
|
-
data-testid="apples/macintosh"
|
|
58
|
-
href="/apples/macintosh"
|
|
59
|
-
icon={LinkIcon}
|
|
60
|
-
text="Macintosh"
|
|
61
|
-
onClick={handleClick}
|
|
62
|
-
/>
|
|
63
|
-
<TreeItem
|
|
64
|
-
data-testid="apples/granny-smith"
|
|
65
|
-
text="Granny Smith"
|
|
66
|
-
onClick={handleClick}
|
|
67
|
-
/>
|
|
68
|
-
<TreeItem data-testid="apples/fuji" text="Fuji" onClick={handleClick} />
|
|
69
|
-
</TreeItem>
|
|
70
|
-
<TreeItem data-testid="bananas" text="Bananas" onClick={handleClick} />
|
|
71
|
-
<TreeItem data-testid="pears" text="Pears" onClick={handleClick}>
|
|
72
|
-
<TreeItem data-testid="pears/anjou" text="Anjou" onClick={handleClick} />
|
|
73
|
-
<TreeItem data-testid="pears/bartlett" text="Bartlett" onClick={handleClick} />
|
|
74
|
-
<TreeItem data-testid="pears/bosc" text="Bosc" onClick={handleClick} />
|
|
75
|
-
<TreeItem data-testid="pears/concorde" text="Concorde" onClick={handleClick} />
|
|
76
|
-
<TreeItem data-testid="pears/seckel" text="Seckel" onClick={handleClick} />
|
|
77
|
-
<TreeItem data-testid="pears/starkrimson" text="Starkrimson" onClick={handleClick} />
|
|
78
|
-
</TreeItem>
|
|
79
|
-
</TreeItem>
|
|
80
|
-
</Tree>
|
|
81
|
-
</Wrapper>
|
|
82
|
-
</Box>
|
|
83
|
-
)
|
|
84
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type {PerfTestProps, PerfTestRunFn} from '@sanity/ui-workshop/plugin-perf'
|
|
2
|
-
import {findByTestId, fireEvent} from '@testing-library/dom'
|
|
3
|
-
|
|
4
|
-
function test<ElementType = unknown>(
|
|
5
|
-
title: string,
|
|
6
|
-
run: PerfTestRunFn<ElementType>,
|
|
7
|
-
): PerfTestProps<ElementType> {
|
|
8
|
-
return {name: title, run}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const perfTests: PerfTestProps<HTMLDivElement>[] = [
|
|
12
|
-
test('Toggle tree groups', async ({target}: {target: HTMLDivElement}) => {
|
|
13
|
-
const apples = await findByTestId(target, 'apples')
|
|
14
|
-
const oranges = await findByTestId(target, 'oranges')
|
|
15
|
-
|
|
16
|
-
fireEvent.click(apples)
|
|
17
|
-
fireEvent.click(oranges)
|
|
18
|
-
}),
|
|
19
|
-
]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type {WorkshopScope} from '@sanity/ui-workshop'
|
|
2
|
-
import {lazy} from 'react'
|
|
3
|
-
|
|
4
|
-
const scope: WorkshopScope = {
|
|
5
|
-
name: 'components/tree',
|
|
6
|
-
title: 'Tree',
|
|
7
|
-
stories: [
|
|
8
|
-
{
|
|
9
|
-
name: 'basic',
|
|
10
|
-
title: 'Basic',
|
|
11
|
-
component: lazy(() => import('./Basic')),
|
|
12
|
-
// options: {perfTests: () => import('./Basic.perf')},
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'tab',
|
|
16
|
-
title: 'Tab',
|
|
17
|
-
component: lazy(() => import('./TabFromElement')),
|
|
18
|
-
// options: {perfTests: () => import('./Basic.perf')},
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default scope
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type {TreeState} from './types'
|
|
2
|
-
|
|
3
|
-
export function _findPrevItemElement(
|
|
4
|
-
state: TreeState,
|
|
5
|
-
itemElements: HTMLElement[],
|
|
6
|
-
focusedElement: HTMLElement,
|
|
7
|
-
): HTMLElement | null {
|
|
8
|
-
const idx = itemElements.indexOf(focusedElement)
|
|
9
|
-
const els = itemElements.slice(0, idx)
|
|
10
|
-
const len = els.length
|
|
11
|
-
|
|
12
|
-
for (let i = len - 1; i >= 0; i -= 1) {
|
|
13
|
-
const itemKey = els[i].getAttribute('data-tree-key')
|
|
14
|
-
|
|
15
|
-
if (!itemKey) {
|
|
16
|
-
continue
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const segments = itemKey.split('/')
|
|
20
|
-
|
|
21
|
-
segments.pop()
|
|
22
|
-
|
|
23
|
-
const p: string[] = []
|
|
24
|
-
|
|
25
|
-
let expanded = true
|
|
26
|
-
|
|
27
|
-
for (let j = 0; j < segments.length; j += 1) {
|
|
28
|
-
p.push(segments[j])
|
|
29
|
-
|
|
30
|
-
const k = p.join('/')
|
|
31
|
-
|
|
32
|
-
if (!state[k]?.expanded) {
|
|
33
|
-
expanded = false
|
|
34
|
-
break
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (expanded) {
|
|
39
|
-
return els[i]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function _findNextItemElement(
|
|
47
|
-
state: TreeState,
|
|
48
|
-
itemElements: HTMLElement[],
|
|
49
|
-
focusedElement: HTMLElement,
|
|
50
|
-
): HTMLElement | null {
|
|
51
|
-
const idx = itemElements.indexOf(focusedElement)
|
|
52
|
-
const els = itemElements.slice(idx)
|
|
53
|
-
const len = itemElements.length
|
|
54
|
-
|
|
55
|
-
for (let i = 1; i < len; i += 1) {
|
|
56
|
-
if (!els[i]) {
|
|
57
|
-
continue
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const itemKey = els[i].getAttribute('data-tree-key')
|
|
61
|
-
|
|
62
|
-
if (!itemKey) {
|
|
63
|
-
continue
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const segments = itemKey.split('/')
|
|
67
|
-
|
|
68
|
-
segments.pop()
|
|
69
|
-
|
|
70
|
-
const p: string[] = []
|
|
71
|
-
|
|
72
|
-
let expanded = true
|
|
73
|
-
|
|
74
|
-
for (let j = 0; j < segments.length; j += 1) {
|
|
75
|
-
p.push(segments[j])
|
|
76
|
-
|
|
77
|
-
const k = p.join('/')
|
|
78
|
-
|
|
79
|
-
if (!state[k]?.expanded) {
|
|
80
|
-
expanded = false
|
|
81
|
-
break
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (expanded) {
|
|
86
|
-
return els[i]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function _focusItemElement(el: HTMLElement): void {
|
|
94
|
-
if (el.getAttribute('role') === 'treeitem') {
|
|
95
|
-
el.focus()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (el.getAttribute('role') === 'none') {
|
|
99
|
-
const firstChild = el.firstChild
|
|
100
|
-
|
|
101
|
-
if (firstChild && firstChild instanceof HTMLElement) {
|
|
102
|
-
firstChild.focus()
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type {ResponsiveProp} from '@sanity/ui-css'
|
|
2
|
-
import type {Space} from '@sanity/ui-tokens'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @beta
|
|
6
|
-
*/
|
|
7
|
-
export interface TreeState {
|
|
8
|
-
[key: string]: {element: HTMLElement; expanded: boolean} | undefined
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @beta
|
|
13
|
-
*/
|
|
14
|
-
export interface TreeContextValue {
|
|
15
|
-
version: 0.0
|
|
16
|
-
focusedElement: HTMLElement | null
|
|
17
|
-
gap: ResponsiveProp<Space>
|
|
18
|
-
level: number
|
|
19
|
-
path: string[]
|
|
20
|
-
registerItem: (element: HTMLElement, path: string, expanded: boolean, selected: boolean) => void
|
|
21
|
-
setExpanded: (path: string, expanded: boolean) => void
|
|
22
|
-
setFocusedElement: (focusedElement: HTMLElement | null) => void
|
|
23
|
-
state: TreeState
|
|
24
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {use} from 'react'
|
|
2
|
-
|
|
3
|
-
import {TreeContext} from './TreeContext'
|
|
4
|
-
import type {TreeContextValue} from './types'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @beta
|
|
8
|
-
*/
|
|
9
|
-
export function useTree(): TreeContextValue {
|
|
10
|
-
const tree = use(TreeContext)
|
|
11
|
-
|
|
12
|
-
if (!tree) {
|
|
13
|
-
throw new Error('Tree: missing context value')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return tree
|
|
17
|
-
}
|