aeon-ui-engine 1.0.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/.changeset/README.md +23 -0
- package/.changeset/combobox-and-changesets.md +9 -0
- package/.changeset/config.json +30 -0
- package/.changeset/framework-adapters.md +12 -0
- package/.changeset/scene-3d.md +6 -0
- package/.changeset/scene-plane.md +8 -0
- package/.changeset/site-og.md +5 -0
- package/.cursor/rules/aeon-ui.mdc +22 -0
- package/ACCESSIBILITY.md +32 -0
- package/AGENTS.md +226 -0
- package/COMPONENTS.md +36 -0
- package/FRAMEWORKS.md +57 -0
- package/INTEGRATION.md +89 -0
- package/LICENSE +21 -0
- package/PHILOSOPHY.md +71 -0
- package/PUBLISHING.md +85 -0
- package/README.md +154 -0
- package/SCENE.md +113 -0
- package/STATES.md +243 -0
- package/apps/demo/index.html +31 -0
- package/apps/demo/og.config.mjs +15 -0
- package/apps/demo/package.json +41 -0
- package/apps/demo/public/favicon.svg +16 -0
- package/apps/demo/public/og.png +0 -0
- package/apps/demo/public/og.svg +35 -0
- package/apps/demo/scripts/generate-og-png.mjs +60 -0
- package/apps/demo/src/App.tsx +31 -0
- package/apps/demo/src/aeonDiagrams.ts +100 -0
- package/apps/demo/src/app.css +16 -0
- package/apps/demo/src/components/ActionCluster.tsx +20 -0
- package/apps/demo/src/components/AsyncMachineDemo.tsx +97 -0
- package/apps/demo/src/components/ButtonLifecycleDemo.tsx +63 -0
- package/apps/demo/src/components/CodeExample.tsx +7 -0
- package/apps/demo/src/components/ComboboxDemo.tsx +30 -0
- package/apps/demo/src/components/DiagramsSection.tsx +38 -0
- package/apps/demo/src/components/FieldStateDemo.tsx +51 -0
- package/apps/demo/src/components/GridMesh.tsx +8 -0
- package/apps/demo/src/components/HeroInstall.tsx +10 -0
- package/apps/demo/src/components/LandingFaq.tsx +29 -0
- package/apps/demo/src/components/LandingFooter.tsx +22 -0
- package/apps/demo/src/components/LandingHeader.tsx +60 -0
- package/apps/demo/src/components/LandingHero.tsx +55 -0
- package/apps/demo/src/components/LayersSection.tsx +51 -0
- package/apps/demo/src/components/MermaidDiagram.tsx +84 -0
- package/apps/demo/src/components/PhilosophySection.tsx +33 -0
- package/apps/demo/src/components/PlaygroundBlock.tsx +23 -0
- package/apps/demo/src/components/PlaygroundSection.tsx +204 -0
- package/apps/demo/src/components/SceneSection.tsx +157 -0
- package/apps/demo/src/components/ScrollRegionDemo.tsx +74 -0
- package/apps/demo/src/components/ThemeSwitcher.tsx +76 -0
- package/apps/demo/src/demo-layout.css +264 -0
- package/apps/demo/src/landing.css +1094 -0
- package/apps/demo/src/main.tsx +14 -0
- package/apps/demo/src/nav.ts +9 -0
- package/apps/demo/src/site.ts +347 -0
- package/apps/demo/tsconfig.json +17 -0
- package/apps/demo/vite-plugins/og-meta.ts +30 -0
- package/apps/demo/vite.config.ts +69 -0
- package/docs/API_PATTERNS.md +234 -0
- package/docs/ARCHITECTURE.md +125 -0
- package/docs/COMPONENT_CHECKLIST.md +103 -0
- package/docs/FILE_MAP.md +122 -0
- package/docs/GLOSSARY.md +125 -0
- package/docs/INDEX.md +53 -0
- package/docs/LAYOUT_COORDINATES.md +178 -0
- package/docs/MACHINES.md +166 -0
- package/docs/MIGRATION_FROM_ARK.md +295 -0
- package/docs/VITE_CONSUMER.md +114 -0
- package/package.json +25 -0
- package/packages/core/README.md +69 -0
- package/packages/core/package.json +37 -0
- package/packages/core/src/anatomy.ts +144 -0
- package/packages/core/src/attrs.ts +47 -0
- package/packages/core/src/index.ts +8 -0
- package/packages/core/src/layout.ts +176 -0
- package/packages/core/src/machine.test.ts +18 -0
- package/packages/core/src/machine.ts +15 -0
- package/packages/core/src/philosophy.ts +10 -0
- package/packages/core/src/scroll.ts +72 -0
- package/packages/core/src/theme.test.ts +14 -0
- package/packages/core/src/theme.ts +53 -0
- package/packages/core/src/types.ts +25 -0
- package/packages/core/theme-transition.css +58 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/core/vitest.config.ts +8 -0
- package/packages/geometry/README.md +7 -0
- package/packages/geometry/package.json +35 -0
- package/packages/geometry/src/index.ts +3 -0
- package/packages/geometry/src/patterns.ts +55 -0
- package/packages/geometry/src/scene-attrs.ts +11 -0
- package/packages/geometry/src/svg.ts +60 -0
- package/packages/geometry/tsconfig.json +8 -0
- package/packages/panda/README.md +66 -0
- package/packages/panda/package.json +40 -0
- package/packages/panda/panda.config.ts +229 -0
- package/packages/panda/scripts/emit-theme-runtime.ts +37 -0
- package/packages/panda/src/recipes/accordion.ts +95 -0
- package/packages/panda/src/recipes/async.ts +76 -0
- package/packages/panda/src/recipes/badge.ts +44 -0
- package/packages/panda/src/recipes/button-group.ts +33 -0
- package/packages/panda/src/recipes/button.ts +91 -0
- package/packages/panda/src/recipes/checkbox.ts +41 -0
- package/packages/panda/src/recipes/combobox.ts +121 -0
- package/packages/panda/src/recipes/dialog.ts +96 -0
- package/packages/panda/src/recipes/field-shared.ts +29 -0
- package/packages/panda/src/recipes/field.ts +72 -0
- package/packages/panda/src/recipes/floating.ts +170 -0
- package/packages/panda/src/recipes/index.ts +14 -0
- package/packages/panda/src/recipes/scroll-region.ts +55 -0
- package/packages/panda/src/recipes/select.ts +111 -0
- package/packages/panda/src/recipes/switch.ts +51 -0
- package/packages/panda/src/recipes/tabs.ts +50 -0
- package/packages/panda/src/theme/catalog-types.ts +24 -0
- package/packages/panda/src/theme/catalog.ts +73 -0
- package/packages/panda/src/theme/chrome.css +75 -0
- package/packages/panda/src/theme/global-theme-css.ts +42 -0
- package/packages/panda/src/theme/index.ts +5 -0
- package/packages/panda/src/theme/palette.ts +65 -0
- package/packages/panda/src/theme/scrollbars.css +96 -0
- package/packages/panda/src/theme/semantic-tokens.ts +17 -0
- package/packages/panda/src/theme/themes.config.ts +516 -0
- package/packages/panda/src/theme/tokens.ts +51 -0
- package/packages/panda/styled-system/css/conditions.mjs +36 -0
- package/packages/panda/styled-system/css/css.d.ts +22 -0
- package/packages/panda/styled-system/css/css.mjs +45 -0
- package/packages/panda/styled-system/css/cva.d.ts +6 -0
- package/packages/panda/styled-system/css/cva.mjs +87 -0
- package/packages/panda/styled-system/css/cx.d.ts +5 -0
- package/packages/panda/styled-system/css/cx.mjs +15 -0
- package/packages/panda/styled-system/css/index.d.ts +5 -0
- package/packages/panda/styled-system/css/index.mjs +4 -0
- package/packages/panda/styled-system/css/sva.d.ts +4 -0
- package/packages/panda/styled-system/css/sva.mjs +41 -0
- package/packages/panda/styled-system/helpers.mjs +339 -0
- package/packages/panda/styled-system/jsx/aspect-ratio.d.ts +10 -0
- package/packages/panda/styled-system/jsx/aspect-ratio.mjs +14 -0
- package/packages/panda/styled-system/jsx/bleed.d.ts +10 -0
- package/packages/panda/styled-system/jsx/bleed.mjs +14 -0
- package/packages/panda/styled-system/jsx/box.d.ts +10 -0
- package/packages/panda/styled-system/jsx/box.mjs +14 -0
- package/packages/panda/styled-system/jsx/center.d.ts +10 -0
- package/packages/panda/styled-system/jsx/center.mjs +14 -0
- package/packages/panda/styled-system/jsx/circle.d.ts +10 -0
- package/packages/panda/styled-system/jsx/circle.mjs +14 -0
- package/packages/panda/styled-system/jsx/container.d.ts +10 -0
- package/packages/panda/styled-system/jsx/container.mjs +14 -0
- package/packages/panda/styled-system/jsx/cq.d.ts +10 -0
- package/packages/panda/styled-system/jsx/cq.mjs +14 -0
- package/packages/panda/styled-system/jsx/divider.d.ts +10 -0
- package/packages/panda/styled-system/jsx/divider.mjs +14 -0
- package/packages/panda/styled-system/jsx/factory-helper.mjs +22 -0
- package/packages/panda/styled-system/jsx/factory.d.ts +3 -0
- package/packages/panda/styled-system/jsx/factory.mjs +80 -0
- package/packages/panda/styled-system/jsx/flex.d.ts +10 -0
- package/packages/panda/styled-system/jsx/flex.mjs +14 -0
- package/packages/panda/styled-system/jsx/float.d.ts +10 -0
- package/packages/panda/styled-system/jsx/float.mjs +14 -0
- package/packages/panda/styled-system/jsx/grid-item.d.ts +10 -0
- package/packages/panda/styled-system/jsx/grid-item.mjs +14 -0
- package/packages/panda/styled-system/jsx/grid.d.ts +10 -0
- package/packages/panda/styled-system/jsx/grid.mjs +14 -0
- package/packages/panda/styled-system/jsx/hstack.d.ts +10 -0
- package/packages/panda/styled-system/jsx/hstack.mjs +14 -0
- package/packages/panda/styled-system/jsx/index.d.ts +24 -0
- package/packages/panda/styled-system/jsx/index.mjs +22 -0
- package/packages/panda/styled-system/jsx/is-valid-prop.d.ts +11 -0
- package/packages/panda/styled-system/jsx/is-valid-prop.mjs +17 -0
- package/packages/panda/styled-system/jsx/link-overlay.d.ts +10 -0
- package/packages/panda/styled-system/jsx/link-overlay.mjs +14 -0
- package/packages/panda/styled-system/jsx/spacer.d.ts +10 -0
- package/packages/panda/styled-system/jsx/spacer.mjs +14 -0
- package/packages/panda/styled-system/jsx/square.d.ts +10 -0
- package/packages/panda/styled-system/jsx/square.mjs +14 -0
- package/packages/panda/styled-system/jsx/stack.d.ts +10 -0
- package/packages/panda/styled-system/jsx/stack.mjs +14 -0
- package/packages/panda/styled-system/jsx/visually-hidden.d.ts +10 -0
- package/packages/panda/styled-system/jsx/visually-hidden.mjs +14 -0
- package/packages/panda/styled-system/jsx/vstack.d.ts +10 -0
- package/packages/panda/styled-system/jsx/vstack.mjs +14 -0
- package/packages/panda/styled-system/jsx/wrap.d.ts +10 -0
- package/packages/panda/styled-system/jsx/wrap.mjs +14 -0
- package/packages/panda/styled-system/patterns/aspect-ratio.d.ts +21 -0
- package/packages/panda/styled-system/patterns/aspect-ratio.mjs +38 -0
- package/packages/panda/styled-system/patterns/bleed.d.ts +22 -0
- package/packages/panda/styled-system/patterns/bleed.mjs +24 -0
- package/packages/panda/styled-system/patterns/box.d.ts +21 -0
- package/packages/panda/styled-system/patterns/box.mjs +15 -0
- package/packages/panda/styled-system/patterns/center.d.ts +21 -0
- package/packages/panda/styled-system/patterns/center.mjs +21 -0
- package/packages/panda/styled-system/patterns/circle.d.ts +21 -0
- package/packages/panda/styled-system/patterns/circle.mjs +25 -0
- package/packages/panda/styled-system/patterns/container.d.ts +21 -0
- package/packages/panda/styled-system/patterns/container.mjs +21 -0
- package/packages/panda/styled-system/patterns/cq.d.ts +22 -0
- package/packages/panda/styled-system/patterns/cq.mjs +21 -0
- package/packages/panda/styled-system/patterns/divider.d.ts +23 -0
- package/packages/panda/styled-system/patterns/divider.mjs +25 -0
- package/packages/panda/styled-system/patterns/flex.d.ts +27 -0
- package/packages/panda/styled-system/patterns/flex.mjs +26 -0
- package/packages/panda/styled-system/patterns/float.d.ts +24 -0
- package/packages/panda/styled-system/patterns/float.mjs +52 -0
- package/packages/panda/styled-system/patterns/grid-item.d.ts +26 -0
- package/packages/panda/styled-system/patterns/grid-item.mjs +25 -0
- package/packages/panda/styled-system/patterns/grid.d.ts +25 -0
- package/packages/panda/styled-system/patterns/grid.mjs +27 -0
- package/packages/panda/styled-system/patterns/hstack.d.ts +22 -0
- package/packages/panda/styled-system/patterns/hstack.mjs +24 -0
- package/packages/panda/styled-system/patterns/index.d.ts +21 -0
- package/packages/panda/styled-system/patterns/index.mjs +20 -0
- package/packages/panda/styled-system/patterns/link-overlay.d.ts +21 -0
- package/packages/panda/styled-system/patterns/link-overlay.mjs +24 -0
- package/packages/panda/styled-system/patterns/spacer.d.ts +21 -0
- package/packages/panda/styled-system/patterns/spacer.mjs +21 -0
- package/packages/panda/styled-system/patterns/square.d.ts +21 -0
- package/packages/panda/styled-system/patterns/square.mjs +24 -0
- package/packages/panda/styled-system/patterns/stack.d.ts +24 -0
- package/packages/panda/styled-system/patterns/stack.mjs +24 -0
- package/packages/panda/styled-system/patterns/visually-hidden.d.ts +21 -0
- package/packages/panda/styled-system/patterns/visually-hidden.mjs +18 -0
- package/packages/panda/styled-system/patterns/vstack.d.ts +22 -0
- package/packages/panda/styled-system/patterns/vstack.mjs +24 -0
- package/packages/panda/styled-system/patterns/wrap.d.ts +25 -0
- package/packages/panda/styled-system/patterns/wrap.mjs +25 -0
- package/packages/panda/styled-system/recipes/aeon-accordion.d.ts +32 -0
- package/packages/panda/styled-system/recipes/aeon-accordion.mjs +48 -0
- package/packages/panda/styled-system/recipes/aeon-async.d.ts +32 -0
- package/packages/panda/styled-system/recipes/aeon-async.mjs +56 -0
- package/packages/panda/styled-system/recipes/aeon-badge.d.ts +31 -0
- package/packages/panda/styled-system/recipes/aeon-badge.mjs +32 -0
- package/packages/panda/styled-system/recipes/aeon-button-group.d.ts +39 -0
- package/packages/panda/styled-system/recipes/aeon-button-group.mjs +37 -0
- package/packages/panda/styled-system/recipes/aeon-button.d.ts +39 -0
- package/packages/panda/styled-system/recipes/aeon-button.mjs +39 -0
- package/packages/panda/styled-system/recipes/aeon-checkbox.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-checkbox.mjs +48 -0
- package/packages/panda/styled-system/recipes/aeon-combobox.d.ts +32 -0
- package/packages/panda/styled-system/recipes/aeon-combobox.mjs +52 -0
- package/packages/panda/styled-system/recipes/aeon-dialog.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-dialog.mjs +60 -0
- package/packages/panda/styled-system/recipes/aeon-field.d.ts +32 -0
- package/packages/panda/styled-system/recipes/aeon-field.mjs +52 -0
- package/packages/panda/styled-system/recipes/aeon-menu.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-menu.mjs +52 -0
- package/packages/panda/styled-system/recipes/aeon-popover.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-popover.mjs +52 -0
- package/packages/panda/styled-system/recipes/aeon-scroll.d.ts +43 -0
- package/packages/panda/styled-system/recipes/aeon-scroll.mjs +63 -0
- package/packages/panda/styled-system/recipes/aeon-select.d.ts +32 -0
- package/packages/panda/styled-system/recipes/aeon-select.mjs +56 -0
- package/packages/panda/styled-system/recipes/aeon-switch.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-switch.mjs +48 -0
- package/packages/panda/styled-system/recipes/aeon-tabs.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-tabs.mjs +48 -0
- package/packages/panda/styled-system/recipes/aeon-toast.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-toast.mjs +48 -0
- package/packages/panda/styled-system/recipes/aeon-tooltip.d.ts +28 -0
- package/packages/panda/styled-system/recipes/aeon-tooltip.mjs +48 -0
- package/packages/panda/styled-system/recipes/create-recipe.mjs +82 -0
- package/packages/panda/styled-system/recipes/index.d.ts +18 -0
- package/packages/panda/styled-system/recipes/index.mjs +17 -0
- package/packages/panda/styled-system/styles.css +2157 -0
- package/packages/panda/styled-system/tokens/index.d.ts +9 -0
- package/packages/panda/styled-system/tokens/index.mjs +2156 -0
- package/packages/panda/styled-system/tokens/tokens.d.ts +60 -0
- package/packages/panda/styled-system/types/composition.d.ts +164 -0
- package/packages/panda/styled-system/types/conditions.d.ts +322 -0
- package/packages/panda/styled-system/types/csstype.d.ts +21298 -0
- package/packages/panda/styled-system/types/global.d.ts +20 -0
- package/packages/panda/styled-system/types/index.d.ts +8 -0
- package/packages/panda/styled-system/types/jsx.d.ts +52 -0
- package/packages/panda/styled-system/types/parts.d.ts +8 -0
- package/packages/panda/styled-system/types/pattern.d.ts +78 -0
- package/packages/panda/styled-system/types/prop-type.d.ts +240 -0
- package/packages/panda/styled-system/types/recipe.d.ts +181 -0
- package/packages/panda/styled-system/types/selectors.d.ts +59 -0
- package/packages/panda/styled-system/types/static-css.d.ts +56 -0
- package/packages/panda/styled-system/types/style-props.d.ts +7491 -0
- package/packages/panda/styled-system/types/system-types.d.ts +193 -0
- package/packages/panda/theme-runtime.css +842 -0
- package/packages/panda/tsconfig.json +8 -0
- package/packages/primitives/README.md +54 -0
- package/packages/primitives/package.json +41 -0
- package/packages/primitives/src/__tests__/floating-surface.test.ts +29 -0
- package/packages/primitives/src/index.ts +9 -0
- package/packages/primitives/src/machines/accordion.ts +56 -0
- package/packages/primitives/src/machines/async.ts +108 -0
- package/packages/primitives/src/machines/button.ts +66 -0
- package/packages/primitives/src/machines/dialog.ts +61 -0
- package/packages/primitives/src/machines/field.ts +85 -0
- package/packages/primitives/src/machines/popover.ts +52 -0
- package/packages/primitives/src/machines/tabs.ts +46 -0
- package/packages/primitives/src/machines/toast.ts +48 -0
- package/packages/primitives/src/machines/toggle.ts +61 -0
- package/packages/primitives/tsconfig.json +8 -0
- package/packages/primitives/vitest.config.ts +8 -0
- package/packages/react/README.md +65 -0
- package/packages/react/package.json +52 -0
- package/packages/react/src/accordion/index.tsx +179 -0
- package/packages/react/src/async/actions.tsx +22 -0
- package/packages/react/src/async/context.tsx +54 -0
- package/packages/react/src/async/index.tsx +21 -0
- package/packages/react/src/async/legacy-region.tsx +38 -0
- package/packages/react/src/async/readout.tsx +34 -0
- package/packages/react/src/async/root.tsx +39 -0
- package/packages/react/src/async/track.tsx +59 -0
- package/packages/react/src/avatar/avatar.test.tsx +27 -0
- package/packages/react/src/avatar/index.tsx +122 -0
- package/packages/react/src/button/index.tsx +70 -0
- package/packages/react/src/checkbox/index.tsx +180 -0
- package/packages/react/src/combobox/index.tsx +430 -0
- package/packages/react/src/dialog/dialog.test.tsx +50 -0
- package/packages/react/src/dialog/index.tsx +275 -0
- package/packages/react/src/field/index.tsx +172 -0
- package/packages/react/src/hooks/use-aeon-machine.ts +10 -0
- package/packages/react/src/hooks/use-anchor-position.ts +33 -0
- package/packages/react/src/hooks/use-focus-trap.ts +51 -0
- package/packages/react/src/hooks/use-layout-mode.ts +22 -0
- package/packages/react/src/hooks/use-outside-click.ts +19 -0
- package/packages/react/src/hooks/use-portalled.ts +16 -0
- package/packages/react/src/hooks/use-scroll-lock.ts +13 -0
- package/packages/react/src/index.ts +18 -0
- package/packages/react/src/menu/index.tsx +195 -0
- package/packages/react/src/popover/index.tsx +191 -0
- package/packages/react/src/scroll/index.tsx +98 -0
- package/packages/react/src/scroll/use-scroll-state.ts +30 -0
- package/packages/react/src/select/index.tsx +372 -0
- package/packages/react/src/select/select.test.tsx +60 -0
- package/packages/react/src/switch/index.tsx +215 -0
- package/packages/react/src/tabs/index.tsx +140 -0
- package/packages/react/src/toast/context.tsx +28 -0
- package/packages/react/src/toast/index.tsx +20 -0
- package/packages/react/src/toast/primitives.tsx +129 -0
- package/packages/react/src/toast/provider.tsx +111 -0
- package/packages/react/src/toast/toast-item.tsx +32 -0
- package/packages/react/src/tooltip/index.tsx +191 -0
- package/packages/react/src/utils/merge-props.ts +24 -0
- package/packages/react/tsconfig.json +8 -0
- package/packages/react/vitest.config.ts +9 -0
- package/packages/react/vitest.setup.ts +5 -0
- package/packages/react-scene/README.md +11 -0
- package/packages/react-scene/package.json +47 -0
- package/packages/react-scene/scene-3d.css +37 -0
- package/packages/react-scene/scene-room.css +95 -0
- package/packages/react-scene/src/index.ts +20 -0
- package/packages/react-scene/src/procedural-grid.tsx +35 -0
- package/packages/react-scene/src/scene-layer.tsx +38 -0
- package/packages/react-scene/src/scene-plane.tsx +69 -0
- package/packages/react-scene/src/scene-room.tsx +81 -0
- package/packages/react-scene/src/scene-root.tsx +49 -0
- package/packages/react-scene/src/scene-slot.tsx +41 -0
- package/packages/react-scene/src/scene-stage.tsx +37 -0
- package/packages/react-scene/src/scene-surface.tsx +20 -0
- package/packages/react-scene/src/signal-bars.tsx +57 -0
- package/packages/react-scene/src/use-signal-visualizer.ts +103 -0
- package/packages/react-scene/tsconfig.json +8 -0
- package/packages/scene/README.md +5 -0
- package/packages/scene/package.json +32 -0
- package/packages/scene/src/index.ts +2 -0
- package/packages/scene/src/room.ts +40 -0
- package/packages/scene/src/transform.ts +60 -0
- package/packages/scene/tsconfig.json +8 -0
- package/packages/signal/README.md +9 -0
- package/packages/signal/package.json +32 -0
- package/packages/signal/src/analyser.ts +113 -0
- package/packages/signal/src/bands.ts +33 -0
- package/packages/signal/src/index.ts +3 -0
- package/packages/signal/src/motion.ts +80 -0
- package/packages/signal/tsconfig.json +8 -0
- package/packages/site/README.md +19 -0
- package/packages/site/package.json +32 -0
- package/packages/site/src/index.ts +8 -0
- package/packages/site/src/open-graph.ts +90 -0
- package/packages/site/tsconfig.json +8 -0
- package/packages/solid/README.md +30 -0
- package/packages/solid/package.json +42 -0
- package/packages/solid/src/hooks/use-aeon-machine.ts +10 -0
- package/packages/solid/src/index.ts +2 -0
- package/packages/solid/src/switch/index.tsx +191 -0
- package/packages/solid/src/utils/merge-props.ts +3 -0
- package/packages/solid/tsconfig.json +10 -0
- package/packages/surface/README.md +10 -0
- package/packages/surface/package.json +33 -0
- package/packages/surface/src/index.ts +1 -0
- package/packages/surface/src/materials.ts +14 -0
- package/packages/surface/surface.css +113 -0
- package/packages/surface/tsconfig.json +8 -0
- package/packages/svelte/README.md +45 -0
- package/packages/svelte/package.json +49 -0
- package/packages/svelte/src/Switch.svelte +86 -0
- package/packages/svelte/src/SwitchControl.svelte +45 -0
- package/packages/svelte/src/SwitchHiddenInput.svelte +12 -0
- package/packages/svelte/src/SwitchLabel.svelte +9 -0
- package/packages/svelte/src/SwitchThumb.svelte +16 -0
- package/packages/svelte/src/hooks/use-aeon-machine.ts +23 -0
- package/packages/svelte/src/index.ts +2 -0
- package/packages/svelte/src/switch-context.ts +13 -0
- package/packages/svelte/tsconfig.json +8 -0
- package/packages/ui/README.md +63 -0
- package/packages/ui/package.json +45 -0
- package/packages/ui/src/accordion.tsx +27 -0
- package/packages/ui/src/async.tsx +43 -0
- package/packages/ui/src/badge.tsx +18 -0
- package/packages/ui/src/button.tsx +38 -0
- package/packages/ui/src/checkbox.tsx +24 -0
- package/packages/ui/src/cn.ts +1 -0
- package/packages/ui/src/combobox.tsx +29 -0
- package/packages/ui/src/dialog.tsx +32 -0
- package/packages/ui/src/field.tsx +33 -0
- package/packages/ui/src/index.ts +17 -0
- package/packages/ui/src/menu.tsx +25 -0
- package/packages/ui/src/popover.tsx +22 -0
- package/packages/ui/src/scroll.tsx +51 -0
- package/packages/ui/src/select.tsx +33 -0
- package/packages/ui/src/styles.css +2 -0
- package/packages/ui/src/switch.tsx +22 -0
- package/packages/ui/src/tabs.tsx +22 -0
- package/packages/ui/src/toast.tsx +36 -0
- package/packages/ui/src/tooltip.tsx +19 -0
- package/packages/ui/tsconfig.json +12 -0
- package/packages/vue/README.md +40 -0
- package/packages/vue/package.json +42 -0
- package/packages/vue/src/hooks/use-aeon-machine.ts +10 -0
- package/packages/vue/src/index.ts +2 -0
- package/packages/vue/src/switch/index.ts +208 -0
- package/packages/vue/src/utils/part-props.ts +8 -0
- package/packages/vue/tsconfig.json +8 -0
- package/pnpm-workspace.yaml +3 -0
- package/scripts/ensure-headless-built.mjs +25 -0
- package/tsconfig.base.json +21 -0
- package/vercel.json +12 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { menuAnatomy, partAttrs } from '@aeon-ui/core'
|
|
2
|
+
import { popoverMachine } from '@aeon-ui/primitives'
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useId,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
type ButtonHTMLAttributes,
|
|
13
|
+
type HTMLAttributes,
|
|
14
|
+
type KeyboardEvent,
|
|
15
|
+
type MouseEvent,
|
|
16
|
+
type ReactNode,
|
|
17
|
+
} from 'react'
|
|
18
|
+
import { useAeonMachine } from '../hooks/use-aeon-machine.js'
|
|
19
|
+
import { useOutsideClick } from '../hooks/use-outside-click.js'
|
|
20
|
+
import { mergeProps } from '../utils/merge-props.js'
|
|
21
|
+
|
|
22
|
+
interface MenuContextValue {
|
|
23
|
+
open: boolean
|
|
24
|
+
send: ReturnType<typeof useAeonMachine<typeof popoverMachine>>[1]
|
|
25
|
+
triggerId: string
|
|
26
|
+
menuId: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const MenuCtx = createContext<MenuContextValue | null>(null)
|
|
30
|
+
|
|
31
|
+
function useMenuCtx() {
|
|
32
|
+
const ctx = useContext(MenuCtx)
|
|
33
|
+
if (!ctx) throw new Error('Menu parts must be used within Menu.Root')
|
|
34
|
+
return ctx
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MenuRootProps {
|
|
38
|
+
open?: boolean
|
|
39
|
+
defaultOpen?: boolean
|
|
40
|
+
onOpenChange?: (open: boolean) => void
|
|
41
|
+
children?: ReactNode
|
|
42
|
+
className?: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const Root = forwardRef<HTMLDivElement, MenuRootProps>(function MenuRoot(
|
|
46
|
+
{ open, defaultOpen = false, onOpenChange, children, className, ...rest },
|
|
47
|
+
ref,
|
|
48
|
+
) {
|
|
49
|
+
const [snapshot, send] = useAeonMachine(popoverMachine, { input: { open: defaultOpen } })
|
|
50
|
+
const resolvedOpen = open ?? snapshot.context.open
|
|
51
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
52
|
+
const triggerId = useId()
|
|
53
|
+
const menuId = useId()
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
onOpenChange?.(resolvedOpen)
|
|
57
|
+
}, [resolvedOpen, onOpenChange])
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (open !== undefined) send({ type: 'SET_OPEN', open })
|
|
61
|
+
}, [open, send])
|
|
62
|
+
|
|
63
|
+
const close = useCallback(() => send({ type: 'CLOSE' }), [send])
|
|
64
|
+
useOutsideClick([rootRef], resolvedOpen, close)
|
|
65
|
+
|
|
66
|
+
const value = useMemo(
|
|
67
|
+
() => ({ open: resolvedOpen, send, triggerId, menuId }),
|
|
68
|
+
[resolvedOpen, send, triggerId, menuId],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<MenuCtx.Provider value={value}>
|
|
73
|
+
<div
|
|
74
|
+
ref={(node) => {
|
|
75
|
+
rootRef.current = node
|
|
76
|
+
if (typeof ref === 'function') ref(node)
|
|
77
|
+
else if (ref) ref.current = node
|
|
78
|
+
}}
|
|
79
|
+
className={className}
|
|
80
|
+
{...mergeProps(
|
|
81
|
+
partAttrs(menuAnatomy.scope, menuAnatomy.root, { state: resolvedOpen ? 'open' : 'closed' }),
|
|
82
|
+
rest as HTMLAttributes<HTMLDivElement>,
|
|
83
|
+
)}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</div>
|
|
87
|
+
</MenuCtx.Provider>
|
|
88
|
+
)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const Trigger = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLButtonElement>>(function MenuTrigger(
|
|
92
|
+
{ onClick, ...rest },
|
|
93
|
+
ref,
|
|
94
|
+
) {
|
|
95
|
+
const { open, send, triggerId, menuId } = useMenuCtx()
|
|
96
|
+
return (
|
|
97
|
+
<button
|
|
98
|
+
ref={ref}
|
|
99
|
+
type="button"
|
|
100
|
+
id={triggerId}
|
|
101
|
+
aria-haspopup="menu"
|
|
102
|
+
aria-expanded={open}
|
|
103
|
+
aria-controls={open ? menuId : undefined}
|
|
104
|
+
{...mergeProps(
|
|
105
|
+
partAttrs(menuAnatomy.scope, menuAnatomy.trigger, { state: open ? 'open' : 'closed' }),
|
|
106
|
+
{
|
|
107
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
|
108
|
+
onClick?.(e)
|
|
109
|
+
if (!e.defaultPrevented) send({ type: 'TOGGLE' })
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
rest,
|
|
113
|
+
)}
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const Positioner = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function MenuPositioner(
|
|
119
|
+
props,
|
|
120
|
+
ref,
|
|
121
|
+
) {
|
|
122
|
+
const { open } = useMenuCtx()
|
|
123
|
+
if (!open) return null
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
ref={ref}
|
|
127
|
+
{...mergeProps(partAttrs(menuAnatomy.scope, menuAnatomy.positioner, { state: 'open' }), props)}
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const Content = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function MenuContent(
|
|
133
|
+
{ onKeyDown, ...rest },
|
|
134
|
+
ref,
|
|
135
|
+
) {
|
|
136
|
+
const { open, send, menuId } = useMenuCtx()
|
|
137
|
+
if (!open) return null
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
ref={ref}
|
|
141
|
+
id={menuId}
|
|
142
|
+
role="menu"
|
|
143
|
+
{...mergeProps(
|
|
144
|
+
partAttrs(menuAnatomy.scope, menuAnatomy.content, { state: 'open' }),
|
|
145
|
+
{
|
|
146
|
+
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
|
|
147
|
+
onKeyDown?.(e)
|
|
148
|
+
if (e.key === 'Escape') send({ type: 'ESCAPE' })
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
rest,
|
|
152
|
+
)}
|
|
153
|
+
/>
|
|
154
|
+
)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
export interface MenuItemProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
158
|
+
/** Close menu after selection (default true). */
|
|
159
|
+
closeOnSelect?: boolean
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const Item = forwardRef<HTMLButtonElement, MenuItemProps>(function MenuItem(
|
|
163
|
+
{ closeOnSelect = true, onClick, ...rest },
|
|
164
|
+
ref,
|
|
165
|
+
) {
|
|
166
|
+
const { send } = useMenuCtx()
|
|
167
|
+
return (
|
|
168
|
+
<button
|
|
169
|
+
ref={ref}
|
|
170
|
+
type="button"
|
|
171
|
+
role="menuitem"
|
|
172
|
+
{...mergeProps(
|
|
173
|
+
partAttrs(menuAnatomy.scope, menuAnatomy.item),
|
|
174
|
+
{
|
|
175
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
|
176
|
+
onClick?.(e)
|
|
177
|
+
if (closeOnSelect && !e.defaultPrevented) send({ type: 'CLOSE' })
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
rest,
|
|
181
|
+
)}
|
|
182
|
+
/>
|
|
183
|
+
)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const Separator = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function MenuSeparator(
|
|
187
|
+
props,
|
|
188
|
+
ref,
|
|
189
|
+
) {
|
|
190
|
+
return (
|
|
191
|
+
<div ref={ref} role="separator" {...mergeProps(partAttrs(menuAnatomy.scope, menuAnatomy.separator), props)} />
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
export const Menu = { Root, Trigger, Positioner, Content, Item, Separator }
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { popoverAnatomy, partAttrs } from '@aeon-ui/core'
|
|
2
|
+
import { popoverMachine } from '@aeon-ui/primitives'
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useId,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
type ButtonHTMLAttributes,
|
|
13
|
+
type HTMLAttributes,
|
|
14
|
+
type KeyboardEvent,
|
|
15
|
+
type MouseEvent,
|
|
16
|
+
type ReactNode,
|
|
17
|
+
} from 'react'
|
|
18
|
+
import { useAeonMachine } from '../hooks/use-aeon-machine.js'
|
|
19
|
+
import { useOutsideClick } from '../hooks/use-outside-click.js'
|
|
20
|
+
import { mergeProps } from '../utils/merge-props.js'
|
|
21
|
+
|
|
22
|
+
interface PopoverContextValue {
|
|
23
|
+
open: boolean
|
|
24
|
+
send: ReturnType<typeof useAeonMachine<typeof popoverMachine>>[1]
|
|
25
|
+
triggerId: string
|
|
26
|
+
contentId: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const PopoverCtx = createContext<PopoverContextValue | null>(null)
|
|
30
|
+
|
|
31
|
+
function usePopoverCtx() {
|
|
32
|
+
const ctx = useContext(PopoverCtx)
|
|
33
|
+
if (!ctx) throw new Error('Popover parts must be used within Popover.Root')
|
|
34
|
+
return ctx
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PopoverRootProps {
|
|
38
|
+
open?: boolean
|
|
39
|
+
defaultOpen?: boolean
|
|
40
|
+
onOpenChange?: (open: boolean) => void
|
|
41
|
+
children?: ReactNode
|
|
42
|
+
className?: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const Root = forwardRef<HTMLDivElement, PopoverRootProps>(function PopoverRoot(
|
|
46
|
+
{ open, defaultOpen = false, onOpenChange, children, className, ...rest },
|
|
47
|
+
ref,
|
|
48
|
+
) {
|
|
49
|
+
const [snapshot, send] = useAeonMachine(popoverMachine, {
|
|
50
|
+
input: { open: defaultOpen },
|
|
51
|
+
})
|
|
52
|
+
const resolvedOpen = open ?? snapshot.context.open
|
|
53
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
54
|
+
const triggerId = useId()
|
|
55
|
+
const contentId = useId()
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
onOpenChange?.(resolvedOpen)
|
|
59
|
+
}, [resolvedOpen, onOpenChange])
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (open !== undefined) send({ type: 'SET_OPEN', open })
|
|
63
|
+
}, [open, send])
|
|
64
|
+
|
|
65
|
+
const close = useCallback(() => send({ type: 'CLOSE' }), [send])
|
|
66
|
+
useOutsideClick([rootRef], resolvedOpen, close)
|
|
67
|
+
|
|
68
|
+
const value = useMemo(
|
|
69
|
+
() => ({ open: resolvedOpen, send, triggerId, contentId }),
|
|
70
|
+
[resolvedOpen, send, triggerId, contentId],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<PopoverCtx.Provider value={value}>
|
|
75
|
+
<div
|
|
76
|
+
ref={(node) => {
|
|
77
|
+
rootRef.current = node
|
|
78
|
+
if (typeof ref === 'function') ref(node)
|
|
79
|
+
else if (ref) ref.current = node
|
|
80
|
+
}}
|
|
81
|
+
className={className}
|
|
82
|
+
{...mergeProps(
|
|
83
|
+
partAttrs(popoverAnatomy.scope, popoverAnatomy.root, {
|
|
84
|
+
state: resolvedOpen ? 'open' : 'closed',
|
|
85
|
+
}),
|
|
86
|
+
rest as HTMLAttributes<HTMLDivElement>,
|
|
87
|
+
)}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</div>
|
|
91
|
+
</PopoverCtx.Provider>
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const Trigger = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLButtonElement>>(function PopoverTrigger(
|
|
96
|
+
{ onClick, ...rest },
|
|
97
|
+
ref,
|
|
98
|
+
) {
|
|
99
|
+
const { open, send, triggerId, contentId } = usePopoverCtx()
|
|
100
|
+
return (
|
|
101
|
+
<button
|
|
102
|
+
ref={ref}
|
|
103
|
+
type="button"
|
|
104
|
+
id={triggerId}
|
|
105
|
+
aria-expanded={open}
|
|
106
|
+
aria-controls={open ? contentId : undefined}
|
|
107
|
+
{...mergeProps(
|
|
108
|
+
partAttrs(popoverAnatomy.scope, popoverAnatomy.trigger, { state: open ? 'open' : 'closed' }),
|
|
109
|
+
{
|
|
110
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
|
111
|
+
onClick?.(e)
|
|
112
|
+
if (!e.defaultPrevented) send({ type: 'TOGGLE' })
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
rest,
|
|
116
|
+
)}
|
|
117
|
+
/>
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const Positioner = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function PopoverPositioner(
|
|
122
|
+
props,
|
|
123
|
+
ref,
|
|
124
|
+
) {
|
|
125
|
+
const { open } = usePopoverCtx()
|
|
126
|
+
if (!open) return null
|
|
127
|
+
return (
|
|
128
|
+
<div
|
|
129
|
+
ref={ref}
|
|
130
|
+
{...mergeProps(partAttrs(popoverAnatomy.scope, popoverAnatomy.positioner, { state: 'open' }), props)}
|
|
131
|
+
/>
|
|
132
|
+
)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const Content = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function PopoverContent(
|
|
136
|
+
{ onKeyDown, ...rest },
|
|
137
|
+
ref,
|
|
138
|
+
) {
|
|
139
|
+
const { open, send, triggerId, contentId } = usePopoverCtx()
|
|
140
|
+
if (!open) return null
|
|
141
|
+
return (
|
|
142
|
+
<div
|
|
143
|
+
ref={ref}
|
|
144
|
+
id={contentId}
|
|
145
|
+
role="dialog"
|
|
146
|
+
aria-modal={false}
|
|
147
|
+
aria-labelledby={triggerId}
|
|
148
|
+
{...mergeProps(
|
|
149
|
+
partAttrs(popoverAnatomy.scope, popoverAnatomy.content, { state: 'open' }),
|
|
150
|
+
{
|
|
151
|
+
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
|
|
152
|
+
onKeyDown?.(e)
|
|
153
|
+
if (e.key === 'Escape') send({ type: 'ESCAPE' })
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
rest,
|
|
157
|
+
)}
|
|
158
|
+
/>
|
|
159
|
+
)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
const Arrow = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function PopoverArrow(props, ref) {
|
|
163
|
+
const { open } = usePopoverCtx()
|
|
164
|
+
if (!open) return null
|
|
165
|
+
return <div ref={ref} {...mergeProps(partAttrs(popoverAnatomy.scope, popoverAnatomy.arrow), props)} />
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const CloseTrigger = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLButtonElement>>(
|
|
169
|
+
function PopoverCloseTrigger({ onClick, ...rest }, ref) {
|
|
170
|
+
const { send } = usePopoverCtx()
|
|
171
|
+
return (
|
|
172
|
+
<button
|
|
173
|
+
ref={ref}
|
|
174
|
+
type="button"
|
|
175
|
+
aria-label="Close"
|
|
176
|
+
{...mergeProps(
|
|
177
|
+
partAttrs(popoverAnatomy.scope, popoverAnatomy.closeTrigger),
|
|
178
|
+
{
|
|
179
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
|
180
|
+
onClick?.(e)
|
|
181
|
+
send({ type: 'CLOSE' })
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
rest,
|
|
185
|
+
)}
|
|
186
|
+
/>
|
|
187
|
+
)
|
|
188
|
+
},
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
export const Popover = { Root, Trigger, Positioner, Content, Arrow, CloseTrigger }
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { scrollAnatomy, partAttrs, partOnlyAttrs } from '@aeon-ui/core'
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
type HTMLAttributes,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react'
|
|
11
|
+
import { useScrollState } from './use-scroll-state.js'
|
|
12
|
+
|
|
13
|
+
interface ScrollContextValue {
|
|
14
|
+
stateAttr: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ScrollCtx = createContext<ScrollContextValue | null>(null)
|
|
18
|
+
|
|
19
|
+
export function useScrollContext(): ScrollContextValue {
|
|
20
|
+
const ctx = useContext(ScrollCtx)
|
|
21
|
+
if (!ctx) throw new Error('Scroll parts must be used within <Scroll.Root>')
|
|
22
|
+
return ctx
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ScrollRootProps extends HTMLAttributes<HTMLDivElement> {
|
|
26
|
+
children: ReactNode
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const Root = forwardRef<HTMLDivElement, ScrollRootProps>(function ScrollRoot(
|
|
30
|
+
{ children, className, ...rest },
|
|
31
|
+
ref,
|
|
32
|
+
) {
|
|
33
|
+
const viewportRef = useRef<HTMLDivElement>(null)
|
|
34
|
+
const stateAttr = useScrollState(viewportRef)
|
|
35
|
+
const value = useMemo(() => ({ stateAttr }), [stateAttr])
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<ScrollCtx.Provider value={value}>
|
|
39
|
+
<div
|
|
40
|
+
ref={ref}
|
|
41
|
+
className={className}
|
|
42
|
+
{...partAttrs(scrollAnatomy.scope, scrollAnatomy.root)}
|
|
43
|
+
{...rest}
|
|
44
|
+
>
|
|
45
|
+
<ScrollViewportRefContext.Provider value={viewportRef}>
|
|
46
|
+
{children}
|
|
47
|
+
</ScrollViewportRefContext.Provider>
|
|
48
|
+
</div>
|
|
49
|
+
</ScrollCtx.Provider>
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const ScrollViewportRefContext = createContext<React.RefObject<HTMLDivElement | null> | null>(
|
|
54
|
+
null,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
export interface ScrollViewportProps extends HTMLAttributes<HTMLDivElement> {
|
|
58
|
+
children: ReactNode
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const Viewport = forwardRef<HTMLDivElement, ScrollViewportProps>(function ScrollViewport(
|
|
62
|
+
{ children, className, ...rest },
|
|
63
|
+
forwardedRef,
|
|
64
|
+
) {
|
|
65
|
+
const ctxRef = useContext(ScrollViewportRefContext)
|
|
66
|
+
const { stateAttr } = useScrollContext()
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
ref={(node) => {
|
|
71
|
+
if (ctxRef) ctxRef.current = node
|
|
72
|
+
if (typeof forwardedRef === 'function') forwardedRef(node)
|
|
73
|
+
else if (forwardedRef) forwardedRef.current = node
|
|
74
|
+
}}
|
|
75
|
+
className={className}
|
|
76
|
+
data-aeon-scroll=""
|
|
77
|
+
{...partAttrs(scrollAnatomy.scope, scrollAnatomy.viewport, { state: stateAttr })}
|
|
78
|
+
{...rest}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const Content = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function ScrollContent(
|
|
86
|
+
props,
|
|
87
|
+
ref,
|
|
88
|
+
) {
|
|
89
|
+
return <div ref={ref} {...partOnlyAttrs(scrollAnatomy.content)} {...props} />
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
export const Scroll = {
|
|
93
|
+
Root,
|
|
94
|
+
Viewport,
|
|
95
|
+
Content,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { useScrollState } from './use-scroll-state.js'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getScrollSnapshot } from '@aeon-ui/core'
|
|
2
|
+
import { useLayoutEffect, useState, type RefObject } from 'react'
|
|
3
|
+
|
|
4
|
+
/** Subscribe to scroll + resize; returns data-aeon-state value for a viewport. */
|
|
5
|
+
export function useScrollState(ref: RefObject<HTMLElement | null>): string {
|
|
6
|
+
const [stateAttr, setStateAttr] = useState('idle')
|
|
7
|
+
|
|
8
|
+
useLayoutEffect(() => {
|
|
9
|
+
const el = ref.current
|
|
10
|
+
if (!el) return
|
|
11
|
+
|
|
12
|
+
const update = () => {
|
|
13
|
+
setStateAttr(getScrollSnapshot(el).stateAttr)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
update()
|
|
17
|
+
el.addEventListener('scroll', update, { passive: true })
|
|
18
|
+
const ro = new ResizeObserver(update)
|
|
19
|
+
ro.observe(el)
|
|
20
|
+
const content = el.firstElementChild
|
|
21
|
+
if (content instanceof HTMLElement) ro.observe(content)
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
el.removeEventListener('scroll', update)
|
|
25
|
+
ro.disconnect()
|
|
26
|
+
}
|
|
27
|
+
}, [ref])
|
|
28
|
+
|
|
29
|
+
return stateAttr
|
|
30
|
+
}
|