kempo-ui 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/components/Tags.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Tags extends ShadowComponent{static properties={value:{type:String,reflect:!0},allowedTags:{type:String,reflect:!0,attribute:"allowed-tags"},disallowedTags:{type:String,reflect:!0,attribute:"disallowed-tags"}};constructor(){super(),this.value="",this.allowedTags="",this.disallowedTags=""}firstUpdated(){super.firstUpdated(),this.renderTags()}updated(t){if(super.updated(t),t.has("value")){const
|
|
1
|
+
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Tags extends ShadowComponent{static properties={value:{type:String,reflect:!0},allowedTags:{type:String,reflect:!0,attribute:"allowed-tags"},disallowedTags:{type:String,reflect:!0,attribute:"disallowed-tags"},disabled:{type:Boolean,reflect:!0}};constructor(){super(),this.value="",this.allowedTags="",this.disallowedTags="",this.disabled=!1}firstUpdated(){super.firstUpdated(),this.renderTags()}updated(t){if(super.updated(t),t.has("value")){const e=t.get("value"),a=this.validateTags();a!==this.value?this.value=a:(this.dispatchEvent(new CustomEvent("change",{detail:{oldValue:e,newValue:this.value},bubbles:!0})),this.renderTags())}if(t.has("allowedTags")||t.has("disallowedTags")){const e=t.get("allowedTags")||t.get("disallowedTags"),a=this.allowedTags||this.disallowedTags,s=this.validateTags();if(s!==this.value)this.value=s;else{const s=t.has("allowedTags")?"allowedtagschange":"disallowedtagschange";this.dispatchEvent(new CustomEvent(s,{detail:{oldValue:e,newValue:a},bubbles:!0})),this.renderTags()}}}handleInputChange=()=>{if(this.disabled)return;const t=this.shadowRoot.getElementById("tagsInput"),e=t.value.trim();e&&(this.addTag(e),t.value="")};handleInputInput=t=>{if(!this.disabled&&(","===t.data||"insertFromPaste"===t.inputType)){const t=this.shadowRoot.getElementById("tagsInput"),e=t.value.split(",").filter(t=>!!t.trim());e.length&&(e.forEach(t=>this.addTag(t.trim())),t.value="")}};async renderTags(){await this.updateComplete;const t=this.shadowRoot.getElementById("tags");t.innerHTML="",this.value&&this.value.split(",").forEach(e=>{const a=new Tag(e.trim(),this);t.appendChild(a)})}addTag(t){const e=new Set(this.value.split(",").filter(t=>!!t.trim()));e.add(t.trim()),this.value=[...e].filter(t=>!!t).join(","),this.dispatchEvent(new CustomEvent("addtag",{detail:{tag:t},bubbles:!0}))}removeTag(t){const e=new Set(this.value.split(",").filter(t=>!!t.trim()));e.delete(t),this.value=[...e].join(","),this.dispatchEvent(new CustomEvent("removetag",{detail:{tag:t},bubbles:!0}))}validateTags(){return this.value.split(",").map(t=>t.trim()).map(t=>{const e=new Set(this.allowedTags.split(",").filter(t=>!!t.trim()));if(e.size)return e.has(t)?t:"";const a=new Set(this.disallowedTags.split(",").filter(t=>!!t.trim()));return a.size&&a.has(t)?"":t}).filter(t=>!!t).join(",")}static styles=css`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
|
-
|
|
4
|
+
}
|
|
5
|
+
:host([disabled]) {
|
|
6
|
+
opacity: 0.5;
|
|
7
|
+
cursor: not-allowed;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
}
|
|
5
10
|
#tagsHolder {
|
|
6
11
|
display: flex;
|
|
7
12
|
flex-wrap: wrap;
|
|
@@ -46,13 +51,14 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
46
51
|
<div id="tagsHolder">
|
|
47
52
|
<span id="tags"></span>
|
|
48
53
|
<input
|
|
49
|
-
id="tagsInput"
|
|
54
|
+
id="tagsInput"
|
|
55
|
+
?disabled=${this.disabled}
|
|
50
56
|
@change=${this.handleInputChange}
|
|
51
57
|
@input=${this.handleInputInput}
|
|
52
58
|
/>
|
|
53
59
|
</div>
|
|
54
60
|
</label>
|
|
55
|
-
`}}class Tag extends ShadowComponent{constructor(t,
|
|
61
|
+
`}}class Tag extends ShadowComponent{constructor(t,e){super(),this.tag=t,this.tagsComponent=e,this.innerHTML=t}handleClick=()=>{this.tagsComponent.disabled||this.tagsComponent.removeTag(this.tag)};static styles=css`
|
|
56
62
|
:host {
|
|
57
63
|
display: inline-block;
|
|
58
64
|
width: min-content;
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
<a href="#basicUsage">Basic Usage</a><br />
|
|
25
25
|
<a href="#allowedTags">Allowed Tags</a><br />
|
|
26
26
|
<a href="#disallowedTags">Disallowed Tags</a><br />
|
|
27
|
+
<a href="#disabled">Disabled</a><br />
|
|
27
28
|
|
|
28
29
|
<h6 class="mt"><a href="#jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
29
30
|
<a href="#constructor">Constructor</a><br />
|
|
@@ -98,6 +99,24 @@
|
|
|
98
99
|
|
|
99
100
|
|
|
100
101
|
|
|
102
|
+
<h3 id="disabled"><a href="#disabled" class="no-link">Disabled</a></h3>
|
|
103
|
+
<p>Use the <code>disabled</code> attribute to prevent the user from adding or removing tags while still displaying the current value.</p>
|
|
104
|
+
<div class="row -mx mb">
|
|
105
|
+
<div class="col d-span-6 m-span-12 px">
|
|
106
|
+
<k-card label="HTML">
|
|
107
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-tags</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"design,ui"</span>></span><br> <span class="hljs-tag"><<span class="hljs-name">label</span>></span>Tags<span class="hljs-tag"></<span class="hljs-name">label</span>></span><br><span class="hljs-tag"></<span class="hljs-name">k-tags</span>></span></code></pre>
|
|
108
|
+
</k-card>
|
|
109
|
+
</div>
|
|
110
|
+
<div class="col d-span-6 m-span-12 px">
|
|
111
|
+
<k-card label="Results">
|
|
112
|
+
<k-tags disabled value="design,ui">
|
|
113
|
+
<label>Tags</label>
|
|
114
|
+
</k-tags>
|
|
115
|
+
</k-card>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
|
|
101
120
|
<h2 id="jsRef"><a href="#jsRef" class="no-link">JavaScript Reference</a></h2>
|
|
102
121
|
|
|
103
122
|
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
@@ -120,6 +139,8 @@
|
|
|
120
139
|
<h5><code>disallowedTags<i>: string</i></code></h5>
|
|
121
140
|
<p>A comma-separated list of disallowed tags. If specified, these tags cannot be added. Syncs with the
|
|
122
141
|
<code>disallowed-tags</code> attribute.</p>
|
|
142
|
+
<h5><code>disabled<i>: boolean</i></code></h5>
|
|
143
|
+
<p>When <code>true</code>, prevents the user from adding or removing tags. The current value is still displayed. The element appears at 50% opacity. Syncs with the <code>disabled</code> attribute.</p>
|
|
123
144
|
|
|
124
145
|
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
125
146
|
<h5><code>addTag(tag)<i>: void</i></code></h5>
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Tags extends ShadowComponent{static properties={value:{type:String,reflect:!0},allowedTags:{type:String,reflect:!0,attribute:"allowed-tags"},disallowedTags:{type:String,reflect:!0,attribute:"disallowed-tags"}};constructor(){super(),this.value="",this.allowedTags="",this.disallowedTags=""}firstUpdated(){super.firstUpdated(),this.renderTags()}updated(t){if(super.updated(t),t.has("value")){const
|
|
1
|
+
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Tags extends ShadowComponent{static properties={value:{type:String,reflect:!0},allowedTags:{type:String,reflect:!0,attribute:"allowed-tags"},disallowedTags:{type:String,reflect:!0,attribute:"disallowed-tags"},disabled:{type:Boolean,reflect:!0}};constructor(){super(),this.value="",this.allowedTags="",this.disallowedTags="",this.disabled=!1}firstUpdated(){super.firstUpdated(),this.renderTags()}updated(t){if(super.updated(t),t.has("value")){const e=t.get("value"),a=this.validateTags();a!==this.value?this.value=a:(this.dispatchEvent(new CustomEvent("change",{detail:{oldValue:e,newValue:this.value},bubbles:!0})),this.renderTags())}if(t.has("allowedTags")||t.has("disallowedTags")){const e=t.get("allowedTags")||t.get("disallowedTags"),a=this.allowedTags||this.disallowedTags,s=this.validateTags();if(s!==this.value)this.value=s;else{const s=t.has("allowedTags")?"allowedtagschange":"disallowedtagschange";this.dispatchEvent(new CustomEvent(s,{detail:{oldValue:e,newValue:a},bubbles:!0})),this.renderTags()}}}handleInputChange=()=>{if(this.disabled)return;const t=this.shadowRoot.getElementById("tagsInput"),e=t.value.trim();e&&(this.addTag(e),t.value="")};handleInputInput=t=>{if(!this.disabled&&(","===t.data||"insertFromPaste"===t.inputType)){const t=this.shadowRoot.getElementById("tagsInput"),e=t.value.split(",").filter(t=>!!t.trim());e.length&&(e.forEach(t=>this.addTag(t.trim())),t.value="")}};async renderTags(){await this.updateComplete;const t=this.shadowRoot.getElementById("tags");t.innerHTML="",this.value&&this.value.split(",").forEach(e=>{const a=new Tag(e.trim(),this);t.appendChild(a)})}addTag(t){const e=new Set(this.value.split(",").filter(t=>!!t.trim()));e.add(t.trim()),this.value=[...e].filter(t=>!!t).join(","),this.dispatchEvent(new CustomEvent("addtag",{detail:{tag:t},bubbles:!0}))}removeTag(t){const e=new Set(this.value.split(",").filter(t=>!!t.trim()));e.delete(t),this.value=[...e].join(","),this.dispatchEvent(new CustomEvent("removetag",{detail:{tag:t},bubbles:!0}))}validateTags(){return this.value.split(",").map(t=>t.trim()).map(t=>{const e=new Set(this.allowedTags.split(",").filter(t=>!!t.trim()));if(e.size)return e.has(t)?t:"";const a=new Set(this.disallowedTags.split(",").filter(t=>!!t.trim()));return a.size&&a.has(t)?"":t}).filter(t=>!!t).join(",")}static styles=css`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
|
-
|
|
4
|
+
}
|
|
5
|
+
:host([disabled]) {
|
|
6
|
+
opacity: 0.5;
|
|
7
|
+
cursor: not-allowed;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
}
|
|
5
10
|
#tagsHolder {
|
|
6
11
|
display: flex;
|
|
7
12
|
flex-wrap: wrap;
|
|
@@ -46,13 +51,14 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
46
51
|
<div id="tagsHolder">
|
|
47
52
|
<span id="tags"></span>
|
|
48
53
|
<input
|
|
49
|
-
id="tagsInput"
|
|
54
|
+
id="tagsInput"
|
|
55
|
+
?disabled=${this.disabled}
|
|
50
56
|
@change=${this.handleInputChange}
|
|
51
57
|
@input=${this.handleInputInput}
|
|
52
58
|
/>
|
|
53
59
|
</div>
|
|
54
60
|
</label>
|
|
55
|
-
`}}class Tag extends ShadowComponent{constructor(t,
|
|
61
|
+
`}}class Tag extends ShadowComponent{constructor(t,e){super(),this.tag=t,this.tagsComponent=e,this.innerHTML=t}handleClick=()=>{this.tagsComponent.disabled||this.tagsComponent.removeTag(this.tag)};static styles=css`
|
|
56
62
|
:host {
|
|
57
63
|
display: inline-block;
|
|
58
64
|
width: min-content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kempo-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Lit based web-component library",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "node scripts/build.js",
|
|
15
15
|
"prod": "node scripts/docs.js",
|
|
16
|
-
"dev": "node scripts/docs.js --src --
|
|
16
|
+
"dev": "node scripts/docs.js --src --port 9875",
|
|
17
17
|
"icon": "node bin/icon.js",
|
|
18
18
|
"geticon": "node bin/get_icon.js",
|
|
19
19
|
"listicons": "node bin/list_icons.js",
|
package/src/components/Tags.js
CHANGED
|
@@ -8,7 +8,8 @@ export default class Tags extends ShadowComponent {
|
|
|
8
8
|
static properties = {
|
|
9
9
|
value: { type: String, reflect: true },
|
|
10
10
|
allowedTags: { type: String, reflect: true, attribute: 'allowed-tags' },
|
|
11
|
-
disallowedTags: { type: String, reflect: true, attribute: 'disallowed-tags' }
|
|
11
|
+
disallowedTags: { type: String, reflect: true, attribute: 'disallowed-tags' },
|
|
12
|
+
disabled: { type: Boolean, reflect: true }
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
constructor() {
|
|
@@ -16,6 +17,7 @@ export default class Tags extends ShadowComponent {
|
|
|
16
17
|
this.value = '';
|
|
17
18
|
this.allowedTags = '';
|
|
18
19
|
this.disallowedTags = '';
|
|
20
|
+
this.disabled = false;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/*
|
|
@@ -64,6 +66,7 @@ export default class Tags extends ShadowComponent {
|
|
|
64
66
|
Event Handlers
|
|
65
67
|
*/
|
|
66
68
|
handleInputChange = () => {
|
|
69
|
+
if(this.disabled) return;
|
|
67
70
|
const tagsInput = this.shadowRoot.getElementById('tagsInput');
|
|
68
71
|
const tag = tagsInput.value.trim();
|
|
69
72
|
if(tag) {
|
|
@@ -73,6 +76,7 @@ export default class Tags extends ShadowComponent {
|
|
|
73
76
|
};
|
|
74
77
|
|
|
75
78
|
handleInputInput = (event) => {
|
|
79
|
+
if(this.disabled) return;
|
|
76
80
|
if(event.data === ',' || event.inputType === 'insertFromPaste') {
|
|
77
81
|
const tagsInput = this.shadowRoot.getElementById('tagsInput');
|
|
78
82
|
const tags = tagsInput.value.split(',').filter(tag => !!tag.trim());
|
|
@@ -140,7 +144,12 @@ export default class Tags extends ShadowComponent {
|
|
|
140
144
|
static styles = css`
|
|
141
145
|
:host {
|
|
142
146
|
display: block;
|
|
143
|
-
|
|
147
|
+
}
|
|
148
|
+
:host([disabled]) {
|
|
149
|
+
opacity: 0.5;
|
|
150
|
+
cursor: not-allowed;
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
}
|
|
144
153
|
#tagsHolder {
|
|
145
154
|
display: flex;
|
|
146
155
|
flex-wrap: wrap;
|
|
@@ -191,7 +200,8 @@ export default class Tags extends ShadowComponent {
|
|
|
191
200
|
<div id="tagsHolder">
|
|
192
201
|
<span id="tags"></span>
|
|
193
202
|
<input
|
|
194
|
-
id="tagsInput"
|
|
203
|
+
id="tagsInput"
|
|
204
|
+
?disabled=${this.disabled}
|
|
195
205
|
@change=${this.handleInputChange}
|
|
196
206
|
@input=${this.handleInputInput}
|
|
197
207
|
/>
|
|
@@ -216,6 +226,7 @@ class Tag extends ShadowComponent {
|
|
|
216
226
|
Event Handlers
|
|
217
227
|
*/
|
|
218
228
|
handleClick = () => {
|
|
229
|
+
if(this.tagsComponent.disabled) return;
|
|
219
230
|
this.tagsComponent.removeTag(this.tag);
|
|
220
231
|
};
|
|
221
232
|
|
|
@@ -600,5 +600,110 @@ export default {
|
|
|
600
600
|
|
|
601
601
|
cleanup(container);
|
|
602
602
|
pass('Whitespace-only tags not added');
|
|
603
|
+
},
|
|
604
|
+
|
|
605
|
+
/*
|
|
606
|
+
Disabled
|
|
607
|
+
*/
|
|
608
|
+
'disabled should default to false': async ({pass, fail}) => {
|
|
609
|
+
const { container, tags } = await createTags();
|
|
610
|
+
if(tags.disabled !== false){
|
|
611
|
+
cleanup(container);
|
|
612
|
+
return fail(`Expected disabled to be false, got ${tags.disabled}`);
|
|
613
|
+
}
|
|
614
|
+
cleanup(container);
|
|
615
|
+
pass('disabled defaults to false');
|
|
616
|
+
},
|
|
617
|
+
|
|
618
|
+
'should reflect disabled attribute': async ({pass, fail}) => {
|
|
619
|
+
const container = document.createElement('div');
|
|
620
|
+
container.innerHTML = '<k-tags disabled></k-tags>';
|
|
621
|
+
document.body.appendChild(container);
|
|
622
|
+
const tags = container.querySelector('k-tags');
|
|
623
|
+
await tags.updateComplete;
|
|
624
|
+
if(!tags.hasAttribute('disabled')){
|
|
625
|
+
cleanup(container);
|
|
626
|
+
return fail('Tags should have disabled attribute');
|
|
627
|
+
}
|
|
628
|
+
if(tags.disabled !== true){
|
|
629
|
+
cleanup(container);
|
|
630
|
+
return fail(`Expected disabled property to be true, got ${tags.disabled}`);
|
|
631
|
+
}
|
|
632
|
+
cleanup(container);
|
|
633
|
+
pass('disabled attribute reflects correctly');
|
|
634
|
+
},
|
|
635
|
+
|
|
636
|
+
'input change should not add tag when disabled': async ({pass, fail}) => {
|
|
637
|
+
const container = document.createElement('div');
|
|
638
|
+
container.innerHTML = '<k-tags disabled></k-tags>';
|
|
639
|
+
document.body.appendChild(container);
|
|
640
|
+
const tags = container.querySelector('k-tags');
|
|
641
|
+
await tags.updateComplete;
|
|
642
|
+
const input = tags.shadowRoot.getElementById('tagsInput');
|
|
643
|
+
input.value = 'newtag';
|
|
644
|
+
input.dispatchEvent(new Event('change'));
|
|
645
|
+
await tags.updateComplete;
|
|
646
|
+
if(tags.value !== ''){
|
|
647
|
+
cleanup(container);
|
|
648
|
+
return fail(`Expected value to remain empty when disabled, got "${tags.value}"`);
|
|
649
|
+
}
|
|
650
|
+
cleanup(container);
|
|
651
|
+
pass('Input change does not add tag when disabled');
|
|
652
|
+
},
|
|
653
|
+
|
|
654
|
+
'input event should not add tag when disabled': async ({pass, fail}) => {
|
|
655
|
+
const container = document.createElement('div');
|
|
656
|
+
container.innerHTML = '<k-tags disabled></k-tags>';
|
|
657
|
+
document.body.appendChild(container);
|
|
658
|
+
const tags = container.querySelector('k-tags');
|
|
659
|
+
await tags.updateComplete;
|
|
660
|
+
const input = tags.shadowRoot.getElementById('tagsInput');
|
|
661
|
+
input.value = 'tag1,tag2,';
|
|
662
|
+
input.dispatchEvent(new InputEvent('input', { data: ',' }));
|
|
663
|
+
await tags.updateComplete;
|
|
664
|
+
if(tags.value !== ''){
|
|
665
|
+
cleanup(container);
|
|
666
|
+
return fail(`Expected value to remain empty when disabled, got "${tags.value}"`);
|
|
667
|
+
}
|
|
668
|
+
cleanup(container);
|
|
669
|
+
pass('Input event does not add tag when disabled');
|
|
670
|
+
},
|
|
671
|
+
|
|
672
|
+
'clicking tag should not remove it when disabled': async ({pass, fail}) => {
|
|
673
|
+
const container = document.createElement('div');
|
|
674
|
+
container.innerHTML = '<k-tags disabled value="design,ui"></k-tags>';
|
|
675
|
+
document.body.appendChild(container);
|
|
676
|
+
const tags = container.querySelector('k-tags');
|
|
677
|
+
await tags.updateComplete;
|
|
678
|
+
await new Promise(r => setTimeout(r, 50));
|
|
679
|
+
const tagEl = tags.shadowRoot.getElementById('tags').querySelector('k-tag');
|
|
680
|
+
if(!tagEl){
|
|
681
|
+
cleanup(container);
|
|
682
|
+
return fail('Expected a k-tag element to be rendered');
|
|
683
|
+
}
|
|
684
|
+
const span = tagEl.shadowRoot.querySelector('span');
|
|
685
|
+
span.click();
|
|
686
|
+
await tags.updateComplete;
|
|
687
|
+
if(!tags.value.includes('design') || !tags.value.includes('ui')){
|
|
688
|
+
cleanup(container);
|
|
689
|
+
return fail(`Tags should not be removed when disabled, got "${tags.value}"`);
|
|
690
|
+
}
|
|
691
|
+
cleanup(container);
|
|
692
|
+
pass('Clicking tag does not remove it when disabled');
|
|
693
|
+
},
|
|
694
|
+
|
|
695
|
+
'input should be disabled when disabled attribute is set': async ({pass, fail}) => {
|
|
696
|
+
const container = document.createElement('div');
|
|
697
|
+
container.innerHTML = '<k-tags disabled></k-tags>';
|
|
698
|
+
document.body.appendChild(container);
|
|
699
|
+
const tags = container.querySelector('k-tags');
|
|
700
|
+
await tags.updateComplete;
|
|
701
|
+
const input = tags.shadowRoot.getElementById('tagsInput');
|
|
702
|
+
if(!input.disabled){
|
|
703
|
+
cleanup(container);
|
|
704
|
+
return fail('Input should be disabled when Tags is disabled');
|
|
705
|
+
}
|
|
706
|
+
cleanup(container);
|
|
707
|
+
pass('Input is disabled when Tags is disabled');
|
|
603
708
|
}
|
|
604
709
|
};
|