PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
You can register custom modal dialogs and control them with the standard element APIs (openElement, closeElements, disableElements).
UI.addCustomModal(options) Register a custom modal dialog.
/**
* @method UI.addCustomModal
* @param {object} options
* @param {string} options.dataElement Unique name of the custom modal.
* @param {boolean} [options.disableBackdropClick=false] Disable closing on outside click.
* @param {boolean} [options.disableEscapeKeyDown=false] Disable closing on Escape.
* @param {function} [options.render] Function returning the modal contents.
* @param {object} [options.header] { title, className, style, innerHTML, children }
* @param {object} [options.body] { title, className, style, innerHTML, children }
* @param {object} [options.footer] { title, className, style, innerHTML, children }
*/
UI.addCustomModal({
dataElement: 'myModal',
disableBackdropClick: false,
disableEscapeKeyDown: false,
header: { title: 'My Modal' },
body: { title: 'Modal content' },
footer: { children: [{ title: 'Close', button: true, onClick: () => UI.closeElements(['myModal']) }] },
});Registering a modal with the same dataElement as an existing one replaces it.
Once registered, the modal is controlled like any other element using its dataElement:
UI.openElement('myModal'); // show
UI.closeElements(['myModal']); // hide
UI.isElementOpen('myModal'); // => boolean
UI.disableElements(['myModal']); // remove entirelyA modal is divided into three optional sections — header, body, footer. You can also supply a render function that returns an HTMLElement or a string for full custom content; it is called each time the modal opens.
| Section field | Purpose |
|---|---|
title | Section title text. |
className | Custom class(es) applied to the section. |
style | Inline style object. |
innerHTML | HTML content of the section (used instead of title and children). |
children | Array of child items { title, button, className, style, onClick }. With button: true the child is rendered as a button. |
UI.addCustomModal({
dataElement: 'confirmModal',
disableBackdropClick: true,
header: { title: 'Please confirm' },
body: { title: 'Are you sure you want to continue?' },
footer: {
children: [
{ title: 'Cancel', button: true, onClick: () => UI.closeElements(['confirmModal']) },
{ title: 'OK', button: true, onClick: () => { /* … */ UI.closeElements(['confirmModal']); } },
],
},
});
UI.openElement('confirmModal');UI.addCustomModal({
dataElement: 'customRenderModal',
render: () => {
const el = document.createElement('div');
el.innerHTML = '<h3>Custom</h3><p>Rendered by a function.</p>';
return el;
},
});
UI.openElement('customRenderModal');viewer store holds the list of custom modals; addCustomModal appends or replaces by dataElement.disableBackdropClick / disableEscapeKeyDown is set.