import {
prefersReducedMotion,
animateLayout,
animateEntrance,
animateExit,
} from '@remix-run/ui/animation'
import * as toast from '@remix-run/ui/toast'
import { css, on } from 'remix/component'
const toastManager = toast.createToastManager()
const timeouts = [
{ label: '3 seconds', value: 3000 },
{ label: '10 seconds', value: 10000 },
] as const
export default function ExampleToastTimeout() {
return () => (
{timeouts.map((timeout) => (
))}
)
}
export function ToastRegion() {
return () => (
{(toastItems) => {
let reducedMotion = prefersReducedMotion()
return (
{toastItems.map((toastItem, index) => (
{toastItem.title}
{toastItem.description}
))}
)
}}
)
}
const styles = {
triggers: css({
colorScheme: 'light dark',
font: '14px/1.5 ui-sans-serif, system-ui, sans-serif',
display: 'flex',
flexWrap: 'wrap',
alignItems: 'center',
gap: '8px',
}),
triggerButton: css({
appearance: 'none',
font: 'inherit',
color: 'light-dark(#202027, #eeeef2)',
background: 'light-dark(#fff, #222228)',
border: '1px solid light-dark(#dedee5, #41414a)',
borderRadius: '6px',
padding: '7px 12px',
cursor: 'pointer',
'&:hover': {
background: 'light-dark(#f0f0f5, #34343d)',
},
'&:focus-visible': {
outline: '2px solid currentColor',
outlineOffset: '3px',
},
}),
region: css({
position: 'fixed',
insetInlineEnd: '16px',
bottom: 'max(16px, env(safe-area-inset-bottom))',
width: 'min(380px, calc(100vw - 32px))',
display: 'flex',
flexDirection: 'column-reverse',
colorScheme: 'light dark',
color: 'light-dark(#202027, #eeeef2)',
font: '14px/1.5 "Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif',
pointerEvents: 'auto',
'--stack-expanded': 1,
'--stack-gap': '12px',
'--stack-position': 'relative',
'--stack-height': 'auto',
'--stack-overflow': 'visible',
'--stack-content-visibility': 'visible',
'&:not([data-expanded])': {
'--stack-expanded': 0,
'--stack-gap': '0px',
'--stack-position': 'absolute',
'--stack-height': '100%',
'--stack-overflow': 'hidden',
'--stack-content-visibility': 'hidden',
},
'&, & *': {
boxSizing: 'border-box',
},
}),
toastLayout: css({
position: 'var(--stack-position)',
height: 'var(--stack-height)',
bottom: 'calc(var(--toast-index) * 14px * (1 - var(--stack-expanded)))',
insetInline: 0,
alignSelf: 'end',
zIndex: 'calc(100 - var(--toast-index))',
display: 'grid',
gridTemplateRows: '1fr',
alignContent: 'end',
marginBlockEnd: 'var(--stack-gap)',
flexShrink: 0,
width: '100%',
transition:
'grid-template-rows 140ms ease-out, margin-block-end 140ms ease-out, opacity 120ms ease-out',
'&[data-toast-index="0"]': {
marginBlockEnd: 0,
position: 'relative',
'--stack-height': 'auto',
'--stack-overflow': 'visible',
'--stack-content-visibility': 'visible',
},
'&[data-limited]': {
gridTemplateRows: '0fr',
marginBlockEnd: 0,
opacity: 0,
pointerEvents: 'none',
},
'&:focus-visible': {
outline: '2px solid currentColor',
outlineOffset: '3px',
},
'@media (prefers-reduced-motion: reduce)': {
transition: 'none',
},
}),
collapseSlot: css({
// Keep the surface full-sized while its grid row collapses.
minHeight: 0,
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
}),
surface: css({
position: 'relative',
height: 'var(--stack-height)',
overflow: 'var(--stack-overflow)',
scale: 'max(0.82, calc(1 - var(--toast-index) * 0.055 * (1 - var(--stack-expanded))))',
opacity: 'max(0.5, calc(1 - var(--toast-index) * 0.12 * (1 - var(--stack-expanded))))',
flexShrink: 0,
transformOrigin: 'bottom center',
transition: 'scale 160ms ease-out, opacity 120ms ease-out',
'@media (prefers-reduced-motion: reduce)': {
transition: 'none',
},
display: 'flex',
alignItems: 'center',
gap: '14px',
padding: '17px',
border: '1px solid light-dark(#dedee5, #41414a)',
borderRadius: '12px',
background: 'light-dark(#fff, #222228)',
boxShadow: '0 8px 28px #00000012, 0 2px 6px #00000008',
'&::after': {
content: '""',
position: 'absolute',
insetInline: 0,
top: '100%',
height: '13px',
},
}),
hideWhenCovered: css({
opacity: 'clamp(0, max(var(--stack-expanded), calc(1 - var(--toast-index))), 1)',
visibility: 'var(--stack-content-visibility)',
transition: 'opacity 90ms ease-out',
'@media (prefers-reduced-motion: reduce)': {
transition: 'none',
},
}),
message: css({
flex: 1,
minWidth: 0,
}),
title: css({
margin: 0,
display: 'block',
fontSize: '13px',
}),
description: css({
margin: '4px 0 0',
fontSize: '12px',
color: 'light-dark(#62626c, #b0b0bb)',
}),
dismissButton: css({
appearance: 'none',
flexShrink: 0,
display: 'grid',
placeItems: 'center',
width: '28px',
height: '28px',
margin: '0 -5px 0 0',
border: 0,
borderRadius: '5px',
background: 'none',
color: 'light-dark(#777780, #a2a2ad)',
font: '20px/1 ui-sans-serif, system-ui, sans-serif',
cursor: 'pointer',
'&:hover': {
background: 'light-dark(#f0f0f5, #34343d)',
},
'&:focus-visible': {
outline: '2px solid currentColor',
outlineOffset: '2px',
},
}),
}