{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast",
  "title": "Toast",
  "description": "Toasts in the bottom corner, each one open in a column, or stacked in a deck that spreads on hover. A new one arrives from the screen edge while the others make room, and a promise turns its toast from loading into the result in place.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/notice.json",
    "https://kinoui.com/r/theme.json",
    "https://kinoui.com/r/button.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/toast.tsx",
      "content": "'use client'\n\nimport { Button, buttonVariants } from '@/registry/components/kino/button'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  NoticeIcon,\n  noticeActionsClassName,\n  noticeDescriptionClassName,\n  noticeTextClassName,\n  noticeTitleClassName,\n} from '@/registry/lib/notice'\nimport {\n  createToaster,\n  toast,\n  ToastAction as ToastActionPrimitive,\n  ToastClose as ToastClosePrimitive,\n  ToastDescription as ToastDescriptionPrimitive,\n  Toast as ToastPrimitive,\n  ToastRegion,\n  type ToastData,\n  ToastTitle as ToastTitlePrimitive,\n} from '@ui-sdk/react/toast'\nimport { cva } from 'class-variance-authority'\nimport { type ComponentProps, createContext, type ReactNode, use, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype ToastVariant = 'list' | 'deck'\n\n/** Each toast reads how its region stacks them here. */\nconst ToastVariantContext = createContext<ToastVariant>('list')\n\n/** Whether the toast was sent back to wait past `maxVisible`, and now shows again behind the others. */\nconst ToastReturningContext = createContext(false)\n\n/*\n * Each toast sits at the bottom of the region and is moved up by ui-sdk's\n * `--toast-offset` (the toasts in front of it) and a gap per toast. Its\n * visible size is `--toast-surface-height`: the surface behind the content\n * transitions to it, and the content's clip follows, because the toast's own\n * height is measured by ui-sdk and can't transition.\n */\nconst toastVariants = cva(\n  [\n    'group/toast pointer-events-none absolute inset-x-0 bottom-0 z-[calc(100-var(--toast-index))] text-popover-foreground select-none [--toast-scale:1] [--toast-surface-height:var(--toast-height,100%)] [--toast-content-clip:inset(0_0_calc(100%-var(--toast-surface-height))_0)] [--toast-content-shift:calc(100%-var(--toast-surface-height))]',\n    'translate-y-[calc(-1*(var(--toast-offset)+var(--toast-index)*var(--toast-gap,0.625rem)))] scale-(--toast-scale) [transform:translateX(var(--toast-swipe-x,0px))_translateY(var(--toast-swipe-y,0px))]',\n    // A bridge over the gap below, so the pointer crossing it stays on the stack. The front one has no gap below it.\n    'after:pointer-events-auto after:absolute after:inset-x-0 after:top-full after:h-[calc(var(--toast-gap,0.625rem)+1px)] data-front:after:hidden',\n    // F6 focuses the front toast.\n    'rounded-(--surface-radius) focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-hidden',\n    /*\n     * Arrives from below the screen edge while the others make room; one that\n     * comes back from waiting past `maxVisible` fades in behind them, where it is. Closed, or\n     * sent back to wait, it fades and shrinks a little where it is. Swiped, it\n     * carries on the way it was thrown. While a finger drags it, it follows\n     * with no transition.\n     */\n    '[transition:translate_var(--motion-layout-duration)_var(--motion-layout-easing),scale_var(--motion-layout-duration)_var(--motion-layout-easing),transform_var(--motion-enter-duration)_var(--motion-enter-easing),opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] data-starting-style:opacity-0 data-starting-style:[transform:translateY(calc(100%+(--spacing(6))))] data-returning:data-starting-style:[transform:translateX(var(--toast-swipe-x,0px))_translateY(var(--toast-swipe-y,0px))] data-returning:data-starting-style:[transition-property:opacity] data-ending-style:scale-[calc(var(--toast-scale)*0.96)] data-ending-style:opacity-0 data-ending-style:[transition:translate_var(--motion-layout-duration)_var(--motion-layout-easing),scale_var(--motion-exit-duration)_var(--motion-exit-easing),transform_var(--motion-exit-duration)_var(--motion-exit-easing),opacity_var(--motion-exit-duration)_var(--motion-exit-easing)] data-swiping:[transition-property:translate,scale,opacity] data-ending-style:data-swipe-direction:scale-(--toast-scale) data-ending-style:data-[swipe-direction=down]:[transform:translateX(var(--toast-swipe-x,0px))_translateY(calc(var(--toast-swipe-y,0px)+110%))] data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-x,0px)-110%))_translateY(var(--toast-swipe-y,0px))] data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-x,0px)+110%))_translateY(var(--toast-swipe-y,0px))] motion-reduce:[transition-property:opacity] motion-reduce:data-ending-style:[transition-property:opacity] motion-reduce:data-starting-style:[transform:none] motion-reduce:data-ending-style:scale-(--toast-scale)! motion-reduce:data-ending-style:[transform:translateX(var(--toast-swipe-x,0px))_translateY(var(--toast-swipe-y,0px))]!',\n  ],\n  {\n    variants: {\n      variant: {\n        list: '',\n        // Collapsed, the ones behind take the front one's height, shrink and peek out above it.\n        deck: 'not-data-expanded:origin-bottom not-data-expanded:translate-y-[calc(-1*var(--toast-index)*var(--toast-peek,0.625rem)-(1-var(--toast-scale))*var(--toast-front-height,var(--toast-height)))] not-data-expanded:[--toast-scale:max(0,1-var(--toast-index)*0.05)] not-data-expanded:[--toast-surface-height:var(--toast-front-height,var(--toast-height,100%))]',\n      },\n    },\n    defaultVariants: { variant: 'list' },\n  },\n)\n\nfunction Toast({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof ToastPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const variant = use(ToastVariantContext)\n  const returning = use(ToastReturningContext)\n  return (\n    <ToastPrimitive\n      data-returning={returning ? '' : undefined}\n      className={cn(toastVariants({ variant }), className)}\n      {...props}\n    >\n      <span\n        aria-hidden\n        data-toast-surface=''\n        className='bg-popover ring-foreground/10 pointer-events-none absolute inset-x-0 bottom-0 h-(--toast-surface-height) rounded-(--surface-radius) shadow-lg ring-1 transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none forced-colors:outline'\n      />\n      {children}\n    </ToastPrimitive>\n  )\n}\n\nconst toastContentVariants = cva(\n  // Pinned to the surface's top and cut at its end while the surface catches up, so a toast that grows shows its title first.\n  // The close button sits 8px nearer the end than the content does, at every density.\n  'pointer-events-auto relative flex items-start gap-3 p-(--surface-padding) pe-[calc(var(--surface-padding)-(--spacing(2)))] translate-y-[var(--toast-content-shift,0px)] [clip-path:var(--toast-content-clip,none)] [transition:clip-path_var(--motion-layout-duration)_var(--motion-layout-easing),translate_var(--motion-layout-duration)_var(--motion-layout-easing),opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] motion-reduce:[transition-property:opacity]',\n  {\n    variants: {\n      variant: {\n        list: '',\n        // The text behind the front toast goes quickly, so it never shows through.\n        deck: 'group-not-data-front/toast:group-not-data-expanded/toast:opacity-0 group-not-data-front/toast:group-not-data-expanded/toast:[transition:clip-path_var(--motion-layout-duration)_var(--motion-layout-easing),translate_var(--motion-layout-duration)_var(--motion-layout-easing),opacity_calc(var(--motion-exit-duration)*0.5)_var(--motion-exit-easing)] motion-reduce:group-not-data-front/toast:group-not-data-expanded/toast:[transition-property:opacity]',\n      },\n    },\n    defaultVariants: { variant: 'list' },\n  },\n)\n\n/** What a toast shows, laid out in a row. */\nfunction ToastContent({\n  className,\n  ...props\n}: Omit<ComponentProps<'div'>, 'className'> & { className?: string }) {\n  const variant = use(ToastVariantContext)\n  return (\n    <div\n      data-slot='toast-content'\n      className={cn(toastContentVariants({ variant }), className)}\n      {...props}\n    />\n  )\n}\n\nfunction ToastTitle({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof ToastTitlePrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <ToastTitlePrimitive className={cn(noticeTitleClassName, className)} {...props} />\n  )\n}\n\nfunction ToastDescription({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof ToastDescriptionPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <ToastDescriptionPrimitive\n      className={cn(noticeDescriptionClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/*\n * The Button's look on ui-sdk's own element, which is a link when the action\n * has an `href`.\n */\nfunction ToastAction({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof ToastActionPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <ToastActionPrimitive\n      className={cn(buttonVariants({ variant: 'outline', size: 'sm' }), className)}\n      {...props}\n    />\n  )\n}\n\nfunction ToastClose({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof ToastClosePrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  return (\n    <ToastClosePrimitive\n      aria-label='Close'\n      render={\n        <Button\n          variant='ghost'\n          size='icon-xs'\n          className={cn('text-muted-foreground -mt-0.5', className)}\n        />\n      }\n      {...props}\n    >\n      {children ?? (\n        <IconPlaceholder\n          lucide='XIcon'\n          tabler='IconX'\n          hugeicons='Cancel01Icon'\n          phosphor='XIcon'\n          remixicon='RiCloseLine'\n          aria-hidden\n        />\n      )}\n    </ToastClosePrimitive>\n  )\n}\n\n/** The icon for a toast's `type`. The loading spinner rolls into the result. */\nfunction ToastIcon(props: ComponentProps<typeof NoticeIcon>) {\n  return <NoticeIcon data-toast-icon='' {...props} />\n}\n\ntype ToastRegionProps = ComponentProps<typeof ToastRegion>\n\n/**\n * The corner the toasts sit in, holding ui-sdk's region. Each toast shows in\n * the default layout (the icon for its type, its title, description and\n * action, and a close button), or as `children` renders it.\n */\nfunction Toaster({\n  variant = 'list',\n  className,\n  children,\n  ...props\n}: Omit<ToastRegionProps, 'className' | 'side' | 'align'> & {\n  className?: string\n  /** `list` keeps every toast open in a column; `deck` stacks them until hover or focus spreads them. */\n  variant?: ToastVariant\n}) {\n  const [waited] = useState(() => new Set<string>())\n  const render = children ?? defaultToast\n  return (\n    <ToastVariantContext value={variant}>\n      <ToastRegion\n        data-variant={variant}\n        className={cn(\n          // As wide as a phone's screen allows, with the same margin on each side as below; fixed\n          // from the server's page on, so the region never takes room beside what it sits in.\n          'group/toast-region fixed end-4 bottom-4 w-88 max-w-[calc(100vw-(--spacing(8)))]',\n          className,\n        )}\n        {...props}\n      >\n        {(data, item) => {\n          // ui-sdk marks a toast leaving when it closes and when it goes back to wait; only one that waited shows again.\n          if (item.leaving) waited.add(data.id)\n          return (\n            <ToastReturningContext value={item.index > 0 && waited.has(data.id)}>\n              {render(data, item)}\n            </ToastReturningContext>\n          )\n        }}\n      </ToastRegion>\n    </ToastVariantContext>\n  )\n}\n\nfunction defaultToast(data: ToastData<ReactNode>) {\n  return (\n    <Toast>\n      <ToastContent>\n        <ToastIcon type={data.type} />\n        <div className={noticeTextClassName}>\n          <ToastTitle />\n          <ToastDescription />\n          {data.action ? (\n            <div className={noticeActionsClassName}>\n              <ToastAction />\n            </div>\n          ) : null}\n        </div>\n        <ToastClose />\n      </ToastContent>\n    </Toast>\n  )\n}\n\nexport {\n  createToaster,\n  toast,\n  Toast,\n  ToastAction,\n  ToastClose,\n  ToastContent,\n  ToastDescription,\n  Toaster,\n  ToastIcon,\n  ToastTitle,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/toast.tsx"
    }
  ],
  "type": "registry:component"
}