Skip to content

Commit 0dc1e92

Browse files
author
Cathy Siller
committed
feat(pills): add styles for search pills
1 parent 08b2ddf commit 0dc1e92

File tree

12 files changed

+227
-1
lines changed

12 files changed

+227
-1
lines changed

docs/_data/nav.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
{ label: 'Modals', path: 'modals' },
4545
{ label: 'Panels', path: 'panels' },
4646
{ label: 'Pagination', path: 'pagination' },
47+
{ label: 'Pills', path: 'pills' },
4748
{ label: 'Popovers', path: 'popovers' },
4849
{ label: 'Progress', path: 'progress' },
4950
{ label: 'Reveals', path: 'reveals' },
@@ -85,6 +86,7 @@
8586
{ label: '<hx-panelbody>', path: 'hx-panelbody' },
8687
{ label: '<hx-panelfoot>', path: 'hx-panelfoot' },
8788
{ label: '<hx-panelhead>', path: 'hx-panelhead' },
89+
{ label: '<hx-pill>', path: 'hx-pill' },
8890
{ label: '<hx-popover>', path: 'hx-popover' },
8991
{ label: '<hx-popover-body>', path: 'hx-popover-body' },
9092
{ label: '<hx-popover-foot>', path: 'hx-popover-foot' },

docs/components/pills/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Pills
3+
also:
4+
elements/hx-pill: <hx-pill>
5+
---
6+
{% extends 'component.njk' %}
7+
{% block content %}
8+
<section>
9+
<h2 id="basic-pill">Basic Pill</h2>
10+
<div id="vue-pillDemo" class="hxRow" v-cloak>
11+
<div class="hxCol hxSpan-12-xs hxSpan-3-lg hxOrder-2-lg">
12+
<h3>Options</h3>
13+
<p>
14+
<label>
15+
<input type="checkbox" v-model="isDismissable">
16+
Dismissable
17+
</label>
18+
</p>
19+
<p>
20+
<b>Content:</b><br />
21+
<textarea class="hxTextCtrl" v-model="content"></textarea>
22+
</p>
23+
</div>
24+
<div class="hxCol hxSpan-12-xs hxSpan-9-lg hxOrder-1-lg">
25+
<div class="demo pill-demo">
26+
<hx-pill
27+
:dismissable="isDismissable"
28+
v-text="content">
29+
</hx-pill>
30+
</div>
31+
<pre><code>{% raw %}{{snippet}}{% endraw %}</code></pre>
32+
</div>
33+
</div>
34+
</section>
35+
{% endblock %}

docs/components/pills/pill-demo.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Util from '../../_util';
2+
3+
if (document.getElementById('vue-pillDemo')) {
4+
new Vue({
5+
el: '#vue-pillDemo',
6+
data: {
7+
content: 'status: unicorns!',
8+
isDismissable: false,
9+
},
10+
computed: {
11+
snippet: function () {
12+
return Util.snippet(`
13+
<hx-pill
14+
${this.isDismissable ? 'dismissable' : ''}
15+
>
16+
${this.content}
17+
</hx-pill>
18+
`);
19+
},
20+
},
21+
});
22+
}

docs/components/toasts/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h3>Options</h3>
4141
</p>
4242
</div>
4343
<div class="hxCol hxSpan-12-xs hxSpan-9-lg hxOrder-1-lg">
44-
<div class="demo alert-demo">
44+
<div class="demo toast-demo">
4545
<hx-toast
4646
:type="type.value"
4747
:cta="cta"

docs/docs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import './components/choice-tiles/choice-tile-demo';
1010
import './components/icons/icon-demo';
1111
import './components/lists/list-demo';
1212
import './components/panels/panel-demo';
13+
import './components/pills/pill-demo';
1314
import './components/popovers/popover-demo';
1415
import './components/progress/progress-demo';
1516
import './components/reveals/reveal-demo';

docs/elements/hx-pill/index.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: <hx-pill>
3+
also:
4+
components/pills: Pills
5+
---
6+
{% extends 'element.njk' %}
7+
{% block content %}
8+
<section>
9+
<p>
10+
The custom <code>{{page.title}}</code> element provides a pill-like
11+
element that can be optionally dismissed.
12+
</p>
13+
14+
<hx-dl class="hxBox-md metadata">
15+
<hx-def>
16+
<hx-dt>Permitted Parents</hx-dt>
17+
<hx-dd>any</hx-dd>
18+
</hx-def>
19+
<hx-def>
20+
<hx-dt>Permitted Children</hx-dt>
21+
<hx-dd>phrasing content</hx-dd>
22+
</hx-def>
23+
<hx-def>
24+
<hx-dt>Events</hx-dt>
25+
<hx-dd>
26+
Any of the following:
27+
<ul>
28+
<li>
29+
<code>dismiss</code> - User presses "X" to dismiss the pill.
30+
</li>
31+
</ul>
32+
</hx-dd>
33+
</hx-def>
34+
</hx-dl>
35+
</section>
36+
37+
<section>
38+
<h2 id="methods">Methods</h2>
39+
<dl>
40+
<dt>dismiss()</dt>
41+
<dd>Dismisses the pill.</dd>
42+
</dl>
43+
</section>
44+
{% endblock %}
45+
46+
{% block attributes %}
47+
<dl>
48+
<dt>dismissable {Boolean=false} <i>(optional)</i></dt>
49+
<dd>
50+
When present, pill will be dismissable.
51+
</dd>
52+
</dl>
53+
{% endblock %}
54+
55+
{% block properties %}
56+
<dl>
57+
<dt>dismissable {Boolean=false}</dt>
58+
<dd>
59+
When <code>true</code>, pill will be dismissable.
60+
</dd>
61+
</dl>
62+
{% endblock %}

src/helix-ui/elements.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export { HXIconElement } from './elements/HXIconElement.js';
1414
export { HXMenuElement } from './elements/HXMenuElement.js';
1515
export { HXMenuitemElement } from './elements/HXMenuitemElement.js';
1616
export { HXModalElement } from './elements/HXModalElement.js';
17+
export { HXPillElement } from './elements/HXPillElement.js';
1718
export { HXPopoverElement } from './elements/HXPopoverElement.js';
1819
export { HXProgressElement } from './elements/HXProgressElement.js';
1920
export { HXRevealElement } from './elements/HXRevealElement.js';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div id="wrapper">
2+
<slot></slot>
3+
<button id="dismiss" type="button">
4+
<hx-icon type="times"></hx-icon>
5+
</button>
6+
</div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { HXElement } from './HXElement';
2+
import shadowMarkup from './HXPillElement.html';
3+
import shadowStyles from './HXPillElement.less';
4+
5+
/**
6+
* Fires when the user triggers the dismiss button.
7+
*
8+
* @event Pills:dismiss
9+
* @type {CustomEvent}
10+
*/
11+
12+
export class HXPillElement extends HXElement {
13+
static get is () {
14+
return `hx-pill`;
15+
}
16+
17+
static get template () {
18+
return `<style>${shadowStyles}</style>${shadowMarkup}`;
19+
}
20+
21+
$onCreate () {
22+
this._onDismiss = this._onDismiss.bind(this);
23+
}
24+
25+
$onConnect () {
26+
this._btnDismiss.addEventListener('click', this._onDismiss);
27+
}
28+
29+
$onDisconnect () {
30+
this._btnDismiss.removeEventListener('click', this._onDismiss);
31+
}
32+
33+
/**
34+
* Programmatically dismiss the pill (removes element from the DOM).
35+
*/
36+
dismiss () {
37+
this.remove();
38+
}
39+
40+
/** @private */
41+
_onDismiss (evt) {
42+
evt.preventDefault();
43+
44+
if (this.$emit('dismiss')) {
45+
// only if event was not canceled by consumer
46+
this.dismiss();
47+
}
48+
}
49+
50+
/** @private */
51+
get _btnDismiss () {
52+
return this.shadowRoot.getElementById('dismiss');
53+
}
54+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@import "./HXElement";
2+
@import "elements/hx-icon";
3+
4+
button {
5+
background-color: transparent;
6+
border: 0;
7+
cursor: pointer;
8+
padding: 0;
9+
}
10+
11+
#wrapper {
12+
background-color: @gray-400;
13+
border-radius: 1em;
14+
color: @gray-900;
15+
padding: 0 1rem;
16+
white-space: nowrap;
17+
}
18+
19+
#dismiss {
20+
color: @gray-600;
21+
display: none;
22+
height: 1.5em;
23+
margin: 0 -0.5rem 0 0;
24+
width: 1.5em;
25+
26+
hx-icon {
27+
font-size: 0.75em;
28+
}
29+
30+
&:hover {
31+
color: @gray-1000;
32+
}
33+
}
34+
35+
:host([dismissable]) {
36+
#dismiss {
37+
display: inline-block;
38+
}
39+
}

0 commit comments

Comments
 (0)