feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Wombosvideo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,2 @@
|
||||
/* Same animation utilities as the fixed HeroUI baseline (tw-animate-css, MIT). */
|
||||
@import "tw-animate-css";
|
||||
@@ -0,0 +1,374 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue/Reka adapters. */
|
||||
/* -------------------------------------------------------------------------------------------------
|
||||
* Modal Component Styles
|
||||
* Block: modal
|
||||
* -----------------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Element: trigger - the element that opens the modal
|
||||
*/
|
||||
.hv-modal__trigger {
|
||||
@apply inline-block cursor-(--cursor-interactive);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out-quart),
|
||||
background-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Active/pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: backdrop - the overlay behind the dialog
|
||||
*/
|
||||
.hv-modal__backdrop {
|
||||
@apply fixed inset-0 z-(--z-index-overlay);
|
||||
@apply flex flex-row items-center justify-center;
|
||||
@apply h-(--visual-viewport-height) w-full;
|
||||
|
||||
/* Entering animation */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-out fade-in-0;
|
||||
}
|
||||
|
||||
/* Exiting animation */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-out fade-out-0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce Animation
|
||||
* CRITICAL: motion-reduce must be AFTER animate for correct override specificity
|
||||
*/
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply will-change-[opacity];
|
||||
@apply motion-reduce:animate-none;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: backdrop--transparent
|
||||
*/
|
||||
.hv-modal__backdrop--transparent {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: backdrop--opaque
|
||||
*/
|
||||
.hv-modal__backdrop--opaque {
|
||||
@apply bg-backdrop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: backdrop--blur
|
||||
*/
|
||||
.hv-modal__backdrop--blur {
|
||||
@apply bg-backdrop backdrop-blur-md;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: container - the positioning wrapper for the modal
|
||||
*/
|
||||
.hv-modal__container {
|
||||
@apply flex flex-col items-center;
|
||||
@apply h-(--visual-viewport-height) w-full min-w-0 flex-1;
|
||||
@apply p-4;
|
||||
@apply sm:w-fit sm:p-10;
|
||||
@apply pointer-events-none;
|
||||
|
||||
/* Entering animation */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-250 ease-out-quad fade-in-0 zoom-in-105;
|
||||
|
||||
&[data-placement="auto"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
@apply sm:slide-in-from-bottom-0;
|
||||
}
|
||||
|
||||
&[data-placement="top"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-placement="center"] {
|
||||
@apply slide-in-from-top-0;
|
||||
}
|
||||
|
||||
&[data-placement="bottom"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Exiting animation */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-out-quad fade-out-0 zoom-out-95;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce Animation
|
||||
* CRITICAL: motion-reduce must be AFTER animate for correct override specificity
|
||||
*/
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply will-change-[opacity,transform];
|
||||
@apply motion-reduce:animate-none;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: container--scroll-outside
|
||||
*
|
||||
* The container is React Aria's modal ref, so it must stay `pointer-events: none`,
|
||||
* otherwise clicks around the dialog count as inside the modal and never dismiss it.
|
||||
* The backdrop owns the scrolling instead.
|
||||
*/
|
||||
.hv-modal__container--scroll-outside {
|
||||
@apply h-auto min-h-(--visual-viewport-height) overflow-y-visible;
|
||||
}
|
||||
|
||||
.hv-modal__backdrop:has(.hv-modal__container--scroll-outside) {
|
||||
@apply scrollbar items-start overflow-y-auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: container--full
|
||||
*/
|
||||
.hv-modal__container--full {
|
||||
@apply p-0 sm:p-0;
|
||||
|
||||
/* Entering animation */
|
||||
&[data-entering="true"] {
|
||||
@apply slide-in-from-bottom-0 zoom-in-100;
|
||||
@apply sm:slide-in-from-bottom-0;
|
||||
}
|
||||
|
||||
/* Exiting animation */
|
||||
&[data-exiting="true"] {
|
||||
@apply zoom-out-100;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: dialog - the content container for the modal
|
||||
*/
|
||||
.hv-modal__dialog {
|
||||
@apply relative;
|
||||
@apply flex w-full flex-col;
|
||||
@apply bg-overlay shadow-overlay outline-none;
|
||||
border-radius: min(32px, var(--radius-3xl));
|
||||
@apply p-6;
|
||||
@apply pointer-events-auto;
|
||||
|
||||
&[data-placement="auto"] {
|
||||
@apply mt-auto;
|
||||
@apply sm:my-auto;
|
||||
}
|
||||
|
||||
&[data-placement="center"] {
|
||||
@apply my-auto;
|
||||
}
|
||||
|
||||
&[data-placement="bottom"] {
|
||||
@apply mt-auto;
|
||||
}
|
||||
|
||||
&[data-placement="top"] {
|
||||
@apply mt-0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--scroll-inside
|
||||
*/
|
||||
.hv-modal__dialog--scroll-inside {
|
||||
@apply max-h-full min-h-0 overflow-clip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--scroll-outside
|
||||
*/
|
||||
.hv-modal__dialog--scroll-outside {
|
||||
@apply h-auto;
|
||||
@apply min-h-0 shrink-0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--xs
|
||||
*/
|
||||
.hv-modal__dialog--xs {
|
||||
@apply max-w-xs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--sm
|
||||
*/
|
||||
.hv-modal__dialog--sm {
|
||||
@apply max-w-sm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--md
|
||||
*/
|
||||
.hv-modal__dialog--md {
|
||||
@apply max-w-md;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--lg
|
||||
*/
|
||||
.hv-modal__dialog--lg {
|
||||
@apply max-w-lg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--cover
|
||||
*/
|
||||
.hv-modal__dialog--cover {
|
||||
@apply h-full min-h-full w-full;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: dialog--full
|
||||
*/
|
||||
.hv-modal__dialog--full {
|
||||
@apply h-full min-h-full w-full;
|
||||
@apply rounded-none shadow-none;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: header - the top section with the title
|
||||
*/
|
||||
.hv-modal__header {
|
||||
@apply flex flex-col gap-3;
|
||||
@apply mb-0;
|
||||
|
||||
/* When header contains icon, use flex-col layout with gap */
|
||||
& > .hv-modal__icon {
|
||||
@apply mb-0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: heading - the main title text
|
||||
*/
|
||||
.hv-modal__heading {
|
||||
@apply align-middle;
|
||||
@apply text-base font-medium text-foreground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: icon - the optional icon indicator
|
||||
*/
|
||||
.hv-modal__icon {
|
||||
@apply flex items-center justify-center;
|
||||
@apply size-10 shrink-0;
|
||||
@apply rounded-3xl select-none;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: body - the main content area
|
||||
*/
|
||||
.hv-modal__body {
|
||||
@apply min-h-0 flex-1;
|
||||
@apply text-sm leading-[1.43] text-muted;
|
||||
@apply -m-[3px] my-0 overflow-visible p-[3px];
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: body--scroll-inside
|
||||
*/
|
||||
.hv-modal__body--scroll-inside {
|
||||
@apply scrollbar overflow-y-auto overscroll-contain;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier: body--scroll-outside
|
||||
*/
|
||||
.hv-modal__body--scroll-outside {
|
||||
@apply overflow-y-visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: footer - the bottom action section
|
||||
*/
|
||||
.hv-modal__footer {
|
||||
@apply flex flex-row items-center justify-end gap-2;
|
||||
@apply mt-0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element: close-trigger - the optional x icon button to close the modal
|
||||
*/
|
||||
.hv-modal__close-trigger {
|
||||
@apply absolute end-4 top-4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Elements Spacing
|
||||
*/
|
||||
.hv-modal__header + .hv-modal__body {
|
||||
@apply mt-2;
|
||||
}
|
||||
|
||||
.hv-modal__header + .hv-modal__footer {
|
||||
@apply mt-5;
|
||||
}
|
||||
|
||||
.hv-modal__body + .hv-modal__footer {
|
||||
@apply mt-5;
|
||||
}
|
||||
|
||||
/* Button remains a flex row when used as a Vue trigger. */
|
||||
.hv-modal__trigger.hv-button {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
/* Reka owns an inline pointer-events rule; exiting surfaces must stay inactive. */
|
||||
.hv-modal__dialog[data-exiting="true"] {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* RAC keeps Dialog alive with its animated Container. Reka observes the Content
|
||||
* node itself, so use a visually neutral keyframe inheriting the Container's
|
||||
* actual duration/delay (including caller utilities) before unmounting. */
|
||||
@keyframes hv-modal-retain {
|
||||
from {
|
||||
visibility: visible;
|
||||
}
|
||||
to {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
.hv-modal__dialog[data-exiting="true"] {
|
||||
animation-name: hv-modal-retain;
|
||||
animation-duration: inherit;
|
||||
animation-delay: inherit;
|
||||
animation-timing-function: linear;
|
||||
animation-fill-mode: both;
|
||||
@apply motion-reduce:animate-none;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue/Reka adapters. */
|
||||
/* Popover component styles */
|
||||
|
||||
/* Base popover styles */
|
||||
.hv-popover {
|
||||
@apply origin-(--reka-popper-transform-origin) bg-overlay p-0 text-sm;
|
||||
border-radius: min(32px, var(--radius-3xl));
|
||||
box-shadow: var(--overlay-shadow);
|
||||
|
||||
/* Entering animations */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-90;
|
||||
|
||||
/* Placement-specific translations */
|
||||
&[data-side="top"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
|
||||
&[data-side="bottom"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-side="left"] {
|
||||
@apply slide-in-from-right-1;
|
||||
}
|
||||
|
||||
&[data-side="right"] {
|
||||
@apply slide-in-from-left-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Exiting animations */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
|
||||
/* Stays non-interactive while closing, even if the exit animation is interrupted. */
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||||
}
|
||||
|
||||
/* Arrow styling */
|
||||
& [data-slot="popover-overlay-arrow"] {
|
||||
fill: var(--overlay);
|
||||
}
|
||||
}
|
||||
|
||||
/* Popover dialog */
|
||||
.hv-popover__dialog {
|
||||
@apply p-4 outline-none;
|
||||
}
|
||||
|
||||
/* Popover heading */
|
||||
.hv-popover__heading {
|
||||
@apply font-medium;
|
||||
}
|
||||
|
||||
/* Popover trigger */
|
||||
.hv-popover__trigger {
|
||||
@apply inline-block;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
color 150ms var(--ease-smooth),
|
||||
background-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reka owns an inline pointer-events rule; exiting surfaces must stay inactive. */
|
||||
.hv-popover[data-exiting="true"] {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* React Aria supplies this stacking level inline; Reka reads it from Content. */
|
||||
.hv-popover {
|
||||
z-index: var(--z-index-overlay);
|
||||
}
|
||||
|
||||
.hv-popover__trigger.hv-button {
|
||||
display: inline-flex;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue/Reka adapters. */
|
||||
/* Tooltip component styles */
|
||||
|
||||
/* Base tooltip styles */
|
||||
.hv-tooltip {
|
||||
@apply max-w-xs origin-(--reka-popper-transform-origin) bg-overlay p-2 text-xs break-all;
|
||||
border-radius: min(32px, var(--radius-xl));
|
||||
box-shadow: var(--overlay-shadow);
|
||||
|
||||
/* Entering animations */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-90;
|
||||
|
||||
/* Placement-specific translations */
|
||||
&[data-side="top"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
|
||||
&[data-side="bottom"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-side="left"] {
|
||||
@apply slide-in-from-right-1;
|
||||
}
|
||||
|
||||
&[data-side="right"] {
|
||||
@apply slide-in-from-left-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Exiting animations */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
|
||||
/* Stays non-interactive while closing, even if the exit animation is interrupted. */
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||||
}
|
||||
|
||||
/* Arrow styling */
|
||||
& [data-slot="overlay-arrow"] {
|
||||
@apply stroke-border/40;
|
||||
fill: var(--overlay);
|
||||
}
|
||||
}
|
||||
|
||||
/* Tooltip trigger */
|
||||
.hv-tooltip__trigger {
|
||||
@apply inline-block;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
color 150ms var(--ease-smooth),
|
||||
background-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reka owns an inline pointer-events rule; exiting surfaces must stay inactive. */
|
||||
.hv-tooltip[data-exiting="true"] {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* React Aria supplies this stacking level inline; Reka reads it from Content. */
|
||||
.hv-tooltip {
|
||||
z-index: var(--z-index-overlay);
|
||||
}
|
||||
|
||||
.hv-tooltip__trigger.hv-button {
|
||||
display: inline-flex;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
@import "./themes/shared/theme.css";
|
||||
@import "./themes/default/variables.css";
|
||||
@import "./utilities/index.css";
|
||||
@import "./animations.css";
|
||||
@import "./variants/index.css";
|
||||
@import "./components/button.css" layer(components);
|
||||
@import "./components/close-button.css" layer(components);
|
||||
@@ -120,3 +121,9 @@
|
||||
@import "./components/disclosure-group.css" layer(components);
|
||||
|
||||
@import "./components/accordion.css" layer(components);
|
||||
|
||||
@import "./components/modal.css" layer(components);
|
||||
|
||||
@import "./components/popover.css" layer(components);
|
||||
|
||||
@import "./components/tooltip.css" layer(components);
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist",
|
||||
"LICENSE"
|
||||
"LICENSE",
|
||||
"LICENSE.tw-animate-css"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
@@ -21,7 +22,8 @@
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"tailwind-variants": "^3.1.0"
|
||||
"tailwind-variants": "^3.1.0",
|
||||
"tw-animate-css": "1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.1.0",
|
||||
|
||||
@@ -891,3 +891,90 @@ export const accordionVariants = tv({
|
||||
});
|
||||
|
||||
export type AccordionVariants = VariantProps<typeof accordionVariants>;
|
||||
|
||||
export const modalVariants = tv({
|
||||
defaultVariants: {
|
||||
scroll: "inside",
|
||||
size: "md",
|
||||
variant: "opaque",
|
||||
},
|
||||
slots: {
|
||||
backdrop: "hv-modal__backdrop",
|
||||
body: "hv-modal__body",
|
||||
closeTrigger: "hv-modal__close-trigger",
|
||||
container: "hv-modal__container",
|
||||
dialog: "hv-modal__dialog",
|
||||
footer: "hv-modal__footer",
|
||||
header: "hv-modal__header",
|
||||
heading: "hv-modal__heading",
|
||||
icon: "hv-modal__icon",
|
||||
trigger: "hv-modal__trigger",
|
||||
},
|
||||
variants: {
|
||||
scroll: {
|
||||
inside: {
|
||||
body: "hv-modal__body--scroll-inside",
|
||||
dialog: "hv-modal__dialog--scroll-inside",
|
||||
},
|
||||
outside: {
|
||||
body: "hv-modal__body--scroll-outside",
|
||||
container: "hv-modal__container--scroll-outside",
|
||||
dialog: "hv-modal__dialog--scroll-outside",
|
||||
},
|
||||
},
|
||||
size: {
|
||||
cover: {
|
||||
dialog: "hv-modal__dialog--cover",
|
||||
},
|
||||
full: {
|
||||
container: "hv-modal__container--full",
|
||||
dialog: "hv-modal__dialog--full",
|
||||
},
|
||||
lg: {
|
||||
dialog: "hv-modal__dialog--lg",
|
||||
},
|
||||
md: {
|
||||
dialog: "hv-modal__dialog--md",
|
||||
},
|
||||
sm: {
|
||||
dialog: "hv-modal__dialog--sm",
|
||||
},
|
||||
xs: {
|
||||
dialog: "hv-modal__dialog--xs",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
blur: {
|
||||
backdrop: "hv-modal__backdrop--blur",
|
||||
},
|
||||
opaque: {
|
||||
backdrop: "hv-modal__backdrop--opaque",
|
||||
},
|
||||
transparent: {
|
||||
backdrop: "hv-modal__backdrop--transparent",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type ModalVariants = VariantProps<typeof modalVariants>;
|
||||
|
||||
export const popoverVariants = tv({
|
||||
slots: {
|
||||
base: "hv-popover",
|
||||
dialog: "hv-popover__dialog",
|
||||
heading: "hv-popover__heading",
|
||||
trigger: "hv-popover__trigger",
|
||||
},
|
||||
});
|
||||
|
||||
export type PopoverVariants = VariantProps<typeof popoverVariants>;
|
||||
|
||||
export const tooltipVariants = tv({
|
||||
slots: {
|
||||
base: "hv-tooltip",
|
||||
trigger: "hv-tooltip__trigger",
|
||||
},
|
||||
});
|
||||
|
||||
export type TooltipVariants = VariantProps<typeof tooltipVariants>;
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
--skeleton-animation: shimmer; /* shimmer, pulse, none */
|
||||
|
||||
/* Tooltip Default Delays */
|
||||
/* Shared portal stacking baseline (HeroUI base/base.css). */
|
||||
--z-index-overlay: 100000;
|
||||
--z-index-toast: calc(var(--z-index-overlay) + 1);
|
||||
|
||||
--tooltip-delay: 1500ms;
|
||||
--tooltip-close-delay: 500ms;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { defineComponent, h, provide, type PropType } from "vue";
|
||||
import {
|
||||
useOverlayState,
|
||||
type OverlayState,
|
||||
} from "../../composables/useOverlayState";
|
||||
import OverlayDialogRoot from "../overlay/OverlayDialogRoot.vue";
|
||||
import { overlayNodes, overlayComponentName } from "../overlay/OverlayAction";
|
||||
import { createModalContext, modalKey } from "./context";
|
||||
import ModalTrigger from "./ModalTrigger.vue";
|
||||
export default defineComponent({
|
||||
name: "Modal",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
open: { type: Boolean, default: undefined },
|
||||
isOpen: { type: Boolean, default: undefined },
|
||||
defaultOpen: Boolean,
|
||||
state: Object as PropType<OverlayState>,
|
||||
},
|
||||
emits: {
|
||||
"update:open": (value: boolean) => typeof value === "boolean",
|
||||
"update:isOpen": (value: boolean) => typeof value === "boolean",
|
||||
openChange: (value: boolean) => typeof value === "boolean",
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const state = useOverlayState({
|
||||
isOpen: () => props.state?.isOpen.value ?? props.open ?? props.isOpen,
|
||||
defaultOpen: props.defaultOpen,
|
||||
onOpenChange(value) {
|
||||
props.state?.setOpen(value);
|
||||
emit("update:open", value);
|
||||
emit("update:isOpen", value);
|
||||
emit("openChange", value);
|
||||
},
|
||||
});
|
||||
provide(modalKey, createModalContext(state));
|
||||
return () =>
|
||||
h(
|
||||
OverlayDialogRoot,
|
||||
{ state },
|
||||
{
|
||||
default: () => {
|
||||
let found = false;
|
||||
return overlayNodes(
|
||||
slots.default?.({
|
||||
isOpen: state.isOpen.value,
|
||||
close: state.close,
|
||||
}),
|
||||
).map((node) => {
|
||||
const name = overlayComponentName(node);
|
||||
if (name === "ModalTrigger") found = true;
|
||||
if (
|
||||
!found &&
|
||||
(name === "Button" ||
|
||||
node.type === "button" ||
|
||||
node.type === "a")
|
||||
) {
|
||||
found = true;
|
||||
return h(
|
||||
ModalTrigger,
|
||||
{ asChild: true, key: node.key ?? undefined },
|
||||
{ default: () => node },
|
||||
);
|
||||
}
|
||||
return node;
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, type PropType } from "vue";
|
||||
import type { ModalVariants } from "@heroui-vue/styles";
|
||||
import Modal from "./Modal";
|
||||
import ModalBackdropSurface from "./ModalBackdropSurface.vue";
|
||||
import { modalKey } from "./context";
|
||||
export default defineComponent({
|
||||
name: "ModalBackdrop",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
open: { type: Boolean, default: undefined },
|
||||
isOpen: { type: Boolean, default: undefined },
|
||||
defaultOpen: Boolean,
|
||||
variant: String as PropType<ModalVariants["variant"]>,
|
||||
isDismissable: { type: Boolean, default: true },
|
||||
isKeyboardDismissDisabled: Boolean,
|
||||
to: [String, Object] as PropType<string | HTMLElement>,
|
||||
},
|
||||
emits: {
|
||||
"update:open": (value: boolean) => typeof value === "boolean",
|
||||
"update:isOpen": (value: boolean) => typeof value === "boolean",
|
||||
openChange: (value: boolean) => typeof value === "boolean",
|
||||
},
|
||||
setup(props, { attrs, slots, emit }) {
|
||||
const parent = inject(modalKey, undefined);
|
||||
return () => {
|
||||
const surface = () =>
|
||||
h(
|
||||
ModalBackdropSurface,
|
||||
{
|
||||
...attrs,
|
||||
variant: props.variant,
|
||||
isDismissable: props.isDismissable,
|
||||
isKeyboardDismissDisabled: props.isKeyboardDismissDisabled,
|
||||
to: props.to,
|
||||
},
|
||||
slots,
|
||||
);
|
||||
if (parent) return surface();
|
||||
return h(
|
||||
Modal,
|
||||
{
|
||||
open: props.open,
|
||||
isOpen: props.isOpen,
|
||||
defaultOpen: props.defaultOpen,
|
||||
"onUpdate:open": (v: boolean) => emit("update:open", v),
|
||||
"onUpdate:isOpen": (v: boolean) => emit("update:isOpen", v),
|
||||
onOpenChange: (v: boolean) => emit("openChange", v),
|
||||
},
|
||||
{ default: surface },
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { useForwardExpose } from "reka-ui";
|
||||
import { computed, provide } from "vue";
|
||||
import { modalVariants, type ModalVariants } from "@heroui-vue/styles";
|
||||
import OverlayPortal from "../overlay/OverlayPortal.vue";
|
||||
import OverlayBackdrop from "../overlay/OverlayBackdrop.vue";
|
||||
import { modalKey, useModal } from "./context";
|
||||
import { useOverlayViewport } from "../overlay/viewport";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant?: ModalVariants["variant"];
|
||||
isDismissable?: boolean;
|
||||
isKeyboardDismissDisabled?: boolean;
|
||||
to?: string | HTMLElement;
|
||||
}>(),
|
||||
{ variant: "opaque", isDismissable: true, isKeyboardDismissDisabled: false },
|
||||
);
|
||||
const ctx = useModal();
|
||||
const height = useOverlayViewport();
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
provide(modalKey, {
|
||||
...ctx,
|
||||
dismissable: computed(() => props.isDismissable),
|
||||
keyboardDisabled: computed(() => props.isKeyboardDismissDisabled),
|
||||
});
|
||||
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
|
||||
ctx.state.isOpen,
|
||||
currentElement,
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<OverlayPortal :to="to">
|
||||
<OverlayBackdrop
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:style="{ '--visual-viewport-height': height }"
|
||||
:class="modalVariants({ variant }).backdrop()"
|
||||
data-slot="modal-backdrop"
|
||||
:data-entering="entering || undefined"
|
||||
:data-exiting="exiting || undefined"
|
||||
@animationend="onAnimationEnd"
|
||||
>
|
||||
<slot :is-open="ctx.state.isOpen.value" :close="ctx.state.close" />
|
||||
</OverlayBackdrop>
|
||||
</OverlayPortal>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { modalVariants } from "@heroui-vue/styles";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
const ctx = useModal();
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
:class="modalVariants({ scroll: ctx.scroll.value }).body()"
|
||||
data-slot="modal-body"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import OverlayAction from "../overlay/OverlayAction";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
|
||||
{ as: "button" },
|
||||
);
|
||||
const ctx = useModal();
|
||||
</script>
|
||||
<template>
|
||||
<OverlayAction
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:is-disabled="isDisabled"
|
||||
:activate="ctx.state.close"
|
||||
>
|
||||
<slot />
|
||||
</OverlayAction>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
import { defineComponent, h, mergeProps, type PropType } from "vue";
|
||||
import type { CloseButtonVariants } from "@heroui-vue/styles";
|
||||
import CloseButton from "../close-button/CloseButton.vue";
|
||||
import { useModal } from "./context";
|
||||
export default defineComponent({
|
||||
name: "ModalCloseTrigger",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
variant: String as PropType<CloseButtonVariants["variant"]>,
|
||||
isDisabled: Boolean,
|
||||
disabled: Boolean,
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useModal();
|
||||
return () =>
|
||||
h(
|
||||
CloseButton,
|
||||
mergeProps(attrs, props, {
|
||||
class: "hv-modal__close-trigger",
|
||||
"data-slot": "modal-close-trigger",
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (!event.defaultPrevented) ctx.state.close();
|
||||
},
|
||||
}),
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, ref } from "vue";
|
||||
import { modalVariants, type ModalVariants } from "@heroui-vue/styles";
|
||||
import { modalKey, useModal, type ModalPlacement } from "./context";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
placement?: ModalPlacement;
|
||||
size?: ModalVariants["size"];
|
||||
scroll?: ModalVariants["scroll"];
|
||||
as?: string;
|
||||
}>(),
|
||||
{ placement: "auto", size: "md", scroll: "inside", as: "div" },
|
||||
);
|
||||
const ctx = useModal();
|
||||
provide(modalKey, {
|
||||
...ctx,
|
||||
placement: computed(() => props.placement),
|
||||
size: computed(() => props.size),
|
||||
scroll: computed(() => props.scroll),
|
||||
});
|
||||
const container = ref<HTMLElement>();
|
||||
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
|
||||
ctx.state.isOpen,
|
||||
container,
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
ref="container"
|
||||
v-bind="$attrs"
|
||||
:class="modalVariants({ size, scroll }).container()"
|
||||
data-slot="modal-container"
|
||||
:data-placement="placement"
|
||||
:data-entering="entering || undefined"
|
||||
:data-exiting="exiting || undefined"
|
||||
@animationend="onAnimationEnd"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, watchEffect, onUnmounted, useAttrs } from "vue";
|
||||
import { DialogTitle } from "reka-ui";
|
||||
import { modalVariants } from "@heroui-vue/styles";
|
||||
import OverlayDialogContent from "../overlay/OverlayDialogContent.vue";
|
||||
import { surfaceContextKey } from "../surface/context";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
|
||||
as: "div",
|
||||
});
|
||||
const ctx = useModal();
|
||||
const attrs = useAttrs();
|
||||
watchEffect(() => {
|
||||
ctx.contentId.value = props.id ?? ctx.defaultId;
|
||||
});
|
||||
onUnmounted(() => {
|
||||
ctx.contentId.value = ctx.defaultId;
|
||||
});
|
||||
provide(surfaceContextKey, { variant: computed(() => "default" as const) });
|
||||
</script>
|
||||
<template>
|
||||
<OverlayDialogContent
|
||||
v-bind="attrs"
|
||||
:as="as"
|
||||
:id="ctx.contentId.value"
|
||||
:class="
|
||||
modalVariants({ size: ctx.size.value, scroll: ctx.scroll.value }).dialog()
|
||||
"
|
||||
:is-dismissable="ctx.dismissable.value"
|
||||
:is-keyboard-dismiss-disabled="ctx.keyboardDisabled.value"
|
||||
data-slot="modal-dialog"
|
||||
:data-exiting="!ctx.state.isOpen.value || undefined"
|
||||
:data-placement="ctx.placement.value"
|
||||
:aria-labelledby="
|
||||
'aria-labelledby' in attrs
|
||||
? (attrs['aria-labelledby'] as string)
|
||||
: Array.from(ctx.titles.values()).join(' ') || undefined
|
||||
"
|
||||
:aria-describedby="attrs['aria-describedby'] as string | undefined"
|
||||
>
|
||||
<DialogTitle
|
||||
v-if="
|
||||
('aria-label' in attrs || 'aria-labelledby' in attrs) &&
|
||||
!ctx.titles.size
|
||||
"
|
||||
as="span"
|
||||
class="sr-only"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<slot :close="ctx.state.close" :is-open="ctx.state.isOpen.value" />
|
||||
</OverlayDialogContent>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { modalVariants } from "@heroui-vue/styles";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
const ctx = useModal();
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
:class="'hv-modal__footer'"
|
||||
data-slot="modal-footer"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { modalVariants } from "@heroui-vue/styles";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
const ctx = useModal();
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
:class="'hv-modal__header'"
|
||||
data-slot="modal-header"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watchEffect, onUnmounted, useId } from "vue";
|
||||
import { DialogTitle, injectDialogRootContext } from "reka-ui";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
|
||||
as: "h2",
|
||||
});
|
||||
const ctx = useModal();
|
||||
const root = injectDialogRootContext();
|
||||
const suffix = useId();
|
||||
const key = Symbol();
|
||||
const generated = ctx.titles.size ? `${root.titleId}-${suffix}` : root.titleId;
|
||||
const id = computed(() => props.id ?? generated);
|
||||
watchEffect(() => {
|
||||
ctx.titles.set(key, id.value);
|
||||
});
|
||||
onUnmounted(() => ctx.titles.delete(key));
|
||||
</script>
|
||||
<template>
|
||||
<DialogTitle v-if="props.id" as="span" class="sr-only" aria-hidden="true" />
|
||||
<DialogTitle
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:id="id"
|
||||
class="hv-modal__heading"
|
||||
data-slot="modal-heading"
|
||||
>
|
||||
<slot />
|
||||
</DialogTitle>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { modalVariants } from "@heroui-vue/styles";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
const ctx = useModal();
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
:class="'hv-modal__icon'"
|
||||
data-slot="modal-icon"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import { watch } from "vue";
|
||||
import { injectDialogRootContext, useForwardExpose } from "reka-ui";
|
||||
import OverlayAction from "../overlay/OverlayAction";
|
||||
import { useModal } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
|
||||
{ as: "div" },
|
||||
);
|
||||
const ctx = useModal();
|
||||
const dialog = injectDialogRootContext();
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
watch(
|
||||
currentElement,
|
||||
(el) => {
|
||||
dialog.triggerElement.value = el;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<OverlayAction
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:is-disabled="isDisabled"
|
||||
:activate="ctx.state.open"
|
||||
class="hv-modal__trigger"
|
||||
data-slot="modal-trigger"
|
||||
aria-haspopup="dialog"
|
||||
:aria-expanded="ctx.state.isOpen.value"
|
||||
:aria-controls="ctx.state.isOpen.value ? ctx.contentId.value : undefined"
|
||||
>
|
||||
<slot />
|
||||
</OverlayAction>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
computed,
|
||||
inject,
|
||||
reactive,
|
||||
ref,
|
||||
useId,
|
||||
type ComputedRef,
|
||||
type InjectionKey,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import type { ModalVariants } from "@heroui-vue/styles";
|
||||
import type { OverlayState } from "../../composables/useOverlayState";
|
||||
export type ModalPlacement = "auto" | "top" | "center" | "bottom";
|
||||
export interface ModalContext {
|
||||
state: OverlayState;
|
||||
contentId: Ref<string>;
|
||||
defaultId: string;
|
||||
titles: Map<symbol, string>;
|
||||
placement: ComputedRef<ModalPlacement>;
|
||||
size: ComputedRef<ModalVariants["size"]>;
|
||||
scroll: ComputedRef<ModalVariants["scroll"]>;
|
||||
dismissable: ComputedRef<boolean>;
|
||||
keyboardDisabled: ComputedRef<boolean>;
|
||||
}
|
||||
export const modalKey: InjectionKey<ModalContext> = Symbol("hv-modal");
|
||||
export function useModal(required = true) {
|
||||
const ctx = inject(modalKey, undefined);
|
||||
if (!ctx && required)
|
||||
throw new Error("Modal parts require Modal or ModalBackdrop.");
|
||||
return ctx!;
|
||||
}
|
||||
export function createModalContext(state: OverlayState): ModalContext {
|
||||
const id = "hv-modal-" + useId();
|
||||
return {
|
||||
state,
|
||||
contentId: ref(id),
|
||||
defaultId: id,
|
||||
titles: reactive(new Map()),
|
||||
placement: computed(() => "auto"),
|
||||
size: computed(() => "md"),
|
||||
scroll: computed(() => "inside"),
|
||||
dismissable: computed(() => true),
|
||||
keyboardDisabled: computed(() => false),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
cloneVNode,
|
||||
defineComponent,
|
||||
h,
|
||||
isVNode,
|
||||
ref,
|
||||
type VNode,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { useForwardExpose } from "reka-ui";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
|
||||
export function overlayNodes(children: unknown): VNode[] {
|
||||
const result: VNode[] = [];
|
||||
for (const child of Array.isArray(children) ? children : [children]) {
|
||||
if (Array.isArray(child)) result.push(...overlayNodes(child));
|
||||
else if (isVNode(child)) {
|
||||
if (child.type === Fragment) result.push(...overlayNodes(child.children));
|
||||
else if (
|
||||
child.type !== Comment &&
|
||||
!(child.type === Text && !String(child.children).trim())
|
||||
)
|
||||
result.push(child);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function overlayComponentName(node: VNode): string {
|
||||
const type = node.type as { name?: string; __name?: string };
|
||||
return typeof node.type === "object" ? (type.name ?? type.__name ?? "") : "";
|
||||
}
|
||||
function handlers(value: unknown): ((event: Event) => void)[] {
|
||||
if (Array.isArray(value)) return value.flatMap(handlers);
|
||||
return typeof value === "function" ? [value as (event: Event) => void] : [];
|
||||
}
|
||||
|
||||
/** Native DOM listener arrays keep cancel/stop semantics. No synthetic emit or invoker internals. */
|
||||
export default defineComponent({
|
||||
name: "OverlayAction",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "button" },
|
||||
asChild: Boolean,
|
||||
isDisabled: Boolean,
|
||||
activate: { type: Function as PropType<() => void>, required: true },
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const inherited = useInheritedDisabled(() => props.isDisabled);
|
||||
const { forwardRef } = useForwardExpose();
|
||||
const spaceDown = ref(false);
|
||||
return () => {
|
||||
const children = slots.default?.();
|
||||
const nodes = overlayNodes(children);
|
||||
if (
|
||||
props.asChild &&
|
||||
(nodes.length !== 1 || typeof nodes[0]?.type === "symbol")
|
||||
)
|
||||
throw new Error(
|
||||
"Overlay trigger asChild requires one element or component root.",
|
||||
);
|
||||
const child = props.asChild ? nodes[0]! : undefined;
|
||||
const original = child?.props ?? {};
|
||||
const disabled = () =>
|
||||
inherited.value ||
|
||||
original.isDisabled === true ||
|
||||
original.disabled === true ||
|
||||
original.isPending === true ||
|
||||
original.loading === true ||
|
||||
attrs.disabled === true;
|
||||
const guard = (event: Event) => {
|
||||
if (disabled()) {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
spaceDown.value = false;
|
||||
}
|
||||
};
|
||||
const native = (el: EventTarget | null) =>
|
||||
el instanceof HTMLElement &&
|
||||
(el.tagName === "BUTTON" ||
|
||||
el.tagName === "INPUT" ||
|
||||
(el.tagName === "A" && el.hasAttribute("href")));
|
||||
const keyboardDown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.repeat ||
|
||||
event.isComposing ||
|
||||
native(event.currentTarget)
|
||||
)
|
||||
return;
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
(event.currentTarget as HTMLElement).click();
|
||||
}
|
||||
if (event.key === " ") {
|
||||
event.preventDefault();
|
||||
spaceDown.value = true;
|
||||
}
|
||||
};
|
||||
const keyboardUp = (event: KeyboardEvent) => {
|
||||
const pressed = spaceDown.value;
|
||||
spaceDown.value = false;
|
||||
if (
|
||||
event.key === " " &&
|
||||
pressed &&
|
||||
!event.defaultPrevented &&
|
||||
!native(event.currentTarget)
|
||||
) {
|
||||
event.preventDefault();
|
||||
(event.currentTarget as HTMLElement).click();
|
||||
}
|
||||
};
|
||||
const tag = child
|
||||
? typeof child.type === "string"
|
||||
? child.type
|
||||
: undefined
|
||||
: props.as;
|
||||
const custom =
|
||||
tag &&
|
||||
!["button", "input"].includes(tag) &&
|
||||
!(tag === "a" && (original.href ?? attrs.href));
|
||||
const merged = {
|
||||
...attrs,
|
||||
type:
|
||||
attrs.type ??
|
||||
(props.as === "button" || child?.type === "button"
|
||||
? "button"
|
||||
: undefined),
|
||||
role: attrs.role ?? original.role ?? (custom ? "button" : undefined),
|
||||
tabindex:
|
||||
attrs.tabindex ??
|
||||
original.tabindex ??
|
||||
(custom ? (disabled() ? -1 : 0) : undefined),
|
||||
disabled: disabled() || undefined,
|
||||
"aria-disabled": disabled() || undefined,
|
||||
onClickCapture: [
|
||||
guard,
|
||||
...handlers(attrs.onClickCapture),
|
||||
...handlers(original.onClickCapture),
|
||||
],
|
||||
onKeydownCapture: [
|
||||
guard,
|
||||
...handlers(attrs.onKeydownCapture),
|
||||
...handlers(original.onKeydownCapture),
|
||||
],
|
||||
onKeyupCapture: [
|
||||
guard,
|
||||
...handlers(attrs.onKeyupCapture),
|
||||
...handlers(original.onKeyupCapture),
|
||||
],
|
||||
onClick: [
|
||||
...handlers(original.onClick),
|
||||
...handlers(attrs.onClick),
|
||||
(event: Event) => {
|
||||
if (!event.defaultPrevented && !disabled()) props.activate();
|
||||
},
|
||||
],
|
||||
onKeydown: [
|
||||
...handlers(original.onKeydown),
|
||||
...handlers(attrs.onKeydown),
|
||||
keyboardDown,
|
||||
],
|
||||
onKeyup: [
|
||||
...handlers(original.onKeyup),
|
||||
...handlers(attrs.onKeyup),
|
||||
keyboardUp,
|
||||
],
|
||||
onBlur: [
|
||||
...handlers(original.onBlur),
|
||||
...handlers(attrs.onBlur),
|
||||
() => {
|
||||
spaceDown.value = false;
|
||||
},
|
||||
],
|
||||
ref: forwardRef,
|
||||
};
|
||||
if (!child) return h(props.as, merged, children);
|
||||
const copy = cloneVNode(child);
|
||||
copy.props = { ...original };
|
||||
for (const event of [
|
||||
"onClick",
|
||||
"onClickCapture",
|
||||
"onKeydown",
|
||||
"onKeyup",
|
||||
"onKeydownCapture",
|
||||
"onKeyupCapture",
|
||||
"onBlur",
|
||||
])
|
||||
delete copy.props[event];
|
||||
return cloneVNode(copy, merged, true);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { cloneVNode, defineComponent, h } from "vue";
|
||||
import { overlayNodes } from "./OverlayAction";
|
||||
/** Canonical arrow path from HeroUI ce90ea3 (Apache-2.0); custom SVGs keep the styling slot. */
|
||||
export default defineComponent({
|
||||
inheritAttrs: false,
|
||||
props: { marker: { type: String, required: true } },
|
||||
setup(props, { attrs, slots }) {
|
||||
return () => {
|
||||
const nodes = overlayNodes(slots.default?.());
|
||||
if (nodes.length > 1)
|
||||
throw new Error("Overlay arrow requires one custom SVG root.");
|
||||
return nodes[0]
|
||||
? cloneVNode(nodes[0], { ...attrs, "data-slot": props.marker })
|
||||
: h(
|
||||
"svg",
|
||||
{
|
||||
...attrs,
|
||||
"aria-hidden": true,
|
||||
"data-slot": props.marker,
|
||||
fill: "none",
|
||||
width: 12,
|
||||
height: 12,
|
||||
viewBox: "0 0 12 12",
|
||||
xmlns: "http://www.w3.org/2000/svg",
|
||||
},
|
||||
[h("path", { d: "M0 0C5.48483 8 6.5 8 12 0Z" })],
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { DialogOverlay, useForwardExpose } from "reka-ui";
|
||||
import { useOverlayDialog } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
useOverlayDialog();
|
||||
const { forwardRef } = useForwardExpose();
|
||||
</script>
|
||||
<template>
|
||||
<DialogOverlay :ref="forwardRef" :as="as" v-bind="$attrs">
|
||||
<slot />
|
||||
</DialogOverlay>
|
||||
</template>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DialogContent,
|
||||
injectDialogRootContext,
|
||||
useForwardExpose,
|
||||
type DialogContentEmits,
|
||||
} from "reka-ui";
|
||||
import { useId } from "vue";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { useOverlayDialog } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
as?: string;
|
||||
isDismissable?: boolean;
|
||||
isKeyboardDismissDisabled?: boolean;
|
||||
}>(),
|
||||
{ as: "div", isDismissable: true, isKeyboardDismissDisabled: false },
|
||||
);
|
||||
const emit = defineEmits<DialogContentEmits>();
|
||||
const context = useOverlayDialog();
|
||||
const config = useConfig();
|
||||
const generatedId = useId();
|
||||
// Programmatic dialogs may have no Trigger to allocate a content ID.
|
||||
const dialog = injectDialogRootContext();
|
||||
dialog.contentId ||= `hv-overlay-${generatedId}`;
|
||||
const { forwardRef } = useForwardExpose();
|
||||
|
||||
function onEscape(event: KeyboardEvent) {
|
||||
emit("escapeKeyDown", event);
|
||||
if (props.isKeyboardDismissDisabled) event.preventDefault();
|
||||
}
|
||||
function onOutside(event: DialogContentEmits["interactOutside"][0]) {
|
||||
emit("interactOutside", event);
|
||||
if (!props.isDismissable) event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<DialogContent
|
||||
:ref="forwardRef"
|
||||
:as="as"
|
||||
v-bind="$attrs"
|
||||
:dir="($attrs.dir as string | undefined) ?? config?.dir.value"
|
||||
:lang="($attrs.lang as string | undefined) ?? config?.locale.value"
|
||||
:aria-modal="context.modal.value ? true : undefined"
|
||||
@escape-key-down="onEscape"
|
||||
@interact-outside="onOutside"
|
||||
@pointer-down-outside="emit('pointerDownOutside', $event)"
|
||||
@focus-outside="emit('focusOutside', $event)"
|
||||
@open-auto-focus="emit('openAutoFocus', $event)"
|
||||
@close-auto-focus="emit('closeAutoFocus', $event)"
|
||||
>
|
||||
<slot />
|
||||
</DialogContent>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, toValue } from "vue";
|
||||
import { DialogRoot } from "reka-ui";
|
||||
import {
|
||||
useOverlayState,
|
||||
type OverlayState,
|
||||
} from "../../composables/useOverlayState";
|
||||
import { overlayDialogKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
open?: boolean;
|
||||
defaultOpen?: boolean;
|
||||
state?: OverlayState;
|
||||
modal?: boolean;
|
||||
}>(),
|
||||
{ open: undefined, defaultOpen: false, modal: true },
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
"update:open": [open: boolean];
|
||||
openChange: [open: boolean];
|
||||
}>();
|
||||
const state = useOverlayState({
|
||||
isOpen: () => (props.state ? toValue(props.state.isOpen) : props.open),
|
||||
defaultOpen: props.defaultOpen,
|
||||
onOpenChange(value) {
|
||||
props.state?.setOpen(value);
|
||||
emit("update:open", value);
|
||||
emit("openChange", value);
|
||||
},
|
||||
});
|
||||
provide(overlayDialogKey, { state, modal: computed(() => props.modal) });
|
||||
defineExpose({ open: state.open, close: state.close, toggle: state.toggle });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DialogRoot
|
||||
:open="state.isOpen.value"
|
||||
:modal="modal"
|
||||
@update:open="state.setOpen"
|
||||
>
|
||||
<slot
|
||||
:is-open="state.isOpen.value"
|
||||
:close="state.close"
|
||||
:open="state.open"
|
||||
/>
|
||||
</DialogRoot>
|
||||
</template>
|
||||
@@ -0,0 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { DialogPortal } from "reka-ui";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
defineProps<{
|
||||
to?: string | HTMLElement;
|
||||
disabled?: boolean;
|
||||
defer?: boolean;
|
||||
}>();
|
||||
</script>
|
||||
<template>
|
||||
<DialogPortal :to="to" :disabled="disabled" :defer="defer">
|
||||
<slot />
|
||||
</DialogPortal>
|
||||
</template>
|
||||
@@ -0,0 +1,63 @@
|
||||
import { computed, nextTick, ref, watch, type Ref } from "vue";
|
||||
/** Phase markers drive source keyframes; Reka Presence still owns exit unmounting. */
|
||||
export function useOverlayAnimation(
|
||||
open: Ref<boolean>,
|
||||
element?: Ref<HTMLElement | null | undefined>,
|
||||
floating = false,
|
||||
) {
|
||||
const entering = ref(open.value);
|
||||
watch(
|
||||
open,
|
||||
(value) => {
|
||||
entering.value = value;
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
function onAnimationEnd(event: AnimationEvent) {
|
||||
if (event.target !== event.currentTarget || !open.value) return;
|
||||
const names = getComputedStyle(event.currentTarget as HTMLElement)
|
||||
.animationName.split(",")
|
||||
.map((s) => s.trim());
|
||||
if (names.includes(event.animationName)) entering.value = false;
|
||||
}
|
||||
if (element)
|
||||
watch(
|
||||
[element, open],
|
||||
([el], _, onCleanup) => {
|
||||
if (!el) return;
|
||||
let stale = false;
|
||||
const wrapper = el.parentElement;
|
||||
const check = () => {
|
||||
if (stale || !open.value || !entering.value) return;
|
||||
// Floating UI briefly suppresses animation while measuring. Wait for placement.
|
||||
if (
|
||||
floating &&
|
||||
wrapper?.hasAttribute("data-reka-popper-content-wrapper") &&
|
||||
/translate\(0(?:px)?,\s*-200%\)/.test(wrapper.style.transform)
|
||||
)
|
||||
return;
|
||||
const animation = getComputedStyle(el).animationName;
|
||||
if (!animation || animation === "none") entering.value = false;
|
||||
};
|
||||
const observer = new MutationObserver(check);
|
||||
observer.observe(el, { attributes: true, attributeFilter: ["style"] });
|
||||
if (floating && wrapper)
|
||||
observer.observe(wrapper, {
|
||||
attributes: true,
|
||||
attributeFilter: ["style"],
|
||||
});
|
||||
const media = el.ownerDocument.defaultView?.matchMedia?.(
|
||||
"(prefers-reduced-motion: reduce)",
|
||||
);
|
||||
media?.addEventListener("change", check);
|
||||
void nextTick(check);
|
||||
onCleanup(() => {
|
||||
stale = true;
|
||||
observer.disconnect();
|
||||
media?.removeEventListener("change", check);
|
||||
});
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
return { entering, exiting: computed(() => !open.value), onAnimationEnd };
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { inject, type ComputedRef, type InjectionKey } from "vue";
|
||||
import type { OverlayState } from "../../composables/useOverlayState";
|
||||
|
||||
export interface OverlayDialogContext {
|
||||
state: OverlayState;
|
||||
modal: ComputedRef<boolean>;
|
||||
}
|
||||
export const overlayDialogKey: InjectionKey<OverlayDialogContext> =
|
||||
Symbol("hv-overlay-dialog");
|
||||
export function useOverlayDialog() {
|
||||
const context = inject(overlayDialogKey);
|
||||
if (!context)
|
||||
throw new Error("Overlay dialog parts require OverlayDialogRoot.");
|
||||
return context;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
export type OverlaySide = "top" | "bottom" | "left" | "right";
|
||||
export type OverlayPlacement =
|
||||
| OverlaySide
|
||||
| "start"
|
||||
| "end"
|
||||
| `${"top" | "bottom"} ${"start" | "end" | "left" | "right"}`
|
||||
| `${"left" | "right" | "start" | "end"} ${"top" | "bottom"}`;
|
||||
export function resolvePlacement(
|
||||
value: OverlayPlacement,
|
||||
dir: "ltr" | "rtl" = "ltr",
|
||||
) {
|
||||
const [base, edge] = value.split(" ");
|
||||
const side: OverlaySide =
|
||||
base === "start"
|
||||
? dir === "rtl"
|
||||
? "right"
|
||||
: "left"
|
||||
: base === "end"
|
||||
? dir === "rtl"
|
||||
? "left"
|
||||
: "right"
|
||||
: (base as OverlaySide);
|
||||
let align: "start" | "center" | "end" = "center";
|
||||
if (edge === "start" || edge === "top") align = "start";
|
||||
else if (edge === "end" || edge === "bottom") align = "end";
|
||||
else if (edge === "left") align = dir === "rtl" ? "end" : "start";
|
||||
else if (edge === "right") align = dir === "rtl" ? "start" : "end";
|
||||
return { side, align };
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/** Private primitive bridge, not a public HeroUI-compatible component API. */
|
||||
export {
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
PopoverRoot,
|
||||
PopoverTrigger,
|
||||
PopoverPortal,
|
||||
PopoverContent,
|
||||
} from "reka-ui";
|
||||
@@ -0,0 +1,18 @@
|
||||
import { onMounted, onBeforeUnmount, ref } from "vue";
|
||||
/** CSS fallback works before mount; use the visual viewport while the keyboard is visible. */
|
||||
export function useOverlayViewport() {
|
||||
const height = ref("100dvh");
|
||||
const update = () => {
|
||||
height.value = `${window.visualViewport?.height ?? window.innerHeight}px`;
|
||||
};
|
||||
onMounted(() => {
|
||||
update();
|
||||
window.addEventListener("resize", update);
|
||||
window.visualViewport?.addEventListener("resize", update);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("resize", update);
|
||||
window.visualViewport?.removeEventListener("resize", update);
|
||||
});
|
||||
return height;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { defineComponent, h, provide } from "vue";
|
||||
import { PopoverRoot } from "reka-ui";
|
||||
import { useOverlayState } from "../../composables/useOverlayState";
|
||||
import { overlayNodes, overlayComponentName } from "../overlay/OverlayAction";
|
||||
import { createPopoverContext, popoverKey } from "./context";
|
||||
import PopoverTrigger from "./PopoverTrigger.vue";
|
||||
export default defineComponent({
|
||||
name: "Popover",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
open: { type: Boolean, default: undefined },
|
||||
isOpen: { type: Boolean, default: undefined },
|
||||
defaultOpen: Boolean,
|
||||
isNonModal: { type: Boolean, default: false },
|
||||
},
|
||||
emits: {
|
||||
"update:open": (value: boolean) => typeof value === "boolean",
|
||||
"update:isOpen": (value: boolean) => typeof value === "boolean",
|
||||
openChange: (value: boolean) => typeof value === "boolean",
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const state = useOverlayState({
|
||||
isOpen: () => props.open ?? props.isOpen,
|
||||
defaultOpen: props.defaultOpen,
|
||||
onOpenChange(v) {
|
||||
emit("update:open", v);
|
||||
emit("update:isOpen", v);
|
||||
emit("openChange", v);
|
||||
},
|
||||
});
|
||||
const context = createPopoverContext(state);
|
||||
provide(popoverKey, context);
|
||||
return () =>
|
||||
h(
|
||||
PopoverRoot,
|
||||
{
|
||||
open: state.isOpen.value,
|
||||
modal: !(context.contentNonModal.value ?? props.isNonModal),
|
||||
"onUpdate:open": state.setOpen,
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
let found = false;
|
||||
return overlayNodes(
|
||||
slots.default?.({
|
||||
isOpen: state.isOpen.value,
|
||||
close: state.close,
|
||||
}),
|
||||
).map((node) => {
|
||||
const name = overlayComponentName(node);
|
||||
if (name === "PopoverTrigger") found = true;
|
||||
if (
|
||||
!found &&
|
||||
(name === "Button" ||
|
||||
node.type === "button" ||
|
||||
node.type === "a")
|
||||
) {
|
||||
found = true;
|
||||
return h(
|
||||
PopoverTrigger,
|
||||
{ asChild: true, key: node.key ?? undefined },
|
||||
{ default: () => node },
|
||||
);
|
||||
}
|
||||
return node;
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { PopoverArrow as RekaArrow } from "reka-ui";
|
||||
import OverlayArrowShape from "../overlay/OverlayArrowShape";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
</script>
|
||||
<template>
|
||||
<RekaArrow v-bind="$attrs" as-child :width="12" :height="12">
|
||||
<OverlayArrowShape marker="popover-overlay-arrow">
|
||||
<slot />
|
||||
</OverlayArrowShape>
|
||||
</RekaArrow>
|
||||
</template>
|
||||
@@ -0,0 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, watchEffect, ref, watch, nextTick } from "vue";
|
||||
import {
|
||||
PopoverPortal,
|
||||
PopoverContent as RekaContent,
|
||||
useForwardExpose,
|
||||
type PopoverContentEmits,
|
||||
injectPopoverRootContext,
|
||||
} from "reka-ui";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { surfaceContextKey } from "../surface/context";
|
||||
import { resolvePlacement, type OverlayPlacement } from "../overlay/placement";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
import { usePopover } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
as?: string;
|
||||
id?: string;
|
||||
placement?: OverlayPlacement;
|
||||
offset?: number;
|
||||
crossOffset?: number;
|
||||
shouldFlip?: boolean;
|
||||
containerPadding?: number;
|
||||
to?: string | HTMLElement;
|
||||
isNonModal?: boolean;
|
||||
isDismissable?: boolean;
|
||||
isKeyboardDismissDisabled?: boolean;
|
||||
}>(),
|
||||
{
|
||||
as: "div",
|
||||
placement: "bottom",
|
||||
offset: 8,
|
||||
crossOffset: 0,
|
||||
shouldFlip: true,
|
||||
containerPadding: 12,
|
||||
isNonModal: undefined,
|
||||
isDismissable: true,
|
||||
isKeyboardDismissDisabled: false,
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<PopoverContentEmits>();
|
||||
const ctx = usePopover(),
|
||||
config = useConfig(),
|
||||
root = injectPopoverRootContext();
|
||||
const originalId = ctx.contentId.value;
|
||||
watchEffect(() => {
|
||||
ctx.contentId.value = props.id ?? originalId;
|
||||
root.contentId = ctx.contentId.value;
|
||||
ctx.contentNonModal.value = props.isNonModal;
|
||||
});
|
||||
provide(surfaceContextKey, { variant: computed(() => "default" as const) });
|
||||
const position = computed(() =>
|
||||
resolvePlacement(props.placement, config?.dir.value),
|
||||
);
|
||||
const { forwardRef } = useForwardExpose();
|
||||
const contentElement = ref<HTMLElement | null>(null);
|
||||
let focusCancelled = false;
|
||||
function openFocus(event: Event) {
|
||||
emit("openAutoFocus", event);
|
||||
focusCancelled = event.defaultPrevented;
|
||||
}
|
||||
watch(
|
||||
contentElement,
|
||||
(element, _, onCleanup) => {
|
||||
let stale = false;
|
||||
onCleanup(() => {
|
||||
stale = true;
|
||||
});
|
||||
void nextTick(() => {
|
||||
if (
|
||||
!stale &&
|
||||
element?.isConnected &&
|
||||
ctx.state.isOpen.value &&
|
||||
!focusCancelled &&
|
||||
!element.contains(element.ownerDocument.activeElement)
|
||||
)
|
||||
element.focus({ preventScroll: true });
|
||||
});
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
|
||||
ctx.state.isOpen,
|
||||
contentElement,
|
||||
true,
|
||||
);
|
||||
function outside(event: PopoverContentEmits["interactOutside"][0]) {
|
||||
emit("interactOutside", event);
|
||||
if (!props.isDismissable) event.preventDefault();
|
||||
}
|
||||
function escape(event: KeyboardEvent) {
|
||||
emit("escapeKeyDown", event);
|
||||
if (props.isKeyboardDismissDisabled) event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<PopoverPortal :to="to">
|
||||
<RekaContent
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
as-child
|
||||
:id="ctx.contentId.value"
|
||||
:side="position.side"
|
||||
:align="position.align"
|
||||
:side-offset="offset"
|
||||
:align-offset="crossOffset"
|
||||
:side-flip="shouldFlip"
|
||||
:collision-padding="containerPadding"
|
||||
class="hv-popover"
|
||||
data-slot="popover-content"
|
||||
:data-entering="entering || undefined"
|
||||
:data-exiting="exiting || undefined"
|
||||
:lang="($attrs.lang as string | undefined) ?? config?.locale.value"
|
||||
@animationend="onAnimationEnd"
|
||||
@interact-outside="outside"
|
||||
@escape-key-down="escape"
|
||||
@pointer-down-outside="emit('pointerDownOutside', $event)"
|
||||
@focus-outside="emit('focusOutside', $event)"
|
||||
@open-auto-focus="openFocus"
|
||||
@close-auto-focus="emit('closeAutoFocus', $event)"
|
||||
>
|
||||
<component
|
||||
:is="as"
|
||||
ref="contentElement"
|
||||
:aria-label="
|
||||
($attrs['aria-label'] as string | undefined) ??
|
||||
(ctx.dialogAttrs.value['aria-label'] as string | undefined)
|
||||
"
|
||||
:aria-describedby="
|
||||
($attrs['aria-describedby'] as string | undefined) ??
|
||||
(ctx.dialogAttrs.value['aria-describedby'] as string | undefined)
|
||||
"
|
||||
:aria-labelledby="
|
||||
'aria-labelledby' in $attrs
|
||||
? ($attrs['aria-labelledby'] as string)
|
||||
: (ctx.dialogAttrs.value['aria-labelledby'] as
|
||||
string | undefined) ||
|
||||
Array.from(ctx.titles.values()).join(' ') ||
|
||||
ctx.triggerId
|
||||
"
|
||||
>
|
||||
<slot :close="ctx.state.close" :is-open="ctx.state.isOpen.value" />
|
||||
</component>
|
||||
</RekaContent>
|
||||
</PopoverPortal>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { useAttrs, onBeforeUpdate, onUnmounted } from "vue";
|
||||
import { usePopover } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
||||
const ctx = usePopover();
|
||||
const attrs = useAttrs();
|
||||
const keys = ["aria-label", "aria-labelledby", "aria-describedby", "role"];
|
||||
function sync() {
|
||||
const next = Object.fromEntries(
|
||||
keys.filter((key) => key in attrs).map((key) => [key, attrs[key]]),
|
||||
);
|
||||
const previous = ctx.dialogAttrs.value;
|
||||
if (keys.some((key) => next[key] !== previous[key]))
|
||||
ctx.dialogAttrs.value = next;
|
||||
}
|
||||
sync();
|
||||
onBeforeUpdate(sync);
|
||||
onUnmounted(() => {
|
||||
ctx.dialogAttrs.value = {};
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
class="hv-popover__dialog"
|
||||
data-slot="popover-dialog"
|
||||
>
|
||||
<slot :close="ctx.state.close" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, useId, watchEffect, onUnmounted } from "vue";
|
||||
import { usePopover } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
|
||||
as: "h2",
|
||||
});
|
||||
const ctx = usePopover(),
|
||||
key = Symbol(),
|
||||
generated = "hv-popover-heading-" + useId();
|
||||
const id = computed(() => props.id ?? generated);
|
||||
watchEffect(() => ctx.titles.set(key, id.value));
|
||||
onUnmounted(() => ctx.titles.delete(key));
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
:id="id"
|
||||
class="hv-popover__heading"
|
||||
data-slot="popover-heading"
|
||||
>
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import { watch } from "vue";
|
||||
import {
|
||||
PopoverAnchor,
|
||||
injectPopoverRootContext,
|
||||
useForwardExpose,
|
||||
} from "reka-ui";
|
||||
import OverlayAction from "../overlay/OverlayAction";
|
||||
import { usePopover } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
|
||||
{ as: "div" },
|
||||
);
|
||||
const ctx = usePopover(),
|
||||
root = injectPopoverRootContext();
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
watch(
|
||||
currentElement,
|
||||
(el) => {
|
||||
root.triggerElement.value = el;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
root.triggerId = ctx.triggerId;
|
||||
</script>
|
||||
<template>
|
||||
<PopoverAnchor as-child>
|
||||
<OverlayAction
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:id="($attrs.id as string | undefined) ?? ctx.triggerId"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:is-disabled="isDisabled"
|
||||
:activate="ctx.state.toggle"
|
||||
class="hv-popover__trigger"
|
||||
data-slot="popover-trigger"
|
||||
aria-haspopup="dialog"
|
||||
:aria-expanded="ctx.state.isOpen.value"
|
||||
:aria-controls="ctx.state.isOpen.value ? ctx.contentId.value : undefined"
|
||||
>
|
||||
<slot />
|
||||
</OverlayAction>
|
||||
</PopoverAnchor>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
inject,
|
||||
reactive,
|
||||
ref,
|
||||
shallowRef,
|
||||
useId,
|
||||
type InjectionKey,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import type { OverlayState } from "../../composables/useOverlayState";
|
||||
export interface PopoverContext {
|
||||
state: OverlayState;
|
||||
contentId: Ref<string>;
|
||||
triggerId: string;
|
||||
contentNonModal: Ref<boolean | undefined>;
|
||||
titles: Map<symbol, string>;
|
||||
dialogAttrs: Ref<Record<string, unknown>>;
|
||||
}
|
||||
export const popoverKey: InjectionKey<PopoverContext> = Symbol("hv-popover");
|
||||
export function usePopover() {
|
||||
const ctx = inject(popoverKey);
|
||||
if (!ctx) throw new Error("Popover parts require Popover.");
|
||||
return ctx;
|
||||
}
|
||||
export function createPopoverContext(state: OverlayState): PopoverContext {
|
||||
const id = "hv-popover-" + useId();
|
||||
return {
|
||||
state,
|
||||
contentId: ref(id + "-content"),
|
||||
triggerId: id + "-trigger",
|
||||
contentNonModal: ref(undefined),
|
||||
titles: reactive(new Map()),
|
||||
dialogAttrs: shallowRef({}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
nextTick,
|
||||
provide,
|
||||
ref,
|
||||
watch,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import {
|
||||
TooltipProvider,
|
||||
TooltipRoot,
|
||||
injectTooltipProviderContext,
|
||||
} from "reka-ui";
|
||||
import { useOverlayState } from "../../composables/useOverlayState";
|
||||
import { overlayNodes, overlayComponentName } from "../overlay/OverlayAction";
|
||||
import { tooltipKey, cssTime } from "./context";
|
||||
import TooltipTrigger from "./TooltipTrigger.vue";
|
||||
export default defineComponent({
|
||||
name: "Tooltip",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
open: { type: Boolean, default: undefined },
|
||||
isOpen: { type: Boolean, default: undefined },
|
||||
defaultOpen: Boolean,
|
||||
delay: Number,
|
||||
closeDelay: Number,
|
||||
trigger: { type: String as PropType<"hover" | "focus">, default: "hover" },
|
||||
isDisabled: Boolean,
|
||||
shouldSkipAnimation: Boolean,
|
||||
},
|
||||
emits: {
|
||||
"update:open": (value: boolean) => typeof value === "boolean",
|
||||
"update:isOpen": (value: boolean) => typeof value === "boolean",
|
||||
openChange: (value: boolean) => typeof value === "boolean",
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const hasProvider = injectTooltipProviderContext(null);
|
||||
const delayCss = ref(1500),
|
||||
closeCss = ref(500);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
let immediate = false;
|
||||
const cancelClose = () => {
|
||||
clearTimeout(timer);
|
||||
timer = undefined;
|
||||
};
|
||||
const state = useOverlayState({
|
||||
isOpen: () => props.open ?? props.isOpen,
|
||||
defaultOpen: props.defaultOpen,
|
||||
onOpenChange(v) {
|
||||
emit("update:open", v);
|
||||
emit("update:isOpen", v);
|
||||
emit("openChange", v);
|
||||
},
|
||||
});
|
||||
const open = computed(() => !props.isDisabled && state.isOpen.value);
|
||||
const justOpening = ref(false);
|
||||
watch(open, (value) => {
|
||||
cancelClose();
|
||||
justOpening.value = value;
|
||||
if (value)
|
||||
void nextTick(() => {
|
||||
justOpening.value = false;
|
||||
});
|
||||
});
|
||||
// Reka 2.11 coordinates roots through this event. It must close the old
|
||||
// tooltip immediately, while an interrupted exit must not close itself.
|
||||
const onAnotherTooltip = () => {
|
||||
if (open.value && !justOpening.value) immediate = true;
|
||||
};
|
||||
onMounted(() =>
|
||||
document.addEventListener("tooltip.open", onAnotherTooltip, true),
|
||||
);
|
||||
onBeforeUnmount(() =>
|
||||
document.removeEventListener("tooltip.open", onAnotherTooltip, true),
|
||||
);
|
||||
function request(v: boolean) {
|
||||
cancelClose();
|
||||
if (v === open.value) {
|
||||
immediate = false;
|
||||
return;
|
||||
}
|
||||
if (v) {
|
||||
immediate = false;
|
||||
if (!props.isDisabled) state.open();
|
||||
} else if (immediate) {
|
||||
immediate = false;
|
||||
state.close();
|
||||
} else {
|
||||
const delay = props.closeDelay ?? closeCss.value;
|
||||
if (delay <= 0) state.close();
|
||||
else
|
||||
timer = setTimeout(() => {
|
||||
timer = undefined;
|
||||
state.close();
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
provide(tooltipKey, {
|
||||
open,
|
||||
justOpening,
|
||||
trigger: computed(() => props.trigger),
|
||||
skipAnimation: computed(() => props.shouldSkipAnimation),
|
||||
cancelClose,
|
||||
immediateClose: () => {
|
||||
immediate = true;
|
||||
},
|
||||
readTiming(el) {
|
||||
const css = getComputedStyle(el);
|
||||
delayCss.value = cssTime(css.getPropertyValue("--tooltip-delay"), 1500);
|
||||
closeCss.value = cssTime(
|
||||
css.getPropertyValue("--tooltip-close-delay"),
|
||||
500,
|
||||
);
|
||||
},
|
||||
});
|
||||
watch(
|
||||
() => props.isDisabled,
|
||||
(disabled) => {
|
||||
if (disabled) {
|
||||
cancelClose();
|
||||
state.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
onBeforeUnmount(cancelClose);
|
||||
const root = () =>
|
||||
h(
|
||||
TooltipRoot,
|
||||
{
|
||||
open: open.value,
|
||||
disabled: props.isDisabled,
|
||||
delayDuration: props.delay ?? delayCss.value,
|
||||
"onUpdate:open": request,
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
let found = false;
|
||||
return overlayNodes(slots.default?.({ isOpen: open.value })).map(
|
||||
(node) => {
|
||||
const name = overlayComponentName(node);
|
||||
if (name === "TooltipTrigger") found = true;
|
||||
if (
|
||||
!found &&
|
||||
(name === "Button" ||
|
||||
node.type === "button" ||
|
||||
node.type === "a")
|
||||
) {
|
||||
found = true;
|
||||
return h(
|
||||
TooltipTrigger,
|
||||
{ asChild: true, key: node.key ?? undefined },
|
||||
{ default: () => node },
|
||||
);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
return () =>
|
||||
hasProvider ? root() : h(TooltipProvider, {}, { default: root });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { TooltipArrow as RekaArrow } from "reka-ui";
|
||||
import OverlayArrowShape from "../overlay/OverlayArrowShape";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
</script>
|
||||
<template>
|
||||
<RekaArrow v-bind="$attrs" as-child :width="12" :height="12">
|
||||
<OverlayArrowShape marker="overlay-arrow"><slot /></OverlayArrowShape>
|
||||
</RekaArrow>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import {
|
||||
TooltipPortal,
|
||||
TooltipContent as RekaContent,
|
||||
injectTooltipRootContext,
|
||||
useForwardExpose,
|
||||
type TooltipContentEmits,
|
||||
} from "reka-ui";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { resolvePlacement, type OverlayPlacement } from "../overlay/placement";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
import { useTooltip } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
as?: string;
|
||||
placement?: OverlayPlacement;
|
||||
offset?: number;
|
||||
crossOffset?: number;
|
||||
showArrow?: boolean;
|
||||
shouldFlip?: boolean;
|
||||
containerPadding?: number;
|
||||
to?: string | HTMLElement;
|
||||
}>(),
|
||||
{
|
||||
as: "div",
|
||||
placement: "top",
|
||||
crossOffset: 0,
|
||||
showArrow: false,
|
||||
shouldFlip: true,
|
||||
containerPadding: 12,
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<TooltipContentEmits>();
|
||||
const ctx = useTooltip(),
|
||||
root = injectTooltipRootContext(),
|
||||
config = useConfig();
|
||||
const position = computed(() =>
|
||||
resolvePlacement(props.placement, config?.dir.value),
|
||||
);
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
|
||||
ctx.open,
|
||||
currentElement,
|
||||
true,
|
||||
);
|
||||
const skip = computed(
|
||||
() => ctx.skipAnimation.value && root.stateAttribute.value === "instant-open",
|
||||
);
|
||||
function escape(e: KeyboardEvent) {
|
||||
emit("escapeKeyDown", e);
|
||||
if (!e.defaultPrevented) ctx.immediateClose();
|
||||
}
|
||||
function outside(e: Event) {
|
||||
emit("pointerDownOutside", e);
|
||||
if (!e.defaultPrevented) ctx.immediateClose();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<TooltipPortal :to="to">
|
||||
<RekaContent
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:side="position.side"
|
||||
:align="position.align"
|
||||
:side-offset="offset ?? (showArrow ? 7 : 3)"
|
||||
:align-offset="crossOffset"
|
||||
:side-flip="shouldFlip"
|
||||
:collision-padding="containerPadding"
|
||||
:lang="($attrs.lang as string | undefined) ?? config?.locale.value"
|
||||
class="hv-tooltip"
|
||||
data-slot="tooltip-content"
|
||||
:data-entering="(entering && !skip) || undefined"
|
||||
:data-exiting="(exiting && !skip) || undefined"
|
||||
@animationend="onAnimationEnd"
|
||||
@escape-key-down="escape"
|
||||
@pointer-down-outside="outside"
|
||||
@pointerenter="ctx.cancelClose"
|
||||
>
|
||||
<slot :is-open="ctx.open.value" />
|
||||
</RekaContent>
|
||||
</TooltipPortal>
|
||||
</template>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onMounted, onBeforeUnmount } from "vue";
|
||||
import {
|
||||
TooltipTrigger as RekaTrigger,
|
||||
injectTooltipRootContext,
|
||||
useForwardExpose,
|
||||
} from "reka-ui";
|
||||
import { useTooltip } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string; asChild?: boolean }>(), { as: "div" });
|
||||
const ctx = useTooltip(),
|
||||
root = injectTooltipRootContext();
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
let hoverGeneration = 0;
|
||||
const originalClose = root.onClose;
|
||||
root.onClose = () => {
|
||||
if (!ctx.justOpening.value) originalClose();
|
||||
};
|
||||
const originalEnter = root.onTriggerEnter,
|
||||
originalLeave = root.onTriggerLeave;
|
||||
root.onTriggerEnter = () => {
|
||||
if (ctx.trigger.value === "focus") return;
|
||||
const gen = ++hoverGeneration;
|
||||
ctx.cancelClose();
|
||||
if (currentElement.value) ctx.readTiming(currentElement.value);
|
||||
void nextTick(() => {
|
||||
if (gen === hoverGeneration) originalEnter();
|
||||
});
|
||||
};
|
||||
root.onTriggerLeave = () => {
|
||||
hoverGeneration++;
|
||||
originalLeave();
|
||||
};
|
||||
onMounted(() => {
|
||||
if (currentElement.value) ctx.readTiming(currentElement.value);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
hoverGeneration++;
|
||||
root.onClose = originalClose;
|
||||
root.onTriggerEnter = originalEnter;
|
||||
root.onTriggerLeave = originalLeave;
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<RekaTrigger
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:type="as === 'button' ? 'button' : undefined"
|
||||
:role="as === 'div' && !asChild ? 'button' : undefined"
|
||||
:tabindex="as === 'div' && !asChild ? 0 : undefined"
|
||||
class="hv-tooltip__trigger"
|
||||
data-slot="tooltip-trigger"
|
||||
@blur.capture="ctx.immediateClose"
|
||||
@pointerdown.capture="ctx.immediateClose"
|
||||
>
|
||||
<slot />
|
||||
</RekaTrigger>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { inject, type InjectionKey, type ComputedRef, type Ref } from "vue";
|
||||
export interface TooltipContext {
|
||||
open: ComputedRef<boolean>;
|
||||
justOpening: Ref<boolean>;
|
||||
trigger: ComputedRef<"hover" | "focus">;
|
||||
skipAnimation: ComputedRef<boolean>;
|
||||
readTiming: (element: HTMLElement) => void;
|
||||
cancelClose: () => void;
|
||||
immediateClose: () => void;
|
||||
}
|
||||
export const tooltipKey: InjectionKey<TooltipContext> = Symbol("hv-tooltip");
|
||||
export function useTooltip() {
|
||||
const ctx = inject(tooltipKey);
|
||||
if (!ctx) throw new Error("Tooltip parts require Tooltip.");
|
||||
return ctx;
|
||||
}
|
||||
export function cssTime(value: string, fallback: number) {
|
||||
const match = value.trim().match(/^(\d+(?:\.\d+)?)(ms|s)$/);
|
||||
return match ? Number(match[1]) * (match[2] === "s" ? 1000 : 1) : fallback;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* Adapted from HeroUI ce90ea3 use-overlay-state. Copyright 2025 NextUI Inc.
|
||||
* Licensed under Apache-2.0; see third-party/HEROUI-LICENSE. Vue reactive adaptation. */
|
||||
import {
|
||||
computed,
|
||||
ref,
|
||||
toValue,
|
||||
type ComputedRef,
|
||||
type MaybeRefOrGetter,
|
||||
} from "vue";
|
||||
|
||||
export interface UseOverlayStateOptions {
|
||||
/** Controlled value; pass a ref/getter to keep it reactive. Undefined selects local state. */
|
||||
isOpen?: MaybeRefOrGetter<boolean | undefined>;
|
||||
defaultOpen?: boolean;
|
||||
onOpenChange?: (isOpen: boolean) => void;
|
||||
}
|
||||
|
||||
export interface OverlayState {
|
||||
readonly isOpen: ComputedRef<boolean>;
|
||||
setOpen: (isOpen: boolean) => void;
|
||||
open: () => void;
|
||||
close: () => void;
|
||||
toggle: () => void;
|
||||
}
|
||||
|
||||
/** Vue adaptation of HeroUI ce90ea3 useOverlayState; no DOM or global singleton. */
|
||||
export function useOverlayState(
|
||||
options: UseOverlayStateOptions = {},
|
||||
): OverlayState {
|
||||
const local = ref(options.defaultOpen ?? false);
|
||||
const isOpen = computed(() => toValue(options.isOpen) ?? local.value);
|
||||
|
||||
function setOpen(value: boolean) {
|
||||
if (toValue(options.isOpen) === undefined) local.value = value;
|
||||
options.onOpenChange?.(value);
|
||||
}
|
||||
|
||||
return {
|
||||
isOpen,
|
||||
setOpen,
|
||||
open: () => setOpen(true),
|
||||
close: () => setOpen(false),
|
||||
toggle: () => setOpen(!isOpen.value),
|
||||
};
|
||||
}
|
||||
@@ -383,3 +383,86 @@ export {
|
||||
type DisclosureGroupVariants,
|
||||
type AccordionVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
|
||||
export {
|
||||
useOverlayState,
|
||||
type OverlayState,
|
||||
type UseOverlayStateOptions,
|
||||
} from "./composables/useOverlayState";
|
||||
export { default as ConfigProvider } from "./providers/ConfigProvider.vue";
|
||||
export type { ConfigProviderProps } from "./types";
|
||||
|
||||
export { default as Modal } from "./components/modal/Modal";
|
||||
export type { ModalProps } from "./types";
|
||||
|
||||
export { default as ModalTrigger } from "./components/modal/ModalTrigger.vue";
|
||||
export type { ModalTriggerProps } from "./types";
|
||||
|
||||
export { default as ModalBackdrop } from "./components/modal/ModalBackdrop.vue";
|
||||
export type { ModalBackdropProps } from "./types";
|
||||
|
||||
export { default as ModalContainer } from "./components/modal/ModalContainer.vue";
|
||||
export type { ModalContainerProps } from "./types";
|
||||
|
||||
export { default as ModalDialog } from "./components/modal/ModalDialog.vue";
|
||||
export type { ModalDialogProps } from "./types";
|
||||
|
||||
export { default as ModalHeading } from "./components/modal/ModalHeading.vue";
|
||||
export type { ModalHeadingProps } from "./types";
|
||||
|
||||
export { default as ModalClose } from "./components/modal/ModalClose.vue";
|
||||
export type { ModalCloseProps } from "./types";
|
||||
|
||||
export { default as ModalCloseTrigger } from "./components/modal/ModalCloseTrigger";
|
||||
export type { ModalCloseTriggerProps } from "./types";
|
||||
|
||||
export { default as ModalHeader } from "./components/modal/ModalHeader.vue";
|
||||
export type { ModalHeaderProps } from "./types";
|
||||
|
||||
export { default as ModalFooter } from "./components/modal/ModalFooter.vue";
|
||||
export type { ModalFooterProps } from "./types";
|
||||
|
||||
export { default as ModalIcon } from "./components/modal/ModalIcon.vue";
|
||||
export type { ModalIconProps } from "./types";
|
||||
|
||||
export { default as ModalBody } from "./components/modal/ModalBody.vue";
|
||||
export type { ModalBodyProps } from "./types";
|
||||
|
||||
export { modalVariants, type ModalVariants } from "@heroui-vue/styles";
|
||||
export type { ModalPlacement } from "./components/modal/context";
|
||||
|
||||
export { default as Popover } from "./components/popover/Popover";
|
||||
export type { PopoverProps } from "./types";
|
||||
|
||||
export { default as PopoverTrigger } from "./components/popover/PopoverTrigger.vue";
|
||||
export type { PopoverTriggerProps } from "./types";
|
||||
|
||||
export { default as PopoverContent } from "./components/popover/PopoverContent.vue";
|
||||
export type { PopoverContentProps } from "./types";
|
||||
|
||||
export { default as PopoverDialog } from "./components/popover/PopoverDialog.vue";
|
||||
export type { PopoverDialogProps } from "./types";
|
||||
|
||||
export { default as PopoverHeading } from "./components/popover/PopoverHeading.vue";
|
||||
export type { PopoverHeadingProps } from "./types";
|
||||
|
||||
export { default as PopoverArrow } from "./components/popover/PopoverArrow.vue";
|
||||
export type { PopoverArrowProps } from "./types";
|
||||
|
||||
export { popoverVariants, type PopoverVariants } from "@heroui-vue/styles";
|
||||
|
||||
export { default as Tooltip } from "./components/tooltip/Tooltip";
|
||||
export type { TooltipProps } from "./types";
|
||||
|
||||
export { default as TooltipTrigger } from "./components/tooltip/TooltipTrigger.vue";
|
||||
export type { TooltipTriggerProps } from "./types";
|
||||
|
||||
export { default as TooltipContent } from "./components/tooltip/TooltipContent.vue";
|
||||
export type { TooltipContentProps } from "./types";
|
||||
|
||||
export { default as TooltipArrow } from "./components/tooltip/TooltipArrow.vue";
|
||||
export type { TooltipArrowProps } from "./types";
|
||||
|
||||
export { tooltipVariants, type TooltipVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type { OverlayPlacement } from "./components/overlay/placement";
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { ConfigProvider as RekaConfigProvider, TooltipProvider } from "reka-ui";
|
||||
import { computed, provide } from "vue";
|
||||
import { configContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
dir?: "ltr" | "rtl";
|
||||
locale?: string;
|
||||
teleportTo?: string | HTMLElement;
|
||||
}>(),
|
||||
{ dir: "ltr", locale: "en-US" },
|
||||
);
|
||||
provide(configContextKey, {
|
||||
dir: computed(() => props.dir),
|
||||
locale: computed(() => props.locale),
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RekaConfigProvider :dir="dir" :locale="locale" :teleport-to="teleportTo">
|
||||
<TooltipProvider><slot /></TooltipProvider>
|
||||
</RekaConfigProvider>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { inject, type ComputedRef, type InjectionKey } from "vue";
|
||||
|
||||
export interface ConfigContext {
|
||||
dir: ComputedRef<"ltr" | "rtl">;
|
||||
locale: ComputedRef<string>;
|
||||
}
|
||||
export const configContextKey: InjectionKey<ConfigContext> =
|
||||
Symbol("hv-config");
|
||||
export function useConfig() {
|
||||
return inject(configContextKey, undefined);
|
||||
}
|
||||
@@ -277,3 +277,74 @@ export type AccordionBodyProps = InstanceType<typeof AccordionBody>["$props"];
|
||||
export type AccordionIndicatorProps = InstanceType<
|
||||
typeof AccordionIndicator
|
||||
>["$props"];
|
||||
|
||||
import type ConfigProvider from "./providers/ConfigProvider.vue";
|
||||
export type ConfigProviderProps = InstanceType<typeof ConfigProvider>["$props"];
|
||||
|
||||
import type Modal from "./components/modal/Modal";
|
||||
export type ModalProps = InstanceType<typeof Modal>["$props"];
|
||||
|
||||
import type ModalTrigger from "./components/modal/ModalTrigger.vue";
|
||||
export type ModalTriggerProps = InstanceType<typeof ModalTrigger>["$props"];
|
||||
|
||||
import type ModalBackdrop from "./components/modal/ModalBackdrop.vue";
|
||||
export type ModalBackdropProps = InstanceType<typeof ModalBackdrop>["$props"];
|
||||
|
||||
import type ModalContainer from "./components/modal/ModalContainer.vue";
|
||||
export type ModalContainerProps = InstanceType<typeof ModalContainer>["$props"];
|
||||
|
||||
import type ModalDialog from "./components/modal/ModalDialog.vue";
|
||||
export type ModalDialogProps = InstanceType<typeof ModalDialog>["$props"];
|
||||
|
||||
import type ModalHeading from "./components/modal/ModalHeading.vue";
|
||||
export type ModalHeadingProps = InstanceType<typeof ModalHeading>["$props"];
|
||||
|
||||
import type ModalClose from "./components/modal/ModalClose.vue";
|
||||
export type ModalCloseProps = InstanceType<typeof ModalClose>["$props"];
|
||||
|
||||
import type ModalCloseTrigger from "./components/modal/ModalCloseTrigger";
|
||||
export type ModalCloseTriggerProps = InstanceType<
|
||||
typeof ModalCloseTrigger
|
||||
>["$props"];
|
||||
|
||||
import type ModalHeader from "./components/modal/ModalHeader.vue";
|
||||
export type ModalHeaderProps = InstanceType<typeof ModalHeader>["$props"];
|
||||
|
||||
import type ModalFooter from "./components/modal/ModalFooter.vue";
|
||||
export type ModalFooterProps = InstanceType<typeof ModalFooter>["$props"];
|
||||
|
||||
import type ModalIcon from "./components/modal/ModalIcon.vue";
|
||||
export type ModalIconProps = InstanceType<typeof ModalIcon>["$props"];
|
||||
|
||||
import type ModalBody from "./components/modal/ModalBody.vue";
|
||||
export type ModalBodyProps = InstanceType<typeof ModalBody>["$props"];
|
||||
|
||||
import type Popover from "./components/popover/Popover";
|
||||
export type PopoverProps = InstanceType<typeof Popover>["$props"];
|
||||
|
||||
import type PopoverTrigger from "./components/popover/PopoverTrigger.vue";
|
||||
export type PopoverTriggerProps = InstanceType<typeof PopoverTrigger>["$props"];
|
||||
|
||||
import type PopoverContent from "./components/popover/PopoverContent.vue";
|
||||
export type PopoverContentProps = InstanceType<typeof PopoverContent>["$props"];
|
||||
|
||||
import type PopoverDialog from "./components/popover/PopoverDialog.vue";
|
||||
export type PopoverDialogProps = InstanceType<typeof PopoverDialog>["$props"];
|
||||
|
||||
import type PopoverHeading from "./components/popover/PopoverHeading.vue";
|
||||
export type PopoverHeadingProps = InstanceType<typeof PopoverHeading>["$props"];
|
||||
|
||||
import type PopoverArrow from "./components/popover/PopoverArrow.vue";
|
||||
export type PopoverArrowProps = InstanceType<typeof PopoverArrow>["$props"];
|
||||
|
||||
import type Tooltip from "./components/tooltip/Tooltip";
|
||||
export type TooltipProps = InstanceType<typeof Tooltip>["$props"];
|
||||
|
||||
import type TooltipTrigger from "./components/tooltip/TooltipTrigger.vue";
|
||||
export type TooltipTriggerProps = InstanceType<typeof TooltipTrigger>["$props"];
|
||||
|
||||
import type TooltipContent from "./components/tooltip/TooltipContent.vue";
|
||||
export type TooltipContentProps = InstanceType<typeof TooltipContent>["$props"];
|
||||
|
||||
import type TooltipArrow from "./components/tooltip/TooltipArrow.vue";
|
||||
export type TooltipArrowProps = InstanceType<typeof TooltipArrow>["$props"];
|
||||
|
||||
Reference in New Issue
Block a user