Dialog
A modal overlay for displaying content that requires user interaction.
<script lang="ts">
import {
Button,
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogPanel,
DialogPopup,
DialogTitle,
DialogTrigger,
Field,
FieldLabel,
Form,
Input,
} from "coss-svelte";
</script>
<Dialog>
<DialogTrigger>Open Dialog</DialogTrigger>
<DialogPopup class="sm:max-w-sm">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you’re done.
</DialogDescription>
</DialogHeader>
<Form class="contents">
<DialogPanel class="grid gap-4">
<Field>
<FieldLabel>Name</FieldLabel>
<Input value="Margaret Welsh" type="text" />
</Field>
<Field>
<FieldLabel>Username</FieldLabel>
<Input value="@maggie.welsh" type="text" />
</Field>
</DialogPanel>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button type="submit">Save</Button>
</DialogFooter>
</Form>
</DialogPopup>
</Dialog>
Installation
Install the component package, shared coss-svelte theme, and Bits UI peer.
npm install coss-svelte @coss-svelte/theme bits-uiUsage
Import the Svelte component exports directly from the package.
import { Dialog, DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogPanel, DialogPopup, DialogTitle, DialogTrigger } from "coss-svelte";Anatomy
- Dialog
- DialogClose
- DialogDescription
- DialogFooter
- DialogHeader
- DialogPanel
- DialogPopup
- DialogTitle
- DialogTrigger
API Reference
Dialog
A modal overlay for displaying content that requires user interaction.
| Prop | Type | Default | Description |
|---|---|---|---|
bind:open | boolean | false | Open state for the popup or disclosure. Bind with `bind:open`. |
trigger | string | "Open" | Fallback trigger text rendered when custom children are not provided. |
title | string | "" | Title text rendered by the component's built-in fallback layout. |
description | string | "" | Supporting text rendered by the component's built-in fallback layout. |
children : Snippet<[]>Inherits from Bits UI Dialog.Root.
DialogClose
Renders a control that closes the parent surface.
children : Snippet<[]>child : Snippet<[{ props: Record<string, unknown> }]>bind:ref : HTMLElement | nullInherits from Bits UI Dialog.Close.
DialogDescription
Provides supporting copy for the parent component.
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Dialog.Description.
DialogHeader
Groups heading content for the parent component.
children : Snippet<[]>Inherits from Svelte <div> attributes.
DialogPanel
Renders the main panel surface for the parent component.
children : Snippet<[]>Inherits from Svelte <div> attributes.
DialogPopup
Renders the floating or modal surface for the parent component.
| Prop | Type | Default | Description |
|---|---|---|---|
portalProps | { disabled?: boolean; to?: PortalTarget } | {} | Configures the exact Bits Portal target (`to`) or renders inline when `disabled`. |
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Dialog.Content.
DialogTitle
Names the parent surface or section.
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Dialog.Title.
DialogTrigger
Renders the control that opens, closes, or selects related content.
children : Snippet<[]>child : Snippet<[{ props: Record<string, unknown> }]>bind:ref : HTMLElement | nullInherits from Bits UI Dialog.Trigger.
Implementation Details
- Status
- Stable
- Foundation
- bits
- Category
- Overlays & Popups
- Particles
- 6