simple-dialog
A simple dialog component for the browser.
Features
- content from string or element
- (optional) backdrop
- (optional) close handle
- (optional) modal
- return values
- life-cycle events
Usage
var SimpleDialog = ; var dialog = ; // open dialogdialog; // close with valuedialog;
Configuration Options
The dialog constructor accepts the following configuration options:
{Boolean} [backdrop=true] if false, do not show backdrop
{Boolean} [closable=true] if false, do not close via close control/backdrop
{String} [id] an id to assign to the dialog
{Element|String} [parent='body'] the parent node to attach the dialog to
{Element|String} [template] the element to display as the dialog content
{String} [className=''] classes to add to the .dlg element
API
open([closeFn])
close([resultValue])
toggleClass('class list')
element: DOMElement
Template
The dialog is built from the following template:
×
Default styling can be found in the less/dialog.less
file.
Access from the DOM
The dialog will attach itself to its dom node via the dialog
property once it is attached to the document tree.
; ;
Close from Template
The dialog will close on elements annotated with .dlg-close
.
A custom close result can be provided via the dlg-close-result
attribute
on .dlg-close
elements.
;
Extend the Dialog
The dialog is an EventEmitter. Extend it by hooking into one of the following life-cycle events:
attach(parentElement) attached to parentElement
pre-open about to open
open dialog is open
pre-close(resultValue) about to close with returnValue
close(resultValue) dialog closed with returnValue
detach(parentElement) detached from parentElement
The this
argument inside an event listener will always refer to the respective dialog instance:
;
Use the life-cycle events in order to make it fit into your favourite front-end library. An example integration into AngularJS can be found here.
License
MIT