feat: migrate Modal Popover and Tooltip with shared overlay foundation

This commit is contained in:
maoyingjie
2026-10-22 23:39:51 +08:00
parent b086d7f30d
commit 2b4ac04df1
108 changed files with 6888 additions and 100 deletions
+21
View File
@@ -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.
+2
View File
@@ -0,0 +1,2 @@
/* Same animation utilities as the fixed HeroUI baseline (tw-animate-css, MIT). */
@import "tw-animate-css";
+374
View File
@@ -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;
}
+102
View File
@@ -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;
}
+84
View File
@@ -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;
}
+7
View File
@@ -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);
+4 -2
View File
@@ -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",
+87
View File
@@ -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;
}