Divan

Voice

Feedback

Use the lowest step that does the job. Most moments never get past step 2. Try each example; they work.

  1. 1

    Prevent

    Format as people type, show limits up front, and keep the main button waiting until the form is complete, with the reason beside it.

    Add your 11-digit mobile to continue.
  2. 2

    Guide

    The hint under the field turns into the instruction, in regular weight, and the field takes a faint warm tint. No icon, no box.

  3. 3

    Note

    When something can’t load, keep what was there, dim it, and add one quiet line with a way forward.

    Unable to update your activity.

    Saved. Applies to new comments.

  4. 4

    Toast with Undo

    Confirm what just happened. For anything that can be undone, do it at once and offer Undo, instead of asking first.

  5. 5

    Ask a second time

    Only for what can’t easily be undone. The first press turns the button into the question, with Cancel and the verb, right where it was. When the decision is made in code, ask() puts the same question in a dialog. Never the browser’s own pop-up.

    In place: ConfirmButton
    From code: ask()

Code

Note · A quiet status line next to what it is about, with a way forward.

import { Note } from '#lib/components/ui/note/index.js';

<Note>
	Unable to update your activity.
	{#snippet action()}<Button variant="plain" size="sm">Try Again</Button>{/snippet}
</Note>
<Note tone="success">Saved. Applies to new comments.</Note>

Field · Label, control, hint and guidance for one form field.

import * as Field from '#lib/components/ui/field/index.js';

<Field.Field>
	<Field.Label for="handle">YouTube handle</Field.Label>
	<Input id="handle" name="handle" dir="ltr" aria-invalid={!ok} />
	{#if ok}<Field.Description>The @name under your channel title.</Field.Description>
	{:else}<Field.Error>Write your handle like @yourchannel.</Field.Error>{/if}
</Field.Field>

ConfirmButton · A second step in place before what is hard to take back (disconnect, delete, end a round): the first press turns the button into the question, with Cancel (focused) and the verb. Escape goes back. In a form the verb submits it; otherwise it calls onconfirm. Never the browser’s confirm().

import { ConfirmButton } from '#lib/components/ui/confirm-button/index.js';

<form method="POST" action="?/disconnect" use:enhance>
	<input type="hidden" name="platform" value="instagram" />
	<ConfirmButton type="submit" question="Disconnect @maryam.k?" detail="You can connect it again any time." confirmLabel="Disconnect">
		Disconnect
	</ConfirmButton>
</form>

<ConfirmButton question="Delete 3 cards?" confirmLabel="Delete" onconfirm={remove}>Delete</ConfirmButton>

ConfirmDialog · The second step when the decision is made in code (a bulk action, a form’s enhance callback): await ask(question, { detail, confirmLabel }) opens a Divan dialog and is true only when the verb is pressed. Mount <ConfirmDialog /> once in the layout. destructive: false for a plain go-ahead (Post Now).

import { ask, ConfirmDialog } from '#lib/components/ui/confirm-dialog/index.js';

<ConfirmDialog />

<form method="POST" action="?/terminate" use:enhance={async ({ cancel }) => {
	if (!(await ask('End this round now?', { detail: 'Donations after this moment will not count.', confirmLabel: 'End Round' }))) cancel();
}}>