merge: integrate reviewed AlertDialog Drawer with ListBox main

This commit is contained in:
maoyingjie
2026-10-23 18:36:19 +08:00
83 changed files with 5885 additions and 3 deletions
+219
View File
@@ -0,0 +1,219 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue/Reka adapters. */
/* -------------------------------------------------------------------------------------------------
* AlertDialog Component Styles
* Block: alert-dialog
* -----------------------------------------------------------------------------------------------*/
.hv-alert-dialog__trigger {
@apply inline-block cursor-(--cursor-interactive);
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-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
&:disabled,
&[aria-disabled="true"] {
@apply status-disabled;
}
&:active,
&[data-pressed="true"] {
transform: scale(0.97);
}
}
.hv-alert-dialog__backdrop {
@apply fixed inset-0 z-(--z-index-overlay);
@apply flex flex-row items-center justify-center;
@apply h-(--visual-viewport-height) w-full;
&[data-entering="true"] {
@apply animate-in duration-150 ease-out fade-in-0;
}
&[data-exiting="true"] {
@apply animate-out duration-100 ease-out fade-out-0;
}
&[data-exiting="true"],
&[data-entering="true"] {
@apply will-change-[opacity];
@apply motion-reduce:animate-none;
}
}
.hv-alert-dialog__backdrop--transparent {
@apply bg-transparent;
}
.hv-alert-dialog__backdrop--opaque {
@apply bg-backdrop;
}
.hv-alert-dialog__backdrop--blur {
@apply bg-backdrop backdrop-blur-md;
}
.hv-alert-dialog__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;
&[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;
}
}
&[data-exiting="true"] {
@apply animate-out duration-100 ease-out-quad fade-out-0 zoom-out-95;
}
&[data-exiting="true"],
&[data-entering="true"] {
@apply will-change-[opacity,transform];
@apply motion-reduce:animate-none;
}
}
.hv-alert-dialog__dialog {
@apply relative;
@apply flex min-h-0 w-full flex-col;
@apply max-h-full;
@apply bg-overlay shadow-overlay outline-none;
border-radius: min(32px, var(--radius-3xl));
@apply p-6;
@apply overflow-clip;
@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;
}
}
.hv-alert-dialog__dialog--xs {
@apply max-w-xs;
}
.hv-alert-dialog__dialog--sm {
@apply max-w-sm;
}
.hv-alert-dialog__dialog--md {
@apply max-w-md;
}
.hv-alert-dialog__dialog--lg {
@apply max-w-lg;
}
.hv-alert-dialog__dialog--cover {
@apply h-full min-h-full w-full;
}
.hv-alert-dialog__header {
@apply flex flex-col gap-3;
@apply mb-0;
}
.hv-alert-dialog__heading {
@apply align-middle;
@apply text-base font-medium text-foreground;
}
.hv-alert-dialog__icon {
@apply flex items-center justify-center;
@apply size-10 shrink-0;
@apply rounded-3xl select-none;
[data-slot="alert-dialog-default-icon"] {
@apply box-content size-5;
}
}
.hv-alert-dialog__icon--default {
@apply bg-default text-foreground;
}
.hv-alert-dialog__icon--accent {
@apply bg-accent-soft text-accent-soft-foreground;
}
.hv-alert-dialog__icon--success {
@apply bg-success-soft text-success-soft-foreground;
}
.hv-alert-dialog__icon--warning {
@apply bg-warning-soft text-warning-soft-foreground;
}
.hv-alert-dialog__icon--danger {
@apply bg-danger-soft text-danger-soft-foreground;
}
.hv-alert-dialog__body {
@apply min-h-0 flex-1 scrollbar;
@apply text-sm leading-[1.43] text-muted;
@apply -m-[3px] my-0 p-[3px];
@apply overflow-y-auto overscroll-contain;
-webkit-overflow-scrolling: touch;
}
.hv-alert-dialog__footer {
@apply flex flex-row items-center justify-end gap-2;
@apply mt-0;
}
.hv-alert-dialog__close-trigger {
@apply absolute end-4 top-4;
}
.hv-alert-dialog__header + .hv-alert-dialog__body {
@apply mt-2;
}
.hv-alert-dialog__header + .hv-alert-dialog__footer {
@apply mt-5;
}
.hv-alert-dialog__body + .hv-alert-dialog__footer {
@apply mt-5;
}
+414
View File
@@ -0,0 +1,414 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue/Reka adapters. */
/**
* Element: trigger - the element that opens the drawer
*/
.hv-drawer__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 drawer
* Enter/exit use CSS animations (not transitions) so Reka Presence
* keeps the node until animationend instead of unmounting immediately.
*/
.hv-drawer__backdrop {
@apply fixed inset-0 z-(--z-index-overlay);
@apply h-(--visual-viewport-height) w-full;
opacity: 1;
&[data-entering="true"] {
animation: hv-drawer-backdrop-in 250ms cubic-bezier(0.32, 0.72, 0, 1);
}
&[data-exiting="true"] {
animation: hv-drawer-backdrop-out 200ms cubic-bezier(0.32, 0.72, 0, 1);
}
&[data-exiting="true"],
&[data-entering="true"] {
will-change: opacity;
}
@media (prefers-reduced-motion: reduce) {
animation: none;
}
}
/**
* Modifier: backdrop--transparent
*/
.hv-drawer__backdrop--transparent {
@apply bg-transparent;
}
/**
* Modifier: backdrop--opaque
*/
.hv-drawer__backdrop--opaque {
@apply bg-backdrop;
}
/**
* Modifier: backdrop--blur
*/
.hv-drawer__backdrop--blur {
@apply bg-backdrop backdrop-blur-md;
}
/**
* Element: content - the positioning wrapper for the drawer panel
*/
.hv-drawer__content {
@apply pointer-events-none;
@apply fixed inset-0 z-(--z-index-overlay) flex;
@apply h-(--visual-viewport-height) w-full min-w-0;
}
/**
* Modifier: content--bottom (default)
* Slides up from the bottom edge
*/
.hv-drawer__content--bottom {
@apply items-end;
}
/**
* Modifier: content--top
* Slides down from the top edge
*/
.hv-drawer__content--top {
@apply items-start;
}
/**
* Modifier: content--left
* Slides in from the left edge
*/
.hv-drawer__content--left {
@apply justify-start;
}
/**
* Modifier: content--right
* Slides in from the right edge
*/
.hv-drawer__content--right {
@apply justify-end;
}
/**
* Element: dialog - the drawer panel itself
* Enter/exit animate the `translate` property so drag can compose via `transform`.
*/
.hv-drawer__dialog {
@apply relative;
@apply flex flex-col;
@apply bg-overlay shadow-overlay outline-none;
@apply p-6;
@apply pointer-events-auto;
--drawer-enter-duration: 250ms;
--drawer-exit-duration: 200ms;
--drawer-enter-ease: cubic-bezier(0.32, 0.72, 0, 1);
--drawer-exit-ease: cubic-bezier(0.32, 0.72, 0, 1);
will-change: translate;
@media (prefers-reduced-motion: reduce) {
animation: none;
}
/* Bottom/top placement: full width, auto height */
&[data-placement="bottom"] {
@apply w-full;
@apply max-h-[85vh];
border-start-start-radius: min(32px, var(--radius-2xl));
border-start-end-radius: min(32px, var(--radius-2xl));
}
&[data-placement="top"] {
@apply w-full;
@apply max-h-[85vh];
border-end-start-radius: min(32px, var(--radius-2xl));
border-end-end-radius: min(32px, var(--radius-2xl));
}
/* Left/right placement: auto width, full height */
&[data-placement="left"] {
@apply h-full rounded-none;
@apply w-80 max-w-[85vw] sm:w-96;
}
&[data-placement="right"] {
@apply h-full rounded-none;
@apply w-80 max-w-[85vw] sm:w-96;
}
}
/* Enter/exit animations live on the dialog node (the real animation owner). */
.hv-drawer__dialog[data-entering="true"][data-placement="left"] {
animation: hv-drawer-in-from-left var(--drawer-enter-duration)
var(--drawer-enter-ease);
}
.hv-drawer__dialog[data-entering="true"][data-placement="right"] {
animation: hv-drawer-in-from-right var(--drawer-enter-duration)
var(--drawer-enter-ease);
}
.hv-drawer__dialog[data-entering="true"][data-placement="top"] {
animation: hv-drawer-in-from-top var(--drawer-enter-duration)
var(--drawer-enter-ease);
}
.hv-drawer__dialog[data-entering="true"][data-placement="bottom"] {
animation: hv-drawer-in-from-bottom var(--drawer-enter-duration)
var(--drawer-enter-ease);
}
.hv-drawer__dialog[data-exiting="true"][data-placement="left"] {
animation: hv-drawer-out-to-left var(--drawer-exit-duration)
var(--drawer-exit-ease);
}
.hv-drawer__dialog[data-exiting="true"][data-placement="right"] {
animation: hv-drawer-out-to-right var(--drawer-exit-duration)
var(--drawer-exit-ease);
}
.hv-drawer__dialog[data-exiting="true"][data-placement="top"] {
animation: hv-drawer-out-to-top var(--drawer-exit-duration)
var(--drawer-exit-ease);
}
.hv-drawer__dialog[data-exiting="true"][data-placement="bottom"] {
animation: hv-drawer-out-to-bottom var(--drawer-exit-duration)
var(--drawer-exit-ease);
}
/* Reduced motion must beat the direction-specific animation rules above. */
@media (prefers-reduced-motion: reduce) {
.hv-drawer__dialog[data-entering="true"],
.hv-drawer__dialog[data-exiting="true"],
.hv-drawer__dialog[data-entering="true"][data-placement="left"],
.hv-drawer__dialog[data-entering="true"][data-placement="right"],
.hv-drawer__dialog[data-entering="true"][data-placement="top"],
.hv-drawer__dialog[data-entering="true"][data-placement="bottom"],
.hv-drawer__dialog[data-exiting="true"][data-placement="left"],
.hv-drawer__dialog[data-exiting="true"][data-placement="right"],
.hv-drawer__dialog[data-exiting="true"][data-placement="top"],
.hv-drawer__dialog[data-exiting="true"][data-placement="bottom"] {
animation: none;
}
.hv-drawer__backdrop[data-entering="true"],
.hv-drawer__backdrop[data-exiting="true"] {
animation: none;
}
}
@keyframes hv-drawer-backdrop-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes hv-drawer-backdrop-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
@keyframes hv-drawer-in-from-left {
from {
translate: -100% 0;
}
to {
translate: 0 0;
}
}
@keyframes hv-drawer-in-from-right {
from {
translate: 100% 0;
}
to {
translate: 0 0;
}
}
@keyframes hv-drawer-in-from-top {
from {
translate: 0 -100%;
}
to {
translate: 0 0;
}
}
@keyframes hv-drawer-in-from-bottom {
from {
translate: 0 100%;
}
to {
translate: 0 0;
}
}
@keyframes hv-drawer-out-to-left {
from {
translate: 0 0;
}
to {
translate: -100% 0;
}
}
@keyframes hv-drawer-out-to-right {
from {
translate: 0 0;
}
to {
translate: 100% 0;
}
}
@keyframes hv-drawer-out-to-top {
from {
translate: 0 0;
}
to {
translate: 0 -100%;
}
}
@keyframes hv-drawer-out-to-bottom {
from {
translate: 0 0;
}
to {
translate: 0 100%;
}
}
.hv-drawer__dialog--top {
@apply pb-2;
.hv-drawer__handle {
@apply pb-0;
}
}
/**
* Element: header - the top section with the title
*/
.hv-drawer__header {
@apply flex flex-col gap-3;
@apply mb-0;
}
/**
* Element: heading - the main title text
*/
.hv-drawer__heading {
@apply align-middle;
@apply text-base font-medium text-foreground;
}
/**
* Element: body - the main content area
* touch-action: pan-y allows vertical scrolling while the dialog captures drag gestures
*/
.hv-drawer__body {
@apply min-h-0 flex-1 scrollbar;
@apply text-sm leading-[1.43] text-muted;
@apply -m-[3px] my-0 p-[3px];
@apply overflow-y-auto overscroll-contain;
-webkit-overflow-scrolling: touch;
}
/**
* Element: footer - the bottom action section
*/
.hv-drawer__footer {
@apply flex flex-row items-center justify-end gap-2;
@apply mt-0;
}
/**
* Element: handle - visual drag handle indicator
*/
.hv-drawer__handle {
@apply flex items-center justify-center;
@apply pb-2;
/* The handle bar */
& > [data-slot="drawer-handle-bar"] {
@apply h-1 w-9 rounded-xs;
@apply bg-separator;
}
}
/**
* Element: close-trigger - the close button
*/
.hv-drawer__close-trigger {
@apply absolute end-4 top-4;
}
/**
* Elements Spacing
*/
.hv-drawer__header + .hv-drawer__body {
@apply mt-2;
}
.hv-drawer__header + .hv-drawer__footer {
@apply mt-5;
}
.hv-drawer__body + .hv-drawer__footer {
@apply mt-5;
}
.hv-drawer__handle + .hv-drawer__header {
@apply mt-0;
}
.hv-drawer__handle + .hv-drawer__body {
@apply mt-0;
}
+2
View File
@@ -123,6 +123,8 @@
@import "./components/accordion.css" layer(components);
@import "./components/modal.css" layer(components);
@import "./components/alert-dialog.css" layer(components);
@import "./components/drawer.css" layer(components);
@import "./components/popover.css" layer(components);
+121
View File
@@ -1298,3 +1298,124 @@ export const listboxSectionVariants = tv({ base: "hv-list-box-section" });
export type ListBoxSectionVariants = VariantProps<
typeof listboxSectionVariants
>;
export const alertDialogVariants = tv({
defaultVariants: {
size: "md",
status: "danger",
variant: "opaque",
},
slots: {
backdrop: "hv-alert-dialog__backdrop",
body: "hv-alert-dialog__body",
closeTrigger: "hv-alert-dialog__close-trigger",
container: "hv-alert-dialog__container",
dialog: "hv-alert-dialog__dialog",
footer: "hv-alert-dialog__footer",
header: "hv-alert-dialog__header",
heading: "hv-alert-dialog__heading",
icon: "hv-alert-dialog__icon",
trigger: "hv-alert-dialog__trigger",
},
variants: {
size: {
cover: {
dialog: "hv-alert-dialog__dialog--cover",
},
lg: {
dialog: "hv-alert-dialog__dialog--lg",
},
md: {
dialog: "hv-alert-dialog__dialog--md",
},
sm: {
dialog: "hv-alert-dialog__dialog--sm",
},
xs: {
dialog: "hv-alert-dialog__dialog--xs",
},
},
status: {
accent: {
icon: "hv-alert-dialog__icon--accent",
},
danger: {
icon: "hv-alert-dialog__icon--danger",
},
default: {
icon: "hv-alert-dialog__icon--default",
},
success: {
icon: "hv-alert-dialog__icon--success",
},
warning: {
icon: "hv-alert-dialog__icon--warning",
},
},
variant: {
blur: {
backdrop: "hv-alert-dialog__backdrop--blur",
},
opaque: {
backdrop: "hv-alert-dialog__backdrop--opaque",
},
transparent: {
backdrop: "hv-alert-dialog__backdrop--transparent",
},
},
},
});
export type AlertDialogVariants = VariantProps<typeof alertDialogVariants>;
export const drawerVariants = tv({
defaultVariants: {
placement: "bottom",
variant: "opaque",
},
slots: {
backdrop: "hv-drawer__backdrop",
body: "hv-drawer__body",
closeTrigger: "hv-drawer__close-trigger",
content: "hv-drawer__content",
dialog: "hv-drawer__dialog",
footer: "hv-drawer__footer",
handle: "hv-drawer__handle",
header: "hv-drawer__header",
heading: "hv-drawer__heading",
trigger: "hv-drawer__trigger",
},
variants: {
placement: {
bottom: {
content: "hv-drawer__content--bottom",
dialog: "hv-drawer__dialog--bottom",
},
left: {
content: "hv-drawer__content--left",
dialog: "hv-drawer__dialog--left",
},
right: {
content: "hv-drawer__content--right",
dialog: "hv-drawer__dialog--right",
},
top: {
content: "hv-drawer__content--top",
dialog: "hv-drawer__dialog--top",
},
},
variant: {
blur: {
backdrop: "hv-drawer__backdrop--blur",
},
opaque: {
backdrop: "hv-drawer__backdrop--opaque",
},
transparent: {
backdrop: "hv-drawer__backdrop--transparent",
},
},
},
});
export type DrawerVariants = VariantProps<typeof drawerVariants>;
@@ -0,0 +1,71 @@
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 { createAlertDialogContext, alertDialogKey } from "./context";
import AlertDialogTrigger from "./AlertDialogTrigger.vue";
export default defineComponent({
name: "AlertDialog",
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(alertDialogKey, createAlertDialogContext(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 === "AlertDialogTrigger") found = true;
if (
!found &&
(name === "Button" ||
node.type === "button" ||
node.type === "a")
) {
found = true;
return h(
AlertDialogTrigger,
{ asChild: true, key: node.key ?? undefined },
{ default: () => node },
);
}
return node;
});
},
},
);
},
});
@@ -0,0 +1,64 @@
<script lang="ts">
import { defineComponent, h, inject, type PropType } from "vue";
import type { AlertDialogVariants } from "@heroui-vue/styles";
import type { OverlayState } from "../../composables/useOverlayState";
import AlertDialog from "./AlertDialog";
import AlertDialogBackdropSurface from "./AlertDialogBackdropSurface.vue";
import { alertDialogKey } from "./context";
/**
* Alert dialogs require explicit action by default:
* isDismissable=false, isKeyboardDismissDisabled=true.
* Both remain independently configurable.
*/
export default defineComponent({
name: "AlertDialogBackdrop",
inheritAttrs: false,
props: {
open: { type: Boolean, default: undefined },
isOpen: { type: Boolean, default: undefined },
defaultOpen: Boolean,
state: Object as PropType<OverlayState>,
variant: String as PropType<AlertDialogVariants["variant"]>,
isDismissable: { type: Boolean, default: false },
isKeyboardDismissDisabled: { type: Boolean, default: true },
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(alertDialogKey, undefined);
return () => {
const surface = () =>
h(
AlertDialogBackdropSurface,
{
...attrs,
variant: props.variant,
isDismissable: props.isDismissable,
isKeyboardDismissDisabled: props.isKeyboardDismissDisabled,
to: props.to,
},
slots,
);
if (parent) return surface();
return h(
AlertDialog,
{
open: props.open,
isOpen: props.isOpen,
defaultOpen: props.defaultOpen,
state: props.state,
"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,57 @@
<script setup lang="ts">
import { useForwardExpose } from "reka-ui";
import { computed, provide } from "vue";
import {
alertDialogVariants,
type AlertDialogVariants,
} from "@heroui-vue/styles";
import OverlayPortal from "../overlay/OverlayPortal.vue";
import OverlayBackdrop from "../overlay/OverlayBackdrop.vue";
import { alertDialogKey, useAlertDialog } from "./context";
import { useOverlayViewport } from "../overlay/viewport";
import { useOverlayAnimation } from "../overlay/animation";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
variant?: AlertDialogVariants["variant"];
isDismissable?: boolean;
isKeyboardDismissDisabled?: boolean;
to?: string | HTMLElement;
}>(),
{
variant: "opaque",
// Alert dialogs require explicit action by default.
isDismissable: false,
isKeyboardDismissDisabled: true,
},
);
const ctx = useAlertDialog();
const height = useOverlayViewport();
const { forwardRef, currentElement } = useForwardExpose();
provide(alertDialogKey, {
...ctx,
variant: computed(() => props.variant),
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="alertDialogVariants({ variant }).backdrop()"
data-slot="alert-dialog-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,12 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div
v-bind="$attrs"
class="hv-alert-dialog__body"
data-slot="alert-dialog-body"
>
<slot />
</div>
</template>
@@ -0,0 +1,29 @@
import OverlayAction from "../overlay/OverlayAction";
import { useAlertDialog } from "./context";
import { defineComponent, h } from "vue";
/** Closes the alert dialog when activated (replaces RAC slot="close"). */
export default defineComponent({
name: "AlertDialogClose",
inheritAttrs: false,
props: {
as: { type: String, default: "button" },
asChild: { type: Boolean, default: false },
isDisabled: { type: Boolean, default: false },
},
setup(props, { attrs, slots }) {
const ctx = useAlertDialog();
return () =>
h(
OverlayAction,
{
...attrs,
as: props.as,
asChild: props.asChild,
isDisabled: props.isDisabled,
activate: ctx.state.close,
},
slots,
);
},
});
@@ -0,0 +1,29 @@
import { defineComponent, h, mergeProps, type PropType } from "vue";
import type { CloseButtonVariants } from "@heroui-vue/styles";
import CloseButton from "../close-button/CloseButton.vue";
import { useAlertDialog } from "./context";
export default defineComponent({
name: "AlertDialogCloseTrigger",
inheritAttrs: false,
props: {
variant: String as PropType<CloseButtonVariants["variant"]>,
isDisabled: Boolean,
disabled: Boolean,
},
setup(props, { attrs, slots }) {
const ctx = useAlertDialog();
return () =>
h(
CloseButton,
mergeProps(attrs, props, {
class: "hv-alert-dialog__close-trigger",
"data-slot": "alert-dialog-close-trigger",
onClick: (event: MouseEvent) => {
if (!event.defaultPrevented) ctx.state.close();
},
}),
slots,
);
},
});
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { computed, provide, ref } from "vue";
import {
alertDialogVariants,
type AlertDialogVariants,
} from "@heroui-vue/styles";
import {
alertDialogKey,
useAlertDialog,
type AlertDialogPlacement,
} from "./context";
import { useOverlayAnimation } from "../overlay/animation";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
placement?: AlertDialogPlacement;
size?: AlertDialogVariants["size"];
as?: string;
}>(),
{ placement: "auto", size: "md", as: "div" },
);
const ctx = useAlertDialog();
provide(alertDialogKey, {
...ctx,
placement: computed(() => props.placement),
size: computed(() => props.size),
});
const container = ref<HTMLElement>();
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
ctx.state.isOpen,
container,
);
</script>
<template>
<component
:is="as"
ref="container"
v-bind="$attrs"
:class="alertDialogVariants({ size }).container()"
data-slot="alert-dialog-container"
:data-placement="placement"
:data-entering="entering || undefined"
:data-exiting="exiting || undefined"
@animationend="onAnimationEnd"
>
<slot :close="ctx.state.close" />
</component>
</template>
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { computed, provide, watchEffect, onUnmounted, useAttrs } from "vue";
import { DialogTitle } from "reka-ui";
import { alertDialogVariants } from "@heroui-vue/styles";
import OverlayDialogContent from "../overlay/OverlayDialogContent.vue";
import { surfaceContextKey } from "../surface/context";
import { useAlertDialog } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
as: "div",
});
const ctx = useAlertDialog();
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="alertDialogVariants({ size: ctx.size.value }).dialog()"
:is-dismissable="ctx.dismissable.value"
:is-keyboard-dismiss-disabled="ctx.keyboardDisabled.value"
role="alertdialog"
data-slot="alert-dialog-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,12 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div
v-bind="$attrs"
class="hv-alert-dialog__footer"
data-slot="alert-dialog-footer"
>
<slot />
</div>
</template>
@@ -0,0 +1,12 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div
v-bind="$attrs"
class="hv-alert-dialog__header"
data-slot="alert-dialog-header"
>
<slot />
</div>
</template>
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { computed, watchEffect, onUnmounted, useId } from "vue";
import { DialogTitle, injectDialogRootContext } from "reka-ui";
import { useAlertDialog } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
as: "h2",
});
const ctx = useAlertDialog();
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-alert-dialog__heading"
data-slot="alert-dialog-heading"
>
<slot />
</DialogTitle>
</template>
@@ -0,0 +1,68 @@
<script lang="ts">
import { computed, defineComponent, h, useAttrs, type PropType } from "vue";
import {
alertDialogVariants,
type AlertDialogVariants,
} from "@heroui-vue/styles";
import {
AlertDialogDangerIcon,
AlertDialogInfoIcon,
AlertDialogSuccessIcon,
AlertDialogWarningIcon,
} from "./icons";
import type { AlertDialogStatus } from "./context";
export default defineComponent({
name: "AlertDialogIcon",
inheritAttrs: false,
props: {
status: {
type: String as PropType<AlertDialogStatus>,
default: "danger",
},
as: {
type: String,
default: "div",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const classes = computed(() =>
alertDialogVariants({
status: props.status as AlertDialogVariants["status"],
}).icon(),
);
function defaultIcon() {
switch (props.status) {
case "default":
case "accent":
return h(AlertDialogInfoIcon, {
"data-slot": "alert-dialog-default-icon",
});
case "success":
return h(AlertDialogSuccessIcon, {
"data-slot": "alert-dialog-default-icon",
});
case "warning":
return h(AlertDialogWarningIcon, {
"data-slot": "alert-dialog-default-icon",
});
default:
return h(AlertDialogDangerIcon, {
"data-slot": "alert-dialog-default-icon",
});
}
}
return () =>
h(
props.as,
{
...attrs,
class: [classes.value, attrs.class],
"data-slot": "alert-dialog-icon",
},
slots.default?.() ?? [defaultIcon()],
);
},
});
</script>
@@ -0,0 +1,38 @@
<script setup lang="ts">
import { watch } from "vue";
import { injectDialogRootContext, useForwardExpose } from "reka-ui";
import OverlayAction from "../overlay/OverlayAction";
import { useAlertDialog } from "./context";
defineOptions({ inheritAttrs: false });
withDefaults(
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
{ as: "div" },
);
const ctx = useAlertDialog();
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-alert-dialog__trigger"
data-slot="alert-dialog-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,60 @@
import {
computed,
inject,
reactive,
ref,
useId,
type ComputedRef,
type InjectionKey,
type Ref,
} from "vue";
import type { AlertDialogVariants } from "@heroui-vue/styles";
import type { OverlayState } from "../../composables/useOverlayState";
export type AlertDialogPlacement = "auto" | "top" | "center" | "bottom";
export type AlertDialogStatus =
"default" | "accent" | "success" | "warning" | "danger";
export interface AlertDialogContext {
state: OverlayState;
contentId: Ref<string>;
defaultId: string;
titles: Map<symbol, string>;
placement: ComputedRef<AlertDialogPlacement>;
size: ComputedRef<AlertDialogVariants["size"]>;
/** Backdrop variant; defaults to opaque. */
variant: ComputedRef<AlertDialogVariants["variant"]>;
dismissable: ComputedRef<boolean>;
keyboardDisabled: ComputedRef<boolean>;
}
export const alertDialogKey: InjectionKey<AlertDialogContext> =
Symbol("hv-alert-dialog");
export function useAlertDialog(required = true) {
const ctx = inject(alertDialogKey, undefined);
if (!ctx && required) {
throw new Error(
"AlertDialog parts require AlertDialog or AlertDialogBackdrop.",
);
}
return ctx!;
}
export function createAlertDialogContext(
state: OverlayState,
): AlertDialogContext {
const id = "hv-alert-dialog-" + useId();
return {
state,
contentId: ref(id),
defaultId: id,
titles: reactive(new Map()),
// Alert dialogs require explicit action by default.
placement: computed(() => "auto"),
size: computed(() => "md"),
variant: computed(() => "opaque"),
dismissable: computed(() => false),
keyboardDisabled: computed(() => true),
};
}
@@ -0,0 +1,53 @@
/** Baseline icons from HeroUI icons.tsx (Apache-2.0). */
import { defineComponent, h } from "vue";
function icon(name: string, d: string) {
return defineComponent({
name,
inheritAttrs: false,
setup(_, { attrs }) {
return () =>
h(
"svg",
{
...attrs,
"aria-hidden": "true",
fill: "none",
height: "16",
role: "presentation",
viewBox: "0 0 16 16",
width: "16",
xmlns: "http://www.w3.org/2000/svg",
},
[
h("path", {
"clip-rule": "evenodd",
d,
fill: "currentColor",
"fill-rule": "evenodd",
}),
],
);
},
});
}
export const AlertDialogInfoIcon = icon(
"AlertDialogInfoIcon",
"M8 13.5a5.5 5.5 0 1 0 0-11a5.5 5.5 0 0 0 0 11M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m1-9.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0m-.25 3a.75.75 0 0 0-1.5 0V11a.75.75 0 0 0 1.5 0z",
);
export const AlertDialogWarningIcon = icon(
"AlertDialogWarningIcon",
"M7.134 2.994L2.217 11.5a1 1 0 0 0 .866 1.5h9.834a1 1 0 0 0 .866-1.5L8.866 2.993a1 1 0 0 0-1.732 0m3.03-.75c-.962-1.665-3.366-1.665-4.329 0L.918 10.749c-.963 1.666.24 3.751 2.165 3.751h9.834c1.925 0 3.128-2.085 2.164-3.751zM8 5a.75.75 0 0 1 .75.75v2a.75.75 0 0 1-1.5 0v-2A.75.75 0 0 1 8 5m1 5.75a1 1 0 1 1-2 0a1 1 0 0 1 2 0",
);
export const AlertDialogDangerIcon = icon(
"AlertDialogDangerIcon",
"M8 13.5a5.5 5.5 0 1 0 0-11a5.5 5.5 0 0 0 0 11M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m1-4.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0M8.75 5a.75.75 0 0 0-1.5 0v2.5a.75.75 0 0 0 1.5 0z",
);
export const AlertDialogSuccessIcon = icon(
"AlertDialogSuccessIcon",
"M13.5 8a5.5 5.5 0 1 1-11 0a5.5 5.5 0 0 1 11 0M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0m-3.9-1.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z",
);
@@ -0,0 +1,71 @@
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 { createDrawerContext, drawerKey } from "./context";
import DrawerTrigger from "./DrawerTrigger.vue";
export default defineComponent({
name: "Drawer",
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(drawerKey, createDrawerContext(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 === "DrawerTrigger") found = true;
if (
!found &&
(name === "Button" ||
node.type === "button" ||
node.type === "a")
) {
found = true;
return h(
DrawerTrigger,
{ asChild: true, key: node.key ?? undefined },
{ default: () => node },
);
}
return node;
});
},
},
);
},
});
@@ -0,0 +1,59 @@
<script lang="ts">
import { defineComponent, h, inject, type PropType } from "vue";
import type { DrawerVariants } from "@heroui-vue/styles";
import type { OverlayState } from "../../composables/useOverlayState";
import Drawer from "./Drawer";
import DrawerBackdropSurface from "./DrawerBackdropSurface.vue";
import { drawerKey } from "./context";
export default defineComponent({
name: "DrawerBackdrop",
inheritAttrs: false,
props: {
open: { type: Boolean, default: undefined },
isOpen: { type: Boolean, default: undefined },
defaultOpen: Boolean,
state: Object as PropType<OverlayState>,
variant: String as PropType<DrawerVariants["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(drawerKey, undefined);
return () => {
const surface = () =>
h(
DrawerBackdropSurface,
{
...attrs,
variant: props.variant,
isDismissable: props.isDismissable,
isKeyboardDismissDisabled: props.isKeyboardDismissDisabled,
to: props.to,
},
slots,
);
if (parent) return surface();
return h(
Drawer,
{
open: props.open,
isOpen: props.isOpen,
defaultOpen: props.defaultOpen,
state: props.state,
"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,49 @@
<script setup lang="ts">
import { useForwardExpose } from "reka-ui";
import { computed, provide } from "vue";
import { drawerVariants, type DrawerVariants } from "@heroui-vue/styles";
import OverlayPortal from "../overlay/OverlayPortal.vue";
import OverlayBackdrop from "../overlay/OverlayBackdrop.vue";
import { drawerKey, useDrawer } from "./context";
import { useOverlayViewport } from "../overlay/viewport";
import { useOverlayAnimation } from "../overlay/animation";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
variant?: DrawerVariants["variant"];
isDismissable?: boolean;
isKeyboardDismissDisabled?: boolean;
to?: string | HTMLElement;
}>(),
{ variant: "opaque", isDismissable: true, isKeyboardDismissDisabled: false },
);
const ctx = useDrawer();
const height = useOverlayViewport();
const { forwardRef, currentElement } = useForwardExpose();
provide(drawerKey, {
...ctx,
variant: computed(() => props.variant),
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="drawerVariants({ variant }).backdrop()"
data-slot="drawer-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,13 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div
v-bind="$attrs"
class="hv-drawer__body"
data-slot="drawer-body"
style="touch-action: pan-y"
>
<slot />
</div>
</template>
@@ -0,0 +1,29 @@
import OverlayAction from "../overlay/OverlayAction";
import { useDrawer } from "./context";
import { defineComponent, h } from "vue";
/** Closes the drawer when activated (replaces RAC slot="close"). */
export default defineComponent({
name: "DrawerClose",
inheritAttrs: false,
props: {
as: { type: String, default: "button" },
asChild: { type: Boolean, default: false },
isDisabled: { type: Boolean, default: false },
},
setup(props, { attrs, slots }) {
const ctx = useDrawer();
return () =>
h(
OverlayAction,
{
...attrs,
as: props.as,
asChild: props.asChild,
isDisabled: props.isDisabled,
activate: ctx.state.close,
},
slots,
);
},
});
@@ -0,0 +1,29 @@
import { defineComponent, h, mergeProps, type PropType } from "vue";
import type { CloseButtonVariants } from "@heroui-vue/styles";
import CloseButton from "../close-button/CloseButton.vue";
import { useDrawer } from "./context";
export default defineComponent({
name: "DrawerCloseTrigger",
inheritAttrs: false,
props: {
variant: String as PropType<CloseButtonVariants["variant"]>,
isDisabled: Boolean,
disabled: Boolean,
},
setup(props, { attrs, slots }) {
const ctx = useDrawer();
return () =>
h(
CloseButton,
mergeProps(attrs, props, {
class: "hv-drawer__close-trigger",
"data-slot": "drawer-close-trigger",
onClick: (event: MouseEvent) => {
if (!event.defaultPrevented) ctx.state.close();
},
}),
slots,
);
},
});
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { computed, provide, ref } from "vue";
import { drawerVariants } from "@heroui-vue/styles";
import { drawerKey, useDrawer, type DrawerPlacement } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
placement?: DrawerPlacement;
as?: string;
}>(),
{ placement: "bottom", as: "div" },
);
const ctx = useDrawer();
provide(drawerKey, {
...ctx,
placement: computed(() => props.placement),
});
const content = ref<HTMLElement>();
</script>
<template>
<component
:is="as"
ref="content"
v-bind="$attrs"
:class="drawerVariants({ placement }).content()"
data-slot="drawer-content"
:data-placement="placement"
>
<slot :close="ctx.state.close" />
</component>
</template>
@@ -0,0 +1,87 @@
<script setup lang="ts">
import {
computed,
provide,
watchEffect,
onUnmounted,
useAttrs,
ref,
} from "vue";
import { DialogTitle } from "reka-ui";
import { drawerVariants } from "@heroui-vue/styles";
import OverlayDialogContent from "../overlay/OverlayDialogContent.vue";
import { surfaceContextKey } from "../surface/context";
import { useOverlayAnimation } from "../overlay/animation";
import { useDrawer } from "./context";
import { useDrawerDrag } from "./useDrawerDrag";
defineOptions({ inheritAttrs: false });
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
as: "div",
});
const ctx = useDrawer();
const attrs = useAttrs();
watchEffect(() => {
ctx.contentId.value = props.id ?? ctx.defaultId;
});
onUnmounted(() => {
ctx.contentId.value = ctx.defaultId;
});
provide(surfaceContextKey, { variant: computed(() => "default" as const) });
const dialogEl = ref<HTMLElement | null>(null);
const { dialogRef } = useDrawerDrag(
ctx.placement,
ctx.dismissable,
ctx.state.isOpen,
() => ctx.state.close(),
);
// Phase markers follow the Dialog element — it is the node that actually
// runs the enter/exit animations, so Presence and CSS stay in sync.
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
ctx.state.isOpen,
dialogRef,
);
function setDialogRef(el: unknown) {
const node = (el as { $el?: HTMLElement } | HTMLElement | null) ?? null;
const next = !node
? null
: node instanceof HTMLElement
? node
: ((node.$el as HTMLElement) ?? null);
dialogEl.value = next;
dialogRef.value = next;
}
</script>
<template>
<OverlayDialogContent
:ref="setDialogRef"
v-bind="attrs"
:as="as"
:id="ctx.contentId.value"
:class="drawerVariants({ placement: ctx.placement.value }).dialog()"
:is-dismissable="ctx.dismissable.value"
:is-keyboard-dismiss-disabled="ctx.keyboardDisabled.value"
data-slot="drawer-dialog"
:data-entering="entering || undefined"
:data-exiting="exiting || undefined"
:data-placement="ctx.placement.value"
:style="ctx.dismissable.value ? { touchAction: 'none' } : undefined"
: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"
@animationend="onAnimationEnd"
>
<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,8 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div v-bind="$attrs" class="hv-drawer__footer" data-slot="drawer-footer">
<slot />
</div>
</template>
@@ -0,0 +1,15 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div
v-bind="$attrs"
class="hv-drawer__handle"
data-slot="drawer-handle"
aria-hidden="true"
>
<slot>
<div data-slot="drawer-handle-bar" />
</slot>
</div>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<div v-bind="$attrs" class="hv-drawer__header" data-slot="drawer-header">
<slot />
</div>
</template>
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { computed, watchEffect, onUnmounted, useId } from "vue";
import { DialogTitle, injectDialogRootContext } from "reka-ui";
import { useDrawer } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
as: "h2",
});
const ctx = useDrawer();
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-drawer__heading"
data-slot="drawer-heading"
>
<slot />
</DialogTitle>
</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 { useDrawer } from "./context";
defineOptions({ inheritAttrs: false });
withDefaults(
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
{ as: "div" },
);
const ctx = useDrawer();
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-drawer__trigger"
data-slot="drawer-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,49 @@
import {
computed,
inject,
reactive,
ref,
useId,
type ComputedRef,
type InjectionKey,
type Ref,
} from "vue";
import type { DrawerVariants } from "@heroui-vue/styles";
import type { OverlayState } from "../../composables/useOverlayState";
export type DrawerPlacement = "top" | "bottom" | "left" | "right";
export interface DrawerContext {
state: OverlayState;
contentId: Ref<string>;
defaultId: string;
titles: Map<symbol, string>;
placement: ComputedRef<DrawerPlacement>;
variant: ComputedRef<DrawerVariants["variant"]>;
dismissable: ComputedRef<boolean>;
keyboardDisabled: ComputedRef<boolean>;
}
export const drawerKey: InjectionKey<DrawerContext> = Symbol("hv-drawer");
export function useDrawer(required = true) {
const ctx = inject(drawerKey, undefined);
if (!ctx && required) {
throw new Error("Drawer parts require Drawer or DrawerBackdrop.");
}
return ctx!;
}
export function createDrawerContext(state: OverlayState): DrawerContext {
const id = "hv-drawer-" + useId();
return {
state,
contentId: ref(id),
defaultId: id,
titles: reactive(new Map()),
placement: computed(() => "bottom"),
variant: computed(() => "opaque"),
dismissable: computed(() => true),
keyboardDisabled: computed(() => false),
};
}
@@ -0,0 +1,281 @@
/**
* Drawer drag-to-dismiss — thresholds match the fixed HeroUI baseline:
* activate after 8px, dismiss at >30% dimension or >0.5px/ms velocity.
* Drag originates from handle/header/footer; body is excluded to avoid scroll conflicts.
*/
import { nextTick, onBeforeUnmount, ref, watch, type Ref } from "vue";
import type { DrawerPlacement } from "./context";
const DRAG_THRESHOLD = 8;
const DISMISS_FRACTION = 0.3;
const VELOCITY_THRESHOLD = 0.5;
const SNAP_BACK_TRANSITION = "transform 300ms cubic-bezier(0.32, 0.72, 0, 1)";
type GesturePhase = "idle" | "dragging" | "dismissed";
function isDrawerDragTargetOwnedBy(
target: HTMLElement,
dialog: HTMLElement,
): boolean {
return target.closest('[data-slot="drawer-dialog"]') === dialog;
}
export function useDrawerDrag(
placement: Ref<DrawerPlacement>,
isDismissable: Ref<boolean>,
isOpen: Ref<boolean>,
onDismiss: () => void,
) {
const dialogRef = ref<HTMLElement | null>(null);
let phase: GesturePhase = "idle";
let isActive = false;
let activePointerId: number | null = null;
let startPos = 0;
let currentOffset = 0;
let velocity = 0;
let lastTime = 0;
let lastPos = 0;
function isVertical() {
return placement.value === "top" || placement.value === "bottom";
}
function getPos(event: PointerEvent) {
return isVertical() ? event.clientY : event.clientX;
}
function clamp(delta: number) {
switch (placement.value) {
case "bottom":
case "right":
return Math.max(0, delta);
case "top":
case "left":
return Math.min(0, delta);
default:
return delta;
}
}
function prefersReducedMotion() {
return Boolean(
dialogRef.value?.ownerDocument.defaultView?.matchMedia?.(
"(prefers-reduced-motion: reduce)",
).matches,
);
}
function clearStyles(el: HTMLElement | null) {
if (!el) return;
el.style.transform = "";
el.style.transition = "";
}
function snapBack(el: HTMLElement) {
el.style.transition = prefersReducedMotion()
? "none"
: SNAP_BACK_TRANSITION;
el.style.transform = "";
const cleanup = () => {
el.style.transition = "";
};
el.addEventListener("transitionend", cleanup, { once: true });
}
function releaseCapture(pointerId: number | null, el = dialogRef.value) {
if (pointerId === null) return;
try {
el?.releasePointerCapture(pointerId);
} catch {
// already released
}
}
/**
* Cancel an in-flight gesture. When `preserveOffset` is true the inline
* transform is kept so an accepted exit continues from the dragged position.
*/
function endGesture(
options: { preserveOffset?: boolean } = {},
el = dialogRef.value,
) {
const pointerId = activePointerId;
phase = "idle";
isActive = false;
activePointerId = null;
currentOffset = 0;
velocity = 0;
releaseCapture(pointerId, el);
if (!options.preserveOffset) clearStyles(el);
}
function onPointerDown(event: Event) {
const pointerEvent = event as PointerEvent;
if (pointerEvent.defaultPrevented) return;
// Do not start gestures on a closing / closed panel.
if (!isDismissable.value || !isOpen.value) return;
if (pointerEvent.button !== 0) return;
if (phase !== "idle" || activePointerId !== null) return;
const target = pointerEvent.target as HTMLElement;
const currentTarget = pointerEvent.currentTarget as HTMLElement;
if (!target || !currentTarget) return;
if (!isDrawerDragTargetOwnedBy(target, currentTarget)) return;
if (
target.closest(
"input, textarea, button, [role='button'], select, a, [data-slot='drawer-body']",
)
) {
return;
}
phase = "dragging";
isActive = false;
activePointerId = pointerEvent.pointerId;
startPos = getPos(pointerEvent);
lastPos = startPos;
lastTime = Date.now();
currentOffset = 0;
velocity = 0;
}
function onPointerMove(event: Event) {
const pointerEvent = event as PointerEvent;
if (phase !== "dragging" || !dialogRef.value) return;
if (pointerEvent.pointerId !== activePointerId) return;
// A retained exit node must not keep accepting drag updates.
if (!isOpen.value) return;
const pos = getPos(pointerEvent);
const rawDelta = pos - startPos;
const delta = clamp(rawDelta);
if (!isActive) {
if (Math.abs(rawDelta) < DRAG_THRESHOLD) return;
isActive = true;
dialogRef.value.style.transition = "none";
try {
dialogRef.value.setPointerCapture(pointerEvent.pointerId);
} catch {
// jsdom / browsers may already have released capture
}
}
currentOffset = delta;
const now = Date.now();
const dt = now - lastTime;
if (dt > 0) {
velocity = (pos - lastPos) / dt;
lastTime = now;
lastPos = pos;
}
const axis = isVertical() ? "Y" : "X";
dialogRef.value.style.transform = `translate${axis}(${delta}px)`;
}
function onPointerUp(event: Event) {
const pointerEvent = event as PointerEvent;
if (phase !== "dragging" || pointerEvent.pointerId !== activePointerId) {
return;
}
const el = dialogRef.value;
const wasActive = isActive;
const pointerId = activePointerId;
phase = "idle";
isActive = false;
activePointerId = null;
if (!el || !wasActive) {
currentOffset = 0;
velocity = 0;
releaseCapture(pointerId);
return;
}
releaseCapture(pointerId);
const dimension = isVertical() ? el.offsetHeight : el.offsetWidth;
const absOffset = Math.abs(currentOffset);
const absVelocity = Math.abs(velocity);
const shouldDismiss =
absOffset > dimension * DISMISS_FRACTION ||
absVelocity > VELOCITY_THRESHOLD;
if (shouldDismiss) {
// Keep the inline transform so exit continues from the dragged position.
// Mark dismissed so a later lostpointercapture does not clear the offset.
phase = "dismissed";
onDismiss();
void nextTick(() => {
if (isOpen.value && dialogRef.value === el) {
// Controlled parent rejected the close request — restore the panel.
phase = "idle";
snapBack(el);
} else {
phase = "idle";
}
});
} else {
snapBack(el);
}
currentOffset = 0;
velocity = 0;
}
function onPointerCancel(event: Event) {
const pointerEvent = event as PointerEvent;
// A normal capture release after an accepted dismiss must not jump the
// panel back — only cancel gestures that are still in flight.
if (phase === "dismissed") return;
if (phase !== "dragging") return;
if (
activePointerId !== null &&
pointerEvent.pointerId !== undefined &&
pointerEvent.pointerId !== activePointerId
) {
return;
}
endGesture();
}
function bind(el: HTMLElement | null) {
el?.addEventListener("pointerdown", onPointerDown);
el?.addEventListener("pointermove", onPointerMove);
el?.addEventListener("pointerup", onPointerUp);
el?.addEventListener("pointercancel", onPointerCancel);
el?.addEventListener("lostpointercapture", onPointerCancel);
}
function unbind(el: HTMLElement | null) {
el?.removeEventListener("pointerdown", onPointerDown);
el?.removeEventListener("pointermove", onPointerMove);
el?.removeEventListener("pointerup", onPointerUp);
el?.removeEventListener("pointercancel", onPointerCancel);
el?.removeEventListener("lostpointercapture", onPointerCancel);
}
// Config changes mid-gesture cancel it; an accepted programmatic close
// stops further updates but keeps whatever offset is already applied.
watch([isDismissable, placement], () => {
if (phase === "dragging") endGesture();
});
watch(isOpen, (open) => {
if (open) {
// Presence may reuse the exiting node on a quick reopen.
endGesture();
} else if (phase === "dragging") {
// Programmatic close during a drag: stop the gesture without jumping.
endGesture({ preserveOffset: true });
}
});
watch(dialogRef, (el, prev) => {
if (prev) {
// Clean up the previous node (capture + any in-flight style).
endGesture({}, prev);
unbind(prev);
}
bind(el);
});
onBeforeUnmount(() => {
endGesture();
unbind(dialogRef.value);
});
return {
dialogRef,
};
}
+66
View File
@@ -658,3 +658,69 @@ export {
type ListBoxItemVariants,
type ListBoxSectionVariants,
} from "@heroui-vue/styles";
export { default as AlertDialog } from "./components/alert-dialog/AlertDialog";
export { default as AlertDialogRoot } from "./components/alert-dialog/AlertDialog";
export { default as AlertDialogTrigger } from "./components/alert-dialog/AlertDialogTrigger.vue";
export { default as AlertDialogBackdrop } from "./components/alert-dialog/AlertDialogBackdrop.vue";
export { default as AlertDialogContainer } from "./components/alert-dialog/AlertDialogContainer.vue";
export { default as AlertDialogDialog } from "./components/alert-dialog/AlertDialogDialog.vue";
export { default as AlertDialogHeader } from "./components/alert-dialog/AlertDialogHeader.vue";
export { default as AlertDialogHeading } from "./components/alert-dialog/AlertDialogHeading.vue";
export { default as AlertDialogBody } from "./components/alert-dialog/AlertDialogBody.vue";
export { default as AlertDialogFooter } from "./components/alert-dialog/AlertDialogFooter.vue";
export { default as AlertDialogIcon } from "./components/alert-dialog/AlertDialogIcon.vue";
export { default as AlertDialogCloseTrigger } from "./components/alert-dialog/AlertDialogCloseTrigger";
export { default as AlertDialogClose } from "./components/alert-dialog/AlertDialogClose";
export {
alertDialogVariants,
type AlertDialogVariants,
} from "@heroui-vue/styles";
export type {
AlertDialogPlacement,
AlertDialogStatus,
} from "./components/alert-dialog/context";
export type {
AlertDialogProps,
AlertDialogTriggerProps,
AlertDialogBackdropProps,
AlertDialogContainerProps,
AlertDialogDialogProps,
AlertDialogHeaderProps,
AlertDialogHeadingProps,
AlertDialogBodyProps,
AlertDialogFooterProps,
AlertDialogIconProps,
AlertDialogCloseTriggerProps,
AlertDialogCloseProps,
} from "./types";
export { default as Drawer } from "./components/drawer/Drawer";
export { default as DrawerRoot } from "./components/drawer/Drawer";
export { default as DrawerTrigger } from "./components/drawer/DrawerTrigger.vue";
export { default as DrawerBackdrop } from "./components/drawer/DrawerBackdrop.vue";
export { default as DrawerContent } from "./components/drawer/DrawerContent.vue";
export { default as DrawerDialog } from "./components/drawer/DrawerDialog.vue";
export { default as DrawerHeader } from "./components/drawer/DrawerHeader.vue";
export { default as DrawerHeading } from "./components/drawer/DrawerHeading.vue";
export { default as DrawerBody } from "./components/drawer/DrawerBody.vue";
export { default as DrawerFooter } from "./components/drawer/DrawerFooter.vue";
export { default as DrawerHandle } from "./components/drawer/DrawerHandle.vue";
export { default as DrawerCloseTrigger } from "./components/drawer/DrawerCloseTrigger";
export { default as DrawerClose } from "./components/drawer/DrawerClose";
export { drawerVariants, type DrawerVariants } from "@heroui-vue/styles";
export type { DrawerPlacement } from "./components/drawer/context";
export type {
DrawerProps,
DrawerTriggerProps,
DrawerBackdropProps,
DrawerContentProps,
DrawerDialogProps,
DrawerHeaderProps,
DrawerHeadingProps,
DrawerBodyProps,
DrawerFooterProps,
DrawerHandleProps,
DrawerCloseTriggerProps,
DrawerCloseProps,
} from "./types";
+76
View File
@@ -515,3 +515,79 @@ export type SliderOutputProps = InstanceType<
export type SliderMarksProps = InstanceType<
(typeof import("./components/slider/SliderMarks.vue"))["default"]
>["$props"];
import type AlertDialog from "./components/alert-dialog/AlertDialog";
import type AlertDialogTrigger from "./components/alert-dialog/AlertDialogTrigger.vue";
import type AlertDialogBackdrop from "./components/alert-dialog/AlertDialogBackdrop.vue";
import type AlertDialogContainer from "./components/alert-dialog/AlertDialogContainer.vue";
import type AlertDialogDialog from "./components/alert-dialog/AlertDialogDialog.vue";
import type AlertDialogHeader from "./components/alert-dialog/AlertDialogHeader.vue";
import type AlertDialogHeading from "./components/alert-dialog/AlertDialogHeading.vue";
import type AlertDialogBody from "./components/alert-dialog/AlertDialogBody.vue";
import type AlertDialogFooter from "./components/alert-dialog/AlertDialogFooter.vue";
import type AlertDialogIcon from "./components/alert-dialog/AlertDialogIcon.vue";
import type AlertDialogCloseTrigger from "./components/alert-dialog/AlertDialogCloseTrigger";
import type AlertDialogClose from "./components/alert-dialog/AlertDialogClose";
export type AlertDialogProps = InstanceType<typeof AlertDialog>["$props"];
export type AlertDialogTriggerProps = InstanceType<
typeof AlertDialogTrigger
>["$props"];
export type AlertDialogBackdropProps = InstanceType<
typeof AlertDialogBackdrop
>["$props"];
export type AlertDialogContainerProps = InstanceType<
typeof AlertDialogContainer
>["$props"];
export type AlertDialogDialogProps = InstanceType<
typeof AlertDialogDialog
>["$props"];
export type AlertDialogHeaderProps = InstanceType<
typeof AlertDialogHeader
>["$props"];
export type AlertDialogHeadingProps = InstanceType<
typeof AlertDialogHeading
>["$props"];
export type AlertDialogBodyProps = InstanceType<
typeof AlertDialogBody
>["$props"];
export type AlertDialogFooterProps = InstanceType<
typeof AlertDialogFooter
>["$props"];
export type AlertDialogIconProps = InstanceType<
typeof AlertDialogIcon
>["$props"];
export type AlertDialogCloseTriggerProps = InstanceType<
typeof AlertDialogCloseTrigger
>["$props"];
export type AlertDialogCloseProps = InstanceType<
typeof AlertDialogClose
>["$props"];
import type Drawer from "./components/drawer/Drawer";
import type DrawerTrigger from "./components/drawer/DrawerTrigger.vue";
import type DrawerBackdrop from "./components/drawer/DrawerBackdrop.vue";
import type DrawerContent from "./components/drawer/DrawerContent.vue";
import type DrawerDialog from "./components/drawer/DrawerDialog.vue";
import type DrawerHeader from "./components/drawer/DrawerHeader.vue";
import type DrawerHeading from "./components/drawer/DrawerHeading.vue";
import type DrawerBody from "./components/drawer/DrawerBody.vue";
import type DrawerFooter from "./components/drawer/DrawerFooter.vue";
import type DrawerHandle from "./components/drawer/DrawerHandle.vue";
import type DrawerCloseTrigger from "./components/drawer/DrawerCloseTrigger";
import type DrawerClose from "./components/drawer/DrawerClose";
export type DrawerProps = InstanceType<typeof Drawer>["$props"];
export type DrawerTriggerProps = InstanceType<typeof DrawerTrigger>["$props"];
export type DrawerBackdropProps = InstanceType<typeof DrawerBackdrop>["$props"];
export type DrawerContentProps = InstanceType<typeof DrawerContent>["$props"];
export type DrawerDialogProps = InstanceType<typeof DrawerDialog>["$props"];
export type DrawerHeaderProps = InstanceType<typeof DrawerHeader>["$props"];
export type DrawerHeadingProps = InstanceType<typeof DrawerHeading>["$props"];
export type DrawerBodyProps = InstanceType<typeof DrawerBody>["$props"];
export type DrawerFooterProps = InstanceType<typeof DrawerFooter>["$props"];
export type DrawerHandleProps = InstanceType<typeof DrawerHandle>["$props"];
export type DrawerCloseTriggerProps = InstanceType<
typeof DrawerCloseTrigger
>["$props"];
export type DrawerCloseProps = InstanceType<typeof DrawerClose>["$props"];