Notification
A message in the bottom right corner of the window, for a few seconds or until it is closed; several pile up.
import { Notification } from "x4js"
Modes
The modes success and danger color its border and its icon; display( 3 ) closes it after 3 s.
export function modes( ) {
return new HBox( { content: [
new Button( { label: "Default", click: ( ) => {
new Notification( { title: "Saved", text: "report.pdf was saved." } ).display( 3 );
} } ),
new Button( { label: "Success", click: ( ) => {
new Notification( { mode: "success", title: "Sent", text: "The mail was sent." } ).display( 3 );
} } ),
new Button( { label: "Danger", cls: "danger", click: ( ) => {
new Notification( { mode: "danger", title: "Error", text: "The server does not answer." } ).display( 3 );
} } ),
] } );
}
Until closed
display( ) without a time keeps it; closable adds the button that closes it. Several pile up in the corner.
export function closable( ) {
let count = 0;
return new HBox( { content: [
new Button( { label: "Notify", click: ( ) => {
count++;
new Notification( { closable: true, iconId: icon_mail, title: `Message ${count}`, text: "Close me with the button." } ).display( );
} } ),
] } );
}
Loading, then done
loading turns its icon; close( ) removes it when the work is done.
export function loading( ) {
return new HBox( { content: [
new Button( { label: "Synchronize", click: ( ) => {
const wait = new Notification( { loading: true, title: "Synchronizing", text: "Two seconds…" } );
wait.display( );
// the work: here a named timer of the notification
wait.setTimeout( "work", 2000, ( ) => {
wait.close( );
new Notification( { mode: "success", title: "Synchronized", text: "12 files are up to date." } ).display( 3 );
} );
} } ),
] } );
}
For an assistant: llms.txt, llms-full.txt.