Files

316 lines
7.1 KiB
CSS

/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue adapters. */
/* Toast component styles */
/* Toast Region */
.hv-toast-region {
@apply pointer-events-none fixed z-(--z-index-toast) outline-none;
@apply w-[calc(100vw-2rem)] sm:w-auto sm:min-w-(--toast-width);
display: block;
}
/* Placement - Bottom */
.hv-toast-region--bottom {
/* left-1/2 + -translate-x-1/2 centers in both LTR and RTL */
@apply bottom-4 left-1/2 -translate-x-1/2;
}
.hv-toast-region--bottom-start {
@apply start-4 bottom-4;
}
.hv-toast-region--bottom-end {
@apply end-4 bottom-4;
}
/* Placement - Top */
.hv-toast-region--top {
@apply top-4 left-1/2 -translate-x-1/2;
}
.hv-toast-region--top-start {
@apply start-4 top-4;
}
.hv-toast-region--top-end {
@apply end-4 top-4;
}
.hv-toast-region:focus-visible {
@apply outline-2 outline-offset-2 outline-focus;
}
/* Base */
.hv-toast {
position: absolute;
inset-inline-start: 0;
inset-inline-end: 0;
border-radius: min(32px, var(--radius-3xl));
/* Motion state */
--toast-y: var(--offset-collapsed, 0px);
--toast-enter: 0%;
--toast-scale: var(--scale-collapsed, 1);
transform: translateY(
calc(var(--dir, 1) * (var(--toast-y) + var(--toast-enter)))
)
scale(var(--toast-scale));
height: var(--toast-height, auto);
@apply pointer-events-auto flex flex-row items-start justify-start gap-1.5 bg-surface px-4 py-3 shadow-overlay;
/* Timing tokens */
--toast-ease: var(--ease-out-fluid);
--toast-enter-duration: 350ms;
--toast-exit-duration: 250ms;
--toast-translate-duration: var(--toast-enter-duration);
--toast-height-duration: var(--toast-enter-duration);
--toast-opacity-duration: 150ms;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER animation/transition for correct override specificity
*/
transition:
transform var(--toast-translate-duration) var(--toast-ease),
height var(--toast-height-duration) var(--toast-ease),
opacity var(--toast-opacity-duration) var(--toast-ease);
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Enter */
.hv-toast[data-entering="true"] {
--toast-enter: -100%;
}
/* Stacking direction */
.hv-toast--bottom,
.hv-toast--bottom-start,
.hv-toast--bottom-end {
--dir: -1;
bottom: 0;
transform-origin: bottom center;
&[data-expanded="true"]::after {
top: calc(-1 * var(--gap, 12px) - 1px);
bottom: 0;
}
}
.hv-toast--top,
.hv-toast--top-start,
.hv-toast--top-end {
--dir: 1;
top: 0;
transform-origin: top center;
&[data-expanded="true"]::after {
top: 0;
bottom: calc(-1 * var(--gap, 12px) - 1px);
}
}
/* Content fade between collapsed / expanded */
.hv-toast > :not([data-slot="toast-close"]) {
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 200ms var(--toast-ease);
@apply motion-reduce:transition-none;
}
/* Collapsed non-front: force height to front toast (Sonner-style unified stack height) */
.hv-toast:not([data-frontmost="true"]):not([data-expanded="true"]) {
--toast-y: var(--offset-collapsed, 0px);
height: var(--front-height, 0px);
overflow: hidden;
> :not([data-slot="toast-close"]) {
opacity: 0;
}
.hv-toast__close-button {
@apply pointer-events-none opacity-0;
outline: none;
}
}
/* Expanded */
.hv-toast[data-expanded="true"] {
--toast-y: var(--offset-expanded, 0px);
--toast-scale: 1;
height: var(--toast-height, auto);
}
/* Expanded hit area that covers the gap between toasts */
.hv-toast[data-expanded="true"]::after {
content: "";
position: absolute;
z-index: -1;
inset-inline: 0;
}
/* Exit */
.hv-toast[data-exiting="true"] {
@apply opacity-0;
}
.hv-toast[data-exiting="true"][data-frontmost="true"] {
--toast-translate-duration: var(--toast-exit-duration);
--toast-opacity-duration: 150ms;
--toast-enter: -100%;
--toast-scale: 1;
}
.hv-toast[data-exiting="true"][data-expanded="true"]:not(
[data-frontmost="true"]
) {
--toast-translate-duration: 200ms;
--toast-opacity-duration: 150ms;
--toast-scale: 0.96;
}
.hv-toast[data-exiting="true"]:not([data-expanded="true"]):not(
[data-frontmost="true"]
) {
--toast-translate-duration: 200ms;
--toast-opacity-duration: 150ms;
--toast-scale: calc(var(--scale-collapsed, 1) * 0.96);
}
/* Hidden (beyond maxVisibleToasts) */
.hv-toast[data-hidden="true"] {
@apply pointer-events-none flex opacity-0;
}
.hv-toast:focus-visible {
@apply outline-2 outline-offset-2 outline-focus;
}
/* Content */
.hv-toast__content {
@apply flex grow flex-col items-start self-center;
}
/* Indicator */
.hv-toast__indicator {
@apply flex shrink-0 items-center justify-center p-1 text-overlay-foreground select-none;
[data-slot="toast-default-icon"] {
@apply box-content size-4;
}
[data-slot="spinner"] {
@apply size-4;
}
[data-slot="spinner-icon"] {
@apply size-4;
}
}
/* Settled promise icon (data-swapped skips first paint) */
.hv-toast__indicator[data-swapped="true"] > :not([data-slot="spinner"]) {
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER animation/transition for correct override specificity
*/
animation:
toast-indicator-fade 150ms var(--toast-ease),
toast-indicator-scale 200ms var(--toast-ease);
@apply motion-reduce:animate-none;
}
/* Title */
.hv-toast__title {
@apply text-sm leading-5 font-medium text-overlay-foreground;
}
/* Description */
.hv-toast__description {
@apply text-sm text-muted;
}
/* Close button */
.hv-toast__close-button {
@apply pointer-events-none absolute -end-1 -top-1 size-5 border-border bg-default opacity-0 sm:border sm:bg-overlay;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
[data-slot="close-button-icon"] {
@apply size-3.5 sm:size-3;
}
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
@apply bg-default;
}
}
}
/* Reveal close button on hover */
.hv-toast[data-frontmost="true"]:hover .hv-toast__close-button,
.hv-toast[data-expanded="true"]:hover .hv-toast__close-button {
@apply pointer-events-auto opacity-100;
}
/* Exiting toasts never show the close button */
.hv-toast[data-exiting="true"] .hv-toast__close-button {
@apply pointer-events-none opacity-0;
}
/* Action */
.hv-toast__action {
@apply mt-2 sm:mt-0;
}
/* Variants */
.hv-toast--accent .hv-toast__title {
@apply text-accent-soft-foreground;
}
.hv-toast--success .hv-toast__title {
@apply text-success-soft-foreground;
}
.hv-toast--success .hv-toast__indicator {
@apply text-success-soft-foreground;
}
.hv-toast--warning .hv-toast__title {
@apply text-warning-soft-foreground;
}
.hv-toast--warning .hv-toast__indicator {
@apply text-warning-soft-foreground;
}
.hv-toast--danger .hv-toast__title {
@apply text-danger-soft-foreground;
}
.hv-toast--danger .hv-toast__indicator {
@apply text-danger-soft-foreground;
}
@keyframes toast-indicator-fade {
from {
opacity: 0;
}
}
@keyframes toast-indicator-scale {
from {
scale: 0.92;
}
}