{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-notification",
  "type": "registry:ui",
  "title": "react-tw/notification.tsx",
  "description": "Carbon notification as a React + Tailwind component, the look and rules of `<ui-notification>`: Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-notification",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/notification.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/notification.tsx",
      "content": "import type { CSSProperties, ReactNode, ComponentProps } from 'react';\nimport type { NotificationKind, NotificationRole, NotificationVariant } from '../core/notification.ts';\nimport { Notification as NotificationPrimitive } from '@purpurabog/ui/headless';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon notification as a React + Tailwind component, the look and rules of `<ui-notification>`:\n * `InlineNotification` (default), `ToastNotification` (`variant=\"toast\"`), `ActionableNotification`\n * (any variant with `actionLabel`) and `Callout` (`variant=\"callout\"`). 3px status bar, 20px\n * icon, inverse surface or `lowContrast` tint, 48px close button. Role and countdown come from\n * core/notification: `status` by default, `alertdialog` with an action (focus moves to it, Tab\n * stays inside it, Esc closes); a toast's `timeout` pauses while hovered or focused and never runs\n * with an action. `fullWidth` fills the container (no Carbon counterpart).\n * Closing calls `onClose(reason)`; return `false` to keep it open.\n */\nexport type NotificationCloseReason = NotificationPrimitive.NotificationCloseReason;\n\nexport interface NotificationProps extends Omit<ComponentProps<'div'>, 'variant' | 'kind' | 'lowContrast' | 'title' | 'subtitle' | 'caption' | 'children' | 'actionLabel' | 'onAction' | 'role' | 'timeout' | 'hideCloseButton' | 'closeOnEscape' | 'noAutofocus' | 'closeLabel' | 'iconLabel' | 'open' | 'onClose' | 'fullWidth' | 'lang' | 'className'> {\n    variant?: NotificationVariant;\n    kind?: NotificationKind;\n    lowContrast?: boolean;\n    title?: ReactNode;\n    subtitle?: ReactNode;\n    /** Toast only: small text under the subtitle, e.g. the time. */\n    caption?: ReactNode;\n    /** Extra content after the subtitle (links, details). */\n    children?: ReactNode;\n    /** Label of the action button (Carbon actionable notification). */\n    actionLabel?: string;\n    onAction?: () => void;\n    role?: NotificationRole;\n    /** Milliseconds after which it closes itself (toast); 0 = never. */\n    timeout?: number;\n    hideCloseButton?: boolean;\n    /** Esc closes an actionable notification while focus is inside it (Carbon `closeOnEscape`). */\n    closeOnEscape?: boolean;\n    /** Keep focus where it is instead of moving it to the action button. */\n    noAutofocus?: boolean;\n    /** Fills its container instead of Carbon's 288–832px cap (inline / callout; a toast stays 288px). */\n    fullWidth?: boolean;\n    closeLabel?: string;\n    /** Accessible name of the status icon (default \"`kind` icon\", as Carbon). */\n    iconLabel?: string;\n    /** Controlled visibility; without it the notification hides itself when closed. */\n    open?: boolean;\n    /** Return `false` to keep it open. */\n    onClose?: (reason: NotificationCloseReason) => boolean | void;\n    lang?: string;\n    className?: string;\n}\n\nconst ICONS: Record<NotificationKind, ReactNode> = {\n    error: <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm3.5 13.5L10 11l-3.5 3.5L5 13l3.5-3.5L5 6l1.5-1.5L10 8l3.5-3.5L15 6l-3.5 3.5L15 13z\" />,\n    success: <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18ZM8.5 14 4.4 9.9l1.4-1.4 2.7 2.7 5.7-5.7 1.4 1.4z\" />,\n    info: <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm0 3.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5ZM12.5 15h-5v-1.5H9V10H7.5V8.5H11v5h1.5z\" />,\n    'info-square': <path d=\"M17 1H3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-7 3.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5ZM12.5 15h-5v-1.5H9V10H7.5V8.5H11v5h1.5z\" />,\n    warning: (\n        <>\n            <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Z\" />\n            <path className=\"mark\" d=\"M9.25 5h1.5v6.5h-1.5zM10 15.3a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2Z\" />\n        </>\n    ),\n    'warning-alt': (\n        <>\n            <path d=\"M10.9 1.6a1 1 0 0 0-1.8 0L1.2 17a1 1 0 0 0 .9 1.5h15.8a1 1 0 0 0 .9-1.5z\" />\n            <path className=\"mark\" d=\"M9.25 7h1.5v5.5h-1.5zM10 16.3a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2Z\" />\n        </>\n    ),\n};\n\n/** Status colour and low-contrast tint of each kind. */\nfunction kindColours(kind: NotificationKind): CSSProperties {\n    const base = kind.split('-')[0] as 'error' | 'success' | 'info' | 'warning';\n    return { '--_kind': `var(--ui-${base})`, '--_bg': `var(--ui-notification-background-${base})` } as CSSProperties;\n}\n\n/** The 3px status bar on the inverse surface (or the low-contrast tint with a 1px frame); toasts are 288px with a shadow. */\nfunction boxClasses(toast: boolean, lowContrast: boolean, fullWidth: boolean) {\n    return cn(\n        // --ui-notification-radius: Carbon's notifications are square; a design can round them\n        'relative box-border flex w-full min-w-[288px] flex-wrap rounded-[var(--ui-notification-radius,0px)] border-0 border-s-[length:var(--ui-notification-bar-width,3px)] border-solid border-s-(--_kind) bg-[var(--ui-notification-background,var(--ui-inverse-canvas))] text-[var(--ui-notification-ink,var(--ui-inverse-ink))]',\n        // the high-contrast surface: a design can make it an elevated one (--ui-notification-*), as <ui-notification>\n        !lowContrast && !toast && 'shadow-[var(--ui-notification-edge,none)]',\n        toast\n            ? 'min-h-0 w-[288px] max-w-[288px] ps-[13px] shadow-[var(--ui-toast-shadow,0_2px_6px_0_rgb(0_0_0/0.2))]'\n            : 'min-h-12 max-w-[288px] min-[672px]:max-w-[608px] min-[672px]:flex-nowrap min-[1056px]:max-w-[736px] min-[1584px]:max-w-[832px]',\n        fullWidth && !toast && 'min-w-0 max-w-none min-[672px]:max-w-none min-[1056px]:max-w-none min-[1584px]:max-w-none',\n        lowContrast && \"bg-(--_bg) text-ink before:pointer-events-none before:absolute before:inset-0 before:box-border before:rounded-[inherit] before:border before:border-s-[length:var(--ui-notification-frame-start,0px)] before:border-solid before:border-(--_kind) before:[filter:opacity(0.4)] before:content-['']\",\n        'forced-colors:border forced-colors:border-s-[3px] forced-colors:border-[CanvasText]',\n    );\n}\n\ninterface NotificationTextProps {\n    title?: ReactNode;\n    subtitle?: ReactNode;\n    caption?: ReactNode;\n    toast: boolean;\n    lowContrast: boolean;\n    children?: ReactNode;\n}\n\n/** Title, subtitle, extra content and (toast) caption; inline they run on one line, a toast stacks them. */\nfunction NotificationText({ title, subtitle, caption, toast, lowContrast, children }: Readonly<NotificationTextProps>) {\n    return (\n        <div\n            className={cn(\n                toast ? 'block p-0' : 'flex flex-wrap py-[15px]',\n                '[&>:not(span)]:type-body-sm [&>:not(span)]:leading-[18px]! [&>:not(span)]:[overflow-wrap:anywhere]',\n                '[&_a]:text-[var(--ui-notification-link,var(--ui-link-inverse))] [&_a]:no-underline [&_a:hover]:underline',\n                lowContrast && '[&_a]:text-primary',\n            )}\n        >\n            {title ? (\n                <NotificationPrimitive.Title className={cn('type-body-emphasis leading-[18px]!', toast ? 'mt-4 block [overflow-wrap:anywhere]' : 'me-1')}>\n                    {title}\n                </NotificationPrimitive.Title>\n            ) : null}\n            {subtitle ? (\n                <NotificationPrimitive.Subtitle className={cn('type-body-sm leading-[18px]! [overflow-wrap:anywhere]', toast && 'mb-4 block')}>\n                    {subtitle}\n                </NotificationPrimitive.Subtitle>\n            ) : null}\n            {children}\n            {caption ? <span className=\"w-full pt-2 type-body-sm leading-[18px]! [overflow-wrap:anywhere]\">{caption}</span> : null}\n        </div>\n    );\n}\n\ninterface ActionButtonProps {\n    onAction?: () => void;\n    toast: boolean;\n    lowContrast: boolean;\n    children: ReactNode;\n}\n\n/** Carbon's notification action: a tertiary-inverse button in a toast, a ghost link-coloured one inline. */\nfunction ActionButton({ onAction, toast, lowContrast, children }: Readonly<ActionButtonProps>) {\n    return (\n        <NotificationPrimitive.Action\n            onClick={onAction}\n            className={cn(\n                // a button: the button setting for its corners (Kanok: a pill)\n                'box-border inline-flex h-8 cursor-pointer items-center rounded-[var(--ui-button-radius,0px)] border border-solid border-transparent bg-transparent px-4 type-button',\n                // Carbon .cds--btn: 70ms, entrance productive\n                'transition-[background,box-shadow,border-color,outline] duration-(--ui-duration-fast) ease-(--ui-easing-entrance)',\n                'focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:[outline-offset:var(--ui-focus-offset,-2px)] focus-visible:outline-[var(--ui-notification-focus,var(--ui-inverse-ink))] forced-colors:border-[ButtonText]',\n                toast\n                    ? 'm-0 ms-[49px] mb-4 border-notification-action-tertiary-inverse text-notification-action-tertiary-inverse hover:bg-notification-action-tertiary-inverse-hover hover:text-notification-action-tertiary-inverse-text active:bg-notification-action-tertiary-inverse-active'\n                    : 'ms-8 mb-2 text-[var(--ui-notification-link,var(--ui-link-inverse))] hover:bg-[var(--ui-notification-hover,var(--ui-inverse-hover))] min-[672px]:mx-0 min-[672px]:my-2',\n                lowContrast && !toast && 'text-[var(--ui-button-tertiary-ink,var(--ui-primary))] hover:bg-notification-action-hover focus-visible:outline-focus',\n                lowContrast && toast && 'border-[var(--ui-button-tertiary-border,var(--ui-primary))] text-[var(--ui-button-tertiary-ink,var(--ui-primary))] hover:bg-primary hover:text-on-primary focus-visible:outline-focus',\n            )}\n        >\n            {children}\n        </NotificationPrimitive.Action>\n    );\n}\n\n/** The 48px close button in the top end corner (inline from 672px: in the row). */\nfunction CloseButton({ label, toast, actionable, lowContrast }: Readonly<{ label: string; toast: boolean; actionable: boolean; lowContrast: boolean }>) {\n    return (\n        <NotificationPrimitive.Close\n            aria-label={label}\n            title={label}\n            className={cn(\n                'absolute end-0 top-0 flex size-[var(--ui-close-size,48px)] min-h-[var(--ui-close-size,48px)] min-w-[var(--ui-close-size,48px)] m-[var(--ui-close-inset,0px)] rounded-[var(--ui-icon-control-radius,0px)] cursor-pointer items-center justify-center border-0 bg-transparent p-0 text-inherit',\n                // Carbon: a toast's close button 250ms (no token) with the default easing, an inline or actionable one 110ms standard\n                toast && !actionable\n                    ? 'transition-[outline,background-color] duration-0 ease-[ease] motion-safe:duration-250'\n                    : 'transition-[outline,background-color] duration-(--ui-duration-moderate) ease-carbon',\n                'focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:[outline-offset:var(--ui-focus-offset,-2px)] focus-visible:outline-[var(--ui-notification-focus,var(--ui-inverse-ink))] [&_svg]:size-5 [&_svg]:fill-current',\n                !toast && 'min-[672px]:static',\n                lowContrast && 'focus-visible:outline-focus',\n                'forced-colors:border forced-colors:border-solid forced-colors:border-[ButtonText]',\n            )}\n        >\n            <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\">\n                <path d=\"M15 6.4 13.6 5 10 8.6 6.4 5 5 6.4 8.6 10 5 13.6 6.4 15l3.6-3.6 3.6 3.6 1.4-1.4-3.6-3.6z\" />\n            </svg>\n        </NotificationPrimitive.Close>\n    );\n}\n\nexport function Notification({\n    variant = 'inline',\n    kind = 'error',\n    lowContrast,\n    title,\n    subtitle,\n    caption,\n    children,\n    actionLabel,\n    onAction,\n    role,\n    timeout = 0,\n    hideCloseButton,\n    closeOnEscape = true,\n    noAutofocus,\n    fullWidth = false,\n    closeLabel,\n    iconLabel,\n    open,\n    onClose,\n    lang,\n    className,\n    ...rest\n}: Readonly<NotificationProps>) {\n    const t = useTranslation(lang).common;\n    const toast = variant === 'toast';\n    const closeName = closeLabel ?? t.closeNotification;\n    return (\n        <NotificationPrimitive.Root open={open} onClose={onClose} variant={variant} role={role} actionable={!!actionLabel} timeout={timeout} closeOnEscape={closeOnEscape} autoFocus={!noAutofocus}>\n            <div {...rest} className={cn('block font-sans', className)}>\n                <NotificationPrimitive.Box style={kindColours(kind)} className={boxClasses(toast, !!lowContrast, fullWidth)}>\n                    <div className={cn('flex grow', toast ? 'm-0 me-12 mb-4' : 'ms-[13px] me-12 min-[672px]:mx-[13px]', fullWidth && !toast && 'max-[671.98px]:basis-[calc(100%-61px)]')}>\n                        <svg\n                            className={cn('me-4 size-5 shrink-0 fill-(--_kind) [&_.mark]:fill-[#161616]', toast ? 'mt-4' : 'mt-[14px]')}\n                            viewBox=\"0 0 20 20\"\n                            role=\"img\"\n                            aria-label={iconLabel ?? `${kind} icon`}\n                        >\n                            {ICONS[kind]}\n                        </svg>\n                        <NotificationText title={title} subtitle={subtitle} caption={caption} toast={toast} lowContrast={!!lowContrast}>\n                            {children}\n                        </NotificationText>\n                    </div>\n                    {actionLabel ? (\n                        <ActionButton onAction={onAction} toast={toast} lowContrast={!!lowContrast}>\n                            {actionLabel}\n                        </ActionButton>\n                    ) : null}\n                    {hideCloseButton || variant === 'callout' ? null : <CloseButton label={closeName} toast={toast} actionable={!!actionLabel} lowContrast={!!lowContrast} />}\n                </NotificationPrimitive.Box>\n            </div>\n        </NotificationPrimitive.Root>\n    );\n}\n"
    }
  ]
}
