Skip to content
weftGitHub

TypeToConfirm

Makes people type a name before an action that cannot be undone.

SourcePackage @weft-js/warp

Preview

tsx
import { state } from '@weft-js/core'import { Button, TypeToConfirm } from '@weft-js/warp'export function Delete() {  const open = state(false)  const gone = state(false)  return (    <>      {gone.value        ? <Button emphasis="ghost" tone="neutral" onClick={() => (gone.value = false)}>reports deleted. Put it back</Button>        : <Button tone="critical" onClick={() => (open.value = true)}>Delete reports</Button>}      <TypeToConfirm open={open} title="Delete reports?" description="This can't be undone." confirmText="reports" items={['41 deploys and their logs', '3 scheduled jobs']} action="Delete project" onConfirm={async () => { await wait(700); gone.value = true }} />    </>  )}const wait = (ms: number) => new Promise<void>(done => { setTimeout(done, ms) })

Installation

npm install @weft-js/warp

Usage

tsx
import { TypeToConfirm } from '@weft-js/warp'

Accessibility

Enter
Confirms once the text matches
Esc
Cancels and returns focus
  • Focus goes to the field, not to Cancel, because typing is the next step.

API Reference

PropTypeDefaultDescription
openState<boolean>—Whether it shows. You own this state.
titleunknown—The heading.
descriptionunknown—One supporting line under the title.
confirmTextstring—The exact text to type.
itemsstring[]—What goes, listed.
actionunknown—The confirm button's words.
glyphstring | IconComponentTrashIconThe icon at the top.
EventTypeDefaultDescription
onConfirm() => void | Promise<void>—Do the work here. A thrown error keeps the dialog and offers Retry.

Parts

Every element carries a stable name, so you can style it from your own CSS: [data-scope="confirm"] [data-part="mark"]

mark

RelatedConfirm dialogDanger zone