From e1a46a20ca3d9fd1700b60e5b3ec4eb77cae2c8c Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Thu, 6 Jan 2022 16:06:41 +0530 Subject: [PATCH] components update --- components/components.js | 2016 ++++++++++++++++++---------------- components/components.min.js | 25 +- 2 files changed, 1101 insertions(+), 940 deletions(-) diff --git a/components/components.js b/components/components.js index 244851d..efa4864 100644 --- a/components/components.js +++ b/components/components.js @@ -30,9 +30,13 @@ smButton.innerHTML = ` color: var(--accent-color); } :host([variant='no-outline']) .button{ - background: rgba(var(--background-color), 1); + background: inherit; color: var(--accent-color); } +:host([disabled]){ + pointer-events: none; + cursor: not-allowed; +} .button { position: relative; display: -webkit-box; @@ -62,17 +66,20 @@ smButton.innerHTML = ` align-items: center; } :host([disabled]) .button{ + pointer-events: none; cursor: not-allowed; opacity: 0.6; color: rgba(var(--text-color), 1); background-color: rgba(var(--text-color), 0.3); } @media (hover: hover){ - :host(:not([disabled])) .button:hover{ + :host(:not([disabled])) .button:hover, + :host(:focus-within:not([disabled])) .button{ -webkit-box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.12); - box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.12); + box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.12); } - :host([variant='outlined']) .button:hover{ + :host([variant='outlined']:not([disabled])) .button:hover, + :host(:focus-within[variant='outlined']:not([disabled])) .button:hover{ -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.12); 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.12); } @@ -94,49 +101,52 @@ smButton.innerHTML = ` customElements.define('sm-button', class extends HTMLElement { constructor() { - super() + super(); this.attachShadow({ mode: 'open' - }).append(smButton.content.cloneNode(true)) + }).append(smButton.content.cloneNode(true)); } static get observedAttributes() { return ['disabled']; } get disabled() { - return this.hasAttribute('disabled') + return this.hasAttribute('disabled'); } set disabled(value) { if (value) { - this.setAttribute('disabled', '') - }else { - this.removeAttribute('disabled') + this.setAttribute('disabled', ''); + } else { + this.removeAttribute('disabled'); } } + focusIn() { + this.focus(); + } handleKeyDown(e) { if (!this.hasAttribute('disabled') && (e.key === 'Enter' || e.code === 'Space')) { - e.preventDefault() - this.click() + e.preventDefault(); + this.click(); } } connectedCallback() { if (!this.hasAttribute('disabled')) { - this.setAttribute('tabindex', '0') + this.setAttribute('tabindex', '0'); } - this.setAttribute('role', 'button') - this.addEventListener('keydown', this.handleKeyDown) + this.setAttribute('role', 'button'); + this.addEventListener('keydown', this.handleKeyDown); } - attributeChangedCallback(name, oldVal, newVal) { + attributeChangedCallback(name) { if (name === 'disabled') { - this.removeAttribute('tabindex') - this.setAttribute('aria-disabled', 'true') - } - else { - this.setAttribute('tabindex', '0') - this.setAttribute('aria-disabled', 'false') + if (this.hasAttribute('disabled')) { + this.removeAttribute('tabindex'); + } else { + this.setAttribute('tabindex', '0'); + } + this.setAttribute('aria-disabled', this.hasAttribute('disabled')); } } }) @@ -512,14 +522,14 @@ customElements.define('sm-carousel', class extends HTMLElement { const resObs = new ResizeObserver(entries => { entries.forEach(entry => { - if(entry.contentBoxSize) { + if (entry.contentBoxSize) { // Firefox implements `contentBoxSize` as a single content rect, rather than an array const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize; - + this.scrollDistance = contentBoxSize.inlineSize * 0.6 } else { this.scrollDistance = entry.contentRect.width * 0.6 - } + } }) }) resObs.observe(this) @@ -653,7 +663,6 @@ smCheckbox.innerHTML = `