Popup box with titlebar and slotted contents, a standards-based DOM Component
npm install rwt-shadowbox

##### Open Source DOM Component
by Read Write Tools | Abstract |
|---|
| The rwt-shadowbox DOM component is a popup dialog box with titlebar caption, close button, shortcut key access, event interface, and either slotted or templated content. |
Dialog boxes are such a common design pattern that they need no explanation.
HTML5 has a special dialog tag for that very purpose. Unfortunately, the HTML
dialog tag does not provide any "standard" behavior for how it should appear.
Nor does it provide a convenient way for the user to dismiss it.
The rwt-shadowbox DOM component has several features which
overcome those limitations, and make for a more pleasant user experience.
* The dialog box has a titlebar with caption and close button.
* The contents may be slotted or provided with a template file.
* The dialog has an event interface for showing and hiding itself.
* The dialog emits a custom event to close sibling dialog boxes.
* A keyboard listener is provided to allow a shortcut key to open/close the
dialog.
#### In the wild
To see an example of this component in use, visit the READ WRITE TOOLS
website and press F2 "Info" or F3 "Rights". To understand
what's going on under the hood, use the browser's inspector to view the HTML
source code and network activity, and follow along as you read this
documentation.
#### Prerequisites
The rwt-shadowbox DOM component works in any browser that
supports modern W3C standards. Templates are written using BLUE
PHRASE notation, which can be compiled into HTML using the free Read Write View
desktop app. It has no other prerequisites. Distribution and installation are
done with either NPM or via Github.
#### Download
OPTION 1: Familiar with Node.js and the OPTION 2: No prior experience using NPM? Important note: This DOM component uses Node.js and NPM and
Download using NPM
package.json file?
Great. Install the component with this command:
npm install rwt-shadowbox
Just follow these general steps:
package.json file in the root of your web project using the command:
npm init
npm install rwt-shadowbox
package.json as a convenient distribution and installation mechanism. The DOM component itself does not need them.
If you prefer using Github directly, simply follow these steps:
Download using Github
node_modules directory in the root of your web project.
git clone https://github.com/readwritetools/rwt-shadowbox.git
After installation, you need to add four things to your HTML page to make use of
it.
* Add a script tag to load the component's rwt-shadowbox.js file:
``html`
* Add the component tag somewhere on the page.
* For scripting purposes, apply an id attribute.titlebar
* Apply a attribute with the text you want to appear as a caption.shortcut
* Optionally, apply a attribute with something like F1, F2, etc. forsourceref
hotkey access.
* Optionally, apply a attribute with a reference to an HTML filerole=contentinfo
containing the dialog's text and any CSS it needs.
* And for WAI-ARIA accessibility apply a attribute.sourceref
* For simple dialog boxes, the may be omitted and the text of the dialog
box may be slotted into the DOM component. Simply place the text directly
between the and tags.`html`
* Add a way for the visitor to show the dialog:
`html`
ℹ
* Add a listener to respond to the click event:
`html`
#### Dialog size and position
The dialog is absolutely positioned towards the bottom left of the viewport. Its
size may be overridden using CSS by defining new values for the size and
position variables.
`css
rwt-shadowbox#info {
--min-width: 10rem;
--optimal-width: 70vw;
--max-width: 40rem;
--min-height: 10rem;
--optimal-height: 50vh;
--max-height: 40rem;
--bottom: 1rem;
--left: 1rem;
--z-index: 1;
}
`
#### Dialog color scheme
The default color palette for the dialog uses a dark mode theme. You can use CSS
to override the variables' defaults:
`css``
rwt-shadowbox#info {
--color: var(--white);
--accent-color1: var(--yellow);
--accent-color2: var(--js-blue);
--background: var(--black);
--accent-background1: var(--medium-black);
--accent-background2: var(--pure-black);
--accent-background3: var(--nav-black);
--accent-background4: var(--black);
}
The component issues life-cycle events.
component-loadedwaitOnLoading() method which returns a promise that resolves when the component-loaded event is received. Call this asynchronously with await.The dialog box can be controlled with its event interface.
toggle-shadowboxdocument for toggle-shadowbox messages. Upon receipt it will show or hide the dialog box.keydowndocument for keydown messages. If the user presses the configured shortcut key (F1, F2, etc) it will show/hide the dialog box. The Esc key closes the dialog box.collapse-popupdocument for collapse-popup messages, which are sent by sibling dialog boxes. Upon receipt it will close itself.clickdocument for click messages. When the user clicks anywhere outside the dialog box, it closes itself.---
| Documentation | READ WRITE HUB | |
| Source code | github | |
| Component catalog | DOM COMPONENTS | |
| Package installation | npm | |
| Publication venue | READ WRITE STACK |
The rwt-shadowbox DOM component is licensed under the MIT
License.

Copyright © 2020 Read Write Tools. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License