# Dialog URL: /lynx/components/dialog Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/dialog.mdx A modal component that appears in the center of the screen to draw user attention and contains title, body, and footer. Lynx Engine 최소 버전: 3.6 사용 XElement: 사용 가능 버전: @seed-design/lynx-react@0.7.0, @seed-design/lynx-css@0.11.0 ## Preview ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( Open Dialog 본문에는 사용자가 확인해야 할 내용이나 추가 입력 폼을 배치할 수 있습니다. 취소 확인 ); } ``` ## Installation - npm: npx @seed-design/cli add ui:dialog - pnpm: pnpm dlx @seed-design/cli add ui:dialog - yarn: yarn dlx @seed-design/cli add ui:dialog - bun: bun x @seed-design/cli add ui:dialog The `Dialog` in `@seed-design/lynx-react` wraps [`@lynx-js/lynx-ui-dialog`](https://github.com/lynx-family/lynx-ui/tree/main/packages/lynx-ui-dialog). The Registry's `DialogContent` assembles Positioner, Backdrop, and Header internally, and `DialogAction` provides `ActionButton` and close action together. ## Usage ```tsx import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton } from "@seed-design/lynx-react"; export function App() { return ( Open Dialog Body content Close ); } ``` The Registry's `DialogContent` assembles `Positioner`, `Backdrop`, and `Header` internally. `DialogTrigger` must be placed outside Content to open the Dialog by tapping. The `showCloseButton` of `DialogContent` defaults to `true` and renders a close `ActionButton` in the header. If you don't need a close button, set `showCloseButton={false}`. `DialogBody` is rendered as native `` and scrolls vertically within the maximum height of the Content. `DialogAction` accepts `ActionButton` props and renders with close action. ## Props ### `DialogRoot` ### `DialogTrigger` ### `DialogContent` ### `DialogBody` ### `DialogFooter` ### `DialogAction` ## Examples ### Trigger Tapping `` opens the Dialog. Lynx does not support React's `asChild`, and Trigger renders a native view wrapping child elements. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( Open Trigger를 탭하면 현재 화면 위에 Dialog가 열립니다. 취소 확인 ); } ``` ### Controlled To open and close the Dialog in ways other than Trigger, control state with `open` and `onOpenChange`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); function handleOpen() { "background only"; setOpen(true); } return ( 열기 Labore do culpa dolore irure nisi dolor dolor laboris veniam ipsum excepteur adipisicing laboris non quis. 취소 확인 ); } ``` ### Size You can change the Dialog width with the `size` prop of ``. `"medium"` is the default and `"large"` is supported. For both sizes, small screens use the recipe's viewport-based width, and larger screens apply the Dialog token's maximum width for each size. Content height is limited by the recipe's maximum height. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; function DialogExample({ size }: { size: "medium" | "large" }) { const isLarge = size === "large"; return ( {isLarge ? "Large Dialog" : "Medium Dialog"} {isLarge ? "large size는 넓은 화면에서 더 큰 Dialog token 너비를 사용합니다." : "medium은 Dialog의 기본 size입니다."} 취소 확인 ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Body `` is a body slot with the `seed-dialog__body` selector applied. It is rendered as native `` and scrolls vertically within the maximum height of Content. The default horizontal padding is provided by the recipe's body token (`x6`). Unlike the web version, Lynx does not display a header divider or bottom fade mask by observing overflow state. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; function DialogExample({ long }: { long: boolean }) { return ( {long ? "긴 본문 (스크롤 적용)" : "짧은 본문 (스크롤 없음)"} {long ? ( Array.from({ length: 16 }, (_, index) => index + 1).map((line) => ( {line}. Lynx의 DialogBody는 native scroll-view로 렌더링됩니다. )) ) : ( 내용이 짧으면 마지막 줄까지 바로 확인할 수 있습니다. )} 취소 확인 ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Custom Body `` accepts existing Lynx styled props. You can redefine `height`, `min-height`, and alignment with `className` or `style`. If you need to override the Recipe's default padding, specify `paddingLeft` and `paddingRight` directly in `style` to avoid being affected by CSS load order. Only explicitly specify when removing the default horizontal padding to place full-bleed content. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; function DialogExample({ variant }: { variant: "maxHeight" | "minHeight" | "fullBleed" }) { const isMaxHeight = variant === "maxHeight"; const isMinHeight = variant === "minHeight"; const isFullBleed = variant === "fullBleed"; return ( {isMaxHeight ? "maxHeight 200px" : isMinHeight ? "minHeight + 가운데 정렬" : "paddingX 0"} {isMaxHeight ? ( {Array.from({ length: 12 }, (_, index) => index + 1).map((line) => ( {line}. 본문이 200px을 넘으면 그 안에서 스크롤됩니다. ))} ) : isMinHeight ? ( 아직 항목이 없습니다 ) : ( 가장자리까지 닿는 영역입니다 )} 취소 확인 ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Show Close Button The Registry's `DialogContent` supports `showCloseButton` and defaults to `true`. Setting it to `false` hides the close `ActionButton` in the header, allowing you to provide explicit close action in the footer and other areas. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; function DialogExample({ showCloseAction }: { showCloseAction: boolean }) { return ( {showCloseAction ? "닫기 액션 있음" : "닫기 액션 없음"} {showCloseAction ? "DialogContent의 showCloseButton을 사용합니다." : "showCloseButton={false}인 경우 푸터 액션만 제공합니다."} 취소 확인 ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Footer Layout `DialogFooter` provides only flex layout. Button arrangement is constructed directly by specifying `flex-direction`, `justify-content`, `gap`, and others on child `view`. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( Footer 레이아웃 DialogFooter는 flex 레이아웃만 제공합니다. 넓은 다이얼로그에서는 주요 액션을 우측에 가로로 정렬할 수 있습니다. 취소 확인 ); } ``` ### Prevent Close Lynx's `DialogAction` does not support the `preventDefault()` method from React events. You can prevent closing by making Dialog controlled and conditionally ignoring `onOpenChange(false)`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); const [preventClose, setPreventClose] = useState(true); function handleTogglePreventClose() { "background only"; setPreventClose((previous) => !previous); } function handleOpenChange(nextOpen: boolean) { if (nextOpen || !preventClose) { setOpen(nextOpen); } } return ( 열기 닫힘 방지: {JSON.stringify(preventClose)} 전환 취소 확인 ); } ``` ### `onOpenChange` Details Lynx's `onOpenChange` passes only the changed `open` value. The second argument `details.reason` from the React version is not supported. If you need the close reason, record it in a separate state in the event handlers of app-owned buttons and Trigger. #### Confirm Before Close Unlike React examples, Lynx does not support showing confirmation Dialogs for `closeButton`, `escapeKeyDown`, `interactOutside` separately. Since Lynx callbacks alone cannot distinguish close reasons, for actions that need confirmation, open the confirmation Dialog first in the handler of an app-owned button and directly control the `open` of the original Dialog. ### Portalled When you specify `container` for `DialogContent`, it renders on the native overlay layer. You can specify the display order of the overlay layer with `overlayLevel`. ```tsx import "./styles"; import { DialogAction, DialogBody, DialogContent, DialogFooter, DialogRoot, DialogTrigger, } from "@/components/ui/dialog"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 콘텐츠는 window 컨테이너와 overlay level 2 위에 표시됩니다. 취소 확인 ); } ``` ### Responsive Automatic switching components like React's `ResponsiveDialog` are not provided in Lynx. Directly select `Dialog` and `BottomSheet` in your app based on screen size, or connect the same controlled state to both components. ## Web Version Differences | Item | Web | Lynx | | ------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | User events | `onClick` | `bindtap` or public callback | | Rendering elements | HTML elements and Portal | native ``, ``, `` and overlay | | State prop | `open`, `defaultOpen`, `onOpenChange` | Same. Internally connected to lynx-ui-dialog's `show`, `defaultShow`, `onShowChange` | | Trigger composition | `asChild` supported | Not supported. Trigger renders a view wrapping child elements | | Body slot | `DialogBody` provided | `DialogBody` provided. Uses native `` and `seed-dialog__body` selector with default horizontal padding from recipe body token(`x6`) | | Close button | `showCloseButton` supported | Default support in Registry's `DialogContent`. Hidden with `showCloseButton={false}` | | Close reason | `details.reason` in `onOpenChange` | Only boolean `open` value provided | | Portal / overlay | `Portal` component | `DialogContent`'s `container`, `overlayLevel` | | Responsive Dialog | `ResponsiveDialog` provided | Not provided. Dialog and BottomSheet combined directly in app | | Mount control | `lazyMount`, `unmountOnExit` | `forceMount` supported | | Imperative ref API | None | Not supported |