Overlays
Prompt
Alerts, dialogs and drawers opened from code. `open` gives the answer as a promise, and an alert stays open while its action runs.
Overlays
Alerts, dialogs and drawers opened from code. `open` gives the answer as a promise, and an alert stays open while its action runs.
Change the options on the right, then open the alert.
import { usePrompt } from 'omuk-ui/prompt';
const prompt = usePrompt();
const yes = await prompt.open({
type: 'alert',
title: 'Discard the draft?',
description: 'The changes since the last save are lost.',
actionLabel: 'Discard',
});Put one PromptProvider in the app. Then any handler opens a prompt with usePrompt, or with prompt outside a component. No open state in the caller.
import { PromptProvider } from 'omuk-ui/prompt';
// Once, near the root of the app, inside the providers that the prompts'
// content needs (a router, a query client). The alert, dialog and drawer
// code loads when the first prompt opens.
export function AppProviders({ children }: { children: React.ReactNode }) {
return (
<>
{children}
<PromptProvider />
</>
);
}open gives true for the action, false for Cancel, Escape or a click outside.
With onAction, the alert stays open while the work runs: its button keeps its size and shows a spinner. If the work throws, the message shows in the alert, and the person can try again. Press Delete twice: the first try fails.
type: 'modal' takes any content. close(value) closes it, and open gives that value; Escape gives null.
Billing
type: 'drawer' slides in from an edge: right by default, or left, top, bottom.