Modal
Alpine x-data 駆動のオーバーレイダイアログ。trigger slot に置いた要素をクリックで開く、または別所から $dispatch("open-modal-{id}") で開く。size (sm/md/lg/xl/full)・title・showClose・closeOnBackdrop の 5 props。背景 click / Escape / × ボタンで閉じる。x-trap で focus trap、x-teleport で body 直下に描画。
1. 最小: trigger slot 付き
Confirm
A centered dialog with a backdrop. Esc and a backdrop click both close it.
<x-modal title="Confirm">
<x-slot:trigger>
<x-button>Open default modal</x-button>
</x-slot:trigger>
<p class="text-sm text-base-content/80">A centered dialog with a backdrop. Esc and a backdrop click both close it.</p>
</x-modal>
title を省略した場合 — ヘッダーは × ボタンのみになる (title が必須でないことを確認)
Without a title the header row is dropped and only the close button remains.
<x-modal>
<x-slot:trigger>
<x-button appearance="soft">Open titleless modal</x-button>
</x-slot:trigger>
<p class="text-sm text-base-content/80">Without a title the header row is dropped and only the close button remains.</p>
</x-modal>
size — sm / md / lg / xl / full
Small modal
Best for short confirmations.
Medium modal (default)
The default width.
Large modal
Room for a short form.
Extra-large modal
Room for a table or a two-column layout.
Full-width modal
Edge-to-edge apart from the outer margin.
<x-modal title="Small modal" size="sm">
<x-slot:trigger><x-button size="sm">sm (max-w-sm)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Best for short confirmations.</p>
</x-modal>
<x-modal title="Medium modal (default)" size="md">
<x-slot:trigger><x-button size="sm">md (max-w-lg)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">The default width.</p>
</x-modal>
<x-modal title="Large modal" size="lg">
<x-slot:trigger><x-button size="sm">lg (max-w-2xl)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Room for a short form.</p>
</x-modal>
<x-modal title="Extra-large modal" size="xl">
<x-slot:trigger><x-button size="sm">xl (max-w-4xl)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Room for a table or a two-column layout.</p>
</x-modal>
<x-modal title="Full-width modal" size="full">
<x-slot:trigger><x-button size="sm">full (max-w-full mx-4)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Edge-to-edge apart from the outer margin.</p>
</x-modal>
showClose — × ボタンの表示制御
showClose=false
The X is hidden — give the user an explicit action instead.
showClose=true (default)
The X sits in the header.
<x-modal title="showClose=false" :showClose="false">
<x-slot:trigger><x-button appearance="outline" size="sm">showClose=false</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">The X is hidden — give the user an explicit action instead.</p>
<x-slot:actions>
<x-button size="sm" @click="open = false">OK</x-button>
</x-slot:actions>
</x-modal>
<x-modal title="showClose=true (default)">
<x-slot:trigger><x-button appearance="outline" size="sm">showClose=true (default)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">The X sits in the header.</p>
</x-modal>
closeOnBackdrop — 背景クリック挙動
closeOnBackdrop=true (default)
Clicking the backdrop closes the dialog.
closeOnBackdrop=false
The backdrop is inert — use this for destructive confirmations.
<x-modal title="closeOnBackdrop=true (default)">
<x-slot:trigger><x-button appearance="outline" size="sm">closeOnBackdrop=true (default)</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Clicking the backdrop closes the dialog.</p>
</x-modal>
<x-modal title="closeOnBackdrop=false" :closeOnBackdrop="false">
<x-slot:trigger><x-button appearance="outline" size="sm">closeOnBackdrop=false</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">The backdrop is inert — use this for destructive confirmations.</p>
</x-modal>
2. title + size + actions slot (確認ダイアログ典型)
Delete confirmation
Are you sure you want to delete this? This cannot be undone.
New project
<x-modal title="Delete confirmation" size="sm" :closeOnBackdrop="false">
<x-slot:trigger><x-button color="error" size="sm">Delete…</x-button></x-slot:trigger>
<p class="text-sm text-base-content/80">Are you sure you want to delete this? This cannot be undone.</p>
<x-slot:actions>
<x-button appearance="ghost" size="sm" @click="open = false">Cancel</x-button>
<x-button color="error" size="sm" @click="open = false">Delete</x-button>
</x-slot:actions>
</x-modal>
<x-modal title="New project" size="md">
<x-slot:trigger><x-button color="primary" size="sm">+ Create</x-button></x-slot:trigger>
<div class="space-y-3">
<x-input label="Project name" placeholder="my-app" />
<x-textarea label="Description" rows="3" placeholder="optional" />
</div>
<x-slot:actions>
<x-button appearance="ghost" size="sm" @click="open = false">Cancel</x-button>
<x-button color="primary" size="sm" @click="open = false">Create</x-button>
</x-slot:actions>
</x-modal>
ビューポートより縦長のコンテンツ — panel は viewport 内に収まり body だけがスクロール、header と actions は常に見える (v0.10.9)
Edit profile
<x-modal title="Edit profile" size="lg">
<x-slot:trigger><x-button color="primary" size="sm">Open a tall form</x-button></x-slot:trigger>
<div class="space-y-3">
<x-input label="First name" placeholder="Ada" />
<x-input label="Last name" placeholder="Lovelace" />
<x-input label="Email" type="email" placeholder="ada@example.com" />
<x-input label="Phone" type="tel" placeholder="+1 555 0100" />
<x-input label="Company" placeholder="Analytical Engines Ltd." />
<x-input label="Job title" placeholder="Chief Engineer" />
<x-input label="Street address" placeholder="12 Byron St." />
<x-input label="City" placeholder="London" />
<x-input label="Postal code" placeholder="W1K 1AA" />
<x-input label="Country" placeholder="United Kingdom" />
<x-input label="Website" type="url" placeholder="https://example.com" />
<x-textarea label="Bio" rows="4" placeholder="A short introduction…" />
</div>
<x-slot:actions>
<x-button appearance="ghost" size="sm" @click="open = false">Cancel</x-button>
<x-button color="primary" size="sm" @click="open = false">Save</x-button>
</x-slot:actions>
</x-modal>
4. id を渡して別所の任意のボタンから dispatch で開く(size: sm/md(default)/lg/xl/full、背景click/Escape/×/actionsの @click='open = false' で閉じる、x-trap で focus trap、x-teleport で body 直下に描画)
Welcome
Declared without a trigger slot: it is opened purely by dispatching open-modal-welcome.
Reset settings
All settings return to their defaults.
<x-button color="primary" size="sm" x-on:click="$dispatch('open-modal-welcome')">Open the welcome modal</x-button>
<x-button color="info" size="sm" x-on:click="$dispatch('open-modal-confirm-reset')">Open the reset modal</x-button>
<x-modal id="welcome" title="Welcome" size="md">
<p class="text-sm text-base-content/80">Declared without a trigger slot: it is opened purely by dispatching <code class="text-xs">open-modal-welcome</code>.</p>
<x-slot:actions>
<x-button size="sm" @click="open = false">Close</x-button>
</x-slot:actions>
</x-modal>
<x-modal id="confirm-reset" title="Reset settings" size="sm" :closeOnBackdrop="false">
<p class="text-sm text-base-content/80">All settings return to their defaults.</p>
<x-slot:actions>
<x-button appearance="ghost" size="sm" @click="open = false">Cancel</x-button>
<x-button color="warning" size="sm" @click="open = false">Reset</x-button>
</x-slot:actions>
</x-modal>