@kit-ng-ui/modal
v0.1.0
Published
Kit UI Modal — declarative <kit-modal> + imperative KitModalService for dialogs and confirms.
Readme
@kit-ng-ui/modal
Modal dialog — both declarative <kit-modal> and imperative KitModalService (with confirm / info / success / warning / error shortcuts).
pnpm add @kit-ng-ui/modalIn your global stylesheet:
@use '@kit-ng-ui/modal/styles' as modal;Declarative
import { KitModalComponent } from '@kit-ng-ui/modal';<kit-modal
[(open)]="open"
title="Delete this item?"
okText="Delete"
okDanger
(okClick)="save()"
(afterClose)="onClosed()"
>
<p>This action cannot be undone.</p>
</kit-modal>Custom footer:
<kit-modal [(open)]="open" title="Custom footer">
Body…
<ng-template #footerTpl>
<kit-button (click)="open.set(false)">Maybe later</kit-button>
<kit-button type="primary" (click)="run()">Run</kit-button>
</ng-template>
</kit-modal>Imperative
private readonly modal = inject(KitModalService);
deleteItem(item: Item) {
this.modal.confirm({
title: 'Delete this item?',
content: `${item.name} will be removed.`,
okDanger: true,
okText: 'Delete',
onOk: () => this.api.delete(item.id), // Promise; rejection keeps the modal open
});
}
savedToast() {
this.modal.success({ title: 'Saved!', content: 'Your changes have been saved.' });
}The handle returned by every method is a KitModalRef:
close(result?)— close and resolveafterClosed()withresultdestroy()— synchronous teardownafterClosed()— Promise resolving with the close resultupdateConfig(patch)— change inputs while the modal is open
Content sources
options.content accepts:
string— plain text rendered as the bodyTemplateRef<unknown>— projected templateType<T>— a component class; passcomponentInputsto set inputs
onOk / onCancel
Either may return:
void— close immediatelyboolean—falsekeeps the modal openPromise<boolean | void>— resolution gates the close (rejection keeps it open)
API — <kit-modal> inputs
| Input | Description | Type | Default |
| ----------------- | ------------------------------------------------------------------------ | ------------------------------------- | ------------ |
| cancelText | Cancel button label. | string | 'Cancel' |
| centered | Vertically center the dialog in the viewport. | boolean | false |
| className | Extra class on the dialog wrapper. | string \| null | null |
| closable | Render the close (×) button. | boolean | true |
| confirmLoading | Show a loading spinner on OK and disable Cancel. | boolean | false |
| keyboard | Close on Escape. | boolean | true |
| mask | Render the backdrop. | boolean | true |
| maskClosable | Close when the backdrop is clicked. | boolean | true |
| okDanger | Style the OK button as danger. | boolean | false |
| okOnly | Hide the cancel button entirely. | boolean | false |
| okText | OK button label. | string | 'OK' |
| open | Two-way bound open state. | boolean | false |
| title | Header text. Falls back to [titleTpl]. | string \| null | null |
| titleTpl | Header template. Overrides [title]. | TemplateRef \| null | null |
| width | Dialog width (px or any CSS length). | number \| string | 520 |
Outputs
| Output | Description |
| -------------- | ----------------------------------------------------------------- |
| okClick | OK button clicked. Fires before onOk resolves. |
| cancelClick | Cancel button clicked / Escape / mask click. |
| afterClose | Fired after the leave animation finishes and the DOM is detached. |
Notes
- The declarative
<kit-modal>renders inline in your template, usingposition: fixed. If an ancestor hastransform,filter, orwill-changeset, the dialog inherits that as its containing block — switch toKitModalService.create()to escape it (those modals are mounted directly under<body>). - Body scroll is locked while any modal is open and restored on destroy.
Escapecloses the modal unless[keyboard]="false".
