-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from rackerlabs/SURF-566-hx-reveal
surf-566-hx-reveal
- Loading branch information
Showing
9 changed files
with
227 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dd { | ||
margin-bottom: 0.5em; | ||
margin-left: 1em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.