overlays
Every overlay part of the kit (Sheet, Dialog, AlertDialog, Menu, Popover, Tooltip, Toast, Select) in its variants and states, light and dark, with toast() from @duolith/client.
Run it
cargo run -p duolith-cli -- dev examples/overlays # live, reloads on save
cargo run -p duolith-cli -- build examples/overlays # static output in examples/overlays/dist
The folder on the web: examples/overlays.
Features it shows
| Feature | Where | Screenshot |
|---|---|---|
| Tooltip | overlays pages/index.duo; gallery pages/overlays.duo | overlays-tooltip.png |
Source
pages/index.duo
---
import { state, toast } from "@duolith/client";
import { AlertDialog, Button, Dialog, IconButton, Menu, Popover } from "@duolith/kit";
import { Section, Select, Sheet, TextField, Toast, Tooltip } from "@duolith/kit";
let sheetOpen = state(false);
let largeSheetOpen = state(false);
let dialogOpen = state(false);
let deleteOpen = state(false);
let signOutOpen = state(false);
let name = state("Ada Lovelace");
let draft = state("Ada Lovelace");
let country = state("gb");
let size = state("");
let last = state("Nothing chosen yet");
const countries = [
{ value: "fr", label: "France" },
{ value: "de", label: "Germany" },
{ value: "gb", label: "United Kingdom" },
{ value: "jp", label: "Japan" },
{ value: "ke", label: "Kenya" },
{ value: "us", label: "United States" },
];
const sizes = [
{ value: "s", label: "Small" },
{ value: "m", label: "Medium" },
{ value: "l", label: "Large" },
];
const postActions = [
{ label: "Edit", icon: "edit", onSelect: () => (last = "Edit") },
{ label: "Share", icon: "share", onSelect: () => (last = "Share") },
{ label: "Copy link", icon: "copy", onSelect: () => (last = "Copy link") },
{ label: "Pin to profile", icon: "bookmark", disabled: true },
{ divider: true },
{ label: "Delete", icon: "trash", destructive: true, onSelect: () => (deleteOpen = true) },
];
function saveName() {
name = draft;
dialogOpen = false;
toast("Name saved", { tone: "success" });
}
function deletePost() {
last = "Deleted";
toast("Post deleted", { action: { label: "Undo", onPress: () => (last = "Restored") } });
}
function queueSeveral() {
for (const step of ["Uploading 1 of 4", "Uploading 2 of 4", "Uploading 3 of 4", "Uploading 4 of 4"]) {
toast(step);
}
}
---
<screen title="Overlays" class="bg-canvas">
<view class="page gap-6 p-4 md:p-8">
<view class="gap-1">
<text role="heading" class="text-title text-ink">Overlays</text>
<text class="text-body text-muted">
Sheets, dialogs, menus, popovers, tooltips, toasts and a select. Last action: {last}.
</text>
</view>
<Section
title="Sheet"
footer="Drag the handle up for the large detent, down to dismiss, or press the backdrop."
>
<view class="row wrap gap-2 p-4">
<Sheet title="Share post" bind:open={sheetOpen}>
<piece name="trigger">
<Button label="Open sheet" icon="share" />
</piece>
<text class="text-body text-muted">Choose where to send it.</text>
<Button
label="Copy link"
icon="copy"
variant="secondary"
full
onPress={() => (sheetOpen = false)}
/>
<Button
label="Send by mail"
icon="mail"
variant="secondary"
full
onPress={() => (sheetOpen = false)}
/>
</Sheet>
<Sheet title="Filters" detent="large" bind:open={largeSheetOpen}>
<piece name="trigger">
<Button label="Large sheet" icon="filter" variant="secondary" />
</piece>
<Select label="Size" options={sizes} bind:value={size} placeholder="Any size" />
<Button label="Apply" full onPress={() => (largeSheetOpen = false)} />
</Sheet>
</view>
</Section>
<Section title="Dialog and AlertDialog">
<view class="row wrap gap-2 p-4">
<Dialog title="Edit name" message="This is how others see you." bind:open={dialogOpen}>
<piece name="trigger">
<Button label={`Edit ${name}`} icon="edit" variant="secondary" />
</piece>
<TextField label="Name" bind:value={draft} />
<piece name="actions">
<Button label="Cancel" variant="ghost" onPress={() => (dialogOpen = false)} />
<Button label="Save" onPress={saveName} />
</piece>
</Dialog>
<AlertDialog
title="Delete this post?"
message="It will be removed for everyone. You can undo for a few seconds."
confirmLabel="Delete"
destructive
bind:open={deleteOpen}
onConfirm={deletePost}
>
<piece name="trigger">
<Button label="Delete post" icon="trash" variant="danger" />
</piece>
</AlertDialog>
<AlertDialog
title="Sign out?"
message="You will need your password to sign in again."
confirmLabel="Sign out"
bind:open={signOutOpen}
onConfirm={() => toast("Signed out")}
>
<piece name="trigger">
<Button label="Sign out" variant="ghost" />
</piece>
</AlertDialog>
</view>
</Section>
<Section title="Menu, Popover and Tooltip">
<view class="row wrap items-center gap-2 p-4">
<Menu label="Post actions" items={postActions}>
<piece name="trigger">
<Button label="Actions" iconEnd="chevron-down" variant="secondary" />
</piece>
</Menu>
<Popover label="About this post">
<piece name="trigger">
<Button label="Details" icon="info" variant="ghost" />
</piece>
<text class="text-label text-ink">Posted 2 hours ago</text>
<text class="text-body text-muted">
Seen by 1,204 people. Only people you follow can reply.
</text>
</Popover>
<Tooltip text="Add to favourites">
<IconButton icon="star" label="Favourite" variant="secondary" />
</Tooltip>
<Tooltip text="Opens your settings" placement="bottom">
<IconButton icon="settings" label="Settings" variant="secondary" />
</Tooltip>
<view class="grow" />
<Menu label="More" items={postActions} placement="bottom-end">
<piece name="trigger">
<IconButton icon="more" label="More" />
</piece>
</Menu>
</view>
</Section>
<Section
title="Toast"
footer="Toasts pause while you hover or focus them, and can be swiped away."
>
<view class="row wrap gap-2 p-4">
<Button label="Show toast" variant="secondary" onPress={() => toast("Draft saved")} />
<Button label="With action" variant="secondary" onPress={deletePost} />
<Button
label="Error"
variant="secondary"
onPress={() => toast("Could not send. Check your connection.", { tone: "danger" })}
/>
<Button label="Queue four" variant="secondary" onPress={queueSeveral} />
</view>
</Section>
<Section title="Select">
<view class="gap-4 p-4">
<Select label="Country" options={countries} bind:value={country} />
<Select label="Size" options={sizes} bind:value={size} placeholder="Any size" />
<Select label="Region" options={countries} placeholder="Not available here" disabled />
</view>
</Section>
</view>
<Toast />
</screen>
<style>
.page {
width: 100%;
max-width: 720px;
margin: 0 auto;
}
</style>