From 0dd4c972f8678e6e96293e250c3ad330033b3864 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Fri, 2 Oct 2020 14:41:15 +0530 Subject: [PATCH] Improved cross browser support --- Standard UI Components/components.js | 4271 +++++++++++++++----------- 1 file changed, 2482 insertions(+), 1789 deletions(-) diff --git a/Standard UI Components/components.js b/Standard UI Components/components.js index 30d8c2f..7ebbf41 100644 --- a/Standard UI Components/components.js +++ b/Standard UI Components/components.js @@ -1,111 +1,148 @@ //Button - const smButton = document.createElement('template') smButton.innerHTML = ` - -
- -
`; + } + :host([variant='outlined']) .button:active{ + -webkit-box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset, 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.8rem rgba(0, 0, 0, 0.2); + box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset, 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.8rem rgba(0, 0, 0, 0.2); + } +} + +
+ +
`; customElements.define('sm-button', class extends HTMLElement { constructor() { super() - this.attachShadow({ mode: 'open' }).append(smButton.content.cloneNode(true)) - } - static get observedAttributes() { - return ['disabled'] + this.attachShadow({ + mode: 'open' + }).append(smButton.content.cloneNode(true)) } get disabled() { - return this.getAttribute('disabled') + return this.isDisabled } - set disabled(val) { - this.setAttribute('disabled', val) + set disabled(value) { + if (value && !this.isDisabled) { + this.isDisabled = true + this.setAttribute('disabled', '') + this.button.removeAttribute('tabindex') + } else if (!value && this.isDisabled) { + this.isDisabled = false + this.removeAttribute('disabled') + } } - dispatch = () => { - if (this.getAttribute('disabled') === 'true') { + dispatch() { + if (this.isDisabled) { this.dispatchEvent(new CustomEvent('disabled', { bubbles: true, composed: true })) - } - else { + } else { this.dispatchEvent(new CustomEvent('clicked', { bubbles: true, composed: true @@ -114,6 +151,10 @@ customElements.define('sm-button', } connectedCallback() { + this.isDisabled = false + this.button = this.shadowRoot.querySelector('.button') + if (this.hasAttribute('disabled') && !this.isDisabled) + this.isDisabled = true this.addEventListener('click', (e) => { this.dispatch() }) @@ -122,137 +163,204 @@ customElements.define('sm-button', this.dispatch() }) } - - attributeChangedCallback(name, oldValue, newValue) { - } }) //Input const smInput = document.createElement('template') smInput.innerHTML = ` - -