nss_libs - NssConfirm
A Promise-based confirm and alert dialog. NUI
Getting Started
NssConfirm provides two static factory methods — confirm() for yes/no decisions and alert() for acknowledgment dialogs. Both return Promises.
import {NssConfirm} from "nui://nss_libs/ui/NssConfirm/NssConfirm.js";
NssConfirm.confirm('Delete this item?', 'Delete', 'Cancel', true)
.then(() => { /* confirmed */ })
.catch(() => { /* cancelled */ });Static Methods
NssConfirm.confirm(message, yes_label, no_label, danger?)
Shows a confirm dialog with two buttons. Returns a Promise that resolves on confirm and rejects on cancel.
| Param | Type | Default | Description |
|---|---|---|---|
message | string | — | The message to display. Supports HTML |
yes_label | string | — | Label for the confirm button |
no_label | string | — | Label for the cancel button |
danger | boolean | false | If true, applies a danger/warning style |
Returns Promise<void> — resolves on confirm, rejects on cancel.
NssConfirm.confirm('Are you sure?', 'Yes', 'No')
.then(() => {
nss_client.post('confirmed');
})
.catch(() => {
// User cancelled — do nothing
});NssConfirm.alert(message, yes_label, danger?)
Shows an alert dialog with a single button.
| Param | Type | Default | Description |
|---|---|---|---|
message | string | — | The message to display. Supports HTML |
yes_label | string | — | Label for the OK button |
danger | boolean | false | If true, applies a danger/warning style |
Returns Promise<void> — resolves when the user clicks the button.
NssConfirm.alert('Action completed successfully.', 'OK').then(() => {
// User acknowledged
});NssConfirm.alert('Invalid input!', 'OK', true).then(() => {
input_el.focus();
});Instance Methods
For advanced usage, you can create an instance directly.
.setMessage(message)
| Param | Type | Default | Description |
|---|---|---|---|
message | string | — | The message HTML |
Returns undefined.
const confirm = new NssConfirm();
confirm.setMessage('Custom message');.setDanger()
Applies the danger style to the dialog.
Returns undefined.
confirm.setDanger();.show()
Creates the dialog DOM and displays it with an animation.
Returns undefined.
confirm.show();.hide()
Plays the out-animation and removes the dialog DOM.
Returns undefined.
confirm.hide();Events / Callbacks
- Confirm — the Promise resolves (or
yes_callbackfires). - Cancel — the Promise rejects (or
no_callbackfires). - Backdrop click — triggers the cancel/no action.
CSS
Classes
| Class | Description |
|---|---|
.nss-confirm-modal | Full-screen backdrop overlay (z-index 2000). |
.nss-confirm-modal--out | Fade-out animation state. |
.nss-confirm-dialog | Centered dialog box (z-index 2001). |
.nss-confirm-dialog--out | Slide-out animation state. |
.nss-confirm__content | Message content area. |
.nss-confirm__buttons | Button row container. |
Custom Properties
| Property | Default | Description |
|---|---|---|
--nss-confirm-anim-dur | 500ms | Animation duration (fade + slide). Defined on :root. |
Animations
| Keyframe | Description |
|---|---|
nss-confirm-anim__fade-in / fade-out | Backdrop opacity animation. |
nss-confirm-anim__slide-in-top / slide-out-bottom | Dialog slide animation. |
Dependencies
NssUiComponent— base class (initializesNssResponsive).
Things to Know
- The static methods
confirm()andalert()are the recommended way to use this component. Direct instantiation is only needed for advanced use cases. - Clicking the backdrop always triggers the cancel action (rejects the Promise).
- The
dangerflag changes the visual style but not the behavior. - The animation duration is read from the CSS variable
--nss-confirm-anim-dur— override it to change the speed.
