floating-window
v0.1.7
Published
JavaScript module which creates a floating window. The window consists of a header, a titlel and a close button. In addition to closing, event handlers to move the window are added. The actual content of the window is then passed when the class is ini
Downloads
10
Readme
floating-window
JavaScript module which creates a floating window. The window consists of a header, a titlel and a close button. In addition to closing, event handlers to move the window are added. The actual content of the window is then passed when the class is initialized.
The Modul has a default export for the class "win". You'll find an example in "demo".
How to use
install
npm install floating-window
import
import Win from './node_modules/floating-win/index.js'
create instance
Inits the class and creates the window. But the window is not added to any tree.
const winId = 'myFloatingTestWin'; // the id for the new window
const winTitle = 'Test title'; // the text that is displayed in the title bar of the window
const winBody = document.createElement('div');
// ... body building
const winFloat = new Win(winId, winTitle, winBody);
append the window
Append the window to a tree. This can be also a shadow tree.
winFloat.appendWindow(document.documentElement);
show the window
Append the window to a tree. This can be also a shadow tree.
winFloat.show();
hide the window
The window can either close by the close button in the window head. Or you use the "hide" method:
winFloat.hide();
destroy the window
To destroy the window and remove all EventListener call the "destroy" method.
winFloat.destory();
styling
The following selectors are available:
- floating-win (for the dialog)
- floating-win-head (for the head of the window)
- floating-win-head-title (for the title inside the head)
- floating-win-head-closer (for the element represents the close button)
- floating-win-body (parent element for the content of the window)
If the window is inserted into the shadow DOM, then the selector must be used as a parameter for "::part".
::part(floating-win-head) {
background-color: darkblue;
}