Skip to content

Commit

Permalink
Merge pull request #44 from rackerlabs/SURF-566-hx-reveal
Browse files Browse the repository at this point in the history
surf-566-hx-reveal
  • Loading branch information
CITguy authored Sep 14, 2017
2 parents ecc98e2 + 0853046 commit 701605b
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 90 deletions.
1 change: 1 addition & 0 deletions source/_data/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ components:
Pagination: /pagination
Popovers: /popovers
"Progress Bars": /progressbars
Reveal: /reveal
Tables: /tables
Tabs: /tabs
Tooltips: /tooltips
Expand Down
4 changes: 4 additions & 0 deletions source/components/lists/_lists.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dd {
margin-bottom: 0.5em;
margin-left: 1em;
}
18 changes: 5 additions & 13 deletions source/components/navigation/_navigation.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,13 @@
}
}

section {
& > div {
display: none;
}

&.open {
hx-reveal {
&[open] {
& > header {
.toggle-icon {
transform: scaleY(-1);
}
}

& > div {
display: block;
}
}

/* Indentation */
Expand All @@ -81,7 +73,7 @@
}

// Level 2
section {
hx-reveal {
header {
padding-left: @l2-indent;
}
Expand All @@ -91,7 +83,7 @@
}

// Level 3
section {
hx-reveal {
header {
padding-left: @l3-indent;
}
Expand All @@ -101,6 +93,6 @@
}
}
}
}//section
}//hx-reveal
}

68 changes: 30 additions & 38 deletions source/components/navigation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,57 +71,49 @@ <h2 id="app-nav">Application Navigation</h2>
<a href="#">Link 1-1</a>
<a href="#">Link 1-2</a>
<a href="#">Link 1-3</a>
<section class="open">
<header>
<hx-reveal open>
<header slot="summary">
L1 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<div>
<a href="#">Link 2-1</a>
<a href="#">Link 2-2</a>
<a href="#">Link 2-3</a>
<section class="open">
<header>
L2 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<div>
<a href="#">Link 3-1</a>
<a href="#">Link 3-2</a>
<a href="#">Link 3-3</a>
</div>
</section>
</div>
</section>
<a href="#">Link 2-1</a>
<a href="#">Link 2-2</a>
<a href="#">Link 2-3</a>
<hx-reveal open>
<header slot="summary">
L2 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<a href="#">Link 3-1</a>
<a href="#">Link 3-2</a>
<a href="#">Link 3-3</a>
</hx-reveal>
</hx-reveal>
</nav>
</div>
```html
<nav class="hx-app-nav">
<a href="#">Link 1-1</a>
<a href="#">Link 1-2</a>
<a href="#">Link 1-3</a>
<section class="open">
<header>
<hx-reveal open>
<header slot="summary">
L1 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<div>
<a href="#">Link 2-1</a>
<a href="#">Link 2-2</a>
<a href="#">Link 2-3</a>
<section class="open">
<header>
L2 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<div>
<a href="#">Link 3-1</a>
<a href="#">Link 3-2</a>
<a href="#">Link 3-3</a>
</div>
</section>
</div>
</section>
<a href="#">Link 2-1</a>
<a href="#">Link 2-2</a>
<a href="#">Link 2-3</a>
<hx-reveal open>
<header slot="summary">
L2 Section
<hx-icon class="toggle-icon" type="angle-down"></hx-icon>
</header>
<a href="#">Link 3-1</a>
<a href="#">Link 3-2</a>
<a href="#">Link 3-3</a>
</hx-reveal>
</hx-reveal>
</nav>
```
</section>
98 changes: 98 additions & 0 deletions source/components/reveal/_HxReveal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
window.addEventListener('WebComponentsReady', function () {
const template = document.createElement('template');

template.innerHTML = `
<style>
:host {
display: block;
}
:host([open]) #content {
display: block;
}
#content {
display: none;
}
#toggle {
background-color: transparent;
border: none;
color: inherit;
font-size: 1em;
margin: 0px;
padding: 0px;
text-align: left;
width: 100%;
}
#toggle:empty {
display: none;
}
#toggle:hover {
cursor: pointer;
}
</style>
<button id="toggle" aria-expanded="false">
<slot name="summary"></slot>
</button>
<div id="content">
<slot></slot>
</div>
`;

class HxReveal extends HTMLElement {
static get is () {
return 'hx-reveal';
}

static get observedAttributes () {
return ['open'];
}

constructor() {
super();
this.attachShadow({mode: 'open'});
if (window.ShadyCSS ) {
ShadyCSS.prepareTemplate(template, 'hx-reveal');
ShadyCSS.styleElement(this);
}
this.shadowRoot.appendChild(template.content.cloneNode(true));
this._btnToggle = this.shadowRoot.querySelector('#toggle');
this.toggle = this.toggle.bind(this);
}

connectedCallback () {
this._btnToggle.addEventListener('click', this.toggle);
}

disconnectedCallback () {
this._btnToggle.removeEventListener('click', this.toggle);
}

attributeChangedCallback (attr, oldValue, newValue) {
if (attr === 'open') {
this._btnToggle.setAttribute('aria-expanded', newValue === '');
}
}

toggle () {
if (this.getAttribute('open') === '') {
this.close();
} else {
this.open();
}
}

open () {
this.setAttribute('open', '');
}

close () {
this.removeAttribute('open');
}
}
customElements.define(HxReveal.is, HxReveal)
});
63 changes: 63 additions & 0 deletions source/components/reveal/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Reveal
assets:
- helix-ui.js
---

<p>
A reveal is a behavior-only web component that implements almost no styling.
</p>

<section>
<h2 id="default-reveal">Default Reveal</h2>
<p>Closed by default</p>
<div class="demo">
<hx-reveal>
<span slot="summary">Click me to show content</span>
<p>You can't see me.</p>
</hx-reveal>
</div>
```html
<hx-reveal>
<span slot="summary">Click me to show content</span>
<p>You can't see me.</p>
</hx-reveal>
```
</section>
<section>
<h2 id="open-reveal">Open Reveal</h2>
<p>Add <code>open</code> attribute to set the reveal in an open state</p>
<div class="demo">
<hx-reveal open>
<span slot="summary">Click me to hide content!</span>
<p>You should see me.</p>
</hx-reveal>
</div>
```html
<hx-reveal open>
<span slot="summary">Click me to hide content!</span>
<p>You should see me.</p>
</hx-reveal>
```
</section>
<section>
<h2 id="attributes">Attributes</h2>
<dl>
<dt>open</dt>
<dd>Opens the reveal</dd>
</dl>
</section>
<section>
<h2 id="functions">Functions</h2>
<p>The following functions are available on the element.</p>
<dl>
<dt>close()</dt>
<dd>Closes the reveal</dd>

<dt>open()</dt>
<dd>Opens the reveal</dd>

<dt>toggle()</dt>
<dd>Inverts the open state</dd>
</dl>
</section>
12 changes: 1 addition & 11 deletions source/scripts/_helix-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@
// Each file will be responsible for defining itself
// with the custom element registry
import '../components/icons/_HxIcon';

/* Left Nav Toggle Behavior */
(function () {
var _headers = document.querySelectorAll('.hx-app-nav header');

_headers.forEach(function (header) {
header.addEventListener('click', function (evt) {
evt.target.parentElement.classList.toggle('open');
});
});
})();
import '../components/reveal/_HxReveal';
1 change: 1 addition & 0 deletions source/styles/helix-ui.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import 'breadcrumbs/_breadcrumbs';
@import 'grid/_grid';
@import 'icons/_icons';
@import 'lists/_lists';
@import 'navigation/_navigation';
@import 'typography/_typography';

Expand Down
Loading

0 comments on commit 701605b

Please sign in to comment.