Skip to content

Commit a5a92bb

Browse files
author
Cathy Siller
committed
fix(hx-pill): invert dismissible behaviour with persist
1 parent a8bc8c5 commit a5a92bb

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

docs/components/pills/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ <h2 id="basic-pill">Basic Pill</h2>
2525
<fieldset>
2626
<legend>Options</legend>
2727
<label>
28-
<input type="checkbox" v-model="isDismissable" />
29-
Dismissable
28+
<input type="checkbox" v-model="isPersistent" />
29+
Persist
3030
</label>
3131
</fieldset>
3232
</form>
3333
</header>
3434

3535
<div>
36-
<hx-pill :dismissable="isDismissable" v-text="content"></hx-pill>
36+
<hx-pill
37+
:persist="isPersistent"
38+
v-text="content"
39+
@dismiss="onEvent">
40+
</hx-pill>
3741
</div>
3842

3943
<footer>

docs/components/pills/pill-demo.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ if (document.getElementById('vue-pillDemo')) {
55
el: '#vue-pillDemo',
66
data: {
77
content: 'status: unicorns!',
8-
isDismissable: false,
8+
isPersistent: false,
9+
},
10+
methods: {
11+
onEvent: function (evt) {
12+
evt.preventDefault();
13+
alert(`Event: "${evt.type}"`);
14+
},
915
},
1016
computed: {
1117
snippet: function () {
1218
return Util.snippet(`
1319
<hx-pill
14-
${this.isDismissable ? 'dismissable' : ''}
20+
${this.isPersistent ? 'persist' : ''}
1521
>
1622
${this.content}
1723
</hx-pill>

docs/components/pills/test.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<section>
1515
<h2>Outside Tables</h2>
1616
<p>
17-
<hx-pill>Persistent</hx-pill>
18-
<hx-pill dismissable>Dismissible</hx-pill>
17+
<hx-pill persist>Persistent</hx-pill>
18+
<hx-pill>Dismissible</hx-pill>
1919
</p>
2020
</section>
2121

@@ -25,12 +25,12 @@ <h2>Inside Tables</h2>
2525
<tbody>
2626
<tr>
2727
<td>
28-
<hx-pill>Persistent</hx-pill>
28+
<hx-pill persist>Persistent</hx-pill>
2929
</td>
3030
</tr>
3131
<tr>
3232
<td>
33-
<hx-pill dismissable>Dismissable</hx-pill>
33+
<hx-pill>Dismissable</hx-pill>
3434
</td>
3535
</tr>
3636
</tbody>
@@ -43,12 +43,12 @@ <h2>Inside Tables (Condensed)</h2>
4343
<tbody>
4444
<tr>
4545
<td>
46-
<hx-pill>Persistent</hx-pill>
46+
<hx-pill persist>Persistent</hx-pill>
4747
</td>
4848
</tr>
4949
<tr>
5050
<td>
51-
<hx-pill dismissable>Dismissable</hx-pill>
51+
<hx-pill>Dismissable</hx-pill>
5252
</td>
5353
</tr>
5454
</tbody>

src/helix-ui/elements/HXPillElement.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,35 @@ export class HXPillElement extends HXElement {
3232

3333
$onConnect () {
3434
this._btnDismiss.addEventListener('click', this._onDismiss);
35+
this.$upgradeProperty('persist');
3536
}
3637

3738
$onDisconnect () {
3839
this._btnDismiss.removeEventListener('click', this._onDismiss);
3940
}
4041

42+
static get $observedAttributes () {
43+
return [ 'persist' ];
44+
}
45+
46+
/**
47+
* Property reflecting the `persist` HTML attribute, indicating whether the
48+
* pill may be dismissed. If true, the dismiss button will not be shown.
49+
*
50+
* @default false
51+
* @type {Boolean}
52+
*/
53+
get persist () {
54+
return this.hasAttribute('persist');
55+
}
56+
set persist (value) {
57+
if (value) {
58+
this.setAttribute('persist', ''); // boolean
59+
} else {
60+
this.removeAttribute('persist');
61+
}
62+
}
63+
4164
/**
4265
* Dismiss the pill (removes element from the DOM)
4366
*/

src/helix-ui/elements/HXPillElement.less

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#Button.reset();
1818
align-items: center;
1919
color: @gray-600;
20-
display: none;
20+
display: inline-flex;
2121
height: 1.5em;
2222
justify-content: center;
2323
margin: 0 -0.5rem 0 0;
@@ -33,8 +33,10 @@
3333
}
3434
}
3535

36-
:host([dismissable]) {
37-
#hxDismiss {
38-
display: inline-flex;
36+
:host([persist]) {
37+
#hxPill {
38+
#hxDismiss {
39+
display: none;
40+
}
3941
}
4042
}

0 commit comments

Comments
 (0)