kempo-ui 0.3.2 → 0.3.3
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/Table.js +1 -1
- package/dist/components/Toggle.js +6 -1
- package/docs/components/toggle.html +20 -0
- package/docs/src/components/Table.js +1 -1
- package/docs/src/components/Toggle.js +6 -1
- package/package.json +1 -1
- package/src/components/Table.js +1 -1
- package/src/components/Toggle.js +10 -1
- package/tests/components/Toggle.browser-test.js +62 -0
package/dist/components/Table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},requestEdit:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-edit"},requestDelete:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-delete"},placeholder:{type:String,reflect:!0},filteredPlaceholder:{type:String,reflect:!0,attribute:"filtered-placeholder"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1),void 0===this.requestEdit&&(this.requestEdit=!1),void 0===this.requestDelete&&(this.requestDelete=!1),void 0===this.placeholder&&(this.placeholder="No Records"),void 0===this.filteredPlaceholder&&(this.filteredPlaceholder="")}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.allOnPageSelected())}}renderColgroupTemplate(){const e=[];return this.enableSelection&&e.push(html`<col style="width: 40px" />`),this.hasBeforeControls()&&e.push(html`<col style="width: ${this.columnSizes.beforeControls}px" />`),this.fields.forEach(({size:t,hidden:s})=>{s||e.push(t?html`<col style="width: ${t}px" />`:html`<col />`)}),this.hasAfterControls()&&e.push(html`<col style="width: ${this.columnSizes.afterControls}px" />`),e}getColumnCount(){let e=0;return this.enableSelection&&e++,this.hasBeforeControls()&&e++,this.fields.forEach(({hidden:t})=>{t||e++}),this.hasAfterControls()&&e++,e}renderFieldsTemplate(){const e=[];return this.enableSelection&&e.push(html`
|
|
1
|
+
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},requestEdit:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-edit"},requestDelete:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-delete"},placeholder:{type:String,reflect:!0},filteredPlaceholder:{type:String,reflect:!0,attribute:"filtered-placeholder"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1),void 0===this.requestEdit&&(this.requestEdit=!1),void 0===this.requestDelete&&(this.requestDelete=!1),void 0===this.placeholder&&(this.placeholder="No Records"),void 0===this.filteredPlaceholder&&(this.filteredPlaceholder="")}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.getDisplayedRecords().length>0&&this.allOnPageSelected())}}renderColgroupTemplate(){const e=[];return this.enableSelection&&e.push(html`<col style="width: 40px" />`),this.hasBeforeControls()&&e.push(html`<col style="width: ${this.columnSizes.beforeControls}px" />`),this.fields.forEach(({size:t,hidden:s})=>{s||e.push(t?html`<col style="width: ${t}px" />`:html`<col />`)}),this.hasAfterControls()&&e.push(html`<col style="width: ${this.columnSizes.afterControls}px" />`),e}getColumnCount(){let e=0;return this.enableSelection&&e++,this.hasBeforeControls()&&e++,this.fields.forEach(({hidden:t})=>{t||e++}),this.hasAfterControls()&&e++,e}renderFieldsTemplate(){const e=[];return this.enableSelection&&e.push(html`
|
|
2
2
|
<th class="controls field-select">
|
|
3
3
|
<input type="checkbox" id="select-all" @change=${this.handleSelectAllChange} />
|
|
4
4
|
</th>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0}};constructor(){super(),this.value=!1,this.tabIndex=0}updated(e){super.updated(e),e.has("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}handleClick=()=>{this.toggle()};handleKeyDown=e=>{["Space","Enter"].includes(e.code)&&(e.preventDefault(),this.toggle())};on(){return this.value=!0,this.dispatchEvent(new CustomEvent("on",{detail:{value:!0},bubbles:!0})),this}off(){return this.value=!1,this.dispatchEvent(new CustomEvent("off",{detail:{value:!1},bubbles:!0})),this}toggle(){return this.value?this.off():this.on(),this.dispatchEvent(new CustomEvent("toggle",{detail:{value:this.value},bubbles:!0})),this}render(){return html`
|
|
1
|
+
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0}};constructor(){super(),this.value=!1,this.disabled=!1,this.tabIndex=0}updated(e){super.updated(e),e.has("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}handleClick=()=>{this.disabled||this.toggle()};handleKeyDown=e=>{this.disabled||["Space","Enter"].includes(e.code)&&(e.preventDefault(),this.toggle())};on(){return this.value=!0,this.dispatchEvent(new CustomEvent("on",{detail:{value:!0},bubbles:!0})),this}off(){return this.value=!1,this.dispatchEvent(new CustomEvent("off",{detail:{value:!1},bubbles:!0})),this}toggle(){return this.value?this.off():this.on(),this.dispatchEvent(new CustomEvent("toggle",{detail:{value:this.value},bubbles:!0})),this}render(){return html`
|
|
2
2
|
<div id="switch">
|
|
3
3
|
<div id="handle"></div>
|
|
4
4
|
</div>
|
|
@@ -26,6 +26,11 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
26
26
|
outline: none;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
:host([disabled]) {
|
|
30
|
+
opacity: 0.5;
|
|
31
|
+
cursor: not-allowed;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
}
|
|
29
34
|
#switch {
|
|
30
35
|
display: flex;
|
|
31
36
|
align-items: center;
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
<a href="#responsiveBehavior">Responsive Behavior</a><br />
|
|
27
27
|
<a href="#customStyles">Custom Styles</a><br />
|
|
28
28
|
<a href="#javascriptUsage">JavaScript Usage</a><br />
|
|
29
|
+
<a href="#disabled">Disabled</a><br />
|
|
29
30
|
|
|
30
31
|
<h6 class="mt"><a href="jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
31
32
|
<a href="#constructor">Constructor</a><br />
|
|
@@ -137,6 +138,22 @@
|
|
|
137
138
|
</div>
|
|
138
139
|
</div>
|
|
139
140
|
|
|
141
|
+
<h3 id="disabled"><a href="#disabled" class="no-link">Disabled</a></h3>
|
|
142
|
+
<p>The <code>disabled</code> attribute prevents the user from changing the toggle's state while still displaying its current value.</p>
|
|
143
|
+
<div class="row -mx">
|
|
144
|
+
<div class="col m-span-12 px">
|
|
145
|
+
<k-card label="HTML">
|
|
146
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">disabled</span>></span>Disabled Off<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span><br><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">value</span>></span>Disabled On<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span></code></pre>
|
|
147
|
+
</k-card>
|
|
148
|
+
</div>
|
|
149
|
+
<div class="col m-span-12 px">
|
|
150
|
+
<k-card label="Output">
|
|
151
|
+
<k-toggle disabled>Disabled Off</k-toggle>
|
|
152
|
+
<k-toggle disabled value>Disabled On</k-toggle>
|
|
153
|
+
</k-card>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
140
157
|
<h2 id="jsRef"><a href="jsRef" class="no-link">JavaScript Reference</a></h2>
|
|
141
158
|
|
|
142
159
|
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
@@ -155,6 +172,9 @@
|
|
|
155
172
|
<p>A boolean that indicates if the switch is on or off, the default value is <code>false</code>. Syncs to <code>value</code> attribute.</p>
|
|
156
173
|
<p>This can be set directly, but it is not recommended as it only triggers the a <code>change</code> event and not a <code>on</code>, <code>off</code> or <code>toggle</code> event as the methods do, so the methods are preferrable.</p>
|
|
157
174
|
|
|
175
|
+
<h5><code>disabled<i>: boolean</i></code></h5>
|
|
176
|
+
<p>When <code>true</code>, the toggle cannot be changed by user interaction. The current state is still displayed. The element will appear at 50% opacity. Syncs to <code>disabled</code> attribute.</p>
|
|
177
|
+
|
|
158
178
|
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
159
179
|
<h5><code>on()<i>: this</i></code></h5>
|
|
160
180
|
<p>Set's the <code>value</code> to <code>true</code>, dispatches a <code><i>change</i></code> and an <code><i>on</i></code> event. The switch visual changes to the <b>on</b> state.</p>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},requestEdit:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-edit"},requestDelete:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-delete"},placeholder:{type:String,reflect:!0},filteredPlaceholder:{type:String,reflect:!0,attribute:"filtered-placeholder"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1),void 0===this.requestEdit&&(this.requestEdit=!1),void 0===this.requestDelete&&(this.requestDelete=!1),void 0===this.placeholder&&(this.placeholder="No Records"),void 0===this.filteredPlaceholder&&(this.filteredPlaceholder="")}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.allOnPageSelected())}}renderColgroupTemplate(){const e=[];return this.enableSelection&&e.push(html`<col style="width: 40px" />`),this.hasBeforeControls()&&e.push(html`<col style="width: ${this.columnSizes.beforeControls}px" />`),this.fields.forEach(({size:t,hidden:s})=>{s||e.push(t?html`<col style="width: ${t}px" />`:html`<col />`)}),this.hasAfterControls()&&e.push(html`<col style="width: ${this.columnSizes.afterControls}px" />`),e}getColumnCount(){let e=0;return this.enableSelection&&e++,this.hasBeforeControls()&&e++,this.fields.forEach(({hidden:t})=>{t||e++}),this.hasAfterControls()&&e++,e}renderFieldsTemplate(){const e=[];return this.enableSelection&&e.push(html`
|
|
1
|
+
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},requestEdit:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-edit"},requestDelete:{type:Boolean,reflect:!0,converter:boolExists,attribute:"request-delete"},placeholder:{type:String,reflect:!0},filteredPlaceholder:{type:String,reflect:!0,attribute:"filtered-placeholder"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1),void 0===this.requestEdit&&(this.requestEdit=!1),void 0===this.requestDelete&&(this.requestDelete=!1),void 0===this.placeholder&&(this.placeholder="No Records"),void 0===this.filteredPlaceholder&&(this.filteredPlaceholder="")}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.getDisplayedRecords().length>0&&this.allOnPageSelected())}}renderColgroupTemplate(){const e=[];return this.enableSelection&&e.push(html`<col style="width: 40px" />`),this.hasBeforeControls()&&e.push(html`<col style="width: ${this.columnSizes.beforeControls}px" />`),this.fields.forEach(({size:t,hidden:s})=>{s||e.push(t?html`<col style="width: ${t}px" />`:html`<col />`)}),this.hasAfterControls()&&e.push(html`<col style="width: ${this.columnSizes.afterControls}px" />`),e}getColumnCount(){let e=0;return this.enableSelection&&e++,this.hasBeforeControls()&&e++,this.fields.forEach(({hidden:t})=>{t||e++}),this.hasAfterControls()&&e++,e}renderFieldsTemplate(){const e=[];return this.enableSelection&&e.push(html`
|
|
2
2
|
<th class="controls field-select">
|
|
3
3
|
<input type="checkbox" id="select-all" @change=${this.handleSelectAllChange} />
|
|
4
4
|
</th>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0}};constructor(){super(),this.value=!1,this.tabIndex=0}updated(e){super.updated(e),e.has("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}handleClick=()=>{this.toggle()};handleKeyDown=e=>{["Space","Enter"].includes(e.code)&&(e.preventDefault(),this.toggle())};on(){return this.value=!0,this.dispatchEvent(new CustomEvent("on",{detail:{value:!0},bubbles:!0})),this}off(){return this.value=!1,this.dispatchEvent(new CustomEvent("off",{detail:{value:!1},bubbles:!0})),this}toggle(){return this.value?this.off():this.on(),this.dispatchEvent(new CustomEvent("toggle",{detail:{value:this.value},bubbles:!0})),this}render(){return html`
|
|
1
|
+
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0}};constructor(){super(),this.value=!1,this.disabled=!1,this.tabIndex=0}updated(e){super.updated(e),e.has("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}handleClick=()=>{this.disabled||this.toggle()};handleKeyDown=e=>{this.disabled||["Space","Enter"].includes(e.code)&&(e.preventDefault(),this.toggle())};on(){return this.value=!0,this.dispatchEvent(new CustomEvent("on",{detail:{value:!0},bubbles:!0})),this}off(){return this.value=!1,this.dispatchEvent(new CustomEvent("off",{detail:{value:!1},bubbles:!0})),this}toggle(){return this.value?this.off():this.on(),this.dispatchEvent(new CustomEvent("toggle",{detail:{value:this.value},bubbles:!0})),this}render(){return html`
|
|
2
2
|
<div id="switch">
|
|
3
3
|
<div id="handle"></div>
|
|
4
4
|
</div>
|
|
@@ -26,6 +26,11 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
26
26
|
outline: none;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
:host([disabled]) {
|
|
30
|
+
opacity: 0.5;
|
|
31
|
+
cursor: not-allowed;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
}
|
|
29
34
|
#switch {
|
|
30
35
|
display: flex;
|
|
31
36
|
align-items: center;
|
package/package.json
CHANGED
package/src/components/Table.js
CHANGED
|
@@ -92,7 +92,7 @@ export default class Table extends ShadowComponent {
|
|
|
92
92
|
if(this.enableSelection) {
|
|
93
93
|
const selectAllCheckbox = this.shadowRoot.getElementById('select-all');
|
|
94
94
|
if(selectAllCheckbox) {
|
|
95
|
-
selectAllCheckbox.checked = this.allOnPageSelected();
|
|
95
|
+
selectAllCheckbox.checked = this.getDisplayedRecords().length > 0 && this.allOnPageSelected();
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
package/src/components/Toggle.js
CHANGED
|
@@ -3,12 +3,14 @@ import ShadowComponent from './ShadowComponent.js';
|
|
|
3
3
|
|
|
4
4
|
export default class Toggle extends ShadowComponent {
|
|
5
5
|
static properties = {
|
|
6
|
-
value: { type: Boolean, reflect: true }
|
|
6
|
+
value: { type: Boolean, reflect: true },
|
|
7
|
+
disabled: { type: Boolean, reflect: true }
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
constructor() {
|
|
10
11
|
super();
|
|
11
12
|
this.value = false;
|
|
13
|
+
this.disabled = false;
|
|
12
14
|
this.tabIndex = 0;
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -42,10 +44,12 @@ export default class Toggle extends ShadowComponent {
|
|
|
42
44
|
Event Handlers
|
|
43
45
|
*/
|
|
44
46
|
handleClick = () => {
|
|
47
|
+
if(this.disabled) return;
|
|
45
48
|
this.toggle();
|
|
46
49
|
};
|
|
47
50
|
|
|
48
51
|
handleKeyDown = (event) => {
|
|
52
|
+
if(this.disabled) return;
|
|
49
53
|
if (['Space', 'Enter'].includes(event.code)) {
|
|
50
54
|
event.preventDefault();
|
|
51
55
|
this.toggle();
|
|
@@ -120,6 +124,11 @@ export default class Toggle extends ShadowComponent {
|
|
|
120
124
|
outline: none;
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
:host([disabled]) {
|
|
128
|
+
opacity: 0.5;
|
|
129
|
+
cursor: not-allowed;
|
|
130
|
+
pointer-events: none;
|
|
131
|
+
}
|
|
123
132
|
#switch {
|
|
124
133
|
display: flex;
|
|
125
134
|
align-items: center;
|
|
@@ -584,5 +584,67 @@ export default {
|
|
|
584
584
|
toggle.remove();
|
|
585
585
|
cleanup(container);
|
|
586
586
|
pass('Handles disconnection and reconnection');
|
|
587
|
+
},
|
|
588
|
+
|
|
589
|
+
/*
|
|
590
|
+
Disabled
|
|
591
|
+
*/
|
|
592
|
+
'disabled should default to false': async ({pass, fail}) => {
|
|
593
|
+
const { container, toggle } = await createToggle();
|
|
594
|
+
if(toggle.disabled !== false){
|
|
595
|
+
cleanup(container);
|
|
596
|
+
return fail(`Expected disabled to be false, got ${toggle.disabled}`);
|
|
597
|
+
}
|
|
598
|
+
cleanup(container);
|
|
599
|
+
pass('disabled defaults to false');
|
|
600
|
+
},
|
|
601
|
+
|
|
602
|
+
'should reflect disabled attribute': async ({pass, fail}) => {
|
|
603
|
+
const container = document.createElement('div');
|
|
604
|
+
container.innerHTML = '<k-toggle disabled></k-toggle>';
|
|
605
|
+
document.body.appendChild(container);
|
|
606
|
+
const toggle = container.querySelector('k-toggle');
|
|
607
|
+
await toggle.updateComplete;
|
|
608
|
+
if(!toggle.hasAttribute('disabled')){
|
|
609
|
+
cleanup(container);
|
|
610
|
+
return fail('Toggle should have disabled attribute');
|
|
611
|
+
}
|
|
612
|
+
if(toggle.disabled !== true){
|
|
613
|
+
cleanup(container);
|
|
614
|
+
return fail(`Expected disabled property to be true, got ${toggle.disabled}`);
|
|
615
|
+
}
|
|
616
|
+
cleanup(container);
|
|
617
|
+
pass('disabled attribute reflects correctly');
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
'click should not change value when disabled': async ({pass, fail}) => {
|
|
621
|
+
const container = document.createElement('div');
|
|
622
|
+
container.innerHTML = '<k-toggle disabled></k-toggle>';
|
|
623
|
+
document.body.appendChild(container);
|
|
624
|
+
const toggle = container.querySelector('k-toggle');
|
|
625
|
+
await toggle.updateComplete;
|
|
626
|
+
toggle.click();
|
|
627
|
+
if(toggle.value !== false){
|
|
628
|
+
cleanup(container);
|
|
629
|
+
return fail(`Expected value to remain false after click when disabled, got ${toggle.value}`);
|
|
630
|
+
}
|
|
631
|
+
cleanup(container);
|
|
632
|
+
pass('Click does not change value when disabled');
|
|
633
|
+
},
|
|
634
|
+
|
|
635
|
+
'keydown should not change value when disabled': async ({pass, fail}) => {
|
|
636
|
+
const container = document.createElement('div');
|
|
637
|
+
container.innerHTML = '<k-toggle disabled></k-toggle>';
|
|
638
|
+
document.body.appendChild(container);
|
|
639
|
+
const toggle = container.querySelector('k-toggle');
|
|
640
|
+
await toggle.updateComplete;
|
|
641
|
+
const event = new KeyboardEvent('keydown', { code: 'Space', bubbles: true });
|
|
642
|
+
toggle.dispatchEvent(event);
|
|
643
|
+
if(toggle.value !== false){
|
|
644
|
+
cleanup(container);
|
|
645
|
+
return fail(`Expected value to remain false after Space key when disabled, got ${toggle.value}`);
|
|
646
|
+
}
|
|
647
|
+
cleanup(container);
|
|
648
|
+
pass('Keydown does not change value when disabled');
|
|
587
649
|
}
|
|
588
650
|
};
|