@teaui/core
Version:
A high-level terminal UI library for Node
77 lines (76 loc) • 2.33 kB
TypeScript
import type { Viewport } from '../Viewport.js';
import type { Container } from '../Container.js';
import { Size } from '../geometry.js';
import { type Props as NotificationProps, Notification } from './Notification.js';
export interface Props extends NotificationProps {
/**
* When true, the alert is presented as a modal overlay.
* Default: false
*/
visible?: boolean;
/**
* If true, paints the entire screen with dimStyle before rendering.
* Default: true
*/
dim?: boolean;
/**
* If true, pressing Escape dismisses the alert.
* Default: true
*/
dismissOnEsc?: boolean;
/**
* If true, clicking outside the alert dismisses it.
* Default: true
*/
dismissOnClick?: boolean;
/**
* Called when the alert is dismissed (via click-outside, esc, or dismiss()).
*/
onDismiss?: () => void;
}
/**
* A notification meant to be presented in a modal overlay, drawn in a
* rounded-corner Box.
*
* Call `alert.presentFrom(owner)` to add the alert to a container and present
* it as a modal. The alert renders as zero-size in the layout; when visible,
* it presents a Modal overlay during `render()`.
*
* If the owner is removed from the tree, the alert is automatically removed
* too — no modal will be presented.
*
* Usage (core):
* const alert = new Alert({
* title: 'Confirm Delete',
* purpose: 'cancel',
* dismissOnEsc: true,
* onDismiss() { console.info('dismissed') },
* children: [
* new Text({text: 'Are you sure?'}),
* new Button({title: 'Cancel', onClick() { alert.dismiss() }}),
* ],
* })
*
* new Button({
* title: 'Delete',
* onClick() { alert.presentFrom(layout) },
* })
*/
export declare class Alert extends Notification {
#private;
constructor(props?: Props);
update(props: Props): void;
get visible(): boolean;
set visible(value: boolean);
/**
* Present this alert as a modal, adding it to the given owner container.
* The alert is removed from the owner when dismissed.
*/
presentFrom(owner: Container): void;
/**
* Dismiss this alert, removing it from its owner container.
*/
dismiss(): void;
naturalSize(_available: Size): Size;
render(viewport: Viewport): void;
}