# Modal

Focus-trapped overlay modal, close with Esc



<ComponentPreview base="ink" name="modal-demo" />

Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @termcn/modal
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource base="ink" name="modal" title="components/ui/modal.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

Usage [#usage]

```tsx
import { Modal } from "@/components/ui/modal";
```

```tsx
<Modal open={true} onClose={() => close()} title="Welcome" width={50}>
  <Text>This is a modal dialog. Press Esc to close it.</Text>
</Modal>
```

API Reference [#api-reference]

Modal [#modal]

| Prop               | Type                                                                                         | Default                |
| ------------------ | -------------------------------------------------------------------------------------------- | ---------------------- |
| `open`             | `boolean`                                                                                    | `required`             |
| `onClose`          | `() => void`                                                                                 | `required`             |
| `title`            | `string`                                                                                     | -                      |
| `width`            | `number`                                                                                     | `60`                   |
| `children`         | `ReactNode`                                                                                  | -                      |
| `borderStyle`      | `"single" \| "double" \| "round" \| "bold" \| "singleDouble" \| "doubleSingle" \| "classic"` | `"round"`              |
| `borderColor`      | `string`                                                                                     | -                      |
| `paddingX`         | `number`                                                                                     | `1`                    |
| `paddingY`         | `number`                                                                                     | `0`                    |
| `titleBorderStyle` | `"single" \| "double" \| "round" \| "bold" \| "singleDouble" \| "doubleSingle" \| "classic"` | `"single"`             |
| `closeHint`        | `string \| false`                                                                            | `"Press Esc to close"` |
