Open Source DOM Component

Dockable Panels

Expand, collapse, dock and float

by Read Write Tools
Abstract
The rwt-dockable-panels DOM component is an accordion-style component with panels that expand/collapse and dock/float.

Motivation

Some apps have lots of interactive manipulations for working with a canvas or object. Putting the tools and options for these manipulation commands within menus is a weak design pattern. The use of floatable, dockable, and collapsable panels is a better alternative because it lets the user initiate commands with shorter mouse transit times and fewer clicks. It also provides the user with a personalized mental map of where the commands can be initiated, something that a hierarchical menu doesn't do well.

The component has these features:

  • The component comprises a collection of panels that contain logically related information.
  • Each panel has a titlebar for self-identification and a panel area comprising DOM elements.
  • The titlebar has an expand/collapse button which allows the panel's elements to be shown or hidden.
  • The titlebar has a float/dock button which allows the panel to be detached/attached from the main panel.
  • Floating panels can be moved with the mouse by dragging the titlebar.
  • The initial position of the menu is relative to any one of the four viewport corners.

In the wild

To see an example of this component in use, visit the simply.earth website. It uses this component for its Tangent, Scale, Rotate, Locate, and Identify panels. 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-dockable-panels DOM component works in any browser that supports modern W3C standards. Templates are written using BLUEPHRASE 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.

Installation

Installation using NPM

If you are familiar with Node.js and the package.json file, you'll be comfortable installing the component just using this command:

npm install rwt-dockable-panels

If you are a front-end Web developer with no prior experience with NPM, follow these general steps:

  • Install Node.js/NPM on your development computer.
  • Create a package.json file in the root of your web project using the command:
  • npm init
  • Download and install the DOM component using the command:
  • npm install rwt-dockable-panels

Important note: This DOM component uses Node.js and NPM and package.json as a convenient distribution and installation mechanism. The DOM component itself does not need them.

Installation using Github

If you are more comfortable using Github for installation, follow these steps:

  • Create a directory node_modules in the root of your web project.
  • Clone the rwt-dockable-panels DOM component into it using the command:
  • git clone https://github.com/readwritetools/rwt-dockable-panels.git

Using the DOM component

After installation, you need to add two things to your HTML page to make use of it:

  1. Add a script tag to load the component's rwt-dockable-panels.js file:
  2. <script src='/node_modules/rwt-dockable-panels/rwt-dockable-panels.js' type=module></script>             
  3. Add the component tag somewhere on the page.
    • For scripting purposes, apply an id attribute.
    • For WAI-ARIA accessibility apply a role=contentinfo attribute.
    • Apply a corner attribute with one of these values
      • top-left
      • top-right
      • bottom-left
      • bottom-right
    • Apply a sourceref attribute with a reference to a JSON file containing the panel configuration. (Or optionally use the programmatic interface for panel configuration.)
    • Optionally, apply an open or closed attribute to set the initial state of the toolbar
    <rwt-dockable-panels id=toolbarId sourceref='/panels.json' corner=top-right role=contentinfo open></rwt-dockable-panels>

Panel configuration

The panels can be configured programmatically or through a JSON file. Both accept similar objects.

JSON file configuration

A JSON file containing a collection of panel configurations can be specified as an attribute of the component. Do this with HTML like <rwt-dockable-panels sourceref='panels.json'></rwt-dockable-panels> The JSON object should contain an object with two properties:

  1. toolbar an object for configuring the entire component, having:
    • titlebar the plain text or HTML to use for the main menu.
  2. panels an array of panel objects for configuring the panels, having:
    • options an object to configure each panel's basic properties;
      • id the HTML identifier for the panel
      • titlebar the text title for the panel
      • tabIndex the HTML tabIndex, optional
      • tooltip the fly-over popup title for the panel, optional
    • panelLines an array of line objects to configure the elements of the panel, line by line.
      • lineType specifies what to put on the line, see below
      • id the HTML identifier for the line's principal element, see below

These are the possible lineTypes and their configuration properties:

  1. "input"
    • labelText the text to place before the INPUT element
    • id the identifier for the INPUT element
    • textAfter any text to place after the INPUT element, optional
    • tooltip the fly-over popup title for the INPUT element, optional
  2. "dropdown"
    • labelText the text to place before the SELECT element
    • id the identifier for the SELECT element
    • tooltip the fly-over popup title for the SELECT element, optional
    • selections an array of OPTIONS, specified as objects, each having:
      • v the OPTION value
      • t the OPTION text
  3. "button"
    • buttonText the text to place on the BUTTON element
    • id the identifier for the BUTTON element
    • tooltip the fly-over popup title for the BUTTON element, optional
  4. "multi-button"
    • buttons an array of objects to define each button, having:
      • buttonText the text to place on the BUTTON element
      • id the identifier for the BUTTON element
      • tooltip the fly-over popup title for the BUTTON element, optional
  5. "generic"
    • id the identifier for the DIV element
    • heightInPx the height of the DIV element, specified with "px"
    • overflowY Whether to show the scrollbar, either "scroll" or "hidden"

Programmatic configuration

The component has methods to programmatically configure panels. They use objects with the same properties as just described. The methods are:

setTitlebar (html)
sets the topmost menu titlebar
appendPanel (panelId, options, panelLines)
creates a new panel and adds it to the component
appendInputLine (elPanel, options)
creates a line with a label and an input
appendDropdown (elPanel, options)
creates a line with a label and a select element
appendSingleButton (elPanel, options)
creates an internal button for doing something user-defined
appendMultiButtons (elPanel, options)
creates multiple buttons that logically work together and visually appear on one line
appendGenericArea (elPanel, options)
creates a div suitable for use with dynamic HTML

Programmatic manipulation

The component also has methods to programmatically manipulate the toolbar and its panels.

openToolbar ()
shows all the panels in their current expand/collapse state
closeToolbar ()
leaves only the Star button visible
expandPanel (menuID)
shows all of the panel's lines
collapsePanel (menuID)
shows only the panel's titlebar
detachPanel (menuID)
detaches the panel from the toolbar, allowing it to float independently
attachPanel (menuID)
reattaches the panel to the toolbar

Customization

Initial position

Initially the toolbar is positioned a certain distance from one of the viewport's corners, specified using the corner attribute and two of these offset variables.

rwt-dockable-panels {
--top: 30px;
--bottom: 30px;
--left: 30px;
--right: 30px;
--z-index: 1;
}

Visuals and color scheme

The font for the component can be changed with the --font-family variable.

The width of the component can be set with the --width variable.

The default color palette for the menu uses a dark mode theme. You can use CSS to override the variables' defaults:

rwt-dockable-panels {
--color: var(--pure-white);
--border-color: var(--pure-white);
--background-color1: var(--surfie-green);
--background-color2: var(--coral-atoll);
--background-color3: var(--tiber);
--background-color4: var(--eden);
}

Life-cycle events

The component issues life-cycle events.

component-loaded
Sent when the component is fully loaded and ready to be used. As a convenience you can use the waitOnLoading() method which returns a promise that resolves when the component-loaded event is received. Call this asynchronously with await.

Reference

DOM components logo Documentation READ WRITE HUB
git logo Source code github
DOM components logo Component catalog DOM COMPONENTS
npm logo Package installation npm
Read Write Stack logo Publication venue READ WRITE STACK

License

The rwt-dockable-panels DOM component is licensed under the MIT License.

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.

Dockable Panels — Expand, collapse, dock and float

🔗 🔎