Skip to content

Takeover

A full-viewport modal sheet. Render Takeover.Trigger and Takeover.Content inside it. The root renders no element.

Built on bits-ui Dialog.

<Takeover bind:open>
<Takeover.Trigger class="button">Open</Takeover.Trigger>
<Takeover.Content>
<Takeover.Header>
<Takeover.Title>Settings</Takeover.Title>
<Takeover.Close />
</Takeover.Header>
<p>Body</p>
</Takeover.Content>
</Takeover>
  • Composed from parts, so the trigger, the header, and the body are yours to arrange.
  • One open, bindable. Closing returns focus to the trigger.
  • Focus is trapped inside while open, Escape closes, and the page behind does not scroll, via bits-ui.
  • The sheet fills the viewport in a portal. It has no overlay, border radius, or shadow, and it is labeled by Takeover.Title.

For a floating panel over a dimmed page, use Dialog.

Every part is a property on Takeover. Takeover renders no element. The body is your own markup inside Takeover.Content.

<Takeover>
<Takeover.Trigger />
<Takeover.Content>
<Takeover.Header>
<Takeover.Title />
<Takeover.Close />
</Takeover.Header>
<!-- body -->
</Takeover.Content>
</Takeover>

bind:open on the root.

open: false

Code
TwoWay.svelte
<script lang="ts">
import { Takeover } from "@viamrobotics/prime-ui";
let open = $state(false);
</script>
<div class="not-content">
<Takeover bind:open>
<Takeover.Trigger class="button">Open takeover</Takeover.Trigger>
<Takeover.Content>
<Takeover.Header>
<Takeover.Title>Setup wizard</Takeover.Title>
<Takeover.Close />
</Takeover.Header>
<div class="p-4">Close it with the button or Escape.</div>
</Takeover.Content>
</Takeover>
<p class="mt-3 text-sm text-subtle-2">open: <code>{open}</code></p>
</div>

Takeover.Header is a flex row with its children spread between the ends. Wrap the actions and Takeover.Close in one element so they stay together on the right.

Code
HeaderActions.svelte
<script lang="ts">
import { Takeover } from "@viamrobotics/prime-ui";
</script>
<div class="not-content">
<Takeover>
<Takeover.Trigger class="button">Open takeover</Takeover.Trigger>
<Takeover.Content>
<Takeover.Header>
<Takeover.Title>Edit machine</Takeover.Title>
<div class="flex items-center gap-2">
<button type="button" class="button">Save</button>
<Takeover.Close />
</div>
</Takeover.Header>
<div class="p-4">Actions sit beside the close button.</div>
</Takeover.Content>
</Takeover>
</div>

Takeover.Content is a column flex container and the header does not shrink. Give the body min-h-0 flex-1 overflow-y-auto and it scrolls while the header stays pinned.

Code
ScrollingBody.svelte
<script lang="ts">
import { Takeover } from "@viamrobotics/prime-ui";
const rows = Array.from({ length: 40 }, (_, index) => `Row ${index + 1}`);
</script>
<div class="not-content">
<Takeover>
<Takeover.Trigger class="button">Open takeover</Takeover.Trigger>
<Takeover.Content>
<Takeover.Header>
<Takeover.Title>Logs</Takeover.Title>
<Takeover.Close />
</Takeover.Header>
<div class="min-h-0 flex-1 overflow-y-auto p-4">
{#each rows as row (row)}
<p class="py-1">{row}</p>
{/each}
</div>
</Takeover.Content>
</Takeover>
</div>

Custom close label

A prime-core Takeover was a single component driven by isOpen and onClose. Here it is a set of parts with a bindable open, and the trigger is a part.

prime-core Now
Takeover Takeover with Takeover.Trigger and Takeover.Content.
isOpen bind:open on Takeover.
onClose Watch open, or pass a getter and setter. See State & binding.
cx on Takeover class on Takeover.Content.
TakeoverHeader Takeover.Header
TakeoverTitle Takeover.Title
TakeoverClose Takeover.Close

Every part that renders an element takes class on that element. Takeover renders no element, so it takes no class. Takeover.Trigger is a real <button> with no style of its own, so add button or your own classes. Takeover.Close wears icon-button and shows a close icon labeled Close. Pass children to replace the icon and aria-label to replace the label. With children it wears no class of its own, so class="button" gives a text close the button class alone. Takeover.Content wears z-dialog, so it sits on the same layer as Dialog. See z layers. bits-ui sets the data attributes in the table below.

Part Attribute Value
Trigger data-state open or closed
Content data-state open or closed
Content data-nested Present when inside another dialog
Content data-nested-open Present while a nested dialog is open
KeyAction
Enter / SpaceOn the trigger, opens the takeover.
EscapeCloses the takeover and returns focus to the trigger.
Tab / Shift + TabCycles focus inside the takeover, wrapping at either end.
PropTypeDefaultDescription
bind:openbooleanWhether the sheet is open. Two-way bindable.
childrenSnippetThe Takeover.* parts.

Takeover.Close

A button that closes its Takeover. It renders a close icon by default, labeled Close, and wears icon-button only then. Pass children to replace the icon, and aria-label to replace the label.

PropTypeDefaultDescription
idstringElement id. null is not accepted.

Plus everything in HTMLButtonAttributes, spread onto the element.

Takeover.Content

The sheet of a Takeover, rendered in a portal and filling the viewport on the dialog layer.

It is a white column with no overlay, border radius, or shadow. Put a Takeover.Header first, then the body. The body scrolls when it overflows, so give it min-h-0 flex-1 overflow-y-auto. Focus is trapped inside while it is open, Escape closes it, focus returns to the trigger, and the page behind does not scroll.

Takes extraClasses, children, portal, ...restProps }: Props as its props.

Takeover.Header

The top row of a Takeover, rendered as a header. Place a Takeover.Title and a Takeover.Close in it. It does not shrink and has a bottom border.

Takes extraClasses, children, ...restProps }: Props as its props.

Takeover.Title

The heading of a Takeover, rendered as an h2. The sheet is labeled by it.

PropTypeDefaultDescription
idstringElement id. null is not accepted.

Plus everything in HTMLAttributes<HTMLHeadingElement>, spread onto the element.

Takeover.Trigger

The button that opens a Takeover. It carries no visual style of its own, so add button or another class.

PropTypeDefaultDescription
idstringElement id. null is not accepted.

Plus everything in HTMLButtonAttributes, spread onto the element.