# Alert Dialog URL: /lynx/components/alert-dialog Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/alert-dialog.mdx A component used as a strong expression and warning measure when user confirmation is absolutely required. Lynx Engine 최소 버전: 3.6 사용 XElement: 사용 가능 버전: @seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0 ## Preview ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 주의 이 작업은 되돌릴 수 없습니다. 취소 확인 ); } ``` ## Installation - npm: npx @seed-design/cli add ui:alert-dialog - pnpm: pnpm dlx @seed-design/cli add ui:alert-dialog - yarn: yarn dlx @seed-design/cli add ui:alert-dialog - bun: bun x @seed-design/cli add ui:alert-dialog `@seed-design/lynx-react` provides an `AlertDialog` namespace API. At the low-level package API, you can combine `AlertDialog.Root`, `AlertDialog.Trigger`, `AlertDialog.Positioner`, `AlertDialog.Backdrop`, `AlertDialog.Content` and slot components. The Registry provides commonly used combinations as flat exports, so you import `AlertDialogRoot`, `AlertDialogTrigger`, `AlertDialogContent`, `AlertDialogHeader`, `AlertDialogTitle`, `AlertDialogDescription`, `AlertDialogFooter`, and `AlertDialogAction` from `@/components/ui/alert-dialog`. Registry's `AlertDialogContent` assembles `Positioner` and `Backdrop(clickToClose={false})` internally. ## Usage ```tsx import { ActionButton } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export function App() { return ( Open Warning This action cannot be undone. Cancel Confirm ); } ``` `AlertDialogTrigger` renders a native `view` that wraps child elements. `AlertDialogAction` accepts `ActionButton` props and closes the Alert Dialog when tapped. Since Alert Dialog is used in flows that require user confirmation, it does not close by default when the Backdrop is tapped. ## Props ### `AlertDialogRoot` You can control state with `open` and `defaultOpen`, handle changes with `onOpenChange`, and skip open/close transitions with `skipAnimation`. ### `AlertDialogTrigger` ### `AlertDialogContent` `container` and `overlayLevel` specify the rendering position and order of the internal Positioner's overlay. ### `AlertDialogHeader` ### `AlertDialogTitle` ### `AlertDialogDescription` ### `AlertDialogFooter` ### `AlertDialogAction` `AlertDialogAction` can use public props like `variant` and `size` from `ActionButton`. ## Examples ### Responsive Wrapping Instead of React's `ResponsivePair`, we compose an explicit vertical action layout inside the Footer. In Lynx, we use `flex-direction` on native `view` to adjust long button labels to display vertically. ```tsx import "./styles"; import IconCheckmarkFill from "@karrotmarket/lynx-monochrome-icon/IconCheckmarkFill"; import { ActionButton, PrefixIcon, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 Wrapping Lynx에서는 긴 버튼 레이블을 위해 action을 세로로 배치할 수 있습니다. 취소 } />긴 레이블 예시 ); } ``` ### Single Action An Alert Dialog that provides only one action, such as confirm or close. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 제목 단일 선택지를 제공합니다. 확인 ); } ``` ### Neutral Secondary Action Use `neutralWeak` for secondary actions to distinguish visual priority from primary actions. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 제목 중립적인 선택지를 제공합니다. 취소 확인 ); } ``` ### Nonpreferred An example that expresses action combinations that are not recommended in the main flow. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 제목 중립적인 선택지를 제공합니다. 라벨 라벨 ); } ``` ### Critical Action Use `criticalSolid` for actions that are difficult to undo or dangerous, such as deletion. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 제목 파괴적, 비가역적 작업을 경고합니다. 취소 확인 ); } ``` ### Controlled To open and close the Alert Dialog using methods other than Trigger, control state with `open` and `onOpenChange` that receives a boolean. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); function handleOpen() { "background only"; setOpen(true); } return ( 열림 상태: {open ? "true" : "false"} 열기 주의 이 작업은 되돌릴 수 없습니다. 취소 확인 ); } ``` ### Prevent Close Lynx's `AlertDialogAction` does not have React's `preventDefault()` approach. You can prevent closing by conditionally ignoring `onOpenChange(false)` requests in a controlled Root. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); const [preventClose, setPreventClose] = useState(true); function handleOpen() { "background only"; setOpen(true); } function handleTogglePreventClose() { "background only"; setPreventClose((previous) => !previous); } function handleOpenChange(nextOpen: boolean) { "background only"; if (nextOpen || !preventClose) { setOpen(nextOpen); } } return ( 열림 상태: {open ? "true" : "false"} 열기 닫기 방지 닫힘 방지 상태에서는 확인 버튼을 눌러도 Alert Dialog가 닫히지 않습니다. 닫힘 방지: {preventClose ? "켜짐" : "꺼짐"} {preventClose ? "닫힘 허용" : "닫힘 방지"} 확인 ); } ``` ### Portalled When you specify `container` on `AlertDialogContent`, it renders in the native overlay layer. You can specify the display order of the overlay layer with `overlayLevel`. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 window overlay Lynx에서는 container와 overlayLevel로 네이티브 overlay 위치를 지정합니다. 취소 확인 ); } ``` ### Skip Animation You can skip Alert Dialog's enter/exit transitions using the `skipAnimation` prop on `AlertDialogRoot`. ```tsx import "./styles"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 애니메이션 없이 열기 즉시 표시 skipAnimation이 설정되어 열고 닫을 때 전환 애니메이션을 사용하지 않습니다. 취소 확인 ); } ``` ## Web Version Differences - **State Callback**: Lynx UI Dialog's `onShowChange` passes only a boolean. Therefore, React's `onOpenChange` second argument `details.reason` and `open-change-reason` examples are not supported. If you need the reason, record it as a separate state in the event handler of the Trigger or action owned by the app, and reflect the open state with `onOpenChange(open: boolean)`. - **Close Behavior**: The Registry's Backdrop is assembled with `clickToClose={false}`. Lynx cannot distinguish or recommend close reasons based on external area clicks or ESC key presses from the web. Build necessary close flows using app-owned buttons and controlled state. - **Trigger Composition**: Lynx does not provide React's `asChild` and the Trigger renders a native `view` that wraps children. - **Ref and Focus**: Does not provide DOM ref forwarding or web's automatic focus management API. Use Lynx native accessibility attributes and the host's accessibility flow. - **Portal / Overlay**: Instead of React Portal, specify native overlay position and order with `container` and `overlayLevel` on `AlertDialogContent`. - **Responsive Action Layout**: Does not provide React's `ResponsivePair`. Specify explicit direction and spacing styles on the native `view` inside the Footer. ### Stackflow React's `stackflow` example handles React/Stackflow-specific navigation integration, so Lynx does not provide direct corresponding examples. If you need to use Alert Dialog and screen transitions together in a Lynx app, connect the navigation state corresponding to Stackflow and the Alert Dialog's `open` state in your app's navigation layer.