rwt-file-tabs
v1.0.22
Published
Switch between active views using a file-tab interface, a standards-based DOM Component
Downloads
27
Maintainers
Readme
Premium DOM Component
File Tabs
For multitasking UI/UX
Motivation
The rwt-file-tabs DOM component can be used in scenarios with multiple views or multiple work tasks.
This component can be configured with a fixed set of tabs which are slotted into the component when designing the document. Alternatively, its programming API allows tabs to be created and removed as needed, when working with a dynamic set of tabs.
Tabs can be configured using CSS to adjust their size and typography.
The tab bar occupies a fixed width. When the size of all tabs exceeds that width, scroll buttons are automatically enabled.
Dynamic tabs can be closable or not, based on an attribute set on the DOM component by the developer.
In the wild
To see an example of this component in use, visit the BLUEFIDDLE website. It uses two components: one vertical and one horizontal. 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.
Installation
Prerequisites
The rwt-file-tabs 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
Using the DOM component
After installation, you need to add a few things to your HTML page to make use of it.
- Add a
script
tag to load the component'srwt-file-tabs.js
file:
<script src='/node_modules/rwt-file-tabs/rwt-file-tabs.js' type=module></script>
Add the component tag somewhere on the page, configuring it with these optional attributes:
closable
This optional attribute instructs the component to add an 'x' button to each dynamically added tab, allowing the user to remove the tab.scroll-side={left|right}
When the space occupied by the tabs is too large, scroll buttons are enabled. They can be positioned to theleft
or theright
of the tabs.anchor-side={left|right}
When the space occupied by the tabs is less than the width of the component, the unoccupied space can be anchored to theleft
or to theright
of the tabs.role=navigation
This web accessible ARIA attribute tells readers that the component is used for navigation.
Slotted usage
If the component is to be used with a predetermined set of tabs, they can be slotted in. Here's an example:
<rwt-file-tabs role=contentinfo>
<button slot=tabitem id=tab1 title='Read only view'>READ</button>
<button slot=tabitem id=tab2 title='Text editing view'>WRITE</button>
<button slot=tabitem id=tab3 title='Web browser preview'>PREVIEW</button>
</rwt-file-tabs>
Programmatic API
If the component is to be used with a dynamic set of tabs, they can be added and removed using these methods.
Life-cycle events
The component issues life-cycle events.
Styling
Tab styling
The component can be styled with these CSS variables:
rwt-file-tabs {
--width: 100%;
--height: 2rem;
--nav-button-size: 1.6rem;
}
The tabs can be styled with these CSS variables:
rwt-file-tabs {
--font-weight: normal;
--letter-spacing: 0px;
--text-align: left;
--min-width: 2rem;
--max-width: 6rem;
}
Dialog color scheme
The default color palette for the component uses a dark mode theme. You can use CSS to override the variables' defaults:
rwt-file-tabs {
--color: var(--white);
--accent-color1: var(--pure-white);
--background: var(--black);
--accent-background1: var(--pure-black);
--accent-background2: var(--nav-black);
--accent-background3: var(--medium-black);
--accent-background4: var(--gray);
}
Vertically oriented tabs
The component can be oriented vertically by wrapping it in a positioned element and using a CSS transform. Here's an example of how to do it:
HTML
<div id=viewtabs-area>
<rwt-file-tabs id=viewtabs scroll-side=left anchor-side=right>
<button id=id4 slot=tabitem title='Delta view'>Delta</button>
<button id=id3 slot=tabitem title='Gamma view'>Gamma</button>
<button id=id2 slot=tabitem title='Beta view'>Beta</button>
<button id=id1 slot=tabitem title='Alpha view'>Alpha</button>
</rwt-file-tabs>
</div>
CSS
div#viewtabs-area {
position: absolute;
top: 2.3rem;
left: 0;
bottom: 0;
width: 2.0rem;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
}
#viewtabs {
position: absolute;
transform: rotate(-90deg);
transform-origin: left top;
width: 34rem; /* JavaScript will override */
top: 34rem; /* JavaScript will override */
}
JavaScript
function onResize() {
var viewTabsArea = document.getElementById('viewtabs-area');
var viewTabs = document.getElementById('viewtabs');
var height = viewTabsArea.offsetHeight;
viewTabs.style.width = `${height}px`;
viewTabs.style.top = `${height}px`;
}
window.addEventListener('resize', onResize);
Reference
License
The rwt-file-tabs DOM component is not freeware. After evaluating it and before using it in a public-facing website, eBook, mobile app, or desktop application, you must obtain a license from Read Write Tools .
Activation
To activate your license, copy the rwt-registration-keys.js
file to the root
directory of your website, providing the customer-number
and access-key
sent to
your email address, and replacing example.com
with your website's hostname.
Follow this example: