@bettercms-ai/kit 0.1.0
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 +21 -0
- package/README.md +27 -0
- package/dist/_chunks-cjs/_visual-editing.js +5898 -0
- package/dist/_chunks-cjs/refractor.js +22 -0
- package/dist/_chunks-es/_visual-editing.mjs +5904 -0
- package/dist/_chunks-es/refractor.mjs +25 -0
- package/dist/_color.d.mts +119 -0
- package/dist/_color.d.ts +119 -0
- package/dist/_color.js +1412 -0
- package/dist/_color.mjs +1411 -0
- package/dist/_visual-editing.d.mts +1126 -0
- package/dist/_visual-editing.d.ts +1126 -0
- package/dist/_visual-editing.js +30 -0
- package/dist/_visual-editing.mjs +30 -0
- package/dist/index.d.mts +3140 -0
- package/dist/index.d.ts +3140 -0
- package/dist/index.js +2036 -0
- package/dist/index.mjs +2044 -0
- package/dist/theme.d.mts +1506 -0
- package/dist/theme.d.ts +1506 -0
- package/dist/theme.js +4126 -0
- package/dist/theme.mjs +4126 -0
- package/exports/_visual-editing.ts +31 -0
- package/exports/index.ts +1 -0
- package/exports/theme.ts +1 -0
- package/package.json +78 -0
- package/src/color/index.d.mts +119 -0
- package/src/color/index.mjs +1411 -0
- package/src/core/__workshop__/constants.ts +293 -0
- package/src/core/_compat.ts +264 -0
- package/src/core/components/autocomplete/__mocks__/apiStore.ts +49 -0
- package/src/core/components/autocomplete/__mocks__/countries.ts +245 -0
- package/src/core/components/autocomplete/__workshop__/async.tsx +156 -0
- package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +137 -0
- package/src/core/components/autocomplete/__workshop__/custom.tsx +89 -0
- package/src/core/components/autocomplete/__workshop__/example.tsx +79 -0
- package/src/core/components/autocomplete/__workshop__/focusAndBlur.tsx +36 -0
- package/src/core/components/autocomplete/__workshop__/fullscreen.tsx +294 -0
- package/src/core/components/autocomplete/__workshop__/index.ts +39 -0
- package/src/core/components/autocomplete/__workshop__/types.ts +4 -0
- package/src/core/components/autocomplete/autocomplete.styles.tsx +39 -0
- package/src/core/components/autocomplete/autocomplete.tsx +767 -0
- package/src/core/components/autocomplete/autocompleteOption.tsx +45 -0
- package/src/core/components/autocomplete/autocompleteReducer.ts +47 -0
- package/src/core/components/autocomplete/constants.ts +28 -0
- package/src/core/components/autocomplete/index.ts +2 -0
- package/src/core/components/autocomplete/types.ts +108 -0
- package/src/core/components/breadcrumbs/__workshop__/example.tsx +62 -0
- package/src/core/components/breadcrumbs/__workshop__/index.ts +14 -0
- package/src/core/components/breadcrumbs/breadcrumbs.styles.ts +18 -0
- package/src/core/components/breadcrumbs/breadcrumbs.test.tsx +51 -0
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +133 -0
- package/src/core/components/breadcrumbs/index.ts +1 -0
- package/src/core/components/dialog/__workshop__/activate.tsx +134 -0
- package/src/core/components/dialog/__workshop__/autoFocus.tsx +29 -0
- package/src/core/components/dialog/__workshop__/index.ts +19 -0
- package/src/core/components/dialog/__workshop__/layering.tsx +41 -0
- package/src/core/components/dialog/__workshop__/nested.tsx +72 -0
- package/src/core/components/dialog/__workshop__/onScroll.tsx +39 -0
- package/src/core/components/dialog/__workshop__/panes.tsx +82 -0
- package/src/core/components/dialog/__workshop__/position.tsx +30 -0
- package/src/core/components/dialog/__workshop__/props.tsx +75 -0
- package/src/core/components/dialog/__workshop__/provider.tsx +11 -0
- package/src/core/components/dialog/__workshop__/wrapped.tsx +76 -0
- package/src/core/components/dialog/dialog.tsx +430 -0
- package/src/core/components/dialog/dialogContext.ts +20 -0
- package/src/core/components/dialog/dialogProvider.tsx +35 -0
- package/src/core/components/dialog/index.ts +4 -0
- package/src/core/components/dialog/styles.ts +77 -0
- package/src/core/components/dialog/useDialog.ts +11 -0
- package/src/core/components/hotkeys/__workshop__/index.ts +14 -0
- package/src/core/components/hotkeys/__workshop__/plain.tsx +9 -0
- package/src/core/components/hotkeys/hotkeys.test.tsx +42 -0
- package/src/core/components/hotkeys/hotkeys.tsx +66 -0
- package/src/core/components/hotkeys/index.ts +1 -0
- package/src/core/components/index.ts +9 -0
- package/src/core/components/menu/__workshop__/asComponent.tsx +45 -0
- package/src/core/components/menu/__workshop__/avatarMenu.tsx +51 -0
- package/src/core/components/menu/__workshop__/closableMenuButton.tsx +46 -0
- package/src/core/components/menu/__workshop__/constrainedInBoundary.tsx +134 -0
- package/src/core/components/menu/__workshop__/customMenuItem.tsx +45 -0
- package/src/core/components/menu/__workshop__/customSelectedState.tsx +39 -0
- package/src/core/components/menu/__workshop__/disableFocusOnClose.tsx +40 -0
- package/src/core/components/menu/__workshop__/groups.tsx +156 -0
- package/src/core/components/menu/__workshop__/index.ts +89 -0
- package/src/core/components/menu/__workshop__/menuButton.tsx +80 -0
- package/src/core/components/menu/__workshop__/menuGroupRight.tsx +58 -0
- package/src/core/components/menu/__workshop__/nestedMenu.tsx +22 -0
- package/src/core/components/menu/__workshop__/onCloseMenuButton.tsx +41 -0
- package/src/core/components/menu/__workshop__/selectedItem.tsx +69 -0
- package/src/core/components/menu/__workshop__/shouldFocus.tsx +47 -0
- package/src/core/components/menu/__workshop__/tones.tsx +25 -0
- package/src/core/components/menu/__workshop__/withoutArrow.tsx +32 -0
- package/src/core/components/menu/helpers.ts +82 -0
- package/src/core/components/menu/index.ts +5 -0
- package/src/core/components/menu/menu.spacing.test.tsx +63 -0
- package/src/core/components/menu/menu.test.tsx +125 -0
- package/src/core/components/menu/menu.tsx +178 -0
- package/src/core/components/menu/menuButton.tsx +268 -0
- package/src/core/components/menu/menuContext.ts +18 -0
- package/src/core/components/menu/menuDivider.ts +23 -0
- package/src/core/components/menu/menuGroup.spacing.test.tsx +63 -0
- package/src/core/components/menu/menuGroup.tsx +233 -0
- package/src/core/components/menu/menuItem.spacing.test.tsx +59 -0
- package/src/core/components/menu/menuItem.tsx +197 -0
- package/src/core/components/menu/useMenu.ts +21 -0
- package/src/core/components/menu/useMenuController.ts +231 -0
- package/src/core/components/skeleton/__workshop__/delay.tsx +70 -0
- package/src/core/components/skeleton/__workshop__/index.ts +11 -0
- package/src/core/components/skeleton/__workshop__/skeleton.tsx +64 -0
- package/src/core/components/skeleton/index.ts +2 -0
- package/src/core/components/skeleton/skeleton.tsx +57 -0
- package/src/core/components/skeleton/styles.ts +50 -0
- package/src/core/components/skeleton/textSkeleton.tsx +122 -0
- package/src/core/components/tab/__workshop__/example.tsx +79 -0
- package/src/core/components/tab/__workshop__/index.ts +14 -0
- package/src/core/components/tab/index.ts +3 -0
- package/src/core/components/tab/tab.tsx +101 -0
- package/src/core/components/tab/tabList.test.tsx +48 -0
- package/src/core/components/tab/tabList.tsx +70 -0
- package/src/core/components/tab/tabPanel.tsx +39 -0
- package/src/core/components/toast/__workshop__/hook.tsx +71 -0
- package/src/core/components/toast/__workshop__/index.ts +19 -0
- package/src/core/components/toast/__workshop__/toast.tsx +26 -0
- package/src/core/components/toast/index.ts +4 -0
- package/src/core/components/toast/styles.ts +77 -0
- package/src/core/components/toast/toast.test.tsx +101 -0
- package/src/core/components/toast/toast.tsx +198 -0
- package/src/core/components/toast/toastContext.ts +7 -0
- package/src/core/components/toast/toastLayer.tsx +51 -0
- package/src/core/components/toast/toastProvider.tsx +113 -0
- package/src/core/components/toast/toastState.ts +6 -0
- package/src/core/components/toast/types.ts +26 -0
- package/src/core/components/toast/useToast.ts +25 -0
- package/src/core/components/tree/__workshop__/basic.perf.ts +19 -0
- package/src/core/components/tree/__workshop__/basic.tsx +105 -0
- package/src/core/components/tree/__workshop__/index.ts +21 -0
- package/src/core/components/tree/__workshop__/tabFromElement.tsx +84 -0
- package/src/core/components/tree/helpers.ts +105 -0
- package/src/core/components/tree/index.ts +4 -0
- package/src/core/components/tree/style.ts +105 -0
- package/src/core/components/tree/tree.test.tsx +55 -0
- package/src/core/components/tree/tree.tsx +240 -0
- package/src/core/components/tree/treeContext.ts +10 -0
- package/src/core/components/tree/treeGroup.tsx +28 -0
- package/src/core/components/tree/treeItem.test.tsx +65 -0
- package/src/core/components/tree/treeItem.tsx +224 -0
- package/src/core/components/tree/types.ts +25 -0
- package/src/core/components/tree/useTree.ts +17 -0
- package/src/core/constants.ts +79 -0
- package/src/core/helpers/animation.ts +27 -0
- package/src/core/helpers/element.ts +55 -0
- package/src/core/helpers/focus.ts +100 -0
- package/src/core/helpers/index.ts +4 -0
- package/src/core/helpers/scroll.ts +15 -0
- package/src/core/hooks/index.ts +12 -0
- package/src/core/hooks/useArrayProp.ts +17 -0
- package/src/core/hooks/useClickOutside.test.tsx +482 -0
- package/src/core/hooks/useClickOutside.ts +118 -0
- package/src/core/hooks/useClickOutsideEvent.test.tsx +115 -0
- package/src/core/hooks/useClickOutsideEvent.ts +73 -0
- package/src/core/hooks/useCustomValidity.ts +13 -0
- package/src/core/hooks/useDelayed.test.ts +88 -0
- package/src/core/hooks/useDelayedState.ts +36 -0
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +32 -0
- package/src/core/hooks/useElementRect/__workshop__/index.ts +14 -0
- package/src/core/hooks/useElementRect/index.ts +1 -0
- package/src/core/hooks/useElementRect/useElementRect.ts +13 -0
- package/src/core/hooks/useElementSize.ts +19 -0
- package/src/core/hooks/useForwardedRef.ts +19 -0
- package/src/core/hooks/useGlobalKeyDown.ts +24 -0
- package/src/core/hooks/useIsomorphicEffect.ts +7 -0
- package/src/core/hooks/useMatchMedia.ts +28 -0
- package/src/core/hooks/useMediaIndex/__workshop__/index.ts +14 -0
- package/src/core/hooks/useMediaIndex/__workshop__/test.tsx +14 -0
- package/src/core/hooks/useMediaIndex/index.ts +1 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +36 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +102 -0
- package/src/core/hooks/useMounted.ts +15 -0
- package/src/core/hooks/usePrefersDark.hydration.test.tsx +56 -0
- package/src/core/hooks/usePrefersDark.test.tsx +19 -0
- package/src/core/hooks/usePrefersDark.ts +16 -0
- package/src/core/hooks/usePrefersReducedMotion.hydration.test.tsx +56 -0
- package/src/core/hooks/usePrefersReducedMotion.test.tsx +19 -0
- package/src/core/hooks/usePrefersReducedMotion.ts +16 -0
- package/src/core/index.ts +10 -0
- package/src/core/lib/createGlobalScopedContext.ts +36 -0
- package/src/core/lib/globalScope.ts +19 -0
- package/src/core/lib/isRecord.ts +3 -0
- package/src/core/middleware/origin.ts +47 -0
- package/src/core/observers/elementSizeObserver.ts +116 -0
- package/src/core/observers/index.ts +2 -0
- package/src/core/observers/resizeObserver.ts +9 -0
- package/src/core/primitives/_selectable/index.ts +1 -0
- package/src/core/primitives/_selectable/selectable.tsx +15 -0
- package/src/core/primitives/_selectable/style.ts +115 -0
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +14 -0
- package/src/core/primitives/avatar/__workshop__/index.ts +29 -0
- package/src/core/primitives/avatar/__workshop__/stack.tsx +25 -0
- package/src/core/primitives/avatar/__workshop__/withinButton.tsx +63 -0
- package/src/core/primitives/avatar/__workshop__/withinMenuItem.tsx +70 -0
- package/src/core/primitives/avatar/avatar.tsx +200 -0
- package/src/core/primitives/avatar/avatarCounter.tsx +91 -0
- package/src/core/primitives/avatar/avatarStack.tsx +100 -0
- package/src/core/primitives/avatar/index.ts +4 -0
- package/src/core/primitives/avatar/styles.ts +167 -0
- package/src/core/primitives/avatar/types.ts +17 -0
- package/src/core/primitives/badge/__workshop__/index.ts +19 -0
- package/src/core/primitives/badge/__workshop__/props.tsx +30 -0
- package/src/core/primitives/badge/__workshop__/tones.tsx +21 -0
- package/src/core/primitives/badge/badge.test.tsx +16 -0
- package/src/core/primitives/badge/badge.tsx +70 -0
- package/src/core/primitives/badge/index.ts +1 -0
- package/src/core/primitives/badge/styles.ts +20 -0
- package/src/core/primitives/badge/types.ts +8 -0
- package/src/core/primitives/box/__workshop__/asComponent.tsx +31 -0
- package/src/core/primitives/box/__workshop__/index.ts +24 -0
- package/src/core/primitives/box/__workshop__/props.tsx +20 -0
- package/src/core/primitives/box/__workshop__/responsive.tsx +20 -0
- package/src/core/primitives/box/box.test.tsx +142 -0
- package/src/core/primitives/box/box.tsx +154 -0
- package/src/core/primitives/box/index.ts +1 -0
- package/src/core/primitives/button/__workshop__/custom.tsx +51 -0
- package/src/core/primitives/button/__workshop__/customIcons.tsx +30 -0
- package/src/core/primitives/button/__workshop__/disabled.tsx +74 -0
- package/src/core/primitives/button/__workshop__/index.ts +59 -0
- package/src/core/primitives/button/__workshop__/labelUploadButton.tsx +36 -0
- package/src/core/primitives/button/__workshop__/mixedChildren.tsx +12 -0
- package/src/core/primitives/button/__workshop__/props.tsx +55 -0
- package/src/core/primitives/button/__workshop__/stacked.tsx +58 -0
- package/src/core/primitives/button/__workshop__/styled1.tsx +17 -0
- package/src/core/primitives/button/__workshop__/styled2.tsx +19 -0
- package/src/core/primitives/button/__workshop__/uploadButton.tsx +28 -0
- package/src/core/primitives/button/button.test.tsx +82 -0
- package/src/core/primitives/button/button.tsx +210 -0
- package/src/core/primitives/button/index.ts +1 -0
- package/src/core/primitives/button/styles.ts +117 -0
- package/src/core/primitives/card/__workshop__/allTones.tsx +25 -0
- package/src/core/primitives/card/__workshop__/asButton.tsx +107 -0
- package/src/core/primitives/card/__workshop__/asComponent.tsx +27 -0
- package/src/core/primitives/card/__workshop__/checkered.tsx +26 -0
- package/src/core/primitives/card/__workshop__/index.ts +18 -0
- package/src/core/primitives/card/__workshop__/interactive.tsx +30 -0
- package/src/core/primitives/card/__workshop__/listNavigation.tsx +80 -0
- package/src/core/primitives/card/__workshop__/props.tsx +53 -0
- package/src/core/primitives/card/__workshop__/selected.tsx +94 -0
- package/src/core/primitives/card/__workshop__/styled.tsx +14 -0
- package/src/core/primitives/card/card.tsx +128 -0
- package/src/core/primitives/card/index.ts +2 -0
- package/src/core/primitives/card/styles.ts +147 -0
- package/src/core/primitives/card/types.ts +11 -0
- package/src/core/primitives/checkbox/__workshop__/example.tsx +25 -0
- package/src/core/primitives/checkbox/__workshop__/index.ts +13 -0
- package/src/core/primitives/checkbox/__workshop__/props.tsx +33 -0
- package/src/core/primitives/checkbox/__workshop__/readOnly.tsx +16 -0
- package/src/core/primitives/checkbox/__workshop__/tones.tsx +28 -0
- package/src/core/primitives/checkbox/checkbox.tsx +73 -0
- package/src/core/primitives/checkbox/index.ts +1 -0
- package/src/core/primitives/checkbox/styles.ts +128 -0
- package/src/core/primitives/code/__workshop__/index.ts +19 -0
- package/src/core/primitives/code/__workshop__/opticalAlignment.tsx +48 -0
- package/src/core/primitives/code/__workshop__/props.tsx +21 -0
- package/src/core/primitives/code/code.tsx +55 -0
- package/src/core/primitives/code/index.ts +1 -0
- package/src/core/primitives/code/refractor.tsx +20 -0
- package/src/core/primitives/code/styles.ts +77 -0
- package/src/core/primitives/container/__workshop__/example.tsx +20 -0
- package/src/core/primitives/container/__workshop__/index.ts +8 -0
- package/src/core/primitives/container/container.tsx +54 -0
- package/src/core/primitives/container/index.ts +2 -0
- package/src/core/primitives/container/styles.ts +23 -0
- package/src/core/primitives/container/types.ts +6 -0
- package/src/core/primitives/flex/__workshop__/example.tsx +34 -0
- package/src/core/primitives/flex/__workshop__/gap.tsx +25 -0
- package/src/core/primitives/flex/__workshop__/index.ts +11 -0
- package/src/core/primitives/flex/flex.tsx +64 -0
- package/src/core/primitives/flex/index.ts +1 -0
- package/src/core/primitives/grid/__workshop__/index.ts +10 -0
- package/src/core/primitives/grid/__workshop__/responsive.tsx +54 -0
- package/src/core/primitives/grid/grid.test.tsx +80 -0
- package/src/core/primitives/grid/grid.tsx +74 -0
- package/src/core/primitives/grid/index.ts +1 -0
- package/src/core/primitives/heading/__workshop__/index.ts +19 -0
- package/src/core/primitives/heading/__workshop__/opticalAlignment.tsx +54 -0
- package/src/core/primitives/heading/__workshop__/plain.tsx +32 -0
- package/src/core/primitives/heading/heading.tsx +88 -0
- package/src/core/primitives/heading/index.ts +1 -0
- package/src/core/primitives/heading/styles.ts +64 -0
- package/src/core/primitives/heading/types.ts +7 -0
- package/src/core/primitives/index.ts +27 -0
- package/src/core/primitives/inline/__workshop__/index.ts +8 -0
- package/src/core/primitives/inline/__workshop__/plain.tsx +27 -0
- package/src/core/primitives/inline/index.ts +1 -0
- package/src/core/primitives/inline/inline.test.tsx +51 -0
- package/src/core/primitives/inline/inline.tsx +63 -0
- package/src/core/primitives/inline/styles.ts +32 -0
- package/src/core/primitives/inline/types.ts +6 -0
- package/src/core/primitives/kbd/__workshop__/index.ts +8 -0
- package/src/core/primitives/kbd/__workshop__/plain.tsx +9 -0
- package/src/core/primitives/kbd/index.ts +1 -0
- package/src/core/primitives/kbd/kbd.tsx +69 -0
- package/src/core/primitives/label/__workshop__/index.ts +19 -0
- package/src/core/primitives/label/__workshop__/opticalAlignment.tsx +48 -0
- package/src/core/primitives/label/__workshop__/plain.tsx +24 -0
- package/src/core/primitives/label/index.ts +1 -0
- package/src/core/primitives/label/label.tsx +87 -0
- package/src/core/primitives/label/styles.ts +45 -0
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +77 -0
- package/src/core/primitives/popover/__workshop__/MarginsStory.tsx +31 -0
- package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +32 -0
- package/src/core/primitives/popover/__workshop__/OpenOnMountStory.tsx +11 -0
- package/src/core/primitives/popover/__workshop__/PlainStory.tsx +71 -0
- package/src/core/primitives/popover/__workshop__/RecursiveStory.tsx +71 -0
- package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +89 -0
- package/src/core/primitives/popover/__workshop__/TestStory.tsx +97 -0
- package/src/core/primitives/popover/__workshop__/index.ts +49 -0
- package/src/core/primitives/popover/constants.ts +22 -0
- package/src/core/primitives/popover/floating-ui/size.ts +99 -0
- package/src/core/primitives/popover/helpers.ts +31 -0
- package/src/core/primitives/popover/index.ts +2 -0
- package/src/core/primitives/popover/popover.tsx +511 -0
- package/src/core/primitives/popover/popoverCard.tsx +166 -0
- package/src/core/primitives/popover/types.ts +7 -0
- package/src/core/primitives/radio/__workshop__/example.tsx +63 -0
- package/src/core/primitives/radio/__workshop__/index.ts +11 -0
- package/src/core/primitives/radio/__workshop__/plain.tsx +28 -0
- package/src/core/primitives/radio/index.ts +1 -0
- package/src/core/primitives/radio/radio.tsx +51 -0
- package/src/core/primitives/radio/styles.ts +117 -0
- package/src/core/primitives/select/__workshop__/index.ts +11 -0
- package/src/core/primitives/select/__workshop__/plain.tsx +27 -0
- package/src/core/primitives/select/__workshop__/readOnly.tsx +23 -0
- package/src/core/primitives/select/index.ts +1 -0
- package/src/core/primitives/select/select.test.tsx +52 -0
- package/src/core/primitives/select/select.tsx +94 -0
- package/src/core/primitives/select/styles.ts +166 -0
- package/src/core/primitives/spinner/__workshop__/Props.tsx +15 -0
- package/src/core/primitives/spinner/__workshop__/index.ts +14 -0
- package/src/core/primitives/spinner/index.ts +1 -0
- package/src/core/primitives/spinner/spinner.tsx +46 -0
- package/src/core/primitives/stack/__workshop__/index.ts +14 -0
- package/src/core/primitives/stack/__workshop__/plain.tsx +32 -0
- package/src/core/primitives/stack/index.ts +1 -0
- package/src/core/primitives/stack/stack.test.tsx +57 -0
- package/src/core/primitives/stack/stack.tsx +57 -0
- package/src/core/primitives/stack/styles.ts +32 -0
- package/src/core/primitives/switch/__workshop__/example.tsx +23 -0
- package/src/core/primitives/switch/__workshop__/index.ts +11 -0
- package/src/core/primitives/switch/__workshop__/props.tsx +21 -0
- package/src/core/primitives/switch/index.ts +1 -0
- package/src/core/primitives/switch/styles.ts +173 -0
- package/src/core/primitives/switch/switch.tsx +68 -0
- package/src/core/primitives/text/__workshop__/colored.tsx +30 -0
- package/src/core/primitives/text/__workshop__/example.tsx +39 -0
- package/src/core/primitives/text/__workshop__/index.ts +24 -0
- package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +48 -0
- package/src/core/primitives/text/index.ts +1 -0
- package/src/core/primitives/text/styles.ts +74 -0
- package/src/core/primitives/text/text.tsx +89 -0
- package/src/core/primitives/textArea/__workshop__/index.ts +14 -0
- package/src/core/primitives/textArea/__workshop__/plain.tsx +50 -0
- package/src/core/primitives/textArea/index.ts +1 -0
- package/src/core/primitives/textArea/textArea.tsx +120 -0
- package/src/core/primitives/textInput/__workshop__/clearButton.tsx +30 -0
- package/src/core/primitives/textInput/__workshop__/customValidity.tsx +17 -0
- package/src/core/primitives/textInput/__workshop__/index.ts +44 -0
- package/src/core/primitives/textInput/__workshop__/plain.tsx +98 -0
- package/src/core/primitives/textInput/__workshop__/readOnly.tsx +9 -0
- package/src/core/primitives/textInput/__workshop__/states.tsx +53 -0
- package/src/core/primitives/textInput/__workshop__/tones.tsx +277 -0
- package/src/core/primitives/textInput/__workshop__/typed.tsx +23 -0
- package/src/core/primitives/textInput/index.ts +1 -0
- package/src/core/primitives/textInput/textInput.test.tsx +48 -0
- package/src/core/primitives/textInput/textInput.tsx +395 -0
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +102 -0
- package/src/core/primitives/tooltip/__workshop__/index.ts +29 -0
- package/src/core/primitives/tooltip/__workshop__/overflowingBoundary.tsx +74 -0
- package/src/core/primitives/tooltip/__workshop__/props.tsx +107 -0
- package/src/core/primitives/tooltip/__workshop__/resizableBoundary.tsx +86 -0
- package/src/core/primitives/tooltip/constants.ts +23 -0
- package/src/core/primitives/tooltip/index.ts +2 -0
- package/src/core/primitives/tooltip/tooltip.test.tsx +452 -0
- package/src/core/primitives/tooltip/tooltip.tsx +495 -0
- package/src/core/primitives/tooltip/tooltipCard.tsx +109 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/index.ts +4 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +11 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +57 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/types.ts +10 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +13 -0
- package/src/core/primitives/types.ts +179 -0
- package/src/core/styles/border/borderStyle.ts +56 -0
- package/src/core/styles/border/index.ts +2 -0
- package/src/core/styles/border/types.ts +10 -0
- package/src/core/styles/box/boxStyle.ts +69 -0
- package/src/core/styles/box/index.ts +2 -0
- package/src/core/styles/box/types.ts +11 -0
- package/src/core/styles/card/_cardColorStyle.ts +108 -0
- package/src/core/styles/card/index.ts +1 -0
- package/src/core/styles/flex/flexItemStyle.ts +27 -0
- package/src/core/styles/flex/flexStyle.ts +70 -0
- package/src/core/styles/flex/index.ts +3 -0
- package/src/core/styles/flex/types.ts +25 -0
- package/src/core/styles/focusRing/index.ts +25 -0
- package/src/core/styles/font/codeFontStyle.ts +13 -0
- package/src/core/styles/font/headingFontStyle.ts +13 -0
- package/src/core/styles/font/index.ts +6 -0
- package/src/core/styles/font/labelFontStyle.ts +13 -0
- package/src/core/styles/font/responsiveFont.ts +103 -0
- package/src/core/styles/font/textAlignStyle.ts +19 -0
- package/src/core/styles/font/textFontStyle.ts +13 -0
- package/src/core/styles/font/types.ts +35 -0
- package/src/core/styles/grid/gridItemStyle.ts +82 -0
- package/src/core/styles/grid/gridStyle.ts +108 -0
- package/src/core/styles/grid/index.ts +3 -0
- package/src/core/styles/grid/types.ts +37 -0
- package/src/core/styles/helpers.ts +72 -0
- package/src/core/styles/index.ts +5 -0
- package/src/core/styles/input/index.ts +2 -0
- package/src/core/styles/input/responsiveInputPaddingStyle.ts +78 -0
- package/src/core/styles/input/textInputStyle.ts +263 -0
- package/src/core/styles/internal.ts +12 -0
- package/src/core/styles/margin/index.ts +2 -0
- package/src/core/styles/margin/marginStyle.ts +21 -0
- package/src/core/styles/margin/marginsStyle.test.ts +33 -0
- package/src/core/styles/margin/types.ts +9 -0
- package/src/core/styles/padding/index.ts +2 -0
- package/src/core/styles/padding/paddingStyle.test.ts +33 -0
- package/src/core/styles/padding/paddingStyle.ts +21 -0
- package/src/core/styles/padding/types.ts +12 -0
- package/src/core/styles/radius/index.ts +2 -0
- package/src/core/styles/radius/radiusStyle.ts +23 -0
- package/src/core/styles/radius/types.ts +8 -0
- package/src/core/styles/shadow/index.ts +2 -0
- package/src/core/styles/shadow/shadowStyle.ts +29 -0
- package/src/core/styles/shadow/types.ts +6 -0
- package/src/core/styles/types.ts +8 -0
- package/src/core/theme/__workshop__/build/Root.tsx +367 -0
- package/src/core/theme/__workshop__/build/helpers.ts +46 -0
- package/src/core/theme/__workshop__/build/story.tsx +465 -0
- package/src/core/theme/__workshop__/canvas.tsx +352 -0
- package/src/core/theme/__workshop__/color.tsx +62 -0
- package/src/core/theme/__workshop__/debug/story.tsx +408 -0
- package/src/core/theme/__workshop__/index.ts +39 -0
- package/src/core/theme/__workshop__/layer.tsx +78 -0
- package/src/core/theme/__workshop__/nestedProvider.tsx +15 -0
- package/src/core/theme/index.ts +5 -0
- package/src/core/theme/theme.test.tsx +73 -0
- package/src/core/theme/themeColorProvider.tsx +29 -0
- package/src/core/theme/themeContext.ts +10 -0
- package/src/core/theme/themeProvider.tsx +62 -0
- package/src/core/theme/types.ts +12 -0
- package/src/core/theme/useRootTheme.ts +17 -0
- package/src/core/theme/useTheme.ts +16 -0
- package/src/core/types/avatar.ts +14 -0
- package/src/core/types/badge.ts +12 -0
- package/src/core/types/box.ts +19 -0
- package/src/core/types/button.ts +21 -0
- package/src/core/types/card.ts +6 -0
- package/src/core/types/component.ts +32 -0
- package/src/core/types/dialog.ts +4 -0
- package/src/core/types/flex.ts +30 -0
- package/src/core/types/grid.ts +14 -0
- package/src/core/types/gridItem.ts +29 -0
- package/src/core/types/index.ts +15 -0
- package/src/core/types/placement.ts +18 -0
- package/src/core/types/popover.ts +4 -0
- package/src/core/types/radius.ts +4 -0
- package/src/core/types/selectable.ts +6 -0
- package/src/core/types/text.ts +4 -0
- package/src/core/utils/arrow/arrow.tsx +123 -0
- package/src/core/utils/arrow/cmds.ts +91 -0
- package/src/core/utils/arrow/index.ts +1 -0
- package/src/core/utils/boundaryElement/__workshop__/index.ts +14 -0
- package/src/core/utils/boundaryElement/__workshop__/plain.tsx +19 -0
- package/src/core/utils/boundaryElement/boundaryElement.test.tsx +100 -0
- package/src/core/utils/boundaryElement/boundaryElementContext.ts +7 -0
- package/src/core/utils/boundaryElement/boundaryElementProvider.tsx +24 -0
- package/src/core/utils/boundaryElement/index.ts +3 -0
- package/src/core/utils/boundaryElement/types.ts +7 -0
- package/src/core/utils/boundaryElement/useBoundaryElement.ts +26 -0
- package/src/core/utils/conditionalWrapper/conditionalWrapper.tsx +21 -0
- package/src/core/utils/conditionalWrapper/index.ts +1 -0
- package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +30 -0
- package/src/core/utils/elementQuery/__workshop__/index.ts +14 -0
- package/src/core/utils/elementQuery/elementQuery.tsx +53 -0
- package/src/core/utils/elementQuery/helpers.ts +27 -0
- package/src/core/utils/elementQuery/index.ts +1 -0
- package/src/core/utils/errorBoundary.tsx +48 -0
- package/src/core/utils/getElementRef.ts +26 -0
- package/src/core/utils/index.ts +9 -0
- package/src/core/utils/layer/__workshop__/_debug.tsx +17 -0
- package/src/core/utils/layer/__workshop__/index.ts +24 -0
- package/src/core/utils/layer/__workshop__/multipleRoots.tsx +49 -0
- package/src/core/utils/layer/__workshop__/nested.tsx +98 -0
- package/src/core/utils/layer/__workshop__/responsiveZOffset.tsx +13 -0
- package/src/core/utils/layer/getLayerContext.test.ts +30 -0
- package/src/core/utils/layer/getLayerContext.ts +21 -0
- package/src/core/utils/layer/index.ts +4 -0
- package/src/core/utils/layer/layer.test.tsx +108 -0
- package/src/core/utils/layer/layer.tsx +98 -0
- package/src/core/utils/layer/layerContext.ts +7 -0
- package/src/core/utils/layer/layerProvider.tsx +111 -0
- package/src/core/utils/layer/types.ts +9 -0
- package/src/core/utils/layer/useLayer.ts +26 -0
- package/src/core/utils/portal/__workshop__/index.ts +14 -0
- package/src/core/utils/portal/__workshop__/named.tsx +63 -0
- package/src/core/utils/portal/index.ts +4 -0
- package/src/core/utils/portal/portal.test.tsx +103 -0
- package/src/core/utils/portal/portal.ts +32 -0
- package/src/core/utils/portal/portalContext.ts +31 -0
- package/src/core/utils/portal/portalProvider.tsx +47 -0
- package/src/core/utils/portal/types.ts +9 -0
- package/src/core/utils/portal/usePortal.ts +25 -0
- package/src/core/utils/spanWithTextOverflow.tsx +10 -0
- package/src/core/utils/srOnly/index.ts +1 -0
- package/src/core/utils/srOnly/srOnly.tsx +36 -0
- package/src/core/utils/virtualList/__workshop__/changingProps.tsx +36 -0
- package/src/core/utils/virtualList/__workshop__/elementScroll.tsx +24 -0
- package/src/core/utils/virtualList/__workshop__/index.ts +29 -0
- package/src/core/utils/virtualList/__workshop__/infiniteList.tsx +48 -0
- package/src/core/utils/virtualList/__workshop__/windowScrolll.tsx +22 -0
- package/src/core/utils/virtualList/index.ts +1 -0
- package/src/core/utils/virtualList/virtualList.tsx +200 -0
- package/src/theme/build/_deprecated/color/_selectable/createSelectableTones.ts +76 -0
- package/src/theme/build/_deprecated/color/_solid/createSolidTones.ts +54 -0
- package/src/theme/build/_deprecated/color/button/createButtonModes.ts +22 -0
- package/src/theme/build/_deprecated/color/button/createButtonTones.ts +55 -0
- package/src/theme/build/_deprecated/color/card/createCardStates.ts +60 -0
- package/src/theme/build/_deprecated/color/color.test.ts +63 -0
- package/src/theme/build/_deprecated/color/defaults.ts +390 -0
- package/src/theme/build/_deprecated/color/factory.ts +142 -0
- package/src/theme/build/_deprecated/color/index.ts +1 -0
- package/src/theme/build/_deprecated/color/input/createInputModes.ts +81 -0
- package/src/theme/build/_deprecated/color/muted/createMuted.ts +54 -0
- package/src/theme/build/_deprecated/color/spot/createSpot.ts +20 -0
- package/src/theme/build/buildColorTheme.test.ts +183 -0
- package/src/theme/build/buildColorTheme.ts +499 -0
- package/src/theme/build/buildTheme.test.ts +87 -0
- package/src/theme/build/buildTheme.ts +36 -0
- package/src/theme/build/colorToken/colorToken.ts +19 -0
- package/src/theme/build/colorToken/compileColorToken.ts +21 -0
- package/src/theme/build/colorToken/index.ts +2 -0
- package/src/theme/build/colorToken/types.ts +6 -0
- package/src/theme/build/index.ts +3 -0
- package/src/theme/build/lib/color-fns/blend/index.ts +3 -0
- package/src/theme/build/lib/color-fns/blend/mix.ts +21 -0
- package/src/theme/build/lib/color-fns/blend/multiply.ts +18 -0
- package/src/theme/build/lib/color-fns/blend/screen.ts +18 -0
- package/src/theme/build/lib/color-fns/color-fns.test.ts +68 -0
- package/src/theme/build/lib/color-fns/contrastRatio.ts +31 -0
- package/src/theme/build/lib/color-fns/convert.ts +150 -0
- package/src/theme/build/lib/color-fns/index.ts +6 -0
- package/src/theme/build/lib/color-fns/parse.ts +60 -0
- package/src/theme/build/lib/color-fns/rgba.ts +10 -0
- package/src/theme/build/lib/color-fns/types.ts +28 -0
- package/src/theme/build/lib/isRecord.ts +3 -0
- package/src/theme/build/lib/lazy.ts +30 -0
- package/src/theme/build/lib/utils.ts +19 -0
- package/src/theme/build/merge.ts +26 -0
- package/src/theme/build/mixThemeColor.test.ts +21 -0
- package/src/theme/build/mixThemeColor.ts +53 -0
- package/src/theme/build/renderColorTheme.ts +532 -0
- package/src/theme/build/renderColorValue.ts +85 -0
- package/src/theme/build/resolveColorTokens.ts +268 -0
- package/src/theme/build/theme.test.ts +27 -0
- package/src/theme/config/helpers.ts +55 -0
- package/src/theme/config/index.ts +4 -0
- package/src/theme/config/system.ts +115 -0
- package/src/theme/config/tokens/color/index.ts +1 -0
- package/src/theme/config/tokens/color/types.ts +133 -0
- package/src/theme/config/tokens/index.ts +4 -0
- package/src/theme/config/tokens/parseTokenKey.test.ts +64 -0
- package/src/theme/config/tokens/parseTokenKey.ts +67 -0
- package/src/theme/config/tokens/parseTokenValue.test.ts +42 -0
- package/src/theme/config/tokens/parseTokenValue.ts +133 -0
- package/src/theme/config/tokens/types.ts +53 -0
- package/src/theme/config/types.ts +46 -0
- package/src/theme/defaults/colorPalette.ts +5 -0
- package/src/theme/defaults/colorTokens.ts +648 -0
- package/src/theme/defaults/config.ts +84 -0
- package/src/theme/defaults/fonts.ts +227 -0
- package/src/theme/getScopedTheme.ts +98 -0
- package/src/theme/index.ts +5 -0
- package/src/theme/system/avatar.ts +14 -0
- package/src/theme/system/color/_constants.ts +45 -0
- package/src/theme/system/color/_helpers.ts +24 -0
- package/src/theme/system/color/_system.ts +40 -0
- package/src/theme/system/color/avatar.ts +15 -0
- package/src/theme/system/color/badge.ts +16 -0
- package/src/theme/system/color/button.ts +17 -0
- package/src/theme/system/color/color.ts +34 -0
- package/src/theme/system/color/index.ts +13 -0
- package/src/theme/system/color/input.ts +25 -0
- package/src/theme/system/color/kbd.ts +8 -0
- package/src/theme/system/color/selectable.ts +12 -0
- package/src/theme/system/color/shadow.ts +7 -0
- package/src/theme/system/color/state.ts +43 -0
- package/src/theme/system/color/syntax.ts +41 -0
- package/src/theme/system/css.ts +14 -0
- package/src/theme/system/focusRing.ts +7 -0
- package/src/theme/system/font.ts +52 -0
- package/src/theme/system/index.ts +11 -0
- package/src/theme/system/input.ts +33 -0
- package/src/theme/system/layer.ts +8 -0
- package/src/theme/system/shadow.ts +19 -0
- package/src/theme/system/styles.ts +13 -0
- package/src/theme/system/theme.ts +138 -0
- package/src/theme/system/v0/avatar.ts +10 -0
- package/src/theme/system/v0/color/_generic.ts +35 -0
- package/src/theme/system/v0/color/_system.ts +17 -0
- package/src/theme/system/v0/color/base.ts +21 -0
- package/src/theme/system/v0/color/button.ts +42 -0
- package/src/theme/system/v0/color/card.ts +19 -0
- package/src/theme/system/v0/color/color.ts +40 -0
- package/src/theme/system/v0/color/index.ts +11 -0
- package/src/theme/system/v0/color/input.ts +34 -0
- package/src/theme/system/v0/color/muted.ts +26 -0
- package/src/theme/system/v0/color/selectable.ts +31 -0
- package/src/theme/system/v0/color/solid.ts +26 -0
- package/src/theme/system/v0/color/spot.ts +13 -0
- package/src/theme/system/v0/index.ts +3 -0
- package/src/theme/system/v0/input.ts +23 -0
- package/src/theme/versioning/getTheme_v2.ts +57 -0
- package/src/theme/versioning/index.ts +5 -0
- package/src/theme/versioning/is_v0.ts +6 -0
- package/src/theme/versioning/is_v2.ts +6 -0
- package/src/theme/versioning/themeColor_v0_v2.ts +243 -0
- package/src/theme/versioning/themeColor_v2_v2_9.ts +49 -0
- package/src/theme/versioning/v0_v2.ts +94 -0
- package/src/theme/versioning/v2_v0.ts +135 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import {render} from '../../../../test'
|
|
4
|
+
import {LayerContext} from './layerContext'
|
|
5
|
+
import {LayerContextValue} from './types'
|
|
6
|
+
import {useLayer} from './useLayer'
|
|
7
|
+
|
|
8
|
+
describe('utils/layer', () => {
|
|
9
|
+
describe('useLayer', () => {
|
|
10
|
+
it('should get context value', async () => {
|
|
11
|
+
const log = jest.fn()
|
|
12
|
+
|
|
13
|
+
function Debug() {
|
|
14
|
+
const rootLayer = useLayer()
|
|
15
|
+
|
|
16
|
+
log(rootLayer)
|
|
17
|
+
|
|
18
|
+
return <>debug</>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Root() {
|
|
22
|
+
const value: LayerContextValue = {
|
|
23
|
+
version: 0.0,
|
|
24
|
+
isTopLayer: true,
|
|
25
|
+
level: 0,
|
|
26
|
+
registerChild: () => () => undefined,
|
|
27
|
+
size: 0,
|
|
28
|
+
zIndex: 0,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<LayerContext.Provider value={value}>
|
|
33
|
+
<Debug />
|
|
34
|
+
</LayerContext.Provider>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render(<Root />)
|
|
39
|
+
|
|
40
|
+
expect(log.mock.calls[0][0].version).toBe(0.0)
|
|
41
|
+
expect(log.mock.calls[0][0].isTopLayer).toBe(true)
|
|
42
|
+
expect(typeof log.mock.calls[0][0].registerChild).toBe('function')
|
|
43
|
+
expect(log.mock.calls[0][0].size).toBe(0)
|
|
44
|
+
expect(log.mock.calls[0][0].zIndex).toBe(0)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should fail when no context value is provided', async () => {
|
|
48
|
+
const log = jest.fn()
|
|
49
|
+
|
|
50
|
+
function Debug() {
|
|
51
|
+
try {
|
|
52
|
+
useLayer()
|
|
53
|
+
} catch (err) {
|
|
54
|
+
log(err)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function Root() {
|
|
61
|
+
const value = undefined
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<LayerContext.Provider value={value as any}>
|
|
65
|
+
<Debug />
|
|
66
|
+
</LayerContext.Provider>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render(<Root />)
|
|
71
|
+
|
|
72
|
+
expect(log.mock.calls[0][0].message).toEqual('useLayer(): missing context value')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should fail when context value is not compatible', async () => {
|
|
76
|
+
const log = jest.fn()
|
|
77
|
+
|
|
78
|
+
function Debug() {
|
|
79
|
+
try {
|
|
80
|
+
useLayer()
|
|
81
|
+
} catch (err) {
|
|
82
|
+
log(err)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Root() {
|
|
89
|
+
// NOTE: we’re testing this because the context value may be a function in the future
|
|
90
|
+
const value = () => {
|
|
91
|
+
return {version: 1}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<LayerContext.Provider value={value as any}>
|
|
96
|
+
<Debug />
|
|
97
|
+
</LayerContext.Provider>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
render(<Root />)
|
|
102
|
+
|
|
103
|
+
expect(log.mock.calls[0][0].message).toEqual(
|
|
104
|
+
'useLayer(): the context value is not compatible',
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {FocusEvent, forwardRef, useCallback, useEffect, useImperativeHandle, useRef} from 'react'
|
|
2
|
+
import {styled} from 'styled-components'
|
|
3
|
+
|
|
4
|
+
import {EMPTY_RECORD} from '../../constants'
|
|
5
|
+
import {containsOrEqualsElement, isHTMLElement} from '../../helpers'
|
|
6
|
+
import {LayerProvider} from './layerProvider'
|
|
7
|
+
import {useLayer} from './useLayer'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface LayerProps {
|
|
13
|
+
as?: React.ElementType | keyof React.JSX.IntrinsicElements
|
|
14
|
+
/** A callback that fires when the layer becomes the top layer when it was not the top layer before. */
|
|
15
|
+
onActivate?: (props: {activeElement: HTMLElement | null}) => void
|
|
16
|
+
zOffset?: number | number[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface LayerChildrenProps {
|
|
20
|
+
as?: React.ElementType | keyof React.JSX.IntrinsicElements
|
|
21
|
+
onActivate?: LayerProps['onActivate']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const StyledLayer = styled.div({position: 'relative'})
|
|
25
|
+
|
|
26
|
+
const LayerChildren = forwardRef(function LayerChildren(
|
|
27
|
+
props: LayerChildrenProps & Omit<React.HTMLProps<HTMLDivElement>, 'as'>,
|
|
28
|
+
forwardedRef: React.Ref<HTMLDivElement>,
|
|
29
|
+
) {
|
|
30
|
+
const {children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps} = props
|
|
31
|
+
const {zIndex, isTopLayer} = useLayer()
|
|
32
|
+
const lastFocusedRef = useRef<HTMLElement | null>(null)
|
|
33
|
+
const ref = useRef<HTMLDivElement | null>(null)
|
|
34
|
+
const isTopLayerRef = useRef<boolean>(isTopLayer)
|
|
35
|
+
|
|
36
|
+
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
37
|
+
|
|
38
|
+
// When the layer very first mounts, it will be the top layer, but we don't want to fire
|
|
39
|
+
// the callback in that case. We use a ref to track the previous value of isTopLayer to
|
|
40
|
+
// determine if the layer has become the top layer since the last render.
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const becameTopLayer = isTopLayerRef.current !== isTopLayer && isTopLayer
|
|
43
|
+
|
|
44
|
+
if (becameTopLayer) {
|
|
45
|
+
onActivate?.({activeElement: lastFocusedRef.current})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
isTopLayerRef.current = isTopLayer
|
|
49
|
+
}, [isTopLayer, onActivate])
|
|
50
|
+
|
|
51
|
+
const handleFocus = useCallback(
|
|
52
|
+
(event: FocusEvent<HTMLDivElement, Element>) => {
|
|
53
|
+
// Call the user-provided onFocus handler if any
|
|
54
|
+
onFocus?.(event)
|
|
55
|
+
|
|
56
|
+
const rootElement = ref.current
|
|
57
|
+
const target = document.activeElement
|
|
58
|
+
|
|
59
|
+
if (!isTopLayer || !rootElement || !target) return
|
|
60
|
+
|
|
61
|
+
if (isHTMLElement(target) && containsOrEqualsElement(rootElement, target)) {
|
|
62
|
+
lastFocusedRef.current = target
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[isTopLayer, onFocus],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<StyledLayer
|
|
70
|
+
{...restProps}
|
|
71
|
+
data-ui="Layer"
|
|
72
|
+
onFocus={handleFocus}
|
|
73
|
+
ref={ref}
|
|
74
|
+
style={{...style, zIndex}}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</StyledLayer>
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export const Layer = forwardRef(function Layer(
|
|
85
|
+
props: LayerProps & Omit<React.HTMLProps<HTMLDivElement>, 'as'>,
|
|
86
|
+
ref: React.Ref<HTMLDivElement>,
|
|
87
|
+
) {
|
|
88
|
+
const {children, zOffset = 1, ...restProps} = props
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<LayerProvider zOffset={zOffset}>
|
|
92
|
+
<LayerChildren {...restProps} ref={ref}>
|
|
93
|
+
{children}
|
|
94
|
+
</LayerChildren>
|
|
95
|
+
</LayerProvider>
|
|
96
|
+
)
|
|
97
|
+
})
|
|
98
|
+
Layer.displayName = 'ForwardRef(Layer)'
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {useCallback, useContext, useEffect, useMemo, useState} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useMediaIndex} from '../../hooks'
|
|
4
|
+
import {_getArrayProp} from '../../styles'
|
|
5
|
+
import {getLayerContext} from './getLayerContext'
|
|
6
|
+
import {LayerContext} from './layerContext'
|
|
7
|
+
import {LayerContextValue} from './types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface LayerProviderProps {
|
|
13
|
+
children?: React.ReactNode
|
|
14
|
+
zOffset?: number | number[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export function LayerProvider(props: LayerProviderProps): React.JSX.Element {
|
|
21
|
+
const {children, zOffset: zOffsetProp = 0} = props
|
|
22
|
+
|
|
23
|
+
// Get parent context values
|
|
24
|
+
const parentContextValue = useContext(LayerContext)
|
|
25
|
+
const parent = parentContextValue && getLayerContext(parentContextValue)
|
|
26
|
+
const parentRegisterChild = parent?.registerChild
|
|
27
|
+
const parentLevel = parent?.level ?? 0
|
|
28
|
+
|
|
29
|
+
// Get level
|
|
30
|
+
const level = parentLevel + 1
|
|
31
|
+
|
|
32
|
+
// Get z-index offset
|
|
33
|
+
const zOffset = _getArrayProp(zOffsetProp)
|
|
34
|
+
|
|
35
|
+
// Get responsive z-index value
|
|
36
|
+
const maxMediaIndex = zOffset.length - 1
|
|
37
|
+
const mediaIndex = Math.min(useMediaIndex(), maxMediaIndex)
|
|
38
|
+
const zIndex = parent ? parent.zIndex + zOffset[mediaIndex] : zOffset[mediaIndex]
|
|
39
|
+
|
|
40
|
+
// A state value that is used to keep track of the number of child layers on each level
|
|
41
|
+
const [, setChildLayers] = useState<Record<number, number>>({})
|
|
42
|
+
|
|
43
|
+
// A state value that is used to keep track of the number of child levels
|
|
44
|
+
const [size, setSize] = useState(0)
|
|
45
|
+
|
|
46
|
+
const isTopLayer = size === 0
|
|
47
|
+
|
|
48
|
+
const registerChild = useCallback(
|
|
49
|
+
(childLevel?: number) => {
|
|
50
|
+
// Register child layers to the parent layer
|
|
51
|
+
const parentDispose = parentRegisterChild?.(childLevel)
|
|
52
|
+
|
|
53
|
+
if (childLevel !== undefined) {
|
|
54
|
+
setChildLayers((state) => {
|
|
55
|
+
const prevLen = state[childLevel] ?? 0
|
|
56
|
+
const nextState = {...state, [childLevel]: prevLen + 1}
|
|
57
|
+
|
|
58
|
+
setSize(Object.keys(nextState).length)
|
|
59
|
+
|
|
60
|
+
return nextState
|
|
61
|
+
})
|
|
62
|
+
} else {
|
|
63
|
+
// Legacy behavior: if no child level is provided, increment the size by 1
|
|
64
|
+
setSize((v) => v + 1)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
if (childLevel !== undefined) {
|
|
69
|
+
setChildLayers((state) => {
|
|
70
|
+
const nextState = {...state}
|
|
71
|
+
|
|
72
|
+
if (nextState[childLevel] === 1) {
|
|
73
|
+
delete nextState[childLevel]
|
|
74
|
+
|
|
75
|
+
setSize(Object.keys(nextState).length)
|
|
76
|
+
} else {
|
|
77
|
+
nextState[childLevel] -= 1
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return nextState
|
|
81
|
+
})
|
|
82
|
+
} else {
|
|
83
|
+
// Legacy behavior: if no child level is provided, decrement the size by 1
|
|
84
|
+
setSize((v) => v - 1)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
parentDispose?.()
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
[parentRegisterChild, setSize, setChildLayers],
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
// Register this layer on mount
|
|
94
|
+
useEffect(() => parentRegisterChild?.(level), [level, parentRegisterChild])
|
|
95
|
+
|
|
96
|
+
const value: LayerContextValue = useMemo(
|
|
97
|
+
() => ({
|
|
98
|
+
version: 0.0,
|
|
99
|
+
isTopLayer,
|
|
100
|
+
level,
|
|
101
|
+
registerChild,
|
|
102
|
+
size,
|
|
103
|
+
zIndex,
|
|
104
|
+
}),
|
|
105
|
+
[isTopLayer, level, registerChild, size, zIndex],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return <LayerContext.Provider value={value}>{children}</LayerContext.Provider>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
LayerProvider.displayName = 'LayerProvider'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {useContext} from 'react'
|
|
2
|
+
|
|
3
|
+
import {getLayerContext} from './getLayerContext'
|
|
4
|
+
import {LayerContext} from './layerContext'
|
|
5
|
+
import {LayerContextValue} from './types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export function useLayer(): LayerContextValue {
|
|
11
|
+
const value = useContext(LayerContext)
|
|
12
|
+
|
|
13
|
+
if (!value) {
|
|
14
|
+
throw new Error('useLayer(): missing context value')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return getLayerContext(value)
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (err instanceof Error) {
|
|
21
|
+
throw new Error(`useLayer(): ${err.message}`)
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(`useLayer(): ${err}`)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {defineScope} from '@bettercms-ai/kit-workshop'
|
|
2
|
+
import {lazy} from 'react'
|
|
3
|
+
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'utils/portal',
|
|
6
|
+
title: 'Portal',
|
|
7
|
+
stories: [
|
|
8
|
+
{
|
|
9
|
+
name: 'named',
|
|
10
|
+
title: 'Named portals',
|
|
11
|
+
component: lazy(() => import('./named')),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {Card, Container, Portal, PortalProvider, Stack, Text} from '@bettercms-ai/kit'
|
|
2
|
+
import {useMemo, useState} from 'react'
|
|
3
|
+
|
|
4
|
+
export default function NamedStory() {
|
|
5
|
+
const [portal1Element, setPortal1Element] = useState<HTMLDivElement | null>(null)
|
|
6
|
+
const [portal2Element, setPortal2Element] = useState<HTMLDivElement | null>(null)
|
|
7
|
+
const [portal3Element, setPortal3Element] = useState<HTMLDivElement | null>(null)
|
|
8
|
+
const __unstable_elements = useMemo(
|
|
9
|
+
() => ({
|
|
10
|
+
portal1: portal1Element,
|
|
11
|
+
portal2: portal2Element,
|
|
12
|
+
portal3: portal3Element,
|
|
13
|
+
}),
|
|
14
|
+
[portal1Element, portal2Element, portal3Element],
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<PortalProvider __unstable_elements={__unstable_elements}>
|
|
19
|
+
<Container width={1}>
|
|
20
|
+
<Card height="fill" padding={4}>
|
|
21
|
+
<Stack space={2}>
|
|
22
|
+
<Text size={1} weight="medium">
|
|
23
|
+
Portal 1
|
|
24
|
+
</Text>
|
|
25
|
+
<Card border padding={3} ref={setPortal1Element} />
|
|
26
|
+
</Stack>
|
|
27
|
+
</Card>
|
|
28
|
+
<Card height="fill" padding={4}>
|
|
29
|
+
<Stack space={2}>
|
|
30
|
+
<Text size={1} weight="medium">
|
|
31
|
+
Portal 2
|
|
32
|
+
</Text>
|
|
33
|
+
<Card border padding={3} ref={setPortal2Element} />
|
|
34
|
+
</Stack>
|
|
35
|
+
</Card>
|
|
36
|
+
<Card height="fill" padding={4}>
|
|
37
|
+
<Stack space={2}>
|
|
38
|
+
<Text size={1} weight="medium">
|
|
39
|
+
Portal 3
|
|
40
|
+
</Text>
|
|
41
|
+
<Card border padding={3} ref={setPortal3Element} />
|
|
42
|
+
</Stack>
|
|
43
|
+
</Card>
|
|
44
|
+
</Container>
|
|
45
|
+
|
|
46
|
+
<Portal __unstable_name="portal1">
|
|
47
|
+
<Text>Portal 1</Text>
|
|
48
|
+
</Portal>
|
|
49
|
+
|
|
50
|
+
<Portal __unstable_name="portal2">
|
|
51
|
+
<Text>Portal 2</Text>
|
|
52
|
+
</Portal>
|
|
53
|
+
|
|
54
|
+
<Portal __unstable_name="portal3">
|
|
55
|
+
<Text>Portal 3A</Text>
|
|
56
|
+
</Portal>
|
|
57
|
+
|
|
58
|
+
<Portal __unstable_name="portal3">
|
|
59
|
+
<Text>Portal 3B</Text>
|
|
60
|
+
</Portal>
|
|
61
|
+
</PortalProvider>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import {render} from '../../../../test'
|
|
4
|
+
import {PortalContext} from './portalContext'
|
|
5
|
+
import {PortalContextValue} from './types'
|
|
6
|
+
import {usePortal} from './usePortal'
|
|
7
|
+
|
|
8
|
+
describe('utils/portal', () => {
|
|
9
|
+
describe('usePortal', () => {
|
|
10
|
+
it('should get context value', async () => {
|
|
11
|
+
const log = jest.fn()
|
|
12
|
+
|
|
13
|
+
function Debug() {
|
|
14
|
+
const rootPortal = usePortal()
|
|
15
|
+
|
|
16
|
+
log(rootPortal)
|
|
17
|
+
|
|
18
|
+
return <>debug</>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Root() {
|
|
22
|
+
const value: PortalContextValue = {
|
|
23
|
+
version: 0.0,
|
|
24
|
+
boundaryElement: null,
|
|
25
|
+
element: null,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<PortalContext.Provider value={value}>
|
|
30
|
+
<Debug />
|
|
31
|
+
</PortalContext.Provider>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render(<Root />)
|
|
36
|
+
|
|
37
|
+
expect(log.mock.calls[0][0].version).toBe(0.0)
|
|
38
|
+
expect(log.mock.calls[0][0].boundaryElement).toBe(null)
|
|
39
|
+
expect(log.mock.calls[0][0].element).toBe(null)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should fail when no context value is provided', async () => {
|
|
43
|
+
const log = jest.fn()
|
|
44
|
+
|
|
45
|
+
function Debug() {
|
|
46
|
+
try {
|
|
47
|
+
usePortal()
|
|
48
|
+
} catch (err) {
|
|
49
|
+
log(err)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Root() {
|
|
56
|
+
const value = undefined
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<PortalContext.Provider value={value as any}>
|
|
60
|
+
<Debug />
|
|
61
|
+
</PortalContext.Provider>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render(<Root />)
|
|
66
|
+
|
|
67
|
+
expect(log.mock.calls[0][0].message).toEqual('usePortal(): missing context value')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should fail when context value is not compatible', async () => {
|
|
71
|
+
const log = jest.fn()
|
|
72
|
+
|
|
73
|
+
function Debug() {
|
|
74
|
+
try {
|
|
75
|
+
usePortal()
|
|
76
|
+
} catch (err) {
|
|
77
|
+
log(err)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Root() {
|
|
84
|
+
// NOTE: we’re testing this because the context value may be a function in the future
|
|
85
|
+
const value = () => {
|
|
86
|
+
return {version: 1}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<PortalContext.Provider value={value as any}>
|
|
91
|
+
<Debug />
|
|
92
|
+
</PortalContext.Provider>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
render(<Root />)
|
|
97
|
+
|
|
98
|
+
expect(log.mock.calls[0][0].message).toEqual(
|
|
99
|
+
'usePortal(): the context value is not compatible',
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {createPortal} from 'react-dom'
|
|
2
|
+
|
|
3
|
+
import {usePortal} from './usePortal'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface PortalProps {
|
|
9
|
+
children: React.ReactNode
|
|
10
|
+
/**
|
|
11
|
+
* @beta This API might change. DO NOT USE IN PRODUCTION.
|
|
12
|
+
*/
|
|
13
|
+
__unstable_name?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export function Portal(props: PortalProps): React.ReactPortal | null {
|
|
20
|
+
const {children, __unstable_name: name} = props
|
|
21
|
+
const portal = usePortal()
|
|
22
|
+
const portalElement =
|
|
23
|
+
(name ? portal.elements && portal.elements[name] : portal.element) || portal.elements?.default
|
|
24
|
+
|
|
25
|
+
if (!portalElement) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return createPortal(children, portalElement)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Portal.displayName = 'Portal'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {createGlobalScopedContext} from '../../lib/createGlobalScopedContext'
|
|
2
|
+
import {globalScope} from '../../lib/globalScope'
|
|
3
|
+
import {PortalContextValue} from './types'
|
|
4
|
+
|
|
5
|
+
const key = '@bettercms-ai/kit/context/portal'
|
|
6
|
+
const elementKey = Symbol.for(`${key}/element`)
|
|
7
|
+
|
|
8
|
+
globalScope[elementKey] = null
|
|
9
|
+
|
|
10
|
+
export const defaultContextValue: PortalContextValue = {
|
|
11
|
+
version: 0.0,
|
|
12
|
+
boundaryElement: null,
|
|
13
|
+
get element() {
|
|
14
|
+
if (typeof document === 'undefined') {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (globalScope[elementKey]) {
|
|
19
|
+
return globalScope[elementKey]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
globalScope[elementKey] = document.createElement('div')
|
|
23
|
+
globalScope[elementKey].setAttribute('data-portal', '')
|
|
24
|
+
|
|
25
|
+
document.body.appendChild(globalScope[elementKey])
|
|
26
|
+
|
|
27
|
+
return globalScope[elementKey]
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const PortalContext = createGlobalScopedContext<PortalContextValue>(key, defaultContextValue)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {useMemo, useSyncExternalStore} from 'react'
|
|
2
|
+
|
|
3
|
+
import {PortalContext} from './portalContext'
|
|
4
|
+
import {PortalContextValue} from './types'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface PortalProviderProps {
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `<BoundaryElementProvider element={...} />` instead
|
|
12
|
+
*/
|
|
13
|
+
boundaryElement?: HTMLElement | null
|
|
14
|
+
children: React.ReactNode
|
|
15
|
+
element?: HTMLElement | null
|
|
16
|
+
/**
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
__unstable_elements?: Record<string, HTMLElement | null | undefined>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export function PortalProvider(props: PortalProviderProps): React.JSX.Element {
|
|
26
|
+
const {boundaryElement, children, element, __unstable_elements: elements} = props
|
|
27
|
+
const fallbackElement = useSyncExternalStore(
|
|
28
|
+
emptySubscribe,
|
|
29
|
+
() => document.body,
|
|
30
|
+
() => null,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const value: PortalContextValue = useMemo(() => {
|
|
34
|
+
return {
|
|
35
|
+
version: 0.0,
|
|
36
|
+
boundaryElement: boundaryElement || null,
|
|
37
|
+
element: element || fallbackElement,
|
|
38
|
+
elements,
|
|
39
|
+
}
|
|
40
|
+
}, [boundaryElement, element, elements, fallbackElement])
|
|
41
|
+
|
|
42
|
+
return <PortalContext.Provider value={value}>{children}</PortalContext.Provider>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
PortalProvider.displayName = 'PortalProvider'
|
|
46
|
+
|
|
47
|
+
const emptySubscribe = () => () => {}
|