{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert-dialog",
  "type": "registry:ui",
  "title": "Alert Dialog",
  "description": "Alert dialog for Tile UI.",
  "dependencies": [
    "@radix-ui/react-slot",
    "react-dom"
  ],
  "devDependencies": [
    "sass"
  ],
  "registryDependencies": [
    "@tile-ui/core",
    "button",
    "@tile-ui/portal",
    "@tile-ui/styles"
  ],
  "files": [
    {
      "path": "packages/react/src/components/alert-dialog/alert-dialog.tsx",
      "type": "registry:ui",
      "target": "components/ui/alert-dialog/alert-dialog.tsx",
      "content": "import React, { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Slot } from '@radix-ui/react-slot';\nimport type { ButtonSize, ButtonVariant } from '../lib/core';\nimport { alertDialogStyleKeys, getAlertDialogState } from '../lib/core';\nimport type { AlertDialogBaseProps, AlertDialogSize } from '../lib/core';\nimport { Button } from '../button';\nimport { usePortalContainer, type PortalContainer } from '../portal';\nimport styles from './alert-dialog.module.scss';\n\ninterface AlertDialogContextValue {\n\topen: boolean;\n\tsetOpen: (open: boolean) => void;\n\tclose: () => void;\n\ttitleId: string;\n\tdescriptionId: string;\n}\n\nconst AlertDialogContext = createContext<AlertDialogContextValue | null>(null);\n\nfunction useAlertDialogContext(): AlertDialogContextValue {\n\tconst context = useContext(AlertDialogContext);\n\tif (!context) {\n\t\tthrow new Error('AlertDialog sub-components must be used within <AlertDialog>.');\n\t}\n\treturn context;\n}\n\nexport interface AlertDialogProps extends AlertDialogBaseProps {\n\topen?: boolean;\n\tdefaultOpen?: boolean;\n\tonOpenChange?: (open: boolean) => void;\n\tchildren?: React.ReactNode;\n}\n\nfunction AlertDialog({ open, defaultOpen = false, onOpenChange, children }: AlertDialogProps) {\n\tconst [internalOpen, setInternalOpen] = useState(defaultOpen);\n\tconst onOpenChangeRef = useRef(onOpenChange);\n\n\tuseEffect(() => {\n\t\tonOpenChangeRef.current = onOpenChange;\n\t});\n\n\tconst setOpen = useCallback(\n\t\t(next: boolean) => {\n\t\t\tif (open === undefined) {\n\t\t\t\tsetInternalOpen(next);\n\t\t\t}\n\n\t\t\tonOpenChangeRef.current?.(next);\n\t\t},\n\t\t[open],\n\t);\n\n\tconst close = useCallback(() => {\n\t\tsetOpen(false);\n\t}, [setOpen]);\n\n\tconst isOpen = open !== undefined ? open : internalOpen;\n\tconst titleId = useId();\n\tconst descriptionId = useId();\n\n\treturn <AlertDialogContext.Provider value={{ open: isOpen, setOpen, close, titleId, descriptionId }}>{children}</AlertDialogContext.Provider>;\n}\n\nAlertDialog.displayName = 'AlertDialog';\n\nexport interface AlertDialogTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n\tasChild?: boolean;\n}\n\nconst AlertDialogTrigger = React.forwardRef<HTMLButtonElement, AlertDialogTriggerProps>(({ asChild = false, className = '', children, onClick, ...props }, ref) => {\n\tconst context = useAlertDialogContext();\n\tconst Comp = asChild ? Slot : 'button';\n\n\treturn (\n\t\t<Comp\n\t\t\tref={ref}\n\t\t\ttype={asChild ? undefined : 'button'}\n\t\t\tclassName={className}\n\t\t\tonClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tcontext.setOpen(true);\n\t\t\t}}\n\t\t\t{...props}>\n\t\t\t{children}\n\t\t</Comp>\n\t);\n});\nAlertDialogTrigger.displayName = 'AlertDialogTrigger';\n\nexport interface AlertDialogOverlayProps extends React.HTMLAttributes<HTMLDivElement> {}\n\nconst AlertDialogOverlay = React.forwardRef<HTMLDivElement, AlertDialogOverlayProps>(({ className = '', onClick, ...props }, ref) => {\n\tconst context = useAlertDialogContext();\n\n\tif (!context.open) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-state={getAlertDialogState(context.open)}\n\t\t\tclassName={`${styles[alertDialogStyleKeys.overlay]} ${className}`}\n\t\t\tonClick={(event: React.MouseEvent<HTMLDivElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tcontext.close();\n\t\t\t}}\n\t\t\t{...props}\n\t\t/>\n\t);\n});\nAlertDialogOverlay.displayName = 'AlertDialogOverlay';\n\nexport interface AlertDialogContentProps extends React.HTMLAttributes<HTMLDivElement> {\n\tsize?: AlertDialogSize;\n\tcontainer?: PortalContainer;\n}\n\nconst AlertDialogContent = React.forwardRef<HTMLDivElement, AlertDialogContentProps>(({ className = '', size = 'default', container, children, ...props }, ref) => {\n\tconst { open, close, titleId, descriptionId } = useAlertDialogContext();\n\tconst portalContainer = usePortalContainer(container);\n\tconst contentRef = useRef<HTMLDivElement | null>(null);\n\n\tfunction setContentRef(element: HTMLDivElement | null) {\n\t\tcontentRef.current = element;\n\n\t\tif (typeof ref === 'function') {\n\t\t\tref(element);\n\t\t} else if (ref) {\n\t\t\tref.current = element;\n\t\t}\n\t}\n\n\tuseLayoutEffect(() => {\n\t\tif (!open) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst previouslyFocused = document.activeElement as HTMLElement | null;\n\t\tconst previousOverflow = document.body.style.overflow;\n\t\tdocument.body.style.overflow = 'hidden';\n\n\t\tconst handleKeyDown = (event: KeyboardEvent) => {\n\t\t\tif (event.key === 'Escape') {\n\t\t\t\tclose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (event.key === 'Tab') {\n\t\t\t\tconst container = contentRef.current;\n\t\t\t\tif (!container) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst focusables = Array.from(\n\t\t\t\t\tcontainer.querySelectorAll<HTMLElement>(\n\t\t\t\t\t\t'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])',\n\t\t\t\t\t),\n\t\t\t\t).filter((el) => el.getClientRects().length > 0);\n\t\t\t\tif (focusables.length === 0) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst first = focusables[0];\n\t\t\t\tconst last = focusables[focusables.length - 1];\n\t\t\t\tconst active = document.activeElement;\n\n\t\t\t\tif (event.shiftKey) {\n\t\t\t\t\tif (active === first || active === container || !container.contains(active)) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tlast.focus();\n\t\t\t\t\t}\n\t\t\t\t} else if (active === last || !container.contains(active)) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tfirst.focus();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tdocument.addEventListener('keydown', handleKeyDown);\n\n\t\tconst contentEl = contentRef.current;\n\t\tif (contentEl) {\n\t\t\tcontentEl.focus();\n\t\t}\n\n\t\treturn () => {\n\t\t\tdocument.body.style.overflow = previousOverflow;\n\t\t\tdocument.removeEventListener('keydown', handleKeyDown);\n\t\t\tpreviouslyFocused?.focus();\n\t\t};\n\t}, [close, open]);\n\n\tif (!open || !portalContainer) {\n\t\treturn null;\n\t}\n\n\treturn createPortal(\n\t\t<>\n\t\t\t<AlertDialogOverlay />\n\t\t\t<div\n\t\t\t\tref={setContentRef}\n\t\t\t\trole=\"alertdialog\"\n\t\t\t\taria-modal=\"true\"\n\t\t\t\taria-labelledby={titleId}\n\t\t\t\taria-describedby={descriptionId}\n\t\t\t\ttabIndex={-1}\n\t\t\t\tdata-state={getAlertDialogState(open)}\n\t\t\t\tdata-size={size}\n\t\t\t\tclassName={`${styles[alertDialogStyleKeys.content]} ${className}`}\n\t\t\t\t{...props}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</>,\n\t\tportalContainer,\n\t);\n});\nAlertDialogContent.displayName = 'AlertDialogContent';\n\nexport interface AlertDialogHeaderProps extends React.HTMLAttributes<HTMLDivElement> {}\n\nconst AlertDialogHeader = React.forwardRef<HTMLDivElement, AlertDialogHeaderProps>(({ className = '', children, ...props }, ref) => {\n\treturn (\n\t\t<div ref={ref} className={`${styles[alertDialogStyleKeys.header]} ${className}`} {...props}>\n\t\t\t{children}\n\t\t</div>\n\t);\n});\nAlertDialogHeader.displayName = 'AlertDialogHeader';\n\nexport interface AlertDialogFooterProps extends React.HTMLAttributes<HTMLDivElement> {}\n\nconst AlertDialogFooter = React.forwardRef<HTMLDivElement, AlertDialogFooterProps>(({ className = '', children, ...props }, ref) => {\n\treturn (\n\t\t<div ref={ref} className={`${styles[alertDialogStyleKeys.footer]} ${className}`} {...props}>\n\t\t\t{children}\n\t\t</div>\n\t);\n});\nAlertDialogFooter.displayName = 'AlertDialogFooter';\n\nexport interface AlertDialogTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}\n\nconst AlertDialogTitle = React.forwardRef<HTMLHeadingElement, AlertDialogTitleProps>(({ className = '', children, ...props }, ref) => {\n\tconst context = useAlertDialogContext();\n\n\treturn (\n\t\t<h2 ref={ref} id={context.titleId} className={`${styles[alertDialogStyleKeys.title]} ${className}`} {...props}>\n\t\t\t{children}\n\t\t</h2>\n\t);\n});\nAlertDialogTitle.displayName = 'AlertDialogTitle';\n\nexport interface AlertDialogDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}\n\nconst AlertDialogDescription = React.forwardRef<HTMLParagraphElement, AlertDialogDescriptionProps>(({ className = '', children, ...props }, ref) => {\n\tconst context = useAlertDialogContext();\n\n\treturn (\n\t\t<p ref={ref} id={context.descriptionId} className={`${styles[alertDialogStyleKeys.description]} ${className}`} {...props}>\n\t\t\t{children}\n\t\t</p>\n\t);\n});\nAlertDialogDescription.displayName = 'AlertDialogDescription';\n\nexport interface AlertDialogActionProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n\tvariant?: ButtonVariant;\n\tsize?: ButtonSize;\n}\n\nconst AlertDialogAction = React.forwardRef<HTMLButtonElement, AlertDialogActionProps>(\n\t({ className = '', variant = 'default', size = 'default', children, onClick, ...props }, ref) => {\n\t\tconst context = useAlertDialogContext();\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={variant}\n\t\t\t\tsize={size}\n\t\t\t\tclassName={className}\n\t\t\t\tonClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\t\tonClick?.(event);\n\t\t\t\t\tcontext.close();\n\t\t\t\t}}\n\t\t\t\t{...props}>\n\t\t\t\t{children}\n\t\t\t</Button>\n\t\t);\n\t},\n);\nAlertDialogAction.displayName = 'AlertDialogAction';\n\nexport interface AlertDialogCancelProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n\tvariant?: ButtonVariant;\n\tsize?: ButtonSize;\n}\n\nconst AlertDialogCancel = React.forwardRef<HTMLButtonElement, AlertDialogCancelProps>(\n\t({ className = '', variant = 'outline', size = 'default', children, onClick, ...props }, ref) => {\n\t\tconst context = useAlertDialogContext();\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tref={ref}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={variant}\n\t\t\t\tsize={size}\n\t\t\t\tclassName={className}\n\t\t\t\tonClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n\t\t\t\t\tonClick?.(event);\n\t\t\t\t\tcontext.close();\n\t\t\t\t}}\n\t\t\t\t{...props}>\n\t\t\t\t{children}\n\t\t\t</Button>\n\t\t);\n\t},\n);\nAlertDialogCancel.displayName = 'AlertDialogCancel';\n\nexport {\n\tAlertDialog,\n\tAlertDialogTrigger,\n\tAlertDialogOverlay,\n\tAlertDialogContent,\n\tAlertDialogHeader,\n\tAlertDialogFooter,\n\tAlertDialogTitle,\n\tAlertDialogDescription,\n\tAlertDialogAction,\n\tAlertDialogCancel,\n};\nexport default AlertDialog;\n"
    },
    {
      "path": "packages/styles/scss/components/alert-dialog.module.scss",
      "type": "registry:file",
      "target": "components/ui/alert-dialog/alert-dialog.module.scss",
      "content": "@use '../../../styles/variables/colors' as *;\n\n// 半透明遮罩\n.overlay {\n\tposition: fixed;\n\tinset: 0;\n\tz-index: $z-modal;\n\tbackground-color: var(--tile-alert-dialog-overlay, $overlay);\n\n\t&[data-state='open'] {\n\t\tanimation: alert-dialog-overlay-in $transition-normal;\n\t}\n\n\t&[data-state='closed'] {\n\t\topacity: 0;\n\t}\n}\n\n@keyframes alert-dialog-overlay-in {\n\tfrom {\n\t\topacity: 0;\n\t}\n\n\tto {\n\t\topacity: 1;\n\t}\n}\n\n// 弹层内容面板\n.content {\n\tposition: fixed;\n\ttop: var(--tile-alert-dialog-top, 50%);\n\tleft: 50%;\n\tz-index: $z-modal;\n\tdisplay: grid;\n\twidth: 100%;\n\tmax-width: calc(100% - 2rem);\n\ttransform: translate(-50%, var(--tile-alert-dialog-translate-y, -50%));\n\tgap: $spacing-4;\n\tborder: 1px solid var(--tile-alert-dialog-border, $border);\n\tborder-radius: var(--tile-alert-dialog-radius, $radius-lg);\n\tbackground-color: var(--tile-alert-dialog-background, $card);\n\tcolor: $card-foreground;\n\tpadding: var(--tile-alert-dialog-padding, $spacing-6);\n\tbox-shadow: var(--tile-alert-dialog-shadow, $shadow-lg);\n\toutline: none;\n\n\t@media (min-width: 640px) {\n\t\ttop: var(--tile-alert-dialog-top-desktop, 50%);\n\t\tmax-width: var(--tile-alert-dialog-max-width, 32rem);\n\t}\n\n\t&[data-size='sm'] {\n\t\tmax-width: var(--tile-alert-dialog-sm-max-width, 20rem);\n\t}\n\n\t&[data-state='open'] {\n\t\tanimation: alert-dialog-content-in $transition-normal;\n\t}\n\n\t&[data-state='closed'] {\n\t\topacity: 0;\n\t\ttransform: translate(-50%, var(--tile-alert-dialog-translate-y, -50%)) scale(0.95);\n\t}\n}\n\n@keyframes alert-dialog-content-in {\n\tfrom {\n\t\topacity: 0;\n\t\ttransform: translate(-50%, var(--tile-alert-dialog-translate-y, -50%)) scale(0.95);\n\t}\n\n\tto {\n\t\topacity: 1;\n\t\ttransform: translate(-50%, var(--tile-alert-dialog-translate-y, -50%)) scale(1);\n\t}\n}\n\n.header {\n\tdisplay: flex;\n\tflex-direction: column;\n\talign-items: center;\n\tgap: $spacing-1_5;\n\ttext-align: center;\n\n\t@media (min-width: 640px) {\n\t\t.content[data-size='default'] & {\n\t\t\talign-items: flex-start;\n\t\t\ttext-align: left;\n\t\t}\n\t}\n}\n\n.footer {\n\tdisplay: flex;\n\tflex-direction: column-reverse;\n\tgap: $spacing-2;\n\n\t@media (min-width: 640px) {\n\t\t.content[data-size='default'] & {\n\t\t\tflex-direction: row;\n\t\t\tjustify-content: flex-end;\n\t\t}\n\t}\n}\n\n.title {\n\tmargin: 0;\n\tfont-size: var(--tile-alert-dialog-title-size, $text-lg);\n\tfont-weight: $font-semibold;\n\tline-height: var(--tile-alert-dialog-title-leading, $leading-tight);\n\tcolor: $foreground;\n}\n\n.description {\n\tmargin: 0;\n\tfont-size: var(--tile-alert-dialog-description-size, $text-sm);\n\tline-height: $leading-normal;\n\tcolor: var(--tile-alert-dialog-description-color, $muted-foreground);\n}\n"
    },
    {
      "path": "packages/react/src/components/alert-dialog/index.ts",
      "type": "registry:ui",
      "target": "components/ui/alert-dialog/index.ts",
      "content": "export {\n\tAlertDialog,\n\tAlertDialogTrigger,\n\tAlertDialogOverlay,\n\tAlertDialogContent,\n\tAlertDialogHeader,\n\tAlertDialogFooter,\n\tAlertDialogTitle,\n\tAlertDialogDescription,\n\tAlertDialogAction,\n\tAlertDialogCancel,\n\ttype AlertDialogProps,\n\ttype AlertDialogTriggerProps,\n\ttype AlertDialogOverlayProps,\n\ttype AlertDialogContentProps,\n\ttype AlertDialogHeaderProps,\n\ttype AlertDialogFooterProps,\n\ttype AlertDialogTitleProps,\n\ttype AlertDialogDescriptionProps,\n\ttype AlertDialogActionProps,\n\ttype AlertDialogCancelProps,\n} from './alert-dialog';\n"
    }
  ]
}
