{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-modal",
  "type": "registry:ui",
  "title": "react-tw/modal.tsx",
  "description": "Carbon `Modal` as a React + Tailwind component: the look and rules of `<ui-modal>` on the headless 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-modal",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/modal.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/modal.tsx",
      "content": "import { useId, type ReactNode, type ComponentProps } from 'react';\nimport { closesOnOutsideClick, type ModalCloseReason } from '../core/modal.ts';\nimport { Modal as ModalPrimitive } from '@purpurabog/ui/headless';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Modal` as a React + Tailwind component: the look and rules of `<ui-modal>` on the headless\n * `Modal` (native `<dialog>` + showModal(): top layer, inert page, focus trap, Esc, focus return). First\n * focus as Carbon: an `autoFocus` control, else the first control in the body, else the first\n * footer button, else ×; an `alert` starts on the least destructive footer button. A body that\n * overflows becomes a focusable, labelled region. A modal with a footer never closes on an outside\n * click; a passive one does unless `persistent`. Controlled: `onClose(reason)` reports ×, Esc, an\n * outside click or a `<form method=\"dialog\">`; set `open` to false to close (or don't, to keep it).\n */\nexport interface ModalProps extends Omit<ComponentProps<'dialog'>, 'open' | 'onClose' | 'heading' | 'label' | 'aria-label' | 'size' | 'persistent' | 'alert' | 'closeLabel' | 'footer' | 'headerActions' | 'children' | 'lang' | 'className'> {\n    open: boolean;\n    onClose?: (reason: ModalCloseReason) => void;\n    heading?: ReactNode;\n    /** Small label above the heading. */\n    label?: ReactNode;\n    /** Accessible name when there is no heading or label. */\n    'aria-label'?: string;\n    size?: 'sm' | 'md' | 'lg';\n    /** A passive modal (no footer) doesn't close on an outside click either. */\n    persistent?: boolean;\n    /** role=\"alertdialog\" for confirmations that interrupt; the body becomes the description. */\n    alert?: boolean;\n    closeLabel?: string;\n    /** Action buttons, laid out full-bleed (each half the width), Carbon style. */\n    footer?: ReactNode;\n    /** Controls at the top end of the header, beside × (one 48px button fits). */\n    headerActions?: ReactNode;\n    children?: ReactNode;\n    lang?: string;\n    className?: string;\n}\n\nconst WIDTH = { sm: 'w-[min(100%_-_2*var(--ui-space-md),480px)]', md: 'w-[min(100%_-_2*var(--ui-space-md),672px)]', lg: 'w-[min(100%_-_2*var(--ui-space-md),1056px)]' } as const;\n\nexport function Modal({ open, onClose, heading, label, 'aria-label': ariaLabel, size = 'md', persistent, alert, closeLabel, footer, headerActions, children, lang, className, ref, ...rest }: Readonly<ModalProps>) {\n    const t = useTranslation(lang).common;\n    const ids = useId();\n    // named by the heading (the primitive's Title), else the small label, else aria-label\n    const labelId = !heading && label ? `${ids}-label` : undefined;\n    return (\n        <ModalPrimitive.Root {...rest}\n            ref={ref}\n            open={open}\n            onClose={onClose}\n            alert={alert}\n            closeOnOutsideClick={closesOnOutsideClick(!!persistent, !!footer)}\n            aria-labelledby={labelId}\n            aria-label={heading || label ? undefined : ariaLabel}\n            className={cn(\n                // --ui-modal-radius / -shadow: Carbon's modal is square and flat; a design can round it and lift it\n                'm-auto box-border max-h-[min(100%_-_2*var(--ui-space-xxl),768px)] rounded-[var(--ui-modal-radius,0px)] [border:var(--ui-overlay-border,0_solid)] bg-[var(--ui-overlay-background,var(--ui-surface-1))] p-0 font-sans text-ink shadow-[var(--ui-modal-shadow,none)]',\n                WIDTH[size],\n                // flex-col on the dialog, not only while open: a closing one stays on screen while it fades out\n                'flex-col open:flex backdrop:bg-[var(--ui-modal-scrim,rgb(22_22_22/0.5))] ui-modal-motion',\n                'forced-colors:border forced-colors:border-solid forced-colors:border-[CanvasText]',\n                className,\n            )}\n        >\n            <header className={cn('relative px-4 pt-4 pb-2 pe-12', headerActions && 'pe-24')}>\n                {headerActions ? <div className=\"absolute end-12 top-0 flex h-12 items-center\">{headerActions}</div> : null}\n                {label ? (\n                    <p id={`${ids}-label`} className=\"m-0 mb-1 type-caption text-ink-muted\">\n                        {label}\n                    </p>\n                ) : null}\n                {heading ? (\n                    <ModalPrimitive.Title id={`${ids}-heading`} className=\"m-0 pe-[calc(20%_-_48px)] type-subhead\">\n                        {heading}\n                    </ModalPrimitive.Title>\n                ) : null}\n                <ModalPrimitive.Close\n                    aria-label={closeLabel ?? t.close}\n                    className=\"absolute end-0 top-0 grid size-[var(--ui-close-size,48px)] m-[var(--ui-close-inset,0px)] rounded-[var(--ui-icon-control-radius,0px)] cursor-pointer place-items-center border-0 bg-transparent p-0 text-ink transition-[background-color] duration-(--ui-duration-moderate) ease-carbon hover:bg-ghost-hover focus-visible:focus-ring [&_svg]:size-5 [&_svg]:fill-current\"\n                >\n                    <svg viewBox=\"0 0 32 32\" aria-hidden=\"true\">\n                        <path d=\"M24 9.4 22.6 8 16 14.6 9.4 8 8 9.4l6.6 6.6L8 22.6 9.4 24l6.6-6.6 6.6 6.6 1.4-1.4-6.6-6.6z\" />\n                    </svg>\n                </ModalPrimitive.Close>\n            </header>\n            <ModalPrimitive.Body\n                id={`${ids}-body`}\n                className=\"flex-1 overflow-y-auto px-4 pt-2 pb-12 type-body outline-none focus-visible:focus-ring-inset focus-visible:rounded-[var(--ui-modal-body-focus-radius,0px)]\"\n            >\n                <div>{children}</div>\n            </ModalPrimitive.Body>\n            {/* Carbon: 64px tall, buttons take half each, text at the top; --ui-modal-footer-* / --ui-modal-button-* let a design use ordinary buttons at the end, under a rule */}\n            {footer ? (\n                <ModalPrimitive.Footer\n                    className={cn(\n                        'flex min-h-[var(--ui-modal-footer-height,64px)] justify-end gap-[var(--ui-modal-footer-gap,normal)] p-[var(--ui-modal-footer-padding,0px)] [border-block-start:var(--ui-modal-footer-border,0_solid)]',\n                        '[--ui-field-height-lg:var(--ui-modal-button-height,64px)] [&>*]:[flex:var(--ui-modal-button-flex,0_1_50%)]',\n                        '[&>a]:[align-items:var(--ui-modal-button-align,flex-start)] [&>a]:pt-[var(--ui-modal-button-padding-top,14px)] [&>button]:[align-items:var(--ui-modal-button-align,flex-start)] [&>button]:pt-[var(--ui-modal-button-padding-top,14px)]',\n                    )}\n                >\n                    {footer}\n                </ModalPrimitive.Footer>\n            ) : null}\n        </ModalPrimitive.Root>\n    );\n}\n"
    }
  ]
}
