Skip to content

Commit b91bedf

Browse files
authored
Merge pull request #391 from rackerlabs/surf-1236-invert-pill-dismissible
fix(hx-pill): invert dismissible behaviour with persist
2 parents 6ed29d3 + 97ff0b4 commit b91bedf

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
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>

docs/elements/hx-pill/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ <h2 id="methods">Methods</h2>
5151

5252
{% block attributes %}
5353
<dl>
54-
<dt>dismissable {Boolean [false]} <i>(optional)</i></dt>
54+
<dt>persist {Boolean}</dt>
5555
<dd>
56-
When present, pill will be dismissable.
56+
When present, pill will not be dismissable.
5757
</dd>
5858
</dl>
5959
{% endblock %}
6060

6161
{% block properties %}
6262
<dl>
63-
<dt>dismissable {Boolean [false]}</dt>
63+
<dt>persist {Boolean [false]}</dt>
6464
<dd>
65-
When <code>true</code>, pill will be dismissable.
65+
When <code>true</code>, pill will not be dismissable.
6666
</dd>
6767
</dl>
6868
{% endblock %}

src/helix-ui/elements/HXPillElement.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,36 @@ 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+
/**
43+
* Property reflecting the `persist` HTML attribute, indicating whether the
44+
* pill may be dismissed. If true, the dismiss button will not be shown.
45+
*
46+
* @default false
47+
* @type {Boolean}
48+
*/
49+
get persist () {
50+
return this.hasAttribute('persist');
51+
}
52+
set persist (value) {
53+
if (value) {
54+
this.setAttribute('persist', '');
55+
} else {
56+
this.removeAttribute('persist');
57+
}
58+
}
59+
4160
/**
4261
* Dismiss the pill (removes element from the DOM)
4362
*/
4463
dismiss () {
45-
if (this.$emit('dismiss')) {
64+
if (!this.persist && this.$emit('dismiss')) {
4665
// only if event was not canceled by consumer
4766
this.remove();
4867
}

src/helix-ui/elements/HXPillElement.less

Lines changed: 3 additions & 3 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,8 @@
3333
}
3434
}
3535

36-
:host([dismissable]) {
36+
:host([persist]) {
3737
#hxDismiss {
38-
display: inline-flex;
38+
display: none;
3939
}
4040
}

0 commit comments

Comments
 (0)