/** * Toast style tokens. Kept apart from Toast.tsx for Vite fast refresh. * * The stacking and swipe transforms follow Base UI's Toast docs: each toast * reads --toast-index, --toast-offset-y and the swipe variables Base UI sets. * Every entry is a complete, literal class string so Tailwind finds it. */ import type { Color } from '../lib/styles' export type ToastPlacement = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' export type ToastColor = Color /** `loading` is used by `toast.promise` while the promise is pending. */ export type ToastType = ToastColor | 'loading' export type ToastSwipeDirection = 'up' | 'down' | 'left' | 'right' export const TOAST_PLACEMENTS: ToastPlacement[] = [ 'top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right', ] export const TOAST_COLORS: ToastColor[] = ['neutral', 'primary', 'success', 'warning', 'danger', 'info'] export const TOAST_VIEWPORT_STYLES: Record = { 'top-left': 'fixed top-4 left-4 z-50 w-[calc(100vw-2rem)] sm:top-6 sm:left-6 sm:w-[22.5rem]', 'top-center': 'fixed top-4 inset-x-0 z-50 mx-auto w-[calc(100vw-2rem)] sm:top-6 sm:w-[22.5rem]', 'top-right': 'fixed top-4 right-4 z-50 w-[calc(100vw-2rem)] sm:top-6 sm:right-6 sm:w-[22.5rem]', 'bottom-left': 'fixed bottom-4 left-4 z-50 w-[calc(100vw-2rem)] sm:bottom-6 sm:left-6 sm:w-[22.5rem]', 'bottom-center': 'fixed bottom-4 inset-x-0 z-50 mx-auto w-[calc(100vw-2rem)] sm:bottom-6 sm:w-[22.5rem]', 'bottom-right': 'fixed bottom-4 right-4 z-50 w-[calc(100vw-2rem)] sm:bottom-6 sm:right-6 sm:w-[22.5rem]', } export const TOAST_SWIPE: Record = { 'top-left': ['up', 'left'], 'top-center': ['up'], 'top-right': ['up', 'right'], 'bottom-left': ['down', 'left'], 'bottom-center': ['down'], 'bottom-right': ['down', 'right'], } /** Stack, enter, exit and swipe motion for toasts anchored to the bottom edge. */ const bottomMotion = "[--gap:0.75rem] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))] [--height:var(--toast-frontmost-height,var(--toast-height))] " + '[--offset-y:calc(var(--toast-offset-y)*-1+calc(var(--toast-index)*var(--gap)*-1)+var(--toast-swipe-movement-y))] ' + 'absolute inset-x-0 bottom-0 z-[calc(1000-var(--toast-index))] w-full origin-bottom ' + '[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))] ' + "after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-[''] " + 'data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--offset-y)))] ' + 'data-starting-style:[transform:translateY(150%)] ' + '[&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(150%)] ' + 'data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))] ' + 'data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))] ' + 'data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))] ' + 'data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))] ' + 'h-(--height) data-expanded:h-(--toast-height)' /** The same motion mirrored for toasts anchored to the top edge. */ const topMotion = "[--gap:0.75rem] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))] [--height:var(--toast-frontmost-height,var(--toast-height))] " + '[--offset-y:calc(var(--toast-offset-y)+(var(--toast-index)*var(--gap))+var(--toast-swipe-movement-y))] ' + 'absolute inset-x-0 top-0 z-[calc(1000-var(--toast-index))] w-full origin-top ' + '[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)+(var(--toast-index)*var(--peek))+(var(--shrink)*var(--height))))_scale(var(--scale))] ' + "after:absolute after:bottom-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-[''] " + 'data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--offset-y)))] ' + 'data-starting-style:[transform:translateY(-150%)] ' + '[&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(-150%)] ' + 'data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))] ' + 'data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))] ' + 'data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))] ' + 'data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))] ' + 'h-(--height) data-expanded:h-(--toast-height)' export const TOAST_ROOT_MOTION: Record<'top' | 'bottom', string> = { top: topMotion, bottom: bottomMotion, } export const toastSurface = 'select-none rounded-xl border border-border bg-surface text-fg shadow-popup outline-hidden ' + 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 ' + 'data-ending-style:opacity-0 data-limited:opacity-0 ' + '[transition:transform_0.5s_cubic-bezier(0.22,1,0.36,1),opacity_0.5s,height_0.15s] motion-reduce:[transition:opacity_0.2s]' export const toastContent = 'flex items-start gap-3 overflow-hidden p-4 transition-opacity duration-250 data-behind:opacity-0 data-expanded:opacity-100 motion-reduce:transition-none' /** Icon colour per toast type. */ export const TOAST_ICON_STYLES: Record = { neutral: 'text-fg-muted', primary: 'text-primary-600 dark:text-primary-400', success: 'text-success-600 dark:text-success-400', warning: 'text-warning-600 dark:text-warning-400', danger: 'text-danger-600 dark:text-danger-400', info: 'text-info-600 dark:text-info-400', loading: 'text-fg-muted', }