V1.2.0
This commit is contained in:
parent
5fb9dea9db
commit
85670e5e6a
47
components/dist/button.js
vendored
47
components/dist/button.js
vendored
@ -73,11 +73,13 @@ smButton.innerHTML = `
|
||||
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);
|
||||
}
|
||||
@ -99,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'));
|
||||
}
|
||||
}
|
||||
})
|
||||
2
components/dist/button.min.js
vendored
2
components/dist/button.min.js
vendored
@ -1 +1 @@
|
||||
const smButton=document.createElement("template");smButton.innerHTML="\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n:host{\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n width: auto;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --padding: 0.6rem 1.2rem;\n --border-radius: 0.3rem;\n --background: rgba(var(--text-color), 0.1);\n}\n:host([variant='primary']) .button{\n background: var(--accent-color);\n color: rgba(var(--background-color), 1);\n}\n:host([variant='outlined']) .button{\n -webkit-box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset;\n box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset;\n background: transparent; \n color: var(--accent-color);\n}\n:host([variant='no-outline']) .button{\n background: inherit; \n color: var(--accent-color);\n}\n:host([disabled]){\n pointer-events: none;\n cursor: not-allowed;\n}\n.button {\n position: relative;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n width: 100%;\n padding: var(--padding);\n cursor: pointer;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n border-radius: var(--border-radius); \n -webkit-box-pack: center; \n -ms-flex-pack: center; \n justify-content: center;\n transition: box-shadow 0.3s, background-color 0.3s;\n font-family: inherit;\n font-size: 0.9rem;\n font-weight: 500;\n background-color: var(--background); \n -webkit-tap-highlight-color: transparent;\n outline: none;\n overflow: hidden;\n border: none;\n color: inherit;\n align-items: center;\n}\n:host([disabled]) .button{\n pointer-events: none;\n cursor: not-allowed;\n opacity: 0.6;\n color: rgba(var(--text-color), 1);\n background-color: rgba(var(--text-color), 0.3);\n}\n@media (hover: hover){\n :host(:not([disabled])) .button:hover{\n -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);\n box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.12);\n }\n :host([variant='outlined']) .button:hover{\n -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);\n 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);\n }\n}\n@media (hover: none){\n :host(:not([disabled])) .button:active{\n -webkit-box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2);\n box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2);\n }\n :host([variant='outlined']) .button:active{\n -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);\n 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);\n }\n}\n</style>\n<div part=\"button\" class=\"button\">\n <slot></slot> \n</div>",customElements.define("sm-button",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smButton.content.cloneNode(!0))}static get observedAttributes(){return["disabled"]}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}handleKeyDown(e){this.hasAttribute("disabled")||"Enter"!==e.key&&"Space"!==e.code||(e.preventDefault(),this.click())}connectedCallback(){this.hasAttribute("disabled")||this.setAttribute("tabindex","0"),this.setAttribute("role","button"),this.addEventListener("keydown",this.handleKeyDown)}attributeChangedCallback(e,n,t){"disabled"===e?(this.removeAttribute("tabindex"),this.setAttribute("aria-disabled","true")):(this.setAttribute("tabindex","0"),this.setAttribute("aria-disabled","false"))}});
|
||||
const smButton=document.createElement("template");smButton.innerHTML="\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n:host{\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n width: auto;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --padding: 0.6rem 1.2rem;\n --border-radius: 0.3rem;\n --background: rgba(var(--text-color), 0.1);\n}\n:host([variant='primary']) .button{\n background: var(--accent-color);\n color: rgba(var(--background-color), 1);\n}\n:host([variant='outlined']) .button{\n -webkit-box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset;\n box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset;\n background: transparent; \n color: var(--accent-color);\n}\n:host([variant='no-outline']) .button{\n background: inherit; \n color: var(--accent-color);\n}\n:host([disabled]){\n pointer-events: none;\n cursor: not-allowed;\n}\n.button {\n position: relative;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n width: 100%;\n padding: var(--padding);\n cursor: pointer;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n border-radius: var(--border-radius); \n -webkit-box-pack: center; \n -ms-flex-pack: center; \n justify-content: center;\n transition: box-shadow 0.3s, background-color 0.3s;\n font-family: inherit;\n font-size: 0.9rem;\n font-weight: 500;\n background-color: var(--background); \n -webkit-tap-highlight-color: transparent;\n outline: none;\n overflow: hidden;\n border: none;\n color: inherit;\n align-items: center;\n}\n:host([disabled]) .button{\n pointer-events: none;\n cursor: not-allowed;\n opacity: 0.6;\n color: rgba(var(--text-color), 1);\n background-color: rgba(var(--text-color), 0.3);\n}\n@media (hover: hover){\n :host(:not([disabled])) .button:hover,\n :host(:focus-within:not([disabled])) .button{\n -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);\n box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.12);\n }\n :host([variant='outlined']:not([disabled])) .button:hover,\n :host(:focus-within[variant='outlined']:not([disabled])) .button:hover{\n -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);\n 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);\n }\n}\n@media (hover: none){\n :host(:not([disabled])) .button:active{\n -webkit-box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2);\n box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2);\n }\n :host([variant='outlined']) .button:active{\n -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);\n 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);\n }\n}\n</style>\n<div part=\"button\" class=\"button\">\n <slot></slot> \n</div>",customElements.define("sm-button",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smButton.content.cloneNode(!0))}static get observedAttributes(){return["disabled"]}get disabled(){return this.hasAttribute("disabled")}set disabled(t){t?this.setAttribute("disabled",""):this.removeAttribute("disabled")}focusIn(){this.focus()}handleKeyDown(t){this.hasAttribute("disabled")||"Enter"!==t.key&&"Space"!==t.code||(t.preventDefault(),this.click())}connectedCallback(){this.hasAttribute("disabled")||this.setAttribute("tabindex","0"),this.setAttribute("role","button"),this.addEventListener("keydown",this.handleKeyDown)}attributeChangedCallback(t){"disabled"===t&&(this.hasAttribute("disabled")?this.removeAttribute("tabindex"):this.setAttribute("tabindex","0"),this.setAttribute("aria-disabled",this.hasAttribute("disabled")))}});
|
||||
18
components/dist/checkbox.js
vendored
18
components/dist/checkbox.js
vendored
@ -95,6 +95,7 @@ customElements.define('sm-checkbox', class extends HTMLElement {
|
||||
mode: 'open'
|
||||
}).append(smCheckbox.content.cloneNode(true))
|
||||
|
||||
this.defaultState
|
||||
this.checkbox = this.shadowRoot.querySelector('.checkbox');
|
||||
|
||||
this.reset = this.reset.bind(this)
|
||||
@ -140,31 +141,36 @@ customElements.define('sm-checkbox', class extends HTMLElement {
|
||||
return this.getAttribute('value')
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.removeAttribute('checked')
|
||||
focusIn() {
|
||||
this.focus()
|
||||
}
|
||||
|
||||
dispatch(){
|
||||
reset() {
|
||||
this.value = this.defaultState
|
||||
}
|
||||
|
||||
dispatch() {
|
||||
this.dispatchEvent(new CustomEvent('change', {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}))
|
||||
}
|
||||
handleKeyDown(e){
|
||||
handleKeyDown(e) {
|
||||
if (e.code === "Space") {
|
||||
e.preventDefault()
|
||||
this.click()
|
||||
}
|
||||
}
|
||||
handleClick(e){
|
||||
handleClick(e) {
|
||||
this.toggleAttribute('checked')
|
||||
}
|
||||
|
||||
|
||||
connectedCallback() {
|
||||
if (!this.hasAttribute('disabled')) {
|
||||
this.setAttribute('tabindex', '0')
|
||||
}
|
||||
this.setAttribute('role', 'checkbox')
|
||||
this.defaultState = this.hasAttribute('checked')
|
||||
if (!this.hasAttribute('checked')) {
|
||||
this.setAttribute('aria-checked', 'false')
|
||||
}
|
||||
|
||||
2
components/dist/checkbox.min.js
vendored
2
components/dist/checkbox.min.js
vendored
@ -1 +1 @@
|
||||
const smCheckbox=document.createElement("template");smCheckbox.innerHTML='\n<style>\n *{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n } \n :host{\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --height: 1.2rem;\n --width: 1.2rem;\n --border-radius: 0.2rem;\n --border-color: rgba(var(--text-color), 0.7);\n }\n :host([disabled]) {\n opacity: 0.6;\n user-select: none;\n pointer-events: none;\n }\n .checkbox {\n position: relative;\n display:-webkit-box;\n display:-ms-flexbox;\n display:flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n cursor: pointer;\n outline: none;\n -webkit-tap-highlight-color: transparent;\n }\n \n .checkbox:focus-visible{\n outline: auto;\n }\n .checkbox:active .icon,\n .checkbox:focus-within .icon{\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n }\n \n input {\n display: none;\n }\n \n .checkmark {\n stroke-dashoffset: -65;\n stroke-dasharray: 65;\n -webkit-transition: stroke-dashoffset 0.3s; \n -o-transition: stroke-dashoffset 0.3s; \n transition: stroke-dashoffset 0.3s;\n }\n \n :host([checked]) .checkmark {\n stroke-dashoffset: 0;\n stroke: rgba(var(--background-color), 1);\n }\n :host([checked]) .icon {\n background: var(--accent-color);\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n } \n .icon {\n fill: none;\n height: var(--height);\n width: var(--width);\n padding: 0.1rem;\n stroke-width: 8; \n stroke: var(--border-color);\n overflow: visible;\n stroke-linecap: round;\n stroke-linejoin: round;\n -webkit-transition: background 0.3s;\n -o-transition: background 0.3s;\n transition: background 0.3s;\n border-radius: var(--border-radius);\n box-shadow: 0 0 0 0.1rem var(--border-color) inset;\n }\n</style>\n<label class="checkbox">\n <svg class="icon" viewBox="0 0 64 64">\n <path class="checkmark" d="M50.52,19.56,26,44.08,13.48,31.56" />\n </svg>\n <slot></slot>\n</label>',customElements.define("sm-checkbox",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCheckbox.content.cloneNode(!0)),this.checkbox=this.shadowRoot.querySelector(".checkbox"),this.reset=this.reset.bind(this),this.dispatch=this.dispatch.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleClick=this.handleClick.bind(this)}static get observedAttributes(){return["value","disabled","checked"]}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get checked(){return this.hasAttribute("checked")}set checked(e){e?this.setAttribute("checked",""):this.removeAttribute("checked")}set value(e){this.setAttribute("value",e)}get value(){return this.getAttribute("value")}reset(){this.removeAttribute("checked")}dispatch(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,composed:!0}))}handleKeyDown(e){"Space"===e.code&&(e.preventDefault(),this.click())}handleClick(e){this.toggleAttribute("checked")}connectedCallback(){this.hasAttribute("disabled")||this.setAttribute("tabindex","0"),this.setAttribute("role","checkbox"),this.hasAttribute("checked")||this.setAttribute("aria-checked","false"),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("click",this.handleClick)}attributeChangedCallback(e,t,n){t!==n&&("checked"===e?(this.setAttribute("aria-checked",this.hasAttribute("checked")),this.dispatch()):"disabled"===e&&(this.hasAttribute("disabled")?this.removeAttribute("tabindex"):this.setAttribute("tabindex","0")))}disconnectedCallback(){this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("change",this.handleClick)}});
|
||||
const smCheckbox=document.createElement("template");smCheckbox.innerHTML='\n<style>\n *{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n } \n :host{\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --height: 1.2rem;\n --width: 1.2rem;\n --border-radius: 0.2rem;\n --border-color: rgba(var(--text-color), 0.7);\n }\n :host([disabled]) {\n opacity: 0.6;\n user-select: none;\n pointer-events: none;\n }\n .checkbox {\n position: relative;\n display:-webkit-box;\n display:-ms-flexbox;\n display:flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n cursor: pointer;\n outline: none;\n -webkit-tap-highlight-color: transparent;\n }\n \n .checkbox:focus-visible{\n outline: auto;\n }\n .checkbox:active .icon,\n .checkbox:focus-within .icon{\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n }\n \n input {\n display: none;\n }\n \n .checkmark {\n stroke-dashoffset: -65;\n stroke-dasharray: 65;\n -webkit-transition: stroke-dashoffset 0.3s; \n -o-transition: stroke-dashoffset 0.3s; \n transition: stroke-dashoffset 0.3s;\n }\n \n :host([checked]) .checkmark {\n stroke-dashoffset: 0;\n stroke: rgba(var(--background-color), 1);\n }\n :host([checked]) .icon {\n background: var(--accent-color);\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n } \n .icon {\n fill: none;\n height: var(--height);\n width: var(--width);\n padding: 0.1rem;\n stroke-width: 8; \n stroke: var(--border-color);\n overflow: visible;\n stroke-linecap: round;\n stroke-linejoin: round;\n -webkit-transition: background 0.3s;\n -o-transition: background 0.3s;\n transition: background 0.3s;\n border-radius: var(--border-radius);\n box-shadow: 0 0 0 0.1rem var(--border-color) inset;\n }\n</style>\n<label class="checkbox">\n <svg class="icon" viewBox="0 0 64 64">\n <path class="checkmark" d="M50.52,19.56,26,44.08,13.48,31.56" />\n </svg>\n <slot></slot>\n</label>',customElements.define("sm-checkbox",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCheckbox.content.cloneNode(!0)),this.defaultState,this.checkbox=this.shadowRoot.querySelector(".checkbox"),this.reset=this.reset.bind(this),this.dispatch=this.dispatch.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleClick=this.handleClick.bind(this)}static get observedAttributes(){return["value","disabled","checked"]}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get checked(){return this.hasAttribute("checked")}set checked(e){e?this.setAttribute("checked",""):this.removeAttribute("checked")}set value(e){this.setAttribute("value",e)}get value(){return this.getAttribute("value")}focusIn(){this.focus()}reset(){this.value=this.defaultState}dispatch(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,composed:!0}))}handleKeyDown(e){"Space"===e.code&&(e.preventDefault(),this.click())}handleClick(e){this.toggleAttribute("checked")}connectedCallback(){this.hasAttribute("disabled")||this.setAttribute("tabindex","0"),this.setAttribute("role","checkbox"),this.defaultState=this.hasAttribute("checked"),this.hasAttribute("checked")||this.setAttribute("aria-checked","false"),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("click",this.handleClick)}attributeChangedCallback(e,t,n){t!==n&&("checked"===e?(this.setAttribute("aria-checked",this.hasAttribute("checked")),this.dispatch()):"disabled"===e&&(this.hasAttribute("disabled")?this.removeAttribute("tabindex"):this.setAttribute("tabindex","0")))}disconnectedCallback(){this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("change",this.handleClick)}});
|
||||
46
components/dist/copy.js
vendored
46
components/dist/copy.js
vendored
@ -1,4 +1,4 @@
|
||||
const smCopy = document.createElement('template')
|
||||
const smCopy = document.createElement('template');
|
||||
smCopy.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -8,9 +8,8 @@ smCopy.innerHTML = `
|
||||
box-sizing: border-box;
|
||||
}
|
||||
:host{
|
||||
display: -webkit-inline-box;
|
||||
display: -ms-inline-flexbox;
|
||||
display: inline-flex;
|
||||
display: -webkit-box;
|
||||
display: flex;
|
||||
--accent-color: #4d2588;
|
||||
--text-color: 17, 17, 17;
|
||||
--background-color: 255, 255, 255;
|
||||
@ -21,15 +20,21 @@ smCopy.innerHTML = `
|
||||
}
|
||||
.copy{
|
||||
display: grid;
|
||||
width: 100%;
|
||||
gap: 0.5rem;
|
||||
padding: var(--padding);
|
||||
align-items: center;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
}
|
||||
.copy-content{
|
||||
:host(:not([clip-text])) .copy-content{
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
:host([clip-text]) .copy-content{
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.copy-button{
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
@ -59,7 +64,6 @@ smCopy.innerHTML = `
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
<section class="copy">
|
||||
<p class="copy-content"></p>
|
||||
<button part="button" class="copy-button" title="copy">
|
||||
@ -72,24 +76,24 @@ smCopy.innerHTML = `
|
||||
customElements.define('sm-copy',
|
||||
class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(smCopy.content.cloneNode(true))
|
||||
|
||||
this.copyContent = this.shadowRoot.querySelector('.copy-content')
|
||||
this.copyButton = this.shadowRoot.querySelector('.copy-button')
|
||||
}).append(smCopy.content.cloneNode(true));
|
||||
|
||||
this.copy = this.copy.bind(this)
|
||||
this.copyContent = this.shadowRoot.querySelector('.copy-content');
|
||||
this.copyButton = this.shadowRoot.querySelector('.copy-button');
|
||||
|
||||
this.copy = this.copy.bind(this);
|
||||
}
|
||||
static get observedAttributes() {
|
||||
return ['value']
|
||||
return ['value'];
|
||||
}
|
||||
set value(val) {
|
||||
this.setAttribute('value', val)
|
||||
this.setAttribute('value', val);
|
||||
}
|
||||
get value() {
|
||||
return this.getAttribute('value')
|
||||
return this.getAttribute('value');
|
||||
}
|
||||
fireEvent() {
|
||||
this.dispatchEvent(
|
||||
@ -98,22 +102,22 @@ customElements.define('sm-copy',
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
copy() {
|
||||
navigator.clipboard.writeText(this.copyContent.textContent)
|
||||
.then(res => this.fireEvent())
|
||||
.catch(err => console.error(err))
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
connectedCallback() {
|
||||
this.copyButton.addEventListener('click', this.copy)
|
||||
this.copyButton.addEventListener('click', this.copy);
|
||||
}
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
if (name === 'value') {
|
||||
this.copyContent.textContent = newValue
|
||||
this.copyContent.textContent = newValue;
|
||||
}
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.copyButton.removeEventListener('click', this.copy)
|
||||
this.copyButton.removeEventListener('click', this.copy);
|
||||
}
|
||||
})
|
||||
});
|
||||
2
components/dist/copy.min.js
vendored
2
components/dist/copy.min.js
vendored
@ -1 +1 @@
|
||||
const smCopy=document.createElement("template");smCopy.innerHTML='\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n:host{\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --padding: 0;\n --background-color: inherit;\n --button-background-color: rgba(var(--text-color), 0.2);\n --button-border-radius: 0.3rem;\n}\n.copy{\n display: grid;\n gap: 0.5rem;\n padding: var(--padding);\n align-items: center;\n grid-template-columns: minmax(0, 1fr) auto;\n}\n.copy-content{\n overflow-wrap: break-word;\n word-wrap: break-word;\n}\n.copy-button{\n display: inline-flex;\n justify-content: center;\n cursor: pointer;\n border: none;\n padding: 0.4rem;\n background-color: inherit;\n border-radius: var(--button-border-radius);\n}\n.copy-button:active{\n background-color: var(--button-background-color);\n}\n.icon{\n height: 1.2rem;\n width: 1.2rem;\n fill: rgba(var(--text-color), 0.8);\n}\n@media (any-hover: hover){\n .copy:hover .copy-button{\n opacity: 1;\n }\n .copy-button{\n opacity: 0.6;\n }\n .copy-button:hover{\n background-color: var(--button-background-color);\n }\n}\n</style>\n</style>\n<section class="copy">\n <p class="copy-content"></p>\n <button part="button" class="copy-button" title="copy">\n <slot name="copy-icon">\n <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1.001 1.001 0 0 1 3 21l.003-14c0-.552.45-1 1.007-1H7zM5.003 8L5 20h10V8H5.003zM9 6h8v10h2V4H9v2z"/></svg>\n </slot>\n </button>\n</section>\n',customElements.define("sm-copy",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCopy.content.cloneNode(!0)),this.copyContent=this.shadowRoot.querySelector(".copy-content"),this.copyButton=this.shadowRoot.querySelector(".copy-button"),this.copy=this.copy.bind(this)}static get observedAttributes(){return["value"]}set value(n){this.setAttribute("value",n)}get value(){return this.getAttribute("value")}fireEvent(){this.dispatchEvent(new CustomEvent("copy",{composed:!0,bubbles:!0,cancelable:!0}))}copy(){navigator.clipboard.writeText(this.copyContent.textContent).then(n=>this.fireEvent()).catch(n=>console.error(n))}connectedCallback(){this.copyButton.addEventListener("click",this.copy)}attributeChangedCallback(n,t,o){"value"===n&&(this.copyContent.textContent=o)}disconnectedCallback(){this.copyButton.removeEventListener("click",this.copy)}});
|
||||
const smCopy=document.createElement("template");smCopy.innerHTML='\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n:host{\n display: -webkit-box;\n display: flex;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --padding: 0;\n --background-color: inherit;\n --button-background-color: rgba(var(--text-color), 0.2);\n --button-border-radius: 0.3rem;\n}\n.copy{\n display: grid;\n width: 100%;\n gap: 0.5rem;\n padding: var(--padding);\n align-items: center;\n grid-template-columns: minmax(0, 1fr) auto;\n}\n:host(:not([clip-text])) .copy-content{\n overflow-wrap: break-word;\n word-wrap: break-word;\n}\n:host([clip-text]) .copy-content{\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.copy-button{\n display: inline-flex;\n justify-content: center;\n cursor: pointer;\n border: none;\n padding: 0.4rem;\n background-color: inherit;\n border-radius: var(--button-border-radius);\n}\n.copy-button:active{\n background-color: var(--button-background-color);\n}\n.icon{\n height: 1.2rem;\n width: 1.2rem;\n fill: rgba(var(--text-color), 0.8);\n}\n@media (any-hover: hover){\n .copy:hover .copy-button{\n opacity: 1;\n }\n .copy-button{\n opacity: 0.6;\n }\n .copy-button:hover{\n background-color: var(--button-background-color);\n }\n}\n</style>\n<section class="copy">\n <p class="copy-content"></p>\n <button part="button" class="copy-button" title="copy">\n <slot name="copy-icon">\n <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1.001 1.001 0 0 1 3 21l.003-14c0-.552.45-1 1.007-1H7zM5.003 8L5 20h10V8H5.003zM9 6h8v10h2V4H9v2z"/></svg>\n </slot>\n </button>\n</section>\n',customElements.define("sm-copy",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCopy.content.cloneNode(!0)),this.copyContent=this.shadowRoot.querySelector(".copy-content"),this.copyButton=this.shadowRoot.querySelector(".copy-button"),this.copy=this.copy.bind(this)}static get observedAttributes(){return["value"]}set value(n){this.setAttribute("value",n)}get value(){return this.getAttribute("value")}fireEvent(){this.dispatchEvent(new CustomEvent("copy",{composed:!0,bubbles:!0,cancelable:!0}))}copy(){navigator.clipboard.writeText(this.copyContent.textContent).then(n=>this.fireEvent()).catch(n=>console.error(n))}connectedCallback(){this.copyButton.addEventListener("click",this.copy)}attributeChangedCallback(n,t,o){"value"===n&&(this.copyContent.textContent=o)}disconnectedCallback(){this.copyButton.removeEventListener("click",this.copy)}});
|
||||
60
components/dist/form.js
vendored
60
components/dist/form.js
vendored
@ -1,4 +1,4 @@
|
||||
const smForm = document.createElement('template')
|
||||
const smForm = document.createElement('template');
|
||||
smForm.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -8,19 +8,18 @@ smForm.innerHTML = `
|
||||
}
|
||||
:host{
|
||||
display: flex;
|
||||
--gap: 1rem;
|
||||
width: 100%;
|
||||
}
|
||||
form{
|
||||
display: grid;
|
||||
gap: var(--gap);
|
||||
gap: var(--gap, 1.5rem);
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<form onsubmit="return false">
|
||||
<form part="form" onsubmit="return false">
|
||||
<slot></slot>
|
||||
</form>
|
||||
`
|
||||
`;
|
||||
|
||||
customElements.define('sm-form', class extends HTMLElement {
|
||||
constructor() {
|
||||
@ -29,17 +28,18 @@ customElements.define('sm-form', class extends HTMLElement {
|
||||
mode: 'open'
|
||||
}).append(smForm.content.cloneNode(true))
|
||||
|
||||
this.form = this.shadowRoot.querySelector('form')
|
||||
this.form = this.shadowRoot.querySelector('form');
|
||||
this.formElements
|
||||
this.requiredElements
|
||||
this.submitButton
|
||||
this.resetButton
|
||||
this.allRequiredValid = false
|
||||
this.allRequiredValid = false;
|
||||
|
||||
this.debounce = this.debounce.bind(this)
|
||||
this.handleInput = this.handleInput.bind(this)
|
||||
this._checkValidity = this._checkValidity.bind(this)
|
||||
this.handleKeydown = this.handleKeydown.bind(this)
|
||||
this.reset = this.reset.bind(this)
|
||||
this.elementsChanged = this.elementsChanged.bind(this)
|
||||
}
|
||||
debounce(callback, wait) {
|
||||
let timeoutId = null;
|
||||
@ -50,7 +50,7 @@ customElements.define('sm-form', class extends HTMLElement {
|
||||
}, wait);
|
||||
};
|
||||
}
|
||||
handleInput(e) {
|
||||
_checkValidity() {
|
||||
this.allRequiredValid = this.requiredElements.every(elem => elem.isValid)
|
||||
if (!this.submitButton) return;
|
||||
if (this.allRequiredValid) {
|
||||
@ -61,34 +61,42 @@ customElements.define('sm-form', class extends HTMLElement {
|
||||
}
|
||||
}
|
||||
handleKeydown(e) {
|
||||
if (e.key === 'Enter' && e.target.tagName !== 'SM-TEXTAREA' ) {
|
||||
if (e.key === 'Enter' && e.target.tagName !== 'SM-TEXTAREA') {
|
||||
if (this.allRequiredValid) {
|
||||
this.submitButton.click()
|
||||
if (this.submitButton && this.submitButton.tagName === 'SM-BUTTON') {
|
||||
this.submitButton.click()
|
||||
}
|
||||
this.dispatchEvent(new CustomEvent('submit', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}))
|
||||
}
|
||||
else {
|
||||
this.requiredElements.find(elem => !elem.isValid).vibrate()
|
||||
this.requiredElements.find(elem => !elem.isValid).vibrate()
|
||||
}
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
this.formElements.forEach(elem => elem.reset())
|
||||
}
|
||||
elementsChanged() {
|
||||
this.formElements = [...this.querySelectorAll('sm-input, sm-textarea, sm-checkbox, tags-input, file-input, sm-switch, sm-radio')]
|
||||
this.requiredElements = this.formElements.filter(elem => elem.hasAttribute('required'));
|
||||
this.submitButton = this.querySelector('[variant="primary"], [type="submit"]');
|
||||
this.resetButton = this.querySelector('[type="reset"]');
|
||||
if (this.resetButton) {
|
||||
this.resetButton.addEventListener('click', this.reset);
|
||||
}
|
||||
this._checkValidity()
|
||||
}
|
||||
connectedCallback() {
|
||||
const slot = this.shadowRoot.querySelector('slot')
|
||||
slot.addEventListener('slotchange', e => {
|
||||
this.formElements = [...this.querySelectorAll('sm-input, sm-textarea, sm-checkbox, tags-input, file-input, sm-switch, sm-radio')]
|
||||
this.requiredElements = this.formElements.filter(elem => elem.hasAttribute('required'))
|
||||
this.submitButton = e.target.assignedElements().find(elem => elem.getAttribute('variant') === 'primary' || elem.getAttribute('type') === 'submit');
|
||||
this.resetButton = e.target.assignedElements().find(elem => elem.getAttribute('type') === 'reset');
|
||||
if (this.resetButton) {
|
||||
this.resetButton.addEventListener('click', this.reset)
|
||||
}
|
||||
})
|
||||
this.addEventListener('input', this.debounce(this.handleInput, 100))
|
||||
this.addEventListener('keydown', this.debounce(this.handleKeydown, 100))
|
||||
slot.addEventListener('slotchange', this.elementsChanged)
|
||||
this.addEventListener('input', this.debounce(this._checkValidity, 100));
|
||||
this.addEventListener('keydown', this.debounce(this.handleKeydown, 100));
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.removeEventListener('input', this.debounce(this.handleInput, 100))
|
||||
this.removeEventListener('keydown', this.debounce(this.handleKeydown, 100))
|
||||
this.removeEventListener('input', this.debounce(this._checkValidity, 100));
|
||||
this.removeEventListener('keydown', this.debounce(this.handleKeydown, 100));
|
||||
}
|
||||
})
|
||||
})
|
||||
2
components/dist/form.min.js
vendored
2
components/dist/form.min.js
vendored
@ -1 +1 @@
|
||||
const smForm=document.createElement("template");smForm.innerHTML='\n <style>\n *{\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n :host{\n display: flex;\n --gap: 1rem;\n width: 100%;\n }\n form{\n display: grid;\n gap: var(--gap);\n width: 100%;\n }\n </style>\n\t<form onsubmit="return false">\n\t\t<slot></slot>\n\t</form>\n',customElements.define("sm-form",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smForm.content.cloneNode(!0)),this.form=this.shadowRoot.querySelector("form"),this.formElements,this.requiredElements,this.submitButton,this.resetButton,this.allRequiredValid=!1,this.debounce=this.debounce.bind(this),this.handleInput=this.handleInput.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.reset=this.reset.bind(this)}debounce(t,e){let s=null;return(...n)=>{window.clearTimeout(s),s=window.setTimeout(()=>{t.apply(null,n)},e)}}handleInput(t){this.allRequiredValid=this.requiredElements.every(t=>t.isValid),this.submitButton&&(this.allRequiredValid?this.submitButton.disabled=!1:this.submitButton.disabled=!0)}handleKeydown(t){"Enter"===t.key&&"SM-TEXTAREA"!==t.target.tagName&&(this.allRequiredValid?this.submitButton.click():this.requiredElements.find(t=>!t.isValid).vibrate())}reset(){this.formElements.forEach(t=>t.reset())}connectedCallback(){const t=this.shadowRoot.querySelector("slot");t.addEventListener("slotchange",t=>{this.formElements=[...this.querySelectorAll("sm-input, sm-textarea, sm-checkbox, tags-input, file-input, sm-switch, sm-radio")],this.requiredElements=this.formElements.filter(t=>t.hasAttribute("required")),this.submitButton=t.target.assignedElements().find(t=>"primary"===t.getAttribute("variant")||"submit"===t.getAttribute("type")),this.resetButton=t.target.assignedElements().find(t=>"reset"===t.getAttribute("type")),this.resetButton&&this.resetButton.addEventListener("click",this.reset)}),this.addEventListener("input",this.debounce(this.handleInput,100)),this.addEventListener("keydown",this.debounce(this.handleKeydown,100))}disconnectedCallback(){this.removeEventListener("input",this.debounce(this.handleInput,100)),this.removeEventListener("keydown",this.debounce(this.handleKeydown,100))}});
|
||||
const smForm=document.createElement("template");smForm.innerHTML='\n <style>\n *{\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n :host{\n display: flex;\n width: 100%;\n }\n form{\n display: grid;\n gap: var(--gap, 1.5rem);\n width: 100%;\n }\n </style>\n\t<form part="form" onsubmit="return false">\n\t\t<slot></slot>\n\t</form>\n',customElements.define("sm-form",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smForm.content.cloneNode(!0)),this.form=this.shadowRoot.querySelector("form"),this.formElements,this.requiredElements,this.submitButton,this.resetButton,this.allRequiredValid=!1,this.debounce=this.debounce.bind(this),this._checkValidity=this._checkValidity.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.reset=this.reset.bind(this),this.elementsChanged=this.elementsChanged.bind(this)}debounce(t,e){let i=null;return(...s)=>{window.clearTimeout(i),i=window.setTimeout(()=>{t.apply(null,s)},e)}}_checkValidity(){this.allRequiredValid=this.requiredElements.every(t=>t.isValid),this.submitButton&&(this.allRequiredValid?this.submitButton.disabled=!1:this.submitButton.disabled=!0)}handleKeydown(t){"Enter"===t.key&&"SM-TEXTAREA"!==t.target.tagName&&(this.allRequiredValid?(this.submitButton&&"SM-BUTTON"===this.submitButton.tagName&&this.submitButton.click(),this.dispatchEvent(new CustomEvent("submit",{bubbles:!0,composed:!0}))):this.requiredElements.find(t=>!t.isValid).vibrate())}reset(){this.formElements.forEach(t=>t.reset())}elementsChanged(){this.formElements=[...this.querySelectorAll("sm-input, sm-textarea, sm-checkbox, tags-input, file-input, sm-switch, sm-radio")],this.requiredElements=this.formElements.filter(t=>t.hasAttribute("required")),this.submitButton=this.querySelector('[variant="primary"], [type="submit"]'),this.resetButton=this.querySelector('[type="reset"]'),this.resetButton&&this.resetButton.addEventListener("click",this.reset),this._checkValidity()}connectedCallback(){const t=this.shadowRoot.querySelector("slot");t.addEventListener("slotchange",this.elementsChanged),this.addEventListener("input",this.debounce(this._checkValidity,100)),this.addEventListener("keydown",this.debounce(this.handleKeydown,100))}disconnectedCallback(){this.removeEventListener("input",this.debounce(this._checkValidity,100)),this.removeEventListener("keydown",this.debounce(this.handleKeydown,100))}});
|
||||
191
components/dist/input.js
vendored
191
components/dist/input.js
vendored
@ -43,7 +43,6 @@ border: none;
|
||||
--success-color: #00C853;
|
||||
--danger-color: red;
|
||||
--width: 100%;
|
||||
--font-size: 1rem;
|
||||
--icon-gap: 0.5rem;
|
||||
--border-radius: 0.3rem;
|
||||
--padding: 0.7rem 1rem;
|
||||
@ -105,9 +104,9 @@ border: none;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.label {
|
||||
font-size: inherit;
|
||||
opacity: .7;
|
||||
font-weight: 400;
|
||||
font-size: var(--font-size);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
-webkit-transition: -webkit-transform 0.3s;
|
||||
@ -145,7 +144,7 @@ border: none;
|
||||
flex: 1;
|
||||
}
|
||||
input{
|
||||
font-size: var(--font-size);
|
||||
font-size: inherit;
|
||||
border: none;
|
||||
background: transparent;
|
||||
outline: none;
|
||||
@ -166,7 +165,7 @@ input{
|
||||
color: var(--accent-color)
|
||||
}
|
||||
:host([variant="outlined"]) .input {
|
||||
box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 0.4) inset;
|
||||
box-shadow: 0 0 0 0.1rem var(--border-color, rgba(var(--text-color), 0.4)) inset;
|
||||
background: rgba(var(--background-color), 1);
|
||||
}
|
||||
:host([variant="outlined"]) .label {
|
||||
@ -230,125 +229,131 @@ customElements.define('sm-input',
|
||||
class extends HTMLElement {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(smInput.content.cloneNode(true))
|
||||
}).append(smInput.content.cloneNode(true));
|
||||
|
||||
this.inputParent = this.shadowRoot.querySelector('.input')
|
||||
this.input = this.shadowRoot.querySelector('input')
|
||||
this.clearBtn = this.shadowRoot.querySelector('.clear')
|
||||
this.label = this.shadowRoot.querySelector('.label')
|
||||
this.feedbackText = this.shadowRoot.querySelector('.feedback-text')
|
||||
this.outerContainer = this.shadowRoot.querySelector('.outer-container')
|
||||
this._helperText
|
||||
this._errorText
|
||||
this.isRequired = false
|
||||
this.validationFunction
|
||||
this.reflectedAttributes = ['value', 'required', 'disabled', 'type', 'inputmode', 'readonly', 'min', 'max', 'pattern', 'minlength', 'maxlength', 'step']
|
||||
|
||||
this.reset = this.reset.bind(this)
|
||||
this.focusIn = this.focusIn.bind(this)
|
||||
this.focusOut = this.focusOut.bind(this)
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
this.checkInput = this.checkInput.bind(this)
|
||||
this.vibrate = this.vibrate.bind(this)
|
||||
this.inputParent = this.shadowRoot.querySelector('.input');
|
||||
this.input = this.shadowRoot.querySelector('input');
|
||||
this.clearBtn = this.shadowRoot.querySelector('.clear');
|
||||
this.label = this.shadowRoot.querySelector('.label');
|
||||
this.feedbackText = this.shadowRoot.querySelector('.feedback-text');
|
||||
this.outerContainer = this.shadowRoot.querySelector('.outer-container');
|
||||
this._helperText = '';
|
||||
this._errorText = '';
|
||||
this.isRequired = false;
|
||||
this.hideRequired = false;
|
||||
this.validationFunction = undefined;
|
||||
this.reflectedAttributes = ['value', 'required', 'disabled', 'type', 'inputmode', 'readonly', 'min', 'max', 'pattern', 'minlength', 'maxlength', 'step'];
|
||||
|
||||
this.reset = this.reset.bind(this);
|
||||
this.focusIn = this.focusIn.bind(this);
|
||||
this.focusOut = this.focusOut.bind(this);
|
||||
this.fireEvent = this.fireEvent.bind(this);
|
||||
this.checkInput = this.checkInput.bind(this);
|
||||
this.vibrate = this.vibrate.bind(this);
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
return ['value', 'placeholder', 'required', 'disabled', 'type', 'inputmode', 'readonly', 'min', 'max', 'pattern', 'minlength', 'maxlength', 'step', 'helper-text', 'error-text']
|
||||
return ['value', 'placeholder', 'required', 'disabled', 'type', 'inputmode', 'readonly', 'min', 'max', 'pattern', 'minlength', 'maxlength', 'step', 'helper-text', 'error-text', 'hiderequired'];
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this.input.value
|
||||
return this.input.value;
|
||||
}
|
||||
|
||||
set value(val) {
|
||||
this.input.value = val;
|
||||
this.checkInput()
|
||||
this.fireEvent()
|
||||
this.checkInput();
|
||||
this.fireEvent();
|
||||
}
|
||||
|
||||
get placeholder() {
|
||||
return this.getAttribute('placeholder')
|
||||
return this.getAttribute('placeholder');
|
||||
}
|
||||
|
||||
set placeholder(val) {
|
||||
this.setAttribute('placeholder', val)
|
||||
this.setAttribute('placeholder', val);
|
||||
}
|
||||
|
||||
get type() {
|
||||
return this.getAttribute('type')
|
||||
return this.getAttribute('type');
|
||||
}
|
||||
|
||||
set type(val) {
|
||||
this.setAttribute('type', val)
|
||||
this.setAttribute('type', val);
|
||||
}
|
||||
|
||||
get validity() {
|
||||
return this.input.validity
|
||||
return this.input.validity;
|
||||
}
|
||||
|
||||
get disabled() {
|
||||
return this.hasAttribute('disabled');
|
||||
}
|
||||
set disabled(value) {
|
||||
if (value)
|
||||
this.inputParent.classList.add('disabled')
|
||||
this.inputParent.classList.add('disabled');
|
||||
else
|
||||
this.inputParent.classList.remove('disabled')
|
||||
this.inputParent.classList.remove('disabled');
|
||||
}
|
||||
get readOnly() {
|
||||
return this.hasAttribute('readonly');
|
||||
}
|
||||
set readOnly(value) {
|
||||
if (value) {
|
||||
this.setAttribute('readonly', '')
|
||||
this.setAttribute('readonly', '');
|
||||
} else {
|
||||
this.removeAttribute('readonly')
|
||||
this.removeAttribute('readonly');
|
||||
}
|
||||
}
|
||||
set customValidation(val) {
|
||||
|
||||
this.validationFunction = val
|
||||
this.validationFunction = val;
|
||||
}
|
||||
set errorText(val) {
|
||||
this._errorText = val
|
||||
this._errorText = val;
|
||||
}
|
||||
set helperText(val) {
|
||||
this._helperText = val
|
||||
this._helperText = val;
|
||||
}
|
||||
get isValid() {
|
||||
if (this.input.value !== '') {
|
||||
const _isValid = this.input.checkValidity()
|
||||
let _customValid = true
|
||||
const _isValid = this.input.checkValidity();
|
||||
let _customValid = true;
|
||||
if (this.validationFunction) {
|
||||
_customValid = Boolean(this.validationFunction(this.input.value))
|
||||
_customValid = Boolean(this.validationFunction(this.input.value));
|
||||
}
|
||||
if (_isValid && _customValid) {
|
||||
this.feedbackText.classList.remove('error')
|
||||
this.feedbackText.classList.add('success')
|
||||
this.feedbackText.textContent = ''
|
||||
this.feedbackText.classList.remove('error');
|
||||
this.feedbackText.classList.add('success');
|
||||
this.feedbackText.textContent = '';
|
||||
} else {
|
||||
if (this._errorText) {
|
||||
this.feedbackText.classList.add('error')
|
||||
this.feedbackText.classList.remove('success')
|
||||
this.feedbackText.classList.add('error');
|
||||
this.feedbackText.classList.remove('success');
|
||||
this.feedbackText.innerHTML = `
|
||||
<svg class="status-icon status-icon--error" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>
|
||||
${this._errorText}
|
||||
`
|
||||
`;
|
||||
}
|
||||
}
|
||||
return (_isValid && _customValid)
|
||||
return (_isValid && _customValid);
|
||||
}
|
||||
}
|
||||
reset(){
|
||||
this.value = ''
|
||||
reset() {
|
||||
this.value = '';
|
||||
}
|
||||
|
||||
focusIn(){
|
||||
this.input.focus()
|
||||
focusIn() {
|
||||
this.input.focus();
|
||||
}
|
||||
|
||||
focusOut(){
|
||||
this.input.blur()
|
||||
focusOut() {
|
||||
this.input.blur();
|
||||
}
|
||||
|
||||
fireEvent(){
|
||||
fireEvent() {
|
||||
let event = new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
@ -357,28 +362,28 @@ customElements.define('sm-input',
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
checkInput(e){
|
||||
checkInput(e) {
|
||||
if (!this.hasAttribute('readonly')) {
|
||||
if (this.input.value.trim() !== '') {
|
||||
this.clearBtn.classList.remove('hide')
|
||||
this.clearBtn.classList.remove('hide');
|
||||
} else {
|
||||
this.clearBtn.classList.add('hide')
|
||||
if (this.isRequired) {
|
||||
this.feedbackText.textContent = '* required'
|
||||
this.clearBtn.classList.add('hide');
|
||||
if (this.isRequired && !this.hideRequired) {
|
||||
this.feedbackText.textContent = '*required';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.hasAttribute('placeholder') || this.getAttribute('placeholder').trim() === '') return;
|
||||
if (this.input.value !== '') {
|
||||
if (this.animate)
|
||||
this.inputParent.classList.add('animate-label')
|
||||
this.inputParent.classList.add('animate-label');
|
||||
else
|
||||
this.label.classList.add('hide')
|
||||
this.label.classList.add('hide');
|
||||
} else {
|
||||
if (this.animate)
|
||||
this.inputParent.classList.remove('animate-label')
|
||||
this.inputParent.classList.remove('animate-label');
|
||||
else
|
||||
this.label.classList.remove('hide')
|
||||
this.label.classList.remove('hide');
|
||||
}
|
||||
}
|
||||
vibrate() {
|
||||
@ -391,25 +396,25 @@ customElements.define('sm-input',
|
||||
], {
|
||||
duration: 300,
|
||||
easing: 'ease'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
connectedCallback() {
|
||||
this.animate = this.hasAttribute('animate')
|
||||
this.setAttribute('role', 'textbox')
|
||||
this.input.addEventListener('input', this.checkInput)
|
||||
this.clearBtn.addEventListener('click', this.reset)
|
||||
this.animate = this.hasAttribute('animate');
|
||||
this.setAttribute('role', 'textbox');
|
||||
this.input.addEventListener('input', this.checkInput);
|
||||
this.clearBtn.addEventListener('click', this.reset);
|
||||
}
|
||||
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
if (oldValue !== newValue) {
|
||||
if (this.reflectedAttributes.includes(name)) {
|
||||
if (this.hasAttribute(name)) {
|
||||
this.input.setAttribute(name, this.getAttribute(name) ? this.getAttribute(name) : '')
|
||||
this.input.setAttribute(name, this.getAttribute(name) ? this.getAttribute(name) : '');
|
||||
}
|
||||
else {
|
||||
this.input.removeAttribute(name)
|
||||
this.input.removeAttribute(name);
|
||||
}
|
||||
}
|
||||
if (name === 'placeholder') {
|
||||
@ -417,49 +422,55 @@ customElements.define('sm-input',
|
||||
this.setAttribute('aria-label', newValue);
|
||||
}
|
||||
else if (this.hasAttribute('value')) {
|
||||
this.checkInput()
|
||||
this.checkInput();
|
||||
}
|
||||
else if (name === 'type') {
|
||||
if (this.hasAttribute('type') && this.getAttribute('type') === 'number') {
|
||||
this.input.setAttribute('inputmode', 'numeric')
|
||||
this.input.setAttribute('inputmode', 'numeric');
|
||||
}
|
||||
}
|
||||
else if (name === 'helper-text') {
|
||||
this._helperText = this.getAttribute('helper-text')
|
||||
this._helperText = this.getAttribute('helper-text');
|
||||
}
|
||||
else if (name === 'error-text') {
|
||||
this._errorText = this.getAttribute('error-text')
|
||||
this._errorText = this.getAttribute('error-text');
|
||||
}
|
||||
else if (name === 'required') {
|
||||
this.isRequired = this.hasAttribute('required')
|
||||
this.isRequired = this.hasAttribute('required');
|
||||
if (this.isRequired && !this.hideRequired) {
|
||||
this.feedbackText.textContent = '';
|
||||
} else {
|
||||
this.feedbackText.textContent = '*required';
|
||||
}
|
||||
if (this.isRequired) {
|
||||
this.feedbackText.textContent = '* required'
|
||||
this.setAttribute('aria-required', 'true')
|
||||
this.setAttribute('aria-required', 'true');
|
||||
}
|
||||
else {
|
||||
this.feedbackText.textContent = ''
|
||||
this.setAttribute('aria-required', 'false')
|
||||
this.setAttribute('aria-required', 'false');
|
||||
}
|
||||
}
|
||||
else if (name === 'hiderequired') {
|
||||
this.hideRequired = this.hasAttribute('hiderequired')
|
||||
}
|
||||
else if (name === 'readonly') {
|
||||
if (this.hasAttribute('readonly')) {
|
||||
this.inputParent.classList.add('readonly')
|
||||
this.inputParent.classList.add('readonly');
|
||||
} else {
|
||||
this.inputParent.classList.remove('readonly')
|
||||
this.inputParent.classList.remove('readonly');
|
||||
}
|
||||
}
|
||||
else if (name === 'disabled') {
|
||||
if (this.hasAttribute('disabled')) {
|
||||
this.inputParent.classList.add('disabled')
|
||||
this.inputParent.classList.add('disabled');
|
||||
}
|
||||
else {
|
||||
this.inputParent.classList.remove('disabled')
|
||||
this.inputParent.classList.remove('disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.input.removeEventListener('input', this.checkInput)
|
||||
this.clearBtn.removeEventListener('click', this.reset)
|
||||
this.input.removeEventListener('input', this.checkInput);
|
||||
this.clearBtn.removeEventListener('click', this.reset);
|
||||
}
|
||||
})
|
||||
2
components/dist/input.min.js
vendored
2
components/dist/input.min.js
vendored
File diff suppressed because one or more lines are too long
30
components/dist/menu.js
vendored
30
components/dist/menu.js
vendored
@ -11,6 +11,7 @@ smMenu.innerHTML = `
|
||||
display: -webkit-inline-box;
|
||||
display: -ms-inline-flexbox;
|
||||
display: inline-flex;
|
||||
|
||||
}
|
||||
.menu{
|
||||
display: -ms-grid;
|
||||
@ -55,7 +56,8 @@ smMenu.innerHTML = `
|
||||
right: 0;
|
||||
}
|
||||
.options{
|
||||
padding: 0.5rem 0;
|
||||
top: 100%;
|
||||
padding: 0.3rem;
|
||||
overflow: hidden auto;
|
||||
position: absolute;
|
||||
display: -webkit-box;
|
||||
@ -68,8 +70,8 @@ smMenu.innerHTML = `
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
background: rgba(var(--background-color), 1);
|
||||
border-radius: 0.3rem;
|
||||
background: var(--background, rgba(var(--background-color), 1));
|
||||
border-radius: var(--border-radius, 0.5rem);
|
||||
z-index: 1;
|
||||
-webkit-box-shadow: 0 0.5rem 1.5rem -0.5rem rgba(0,0,0,0.3);
|
||||
box-shadow: 0 0.5rem 1.5rem -0.5rem rgba(0,0,0,0.3);
|
||||
@ -96,7 +98,7 @@ smMenu.innerHTML = `
|
||||
</style>
|
||||
<div class="select">
|
||||
<div class="menu" tabindex="0">
|
||||
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 3c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 14c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg>
|
||||
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg>
|
||||
</div>
|
||||
<div class="options hide">
|
||||
<slot></slot>
|
||||
@ -125,7 +127,7 @@ customElements.define('sm-menu', class extends HTMLElement {
|
||||
this.collapse = this.collapse.bind(this)
|
||||
this.toggle = this.toggle.bind(this)
|
||||
this.handleKeyDown = this.handleKeyDown.bind(this)
|
||||
this.handleClickoutSide = this.handleClickoutSide.bind(this)
|
||||
this.handleClickOutside = this.handleClickOutside.bind(this)
|
||||
|
||||
}
|
||||
static get observedAttributes() {
|
||||
@ -193,7 +195,7 @@ customElements.define('sm-menu', class extends HTMLElement {
|
||||
e.preventDefault()
|
||||
this.toggle()
|
||||
}
|
||||
} else { // If mey is pressed over menu options
|
||||
} else { // If key is pressed over menu options
|
||||
if (e.code === 'ArrowUp') {
|
||||
e.preventDefault()
|
||||
if (document.activeElement.previousElementSibling) {
|
||||
@ -216,7 +218,7 @@ customElements.define('sm-menu', class extends HTMLElement {
|
||||
}
|
||||
}
|
||||
}
|
||||
handleClickoutSide(e) {
|
||||
handleClickOutside(e) {
|
||||
if (!this.contains(e.target) && e.button !== 2) {
|
||||
this.collapse()
|
||||
}
|
||||
@ -231,12 +233,12 @@ customElements.define('sm-menu', class extends HTMLElement {
|
||||
});
|
||||
this.addEventListener('click', this.toggle)
|
||||
this.addEventListener('keydown', this.handleKeyDown)
|
||||
document.addEventListener('mousedown', this.handleClickoutSide)
|
||||
document.addEventListener('mousedown', this.handleClickOutside)
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.removeEventListener('click', this.toggle)
|
||||
this.removeEventListener('keydown', this.handleKeyDown)
|
||||
document.removeEventListener('mousedown', this.handleClickoutSide)
|
||||
document.removeEventListener('mousedown', this.handleClickOutside)
|
||||
}
|
||||
})
|
||||
|
||||
@ -254,20 +256,19 @@ menuOption.innerHTML = `
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
--padding: 0.6rem 1.6rem;
|
||||
}
|
||||
.option{
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
min-width: 100%;
|
||||
padding: var(--padding);
|
||||
padding: var(--padding, 0.6rem 1rem);
|
||||
cursor: pointer;
|
||||
overflow-wrap: break-word;
|
||||
white-space: nowrap;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
user-select: none;
|
||||
border-radius: 0.3rem;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
@ -277,8 +278,8 @@ menuOption.innerHTML = `
|
||||
background: rgba(var(--text-color), 0.1);
|
||||
}
|
||||
@media (any-hover: hover){
|
||||
:host{
|
||||
--padding: 0.8rem 1.6rem;
|
||||
.option{
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
.option:hover{
|
||||
background: rgba(var(--text-color), 0.1);
|
||||
@ -298,6 +299,7 @@ customElements.define('menu-option', class extends HTMLElement {
|
||||
|
||||
connectedCallback() {
|
||||
this.setAttribute('role', 'option')
|
||||
this.setAttribute('tabindex', '0')
|
||||
this.addEventListener('keyup', e => {
|
||||
if (e.code === 'Enter' || e.code === 'Space') {
|
||||
e.preventDefault()
|
||||
|
||||
2
components/dist/menu.min.js
vendored
2
components/dist/menu.min.js
vendored
File diff suppressed because one or more lines are too long
61
components/dist/notifications.js
vendored
61
components/dist/notifications.js
vendored
@ -96,6 +96,13 @@ smNotifications.innerHTML = `
|
||||
width: 100%;
|
||||
fill: rgba(var(--text-color), 0.7);
|
||||
}
|
||||
.icon--success {
|
||||
fill: var(--green);
|
||||
}
|
||||
.icon--failure,
|
||||
.icon--error {
|
||||
fill: var(--danger-color);
|
||||
}
|
||||
.close{
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
@ -142,7 +149,7 @@ smNotifications.innerHTML = `
|
||||
|
||||
customElements.define('sm-notifications', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.shadow = this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(smNotifications.content.cloneNode(true))
|
||||
@ -169,31 +176,31 @@ customElements.define('sm-notifications', class extends HTMLElement {
|
||||
return result;
|
||||
}
|
||||
|
||||
createNotification(message, options) {
|
||||
const { pinned = false, icon = '' } = options
|
||||
createNotification(message, options = {}) {
|
||||
const { pinned = false, icon = '' } = options;
|
||||
const notification = document.createElement('div')
|
||||
notification.id = this.randString(8)
|
||||
notification.classList.add('notification')
|
||||
let composition = ``
|
||||
notification.classList.add('notification');
|
||||
let composition = ``;
|
||||
composition += `
|
||||
<div class="icon-container">${icon}</div>
|
||||
<p>${message}</p>
|
||||
`
|
||||
`;
|
||||
if (pinned) {
|
||||
notification.classList.add('pinned')
|
||||
notification.classList.add('pinned');
|
||||
composition += `
|
||||
<button class="close">
|
||||
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></svg>
|
||||
</button>
|
||||
`
|
||||
`;
|
||||
}
|
||||
notification.innerHTML = composition
|
||||
return notification
|
||||
notification.innerHTML = composition;
|
||||
return notification;
|
||||
}
|
||||
|
||||
push(message, options = {}) {
|
||||
const notification = this.createNotification(message, options)
|
||||
this.notificationPanel.append(notification)
|
||||
const notification = this.createNotification(message, options);
|
||||
this.notificationPanel.append(notification);
|
||||
notification.animate([
|
||||
{
|
||||
transform: `translateY(1rem)`,
|
||||
@ -203,8 +210,8 @@ customElements.define('sm-notifications', class extends HTMLElement {
|
||||
transform: `none`,
|
||||
opacity: '1'
|
||||
},
|
||||
], this.animationOptions)
|
||||
return notification.id
|
||||
], this.animationOptions);
|
||||
return notification.id;
|
||||
}
|
||||
|
||||
removeNotification(notification) {
|
||||
@ -218,36 +225,36 @@ customElements.define('sm-notifications', class extends HTMLElement {
|
||||
opacity: '0'
|
||||
}
|
||||
], this.animationOptions).onfinish = () => {
|
||||
notification.remove()
|
||||
}
|
||||
notification.remove();
|
||||
};
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
Array.from(this.notificationPanel.children).forEach(child => {
|
||||
this.removeNotification(child)
|
||||
})
|
||||
this.removeNotification(child);
|
||||
});
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.notificationPanel.addEventListener('click', e => {
|
||||
if (e.target.closest('.close')) (
|
||||
this.removeNotification(e.target.closest('.notification'))
|
||||
)
|
||||
})
|
||||
if (e.target.closest('.close')) {
|
||||
this.removeNotification(e.target.closest('.notification'));
|
||||
}
|
||||
});
|
||||
|
||||
const observer = new MutationObserver(mutationList => {
|
||||
mutationList.forEach(mutation => {
|
||||
if (mutation.type === 'childList') {
|
||||
if (mutation.addedNodes.length && !mutation.addedNodes[0].classList.contains('pinned')) {
|
||||
setTimeout(() => {
|
||||
this.removeNotification(mutation.addedNodes[0])
|
||||
this.removeNotification(mutation.addedNodes[0]);
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
observer.observe(this.notificationPanel, {
|
||||
childList: true,
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
2
components/dist/notifications.min.js
vendored
2
components/dist/notifications.min.js
vendored
File diff suppressed because one or more lines are too long
378
components/dist/popup.js
vendored
378
components/dist/popup.js
vendored
@ -1,4 +1,22 @@
|
||||
const smPopup = document.createElement('template')
|
||||
class Stack {
|
||||
constructor() {
|
||||
this.items = [];
|
||||
}
|
||||
push(element) {
|
||||
this.items.push(element);
|
||||
}
|
||||
pop() {
|
||||
if (this.items.length == 0)
|
||||
return "Underflow";
|
||||
return this.items.pop();
|
||||
}
|
||||
peek() {
|
||||
return this.items[this.items.length - 1];
|
||||
}
|
||||
}
|
||||
const popupStack = new Stack();
|
||||
|
||||
const smPopup = document.createElement('template');
|
||||
smPopup.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -19,7 +37,6 @@ smPopup.innerHTML = `
|
||||
--height: auto;
|
||||
--min-width: auto;
|
||||
--min-height: auto;
|
||||
--body-padding: 1.5rem;
|
||||
--backdrop-background: rgba(0, 0, 0, 0.6);
|
||||
--border-radius: 0.8rem 0.8rem 0 0;
|
||||
}
|
||||
@ -32,10 +49,6 @@ smPopup.innerHTML = `
|
||||
left: 0;
|
||||
right: 0;
|
||||
place-items: center;
|
||||
background: var(--backdrop-background);
|
||||
-webkit-transition: opacity 0.3s;
|
||||
-o-transition: opacity 0.3s;
|
||||
transition: opacity 0.3s;
|
||||
z-index: 10;
|
||||
touch-action: none;
|
||||
}
|
||||
@ -43,6 +56,18 @@ smPopup.innerHTML = `
|
||||
-webkit-transform: scale(0.9) translateY(-2rem) !important;
|
||||
transform: scale(0.9) translateY(-2rem) !important;
|
||||
}
|
||||
.background{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
pointer-events: none;
|
||||
background: var(--backdrop-background);
|
||||
-webkit-transition: opacity 0.3s;
|
||||
-o-transition: opacity 0.3s;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
.popup{
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
@ -62,17 +87,9 @@ smPopup.innerHTML = `
|
||||
min-height: var(--min-height);
|
||||
max-height: 90vh;
|
||||
border-radius: var(--border-radius);
|
||||
-webkit-transform: scale(1) translateY(100%);
|
||||
transform: scale(1) translateY(100%);
|
||||
-webkit-transition: -webkit-transform 0.3s;
|
||||
transition: -webkit-transform 0.3s;
|
||||
-o-transition: transform 0.3s;
|
||||
transition: transform 0.3s, -webkit-transform 0.3s;
|
||||
transition: transform 0.3s;
|
||||
background: rgba(var(--background-color), 1);
|
||||
-webkit-box-shadow: 0 -1rem 2rem #00000020;
|
||||
box-shadow: 0 -1rem 2rem #00000020;
|
||||
content-visibility: auto;
|
||||
}
|
||||
.container-header{
|
||||
display: -webkit-box;
|
||||
@ -99,17 +116,15 @@ smPopup.innerHTML = `
|
||||
-ms-flex: 1;
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
padding: var(--body-padding);
|
||||
padding: var(--body-padding, 1.5rem);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.hide{
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
visiblity: none;
|
||||
display:none;
|
||||
}
|
||||
@media screen and (min-width: 640px){
|
||||
:host{
|
||||
--border-radius: 0.4rem;
|
||||
--border-radius: 0.5rem;
|
||||
}
|
||||
.popup{
|
||||
-ms-flex-item-align: center;
|
||||
@ -117,8 +132,6 @@ smPopup.innerHTML = `
|
||||
align-self: center;
|
||||
border-radius: var(--border-radius);
|
||||
height: var(--height);
|
||||
-webkit-transform: scale(1) translateY(3rem);
|
||||
transform: scale(1) translateY(3rem);
|
||||
-webkit-box-shadow: 0 3rem 2rem -0.5rem #00000040;
|
||||
box-shadow: 0 3rem 2rem -0.5rem #00000040;
|
||||
}
|
||||
@ -153,7 +166,8 @@ smPopup.innerHTML = `
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div part="background" class="popup-container hide" role="dialog">
|
||||
<div class="popup-container hide" role="dialog">
|
||||
<div part="background" class="background"></div>
|
||||
<div part="popup" class="popup">
|
||||
<div part="popup-header" class="popup-top">
|
||||
<div class="handle"></div>
|
||||
@ -167,34 +181,38 @@ smPopup.innerHTML = `
|
||||
`;
|
||||
customElements.define('sm-popup', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(smPopup.content.cloneNode(true))
|
||||
}).append(smPopup.content.cloneNode(true));
|
||||
|
||||
this.allowClosing = false
|
||||
this.isOpen = false
|
||||
this.pinned = false
|
||||
this.popupStack
|
||||
this.offset
|
||||
this.touchStartY = 0
|
||||
this.touchEndY = 0
|
||||
this.touchStartTime = 0
|
||||
this.touchEndTime = 0
|
||||
this.touchEndAnimataion
|
||||
this.allowClosing = false;
|
||||
this.isOpen = false;
|
||||
this.pinned = false;
|
||||
this.offset = 0;
|
||||
this.touchStartY = 0;
|
||||
this.touchEndY = 0;
|
||||
this.touchStartTime = 0;
|
||||
this.touchEndTime = 0;
|
||||
this.touchEndAnimation = undefined;
|
||||
this.focusable
|
||||
this.autoFocus
|
||||
this.mutationObserver
|
||||
|
||||
this.popupContainer = this.shadowRoot.querySelector('.popup-container')
|
||||
this.popup = this.shadowRoot.querySelector('.popup')
|
||||
this.popupBodySlot = this.shadowRoot.querySelector('.popup-body slot')
|
||||
this.popupHeader = this.shadowRoot.querySelector('.popup-top')
|
||||
this.popupContainer = this.shadowRoot.querySelector('.popup-container');
|
||||
this.backdrop = this.shadowRoot.querySelector('.background');
|
||||
this.popup = this.shadowRoot.querySelector('.popup');
|
||||
this.popupBodySlot = this.shadowRoot.querySelector('.popup-body slot');
|
||||
this.popupHeader = this.shadowRoot.querySelector('.popup-top');
|
||||
|
||||
this.resumeScrolling = this.resumeScrolling.bind(this)
|
||||
this.show = this.show.bind(this)
|
||||
this.hide = this.hide.bind(this)
|
||||
this.handleTouchStart = this.handleTouchStart.bind(this)
|
||||
this.handleTouchMove = this.handleTouchMove.bind(this)
|
||||
this.handleTouchEnd = this.handleTouchEnd.bind(this)
|
||||
this.movePopup = this.movePopup.bind(this)
|
||||
this.resumeScrolling = this.resumeScrolling.bind(this);
|
||||
this.setStateOpen = this.setStateOpen.bind(this);
|
||||
this.show = this.show.bind(this);
|
||||
this.hide = this.hide.bind(this);
|
||||
this.handleTouchStart = this.handleTouchStart.bind(this);
|
||||
this.handleTouchMove = this.handleTouchMove.bind(this);
|
||||
this.handleTouchEnd = this.handleTouchEnd.bind(this);
|
||||
this.detectFocus = this.detectFocus.bind(this);
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
@ -202,172 +220,254 @@ customElements.define('sm-popup', class extends HTMLElement {
|
||||
}
|
||||
|
||||
get open() {
|
||||
return this.isOpen
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
animateTo(element, keyframes, options) {
|
||||
const anime = element.animate(keyframes, { ...options, fill: 'both' })
|
||||
anime.finished.then(() => {
|
||||
anime.commitStyles()
|
||||
anime.cancel()
|
||||
})
|
||||
return anime
|
||||
}
|
||||
|
||||
resumeScrolling() {
|
||||
const scrollY = document.body.style.top;
|
||||
window.scrollTo(0, parseInt(scrollY || '0') * -1);
|
||||
setTimeout(() => {
|
||||
document.body.style.overflow = 'auto';
|
||||
document.body.style.top = 'initial'
|
||||
}, 300);
|
||||
document.body.style.overflow = 'auto';
|
||||
document.body.style.top = 'initial';
|
||||
}
|
||||
|
||||
setStateOpen() {
|
||||
if (!this.isOpen || this.offset) {
|
||||
const animOptions = {
|
||||
duration: 300,
|
||||
easing: 'ease'
|
||||
}
|
||||
const initialAnimation = (window.innerWidth > 640) ? 'scale(1.1)' : `translateY(${this.offset ? `${this.offset}px` : '100%'})`
|
||||
this.animateTo(this.popup, [
|
||||
{
|
||||
opacity: this.offset ? 1 : 0,
|
||||
transform: initialAnimation
|
||||
},
|
||||
{
|
||||
opacity: 1,
|
||||
transform: 'none'
|
||||
},
|
||||
], animOptions)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
show(options = {}) {
|
||||
const {pinned = false, popupStack = undefined} = options
|
||||
if (popupStack)
|
||||
this.popupStack = popupStack
|
||||
if (this.popupStack && !this.hasAttribute('open')) {
|
||||
this.popupStack.push({
|
||||
popup: this,
|
||||
permission: pinned
|
||||
})
|
||||
if (this.popupStack.items.length > 1) {
|
||||
this.popupStack.items[this.popupStack.items.length - 2].popup.classList.add('stacked')
|
||||
const { pinned = false } = options;
|
||||
if (!this.isOpen) {
|
||||
const animOptions = {
|
||||
duration: 300,
|
||||
easing: 'ease'
|
||||
}
|
||||
if (popupStack) {
|
||||
popupStack.push({
|
||||
popup: this,
|
||||
permission: pinned
|
||||
});
|
||||
if (popupStack.items.length > 1) {
|
||||
this.animateTo(popupStack.items[popupStack.items.length - 2].popup.shadowRoot.querySelector('.popup'), [
|
||||
{ transform: 'none' },
|
||||
{ transform: 'translateY(-1.5rem) scale(0.9)' },
|
||||
], animOptions)
|
||||
}
|
||||
}
|
||||
this.popupContainer.classList.remove('hide');
|
||||
if (!this.offset)
|
||||
this.backdrop.animate([
|
||||
{ opacity: 0 },
|
||||
{ opacity: 1 },
|
||||
], animOptions)
|
||||
this.setStateOpen()
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("popupopened", {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
popup: this,
|
||||
popupStack: this.popupStack
|
||||
}
|
||||
})
|
||||
)
|
||||
this.setAttribute('open', '')
|
||||
this.pinned = pinned
|
||||
this.isOpen = true
|
||||
);
|
||||
this.pinned = pinned;
|
||||
this.isOpen = true;
|
||||
document.body.style.overflow = 'hidden';
|
||||
document.body.style.top = `-${window.scrollY}px`;
|
||||
const elementToFocus = this.autoFocus || this.focusable[0];
|
||||
elementToFocus.tagName.includes('SM-') ? elementToFocus.focusIn() : elementToFocus.focus();
|
||||
if (!this.hasAttribute('open'))
|
||||
this.setAttribute('open', '');
|
||||
}
|
||||
this.popupContainer.classList.remove('hide')
|
||||
this.popup.style.transform = 'none';
|
||||
document.body.style.overflow = 'hidden';
|
||||
document.body.style.top = `-${window.scrollY}px`
|
||||
return this.popupStack
|
||||
}
|
||||
hide() {
|
||||
if (window.innerWidth < 640)
|
||||
this.popup.style.transform = 'translateY(100%)';
|
||||
else
|
||||
this.popup.style.transform = 'translateY(3rem)';
|
||||
this.popupContainer.classList.add('hide')
|
||||
this.removeAttribute('open')
|
||||
if (typeof this.popupStack !== 'undefined') {
|
||||
this.popupStack.pop()
|
||||
if (this.popupStack.items.length) {
|
||||
this.popupStack.items[this.popupStack.items.length - 1].popup.classList.remove('stacked')
|
||||
} else {
|
||||
this.resumeScrolling()
|
||||
}
|
||||
} else {
|
||||
this.resumeScrolling()
|
||||
const animOptions = {
|
||||
duration: 150,
|
||||
easing: 'ease'
|
||||
}
|
||||
this.backdrop.animate([
|
||||
{ opacity: 1 },
|
||||
{ opacity: 0 }
|
||||
], animOptions)
|
||||
this.animateTo(this.popup, [
|
||||
{
|
||||
opacity: 1,
|
||||
transform: (window.innerWidth > 640) ? 'none' : `translateY(${this.offset ? `${this.offset}px` : '0'})`
|
||||
},
|
||||
{
|
||||
opacity: 0,
|
||||
transform: (window.innerWidth > 640) ? 'scale(1.1)' : 'translateY(100%)'
|
||||
},
|
||||
], animOptions).finished
|
||||
.finally(() => {
|
||||
this.popupContainer.classList.add('hide');
|
||||
this.popup.style = ''
|
||||
this.removeAttribute('open');
|
||||
if (typeof popupStack !== 'undefined') {
|
||||
popupStack.pop();
|
||||
if (popupStack.items.length) {
|
||||
this.animateTo(popupStack.items[popupStack.items.length - 1].popup.shadowRoot.querySelector('.popup'), [
|
||||
{ transform: 'translateY(-1.5rem) scale(0.9)' },
|
||||
{ transform: 'none' },
|
||||
], animOptions)
|
||||
|
||||
if (this.forms.length) {
|
||||
setTimeout(() => {
|
||||
this.forms.forEach(form => form.reset())
|
||||
}, 300);
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("popupclosed", {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
popup: this,
|
||||
popupStack: this.popupStack
|
||||
} else {
|
||||
this.resumeScrolling();
|
||||
}
|
||||
})
|
||||
)
|
||||
this.isOpen = false
|
||||
}, 300);
|
||||
} else {
|
||||
this.resumeScrolling();
|
||||
}
|
||||
|
||||
if (this.forms.length) {
|
||||
this.forms.forEach(form => form.reset());
|
||||
}
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("popupclosed", {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
popup: this,
|
||||
}
|
||||
})
|
||||
);
|
||||
this.isOpen = false;
|
||||
})
|
||||
}
|
||||
|
||||
handleTouchStart(e) {
|
||||
this.touchStartY = e.changedTouches[0].clientY
|
||||
this.popup.style.transition = 'transform 0.1s'
|
||||
this.touchStartTime = e.timeStamp
|
||||
this.offset = 0
|
||||
this.popupHeader.addEventListener('touchmove', this.handleTouchMove, { passive: true });
|
||||
this.popupHeader.addEventListener('touchend', this.handleTouchEnd, { passive: true });
|
||||
this.touchStartY = e.changedTouches[0].clientY;
|
||||
this.touchStartTime = e.timeStamp;
|
||||
}
|
||||
|
||||
handleTouchMove(e) {
|
||||
if (this.touchStartY < e.changedTouches[0].clientY) {
|
||||
this.offset = e.changedTouches[0].clientY - this.touchStartY;
|
||||
this.touchEndAnimataion = window.requestAnimationFrame(() => this.movePopup())
|
||||
this.touchEndAnimation = window.requestAnimationFrame(() => {
|
||||
this.popup.style.transform = `translateY(${this.offset}px)`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
handleTouchEnd(e) {
|
||||
this.touchEndTime = e.timeStamp
|
||||
cancelAnimationFrame(this.touchEndAnimataion)
|
||||
this.touchEndY = e.changedTouches[0].clientY
|
||||
this.popup.style.transition = 'transform 0.3s'
|
||||
this.threshold = this.popup.getBoundingClientRect().height * 0.3
|
||||
this.touchEndTime = e.timeStamp;
|
||||
cancelAnimationFrame(this.touchEndAnimation);
|
||||
this.touchEndY = e.changedTouches[0].clientY;
|
||||
this.threshold = this.popup.getBoundingClientRect().height * 0.3;
|
||||
if (this.touchEndTime - this.touchStartTime > 200) {
|
||||
if (this.touchEndY - this.touchStartY > this.threshold) {
|
||||
if (this.pinned) {
|
||||
this.show()
|
||||
return
|
||||
this.setStateOpen();
|
||||
return;
|
||||
} else
|
||||
this.hide()
|
||||
this.hide();
|
||||
} else {
|
||||
this.show()
|
||||
this.setStateOpen();
|
||||
}
|
||||
} else {
|
||||
if (this.touchEndY > this.touchStartY)
|
||||
if (this.pinned) {
|
||||
this.show()
|
||||
return
|
||||
this.setStateOpen();
|
||||
return;
|
||||
}
|
||||
else
|
||||
this.hide()
|
||||
this.hide();
|
||||
}
|
||||
this.popupHeader.removeEventListener('touchmove', this.handleTouchMove, { passive: true });
|
||||
this.popupHeader.removeEventListener('touchend', this.handleTouchEnd, { passive: true });
|
||||
}
|
||||
|
||||
|
||||
detectFocus(e) {
|
||||
if (e.code === 'Tab') {
|
||||
const lastElement = this.focusable[this.focusable.length - 1];
|
||||
const firstElement = this.focusable[0];
|
||||
if (e.shiftKey && document.activeElement === firstElement) {
|
||||
e.preventDefault();
|
||||
lastElement.tagName.includes('SM-') ? lastElement.focusIn() : lastElement.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === lastElement) {
|
||||
e.preventDefault();
|
||||
firstElement.tagName.includes('SM-') ? firstElement.focusIn() : firstElement.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
movePopup() {
|
||||
this.popup.style.transform = `translateY(${this.offset}px)`
|
||||
updateFocusableList() {
|
||||
this.focusable = this.querySelectorAll('sm-button:not([disabled]), button:not([disabled]), [href], sm-input, input, sm-select, select, sm-checkbox, sm-textarea, textarea, [tabindex]:not([tabindex="-1"])')
|
||||
this.autoFocus = this.querySelector('[autofocus]')
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.popupBodySlot.addEventListener('slotchange', () => {
|
||||
this.forms = this.querySelectorAll('sm-form')
|
||||
})
|
||||
this.forms = this.querySelectorAll('sm-form');
|
||||
this.updateFocusableList()
|
||||
});
|
||||
this.popupContainer.addEventListener('mousedown', e => {
|
||||
if (e.target === this.popupContainer && !this.pinned) {
|
||||
if (this.pinned) {
|
||||
this.show()
|
||||
this.setStateOpen();
|
||||
} else
|
||||
this.hide()
|
||||
this.hide();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
for (let entry of entries) {
|
||||
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.threshold = contentBoxSize.blockSize.height * 0.3
|
||||
this.threshold = contentBoxSize.blockSize.height * 0.3;
|
||||
} else {
|
||||
this.threshold = entry.contentRect.height * 0.3
|
||||
this.threshold = entry.contentRect.height * 0.3;
|
||||
}
|
||||
}
|
||||
});
|
||||
resizeObserver.observe(this)
|
||||
|
||||
|
||||
this.popupHeader.addEventListener('touchstart', (e) => { this.handleTouchStart(e) }, { passive: true })
|
||||
this.popupHeader.addEventListener('touchmove', (e) => { this.handleTouchMove(e) }, { passive: true })
|
||||
this.popupHeader.addEventListener('touchend', (e) => { this.handleTouchEnd(e) }, { passive: true })
|
||||
resizeObserver.observe(this);
|
||||
|
||||
this.mutationObserver = new MutationObserver(entries => {
|
||||
this.updateFocusableList()
|
||||
})
|
||||
this.mutationObserver.observe(this, { attributes: true, childList: true, subtree: true })
|
||||
|
||||
this.addEventListener('keydown', this.detectFocus);
|
||||
this.popupHeader.addEventListener('touchstart', this.handleTouchStart, { passive: true });
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.popupHeader.removeEventListener('touchstart', this.handleTouchStart, { passive: true })
|
||||
this.popupHeader.removeEventListener('touchmove', this.handleTouchMove, { passive: true })
|
||||
this.popupHeader.removeEventListener('touchend', this.handleTouchEnd, { passive: true })
|
||||
resizeObserver.unobserve()
|
||||
this.removeEventListener('keydown', this.detectFocus);
|
||||
resizeObserver.unobserve();
|
||||
this.mutationObserver.disconnect()
|
||||
this.popupHeader.removeEventListener('touchstart', this.handleTouchStart, { passive: true });
|
||||
}
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
attributeChangedCallback(name) {
|
||||
if (name === 'open') {
|
||||
if (this.hasAttribute('open')) {
|
||||
this.show()
|
||||
this.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
2
components/dist/popup.min.js
vendored
2
components/dist/popup.min.js
vendored
File diff suppressed because one or more lines are too long
49
components/dist/select.js
vendored
49
components/dist/select.js
vendored
@ -21,9 +21,6 @@ smSelect.innerHTML = `
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.hide{
|
||||
display: none !important;
|
||||
}
|
||||
.select{
|
||||
position: relative;
|
||||
display: -webkit-box;
|
||||
@ -38,16 +35,18 @@ smSelect.innerHTML = `
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.icon {
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
height: 1.2rem;
|
||||
width: 1.2rem;
|
||||
margin-left: 0.5rem;
|
||||
fill: rgba(var(--text-color), 0.7);
|
||||
}
|
||||
.selected-option-text{
|
||||
font-size: 0.9rem;
|
||||
font-size: inherit;
|
||||
overflow: hidden;
|
||||
-o-text-overflow: ellipsis;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
}
|
||||
.selection{
|
||||
border-radius: 0.3rem;
|
||||
@ -56,21 +55,19 @@ smSelect.innerHTML = `
|
||||
-ms-grid-columns: 1fr auto;
|
||||
grid-template-columns: 1fr auto;
|
||||
grid-template-areas: 'heading heading' '. .';
|
||||
padding: 0.4rem 1rem;
|
||||
padding: 0.4rem 0.8rem;
|
||||
background: rgba(var(--text-color), 0.06);
|
||||
border: solid 1px rgba(var(--text-color), 0.2);
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
outline: none;
|
||||
z-index: 2;
|
||||
}
|
||||
.selection:focus{
|
||||
-webkit-box-shadow: 0 0 0 0.1rem var(--accent-color);
|
||||
box-shadow: 0 0 0 0.1rem var(--accent-color)
|
||||
}
|
||||
.icon{
|
||||
margin-left: 1rem;
|
||||
}
|
||||
:host([align-select="left"]) .options{
|
||||
left: 0;
|
||||
}
|
||||
@ -79,6 +76,7 @@ smSelect.innerHTML = `
|
||||
}
|
||||
.options{
|
||||
top: 100%;
|
||||
padding: var(--options-padding, 0.3rem);
|
||||
margin-top: 0.2rem;
|
||||
overflow: hidden auto;
|
||||
position: absolute;
|
||||
@ -94,8 +92,8 @@ smSelect.innerHTML = `
|
||||
max-height: var(--max-height);
|
||||
background: rgba(var(--background-color), 1);
|
||||
border: solid 1px rgba(var(--text-color), 0.2);
|
||||
border-radius: 0.3rem;
|
||||
z-index: 2;
|
||||
border-radius: var(--border-radius, 0.5rem);
|
||||
z-index: 1;
|
||||
-webkit-box-shadow: 0.4rem 0.8rem 1.2rem #00000030;
|
||||
box-shadow: 0.4rem 0.8rem 1.2rem #00000030;
|
||||
}
|
||||
@ -104,6 +102,9 @@ smSelect.innerHTML = `
|
||||
-ms-transform: rotate(180deg);
|
||||
transform: rotate(180deg)
|
||||
}
|
||||
.hide{
|
||||
display: none;
|
||||
}
|
||||
@media (any-hover: hover){
|
||||
::-webkit-scrollbar{
|
||||
width: 0.5rem;
|
||||
@ -119,7 +120,7 @@ smSelect.innerHTML = `
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="select" >
|
||||
<div class="select">
|
||||
<div class="selection">
|
||||
<div class="selected-option-text"></div>
|
||||
<svg class="icon toggle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 13.172l4.95-4.95 1.414 1.414L12 16 5.636 9.636 7.05 8.222z"/></svg>
|
||||
@ -135,6 +136,7 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
mode: 'open'
|
||||
}).append(smSelect.content.cloneNode(true))
|
||||
|
||||
this.focusIn = this.focusIn.bind(this)
|
||||
this.reset = this.reset.bind(this)
|
||||
this.open = this.open.bind(this)
|
||||
this.collapse = this.collapse.bind(this)
|
||||
@ -147,6 +149,7 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
this.availableOptions
|
||||
this.previousOption
|
||||
this.isOpen = false;
|
||||
this.label = ''
|
||||
this.slideDown = [{
|
||||
transform: `translateY(-0.5rem)`,
|
||||
opacity: 0
|
||||
@ -177,7 +180,7 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
this.selectedOptionText = this.shadowRoot.querySelector('.selected-option-text')
|
||||
}
|
||||
static get observedAttributes() {
|
||||
return ['value', 'disabled']
|
||||
return ['disabled', 'label']
|
||||
}
|
||||
get value() {
|
||||
return this.getAttribute('value')
|
||||
@ -194,7 +197,7 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
}
|
||||
firstElement.classList.add('check-selected')
|
||||
this.value = firstElement.getAttribute('value')
|
||||
this.selectedOptionText.textContent = firstElement.textContent
|
||||
this.selectedOptionText.textContent = `${this.label}${firstElement.textContent}`
|
||||
this.previousOption = firstElement;
|
||||
if (fire) {
|
||||
this.fireEvent()
|
||||
@ -202,6 +205,10 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
}
|
||||
}
|
||||
|
||||
focusIn() {
|
||||
this.selection.focus()
|
||||
}
|
||||
|
||||
open() {
|
||||
this.optionList.classList.remove('hide')
|
||||
this.optionList.animate(this.slideDown, this.animationOptions)
|
||||
@ -255,7 +262,7 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
handleOptionSelection(e) {
|
||||
if (this.previousOption !== document.activeElement) {
|
||||
this.value = document.activeElement.getAttribute('value')
|
||||
this.selectedOptionText.textContent = document.activeElement.textContent;
|
||||
this.selectedOptionText.textContent = `${this.label}${document.activeElement.textContent}`;
|
||||
this.fireEvent()
|
||||
if (this.previousOption) {
|
||||
this.previousOption.classList.remove('check-selected')
|
||||
@ -325,6 +332,8 @@ customElements.define('sm-select', class extends HTMLElement {
|
||||
} else {
|
||||
this.selection.setAttribute('tabindex', '0')
|
||||
}
|
||||
} else if (name === 'label') {
|
||||
this.label = this.hasAttribute('label') ? `${this.getAttribute('label')} ` : ''
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -349,14 +358,16 @@ smOption.innerHTML = `
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
min-width: 100%;
|
||||
min-width: max-content;
|
||||
width: 100%;
|
||||
gap: 0.5rem;
|
||||
grid-template-columns: max-content minmax(0, 1fr);
|
||||
padding: 0.8rem 1.2rem;
|
||||
padding: var(--padding, 0.6rem 1rem);
|
||||
cursor: pointer;
|
||||
overflow-wrap: break-word;
|
||||
white-space: nowrap;
|
||||
outline: none;
|
||||
user-select: none;
|
||||
border-radius: var(--border-radius, 0.3rem);
|
||||
}
|
||||
:host(:focus){
|
||||
outline: none;
|
||||
|
||||
2
components/dist/select.min.js
vendored
2
components/dist/select.min.js
vendored
File diff suppressed because one or more lines are too long
17
components/dist/spinner.js
vendored
17
components/dist/spinner.js
vendored
@ -1,4 +1,4 @@
|
||||
const spinner = document.createElement('template')
|
||||
const spinner = document.createElement('template');
|
||||
spinner.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -9,10 +9,12 @@ spinner.innerHTML = `
|
||||
}
|
||||
:host{
|
||||
--accent-color: #4d2588;
|
||||
--height: 1.6rem;
|
||||
--width: 1.6rem;
|
||||
}
|
||||
.loader {
|
||||
height: 1.6rem;
|
||||
width: 1.6rem;
|
||||
height: var(--height);
|
||||
width: var(--weight);
|
||||
stroke-width: 8;
|
||||
overflow: visible;
|
||||
stroke: var(--accent-color);
|
||||
@ -38,14 +40,13 @@ spinner.innerHTML = `
|
||||
</style>
|
||||
<svg viewBox="0 0 64 64" class="loader"><circle cx="32" cy="32" r="32" /></svg>
|
||||
|
||||
`
|
||||
class SquareLoader extends HTMLElement {
|
||||
`;
|
||||
class SpinnerLoader extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(spinner.content.cloneNode(true))
|
||||
}).append(spinner.content.cloneNode(true));
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define('sm-spinner', SquareLoader);
|
||||
window.customElements.define('sm-spinner', SpinnerLoader);
|
||||
2
components/dist/spinner.min.js
vendored
2
components/dist/spinner.min.js
vendored
@ -1 +1 @@
|
||||
const spinner=document.createElement("template");spinner.innerHTML='\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n:host{\n --accent-color: #4d2588;\n}\n.loader {\n height: 1.6rem;\n width: 1.6rem;\n stroke-width: 8;\n overflow: visible;\n stroke: var(--accent-color);\n fill: none;\n stroke-dashoffset: 180;\n stroke-dasharray: 180;\n animation: load 2s infinite, spin 1s linear infinite;\n}\n@keyframes load {\n 50% {\n stroke-dashoffset: 0;\n }\n 100%{\n stroke-dashoffset: -180;\n }\n}\n\n@keyframes spin {\n 100% {\n transform: rotate(360deg);\n }\n}\n</style>\n<svg viewBox="0 0 64 64" class="loader"><circle cx="32" cy="32" r="32" /></svg>\n\n';class SquareLoader extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(spinner.content.cloneNode(!0))}}window.customElements.define("sm-spinner",SquareLoader);
|
||||
const spinner=document.createElement("template");spinner.innerHTML='\n<style> \n*{\n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n:host{\n --accent-color: #4d2588;\n --height: 1.6rem;\n --width: 1.6rem;\n}\n.loader {\n height: var(--height);\n width: var(--weight);\n stroke-width: 8;\n overflow: visible;\n stroke: var(--accent-color);\n fill: none;\n stroke-dashoffset: 180;\n stroke-dasharray: 180;\n animation: load 2s infinite, spin 1s linear infinite;\n}\n@keyframes load {\n 50% {\n stroke-dashoffset: 0;\n }\n 100%{\n stroke-dashoffset: -180;\n }\n}\n\n@keyframes spin {\n 100% {\n transform: rotate(360deg);\n }\n}\n</style>\n<svg viewBox="0 0 64 64" class="loader"><circle cx="32" cy="32" r="32" /></svg>\n\n';class SpinnerLoader extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(spinner.content.cloneNode(!0))}}window.customElements.define("sm-spinner",SpinnerLoader);
|
||||
182
components/dist/strip-select.js
vendored
182
components/dist/strip-select.js
vendored
@ -1,4 +1,4 @@
|
||||
const stripSelect = document.createElement('template')
|
||||
const stripSelect = document.createElement('template');
|
||||
stripSelect.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -11,7 +11,6 @@ stripSelect.innerHTML = `
|
||||
--accent-color: #4d2588;
|
||||
--text-color: 17, 17, 17;
|
||||
--background-color: 255, 255, 255;
|
||||
--gap: 0.5rem;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
.hide{
|
||||
@ -31,13 +30,13 @@ stripSelect.innerHTML = `
|
||||
:host([multiline]) .strip-select{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
gap: var(--gap, 0.5rem);
|
||||
overflow: auto hidden;
|
||||
}
|
||||
:host(:not([multiline])) .strip-select{
|
||||
display: grid;
|
||||
grid-auto-flow: column;
|
||||
gap: var(--gap);
|
||||
gap: var(--gap, 0.5rem);
|
||||
max-width: 100%;
|
||||
align-items: center;
|
||||
overflow: auto hidden;
|
||||
@ -73,6 +72,9 @@ stripSelect.innerHTML = `
|
||||
fill: rgba(var(--text-color), .8);
|
||||
}
|
||||
@media (hover: none){
|
||||
::-webkit-scrollbar {
|
||||
height: 0;
|
||||
}
|
||||
.nav-button{
|
||||
display: none;
|
||||
}
|
||||
@ -124,37 +126,37 @@ stripSelect.innerHTML = `
|
||||
<div class="cover cover--right hide"></div>
|
||||
</section>
|
||||
|
||||
`
|
||||
`;
|
||||
customElements.define('strip-select', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(stripSelect.content.cloneNode(true))
|
||||
this.stripSelect = this.shadowRoot.querySelector('.strip-select')
|
||||
this.slottedOptions
|
||||
this._value
|
||||
this.scrollDistance
|
||||
}).append(stripSelect.content.cloneNode(true));
|
||||
this.stripSelect = this.shadowRoot.querySelector('.strip-select');
|
||||
this.slottedOptions = undefined;
|
||||
this._value = undefined;
|
||||
this.scrollDistance = 0;
|
||||
|
||||
this.scrollLeft = this.scrollLeft.bind(this)
|
||||
this.scrollRight = this.scrollRight.bind(this)
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
this.scrollLeft = this.scrollLeft.bind(this);
|
||||
this.scrollRight = this.scrollRight.bind(this);
|
||||
this.fireEvent = this.fireEvent.bind(this);
|
||||
}
|
||||
get value() {
|
||||
return this._value
|
||||
return this._value;
|
||||
}
|
||||
scrollLeft() {
|
||||
this.stripSelect.scrollBy({
|
||||
left: -this.scrollDistance,
|
||||
behavior: 'smooth'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
scrollRight() {
|
||||
this.stripSelect.scrollBy({
|
||||
left: this.scrollDistance,
|
||||
behavior: 'smooth'
|
||||
})
|
||||
});
|
||||
}
|
||||
fireEvent() {
|
||||
this.dispatchEvent(
|
||||
@ -165,104 +167,104 @@ customElements.define('strip-select', class extends HTMLElement {
|
||||
value: this._value
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
connectedCallback() {
|
||||
this.setAttribute('role', 'listbox')
|
||||
this.setAttribute('role', 'listbox');
|
||||
|
||||
const slot = this.shadowRoot.querySelector('slot')
|
||||
const coverLeft = this.shadowRoot.querySelector('.cover--left')
|
||||
const coverRight = this.shadowRoot.querySelector('.cover--right')
|
||||
const navButtonLeft = this.shadowRoot.querySelector('.nav-button--left')
|
||||
const navButtonRight = this.shadowRoot.querySelector('.nav-button--right')
|
||||
const slot = this.shadowRoot.querySelector('slot');
|
||||
const coverLeft = this.shadowRoot.querySelector('.cover--left');
|
||||
const coverRight = this.shadowRoot.querySelector('.cover--right');
|
||||
const navButtonLeft = this.shadowRoot.querySelector('.nav-button--left');
|
||||
const navButtonRight = this.shadowRoot.querySelector('.nav-button--right');
|
||||
slot.addEventListener('slotchange', e => {
|
||||
const assignedElements = slot.assignedElements()
|
||||
const assignedElements = slot.assignedElements();
|
||||
assignedElements.forEach(elem => {
|
||||
if (elem.hasAttribute('selected')) {
|
||||
elem.setAttribute('active', '')
|
||||
this._value = elem.value
|
||||
elem.setAttribute('active', '');
|
||||
this._value = elem.value;
|
||||
}
|
||||
})
|
||||
});
|
||||
if (!this.hasAttribute('multiline')) {
|
||||
if (assignedElements.length > 0) {
|
||||
firstOptionObserver.observe(slot.assignedElements()[0])
|
||||
lastOptionObserver.observe(slot.assignedElements()[slot.assignedElements().length - 1])
|
||||
firstOptionObserver.observe(slot.assignedElements()[0]);
|
||||
lastOptionObserver.observe(slot.assignedElements()[slot.assignedElements().length - 1]);
|
||||
}
|
||||
else {
|
||||
navButtonLeft.classList.add('hide')
|
||||
navButtonRight.classList.add('hide')
|
||||
coverLeft.classList.add('hide')
|
||||
coverRight.classList.add('hide')
|
||||
firstOptionObserver.disconnect()
|
||||
lastOptionObserver.disconnect()
|
||||
navButtonLeft.classList.add('hide');
|
||||
navButtonRight.classList.add('hide');
|
||||
coverLeft.classList.add('hide');
|
||||
coverRight.classList.add('hide');
|
||||
firstOptionObserver.disconnect();
|
||||
lastOptionObserver.disconnect();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
const resObs = new ResizeObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
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
|
||||
this.scrollDistance = contentBoxSize.inlineSize * 0.6;
|
||||
} else {
|
||||
this.scrollDistance = entry.contentRect.width * 0.6
|
||||
this.scrollDistance = entry.contentRect.width * 0.6;
|
||||
}
|
||||
})
|
||||
})
|
||||
resObs.observe(this)
|
||||
});
|
||||
});
|
||||
resObs.observe(this);
|
||||
this.stripSelect.addEventListener('option-clicked', e => {
|
||||
if (this._value !== e.target.value) {
|
||||
this._value = e.target.value
|
||||
slot.assignedElements().forEach(elem => elem.removeAttribute('active'))
|
||||
e.target.setAttribute('active', '')
|
||||
e.target.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" })
|
||||
this.fireEvent()
|
||||
this._value = e.target.value;
|
||||
slot.assignedElements().forEach(elem => elem.removeAttribute('active'));
|
||||
e.target.setAttribute('active', '');
|
||||
e.target.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
|
||||
this.fireEvent();
|
||||
}
|
||||
})
|
||||
});
|
||||
const firstOptionObserver = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
navButtonLeft.classList.add('hide')
|
||||
coverLeft.classList.add('hide')
|
||||
navButtonLeft.classList.add('hide');
|
||||
coverLeft.classList.add('hide');
|
||||
}
|
||||
else {
|
||||
navButtonLeft.classList.remove('hide')
|
||||
coverLeft.classList.remove('hide')
|
||||
navButtonLeft.classList.remove('hide');
|
||||
coverLeft.classList.remove('hide');
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
{
|
||||
threshold: 0.9,
|
||||
root: this
|
||||
})
|
||||
});
|
||||
const lastOptionObserver = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
navButtonRight.classList.add('hide')
|
||||
coverRight.classList.add('hide')
|
||||
navButtonRight.classList.add('hide');
|
||||
coverRight.classList.add('hide');
|
||||
}
|
||||
else {
|
||||
navButtonRight.classList.remove('hide')
|
||||
coverRight.classList.remove('hide')
|
||||
navButtonRight.classList.remove('hide');
|
||||
coverRight.classList.remove('hide');
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
{
|
||||
threshold: 0.9,
|
||||
root: this
|
||||
})
|
||||
navButtonLeft.addEventListener('click', this.scrollLeft)
|
||||
navButtonRight.addEventListener('click', this.scrollRight)
|
||||
});
|
||||
navButtonLeft.addEventListener('click', this.scrollLeft);
|
||||
navButtonRight.addEventListener('click', this.scrollRight);
|
||||
}
|
||||
disconnectedCallback() {
|
||||
navButtonLeft.removeEventListener('click', this.scrollLeft)
|
||||
navButtonRight.removeEventListener('click', this.scrollRight)
|
||||
navButtonLeft.removeEventListener('click', this.scrollLeft);
|
||||
navButtonRight.removeEventListener('click', this.scrollRight);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//Strip option
|
||||
const stripOption = document.createElement('template')
|
||||
const stripOption = document.createElement('template');
|
||||
stripOption.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -272,25 +274,21 @@ stripOption.innerHTML = `
|
||||
box-sizing: border-box;
|
||||
}
|
||||
:host{
|
||||
--border-radius: 2rem;
|
||||
--background-color: inherit;
|
||||
--active-option-color: inherit;
|
||||
--active-option-backgroud-color: rgba(var(--text-color), .2);
|
||||
}
|
||||
.strip-option{
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
padding: 0.5rem 0.8rem;
|
||||
padding: var(--padding, 0.4rem 0.6rem);
|
||||
transition: background 0.3s;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: 0 0 0 1px rgba(var(--text-color), .2) inset;
|
||||
border-radius: var(--border-radius, 2rem);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
:host([active]) .strip-option{
|
||||
color: var(--active-option-color);
|
||||
background-color: var(--active-option-backgroud-color);
|
||||
color: var(--active-option-color, inherit);
|
||||
background-color: var(--active-background-color, rgba(var(--text-color), 0.06));
|
||||
}
|
||||
:host(:focus-within){
|
||||
outline: none;
|
||||
@ -305,21 +303,21 @@ stripOption.innerHTML = `
|
||||
<label class="strip-option">
|
||||
<slot></slot>
|
||||
</label>
|
||||
`
|
||||
`;
|
||||
customElements.define('strip-option', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(stripOption.content.cloneNode(true))
|
||||
this._value
|
||||
this.radioButton = this.shadowRoot.querySelector('input')
|
||||
}).append(stripOption.content.cloneNode(true));
|
||||
this._value = undefined;
|
||||
this.radioButton = this.shadowRoot.querySelector('input');
|
||||
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
this.handleKeyDown = this.handleKeyDown.bind(this)
|
||||
this.fireEvent = this.fireEvent.bind(this);
|
||||
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||
}
|
||||
get value() {
|
||||
return this._value
|
||||
return this._value;
|
||||
}
|
||||
fireEvent() {
|
||||
this.dispatchEvent(
|
||||
@ -330,22 +328,22 @@ customElements.define('strip-option', class extends HTMLElement {
|
||||
value: this._value
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
handleKeyDown(e) {
|
||||
if (e.key === 'Enter' || e.key === 'Space') {
|
||||
this.fireEvent()
|
||||
this.fireEvent();
|
||||
}
|
||||
}
|
||||
connectedCallback() {
|
||||
this.setAttribute('role', 'option')
|
||||
this.setAttribute('tabindex', '0')
|
||||
this._value = this.getAttribute('value')
|
||||
this.addEventListener('click', this.fireEvent)
|
||||
this.addEventListener('keydown', this.handleKeyDown)
|
||||
this.setAttribute('role', 'option');
|
||||
this.setAttribute('tabindex', '0');
|
||||
this._value = this.getAttribute('value');
|
||||
this.addEventListener('click', this.fireEvent);
|
||||
this.addEventListener('keydown', this.handleKeyDown);
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.removeEventListener('click', this.fireEvent)
|
||||
this.removeEventListener('keydown', this.handleKeyDown)
|
||||
this.removeEventListener('click', this.fireEvent);
|
||||
this.removeEventListener('keydown', this.handleKeyDown);
|
||||
}
|
||||
})
|
||||
});
|
||||
2
components/dist/strip-select.min.js
vendored
2
components/dist/strip-select.min.js
vendored
File diff suppressed because one or more lines are too long
39
components/dist/switch.js
vendored
39
components/dist/switch.js
vendored
@ -28,10 +28,6 @@ smSwitch.innerHTML = `
|
||||
cursor: pointer;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
:host(:not([disabled])) label:focus-visible{
|
||||
-webkit-box-shadow: 0 0 0 0.1rem var(--accent-color);
|
||||
box-shadow: 0 0 0 0.1rem var(--accent-color);
|
||||
}
|
||||
:host([disabled]) {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
@ -71,15 +67,12 @@ smSwitch.innerHTML = `
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
.switch:active .button::after,
|
||||
.switch:focus .button::after{
|
||||
opacity: 1
|
||||
}
|
||||
.switch:focus-visible .button::after{
|
||||
opacity: 1
|
||||
label:active .thumb::after,
|
||||
label:focus-within .thumb::after{
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.button::after{
|
||||
.thumb::after{
|
||||
content: '';
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
@ -95,7 +88,7 @@ smSwitch.innerHTML = `
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.button {
|
||||
.thumb {
|
||||
position: relative;
|
||||
display: -webkit-inline-box;
|
||||
display: -ms-inline-flexbox;
|
||||
@ -119,7 +112,7 @@ smSwitch.innerHTML = `
|
||||
border: solid 0.3rem white;
|
||||
}
|
||||
|
||||
input:checked ~ .button {
|
||||
input:checked ~ .thumb {
|
||||
-webkit-transform: translateX(100%);
|
||||
-ms-transform: translateX(100%);
|
||||
transform: translateX(100%);
|
||||
@ -134,7 +127,7 @@ smSwitch.innerHTML = `
|
||||
<div part="switch" class="switch">
|
||||
<input type="checkbox">
|
||||
<div class="track"></div>
|
||||
<div class="button"></div>
|
||||
<div class="thumb"></div>
|
||||
</div>
|
||||
<slot name="right"></slot>
|
||||
</label>`
|
||||
@ -181,12 +174,16 @@ customElements.define('sm-switch', class extends HTMLElement {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(){
|
||||
reset() {
|
||||
|
||||
}
|
||||
|
||||
dispatch() {
|
||||
this.dispatchEvent(new CustomEvent('change', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
detail: {
|
||||
value: this.isChecked
|
||||
value: this.isChecked
|
||||
}
|
||||
}))
|
||||
}
|
||||
@ -210,21 +207,21 @@ customElements.define('sm-switch', class extends HTMLElement {
|
||||
if (oldValue !== newValue) {
|
||||
if (name === 'disabled') {
|
||||
if (this.hasAttribute('disabled')) {
|
||||
this.disabled = true
|
||||
this.disabled = true
|
||||
}
|
||||
else {
|
||||
this.disabled = false
|
||||
this.disabled = false
|
||||
}
|
||||
}
|
||||
else if (name === 'checked') {
|
||||
if (this.hasAttribute('checked')) {
|
||||
this.isChecked = true
|
||||
this.input.checked = true
|
||||
this.input.checked = true
|
||||
}
|
||||
else {
|
||||
this.isChecked = false
|
||||
this.input.checked = false
|
||||
}
|
||||
this.input.checked = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
components/dist/switch.min.js
vendored
2
components/dist/switch.min.js
vendored
File diff suppressed because one or more lines are too long
2
components/dist/tabs.js
vendored
2
components/dist/tabs.js
vendored
@ -155,7 +155,7 @@ customElements.define('sm-tab-header', class extends HTMLElement {
|
||||
this.fireEvent(e.target.dataset.index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
handlePanelChange(e) {
|
||||
this.changeTab(this.allTabs[e.detail.index])
|
||||
}
|
||||
|
||||
15
components/dist/tags-input.js
vendored
15
components/dist/tags-input.js
vendored
@ -88,7 +88,7 @@ customElements.define('tags-input', class extends HTMLElement {
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(tagsInput.content.cloneNode(true))
|
||||
|
||||
|
||||
this.input = this.shadowRoot.querySelector('input')
|
||||
this.tagsWrapper = this.shadowRoot.querySelector('.tags-wrapper')
|
||||
this.placeholder = this.shadowRoot.querySelector('.placeholder')
|
||||
@ -108,17 +108,20 @@ customElements.define('tags-input', class extends HTMLElement {
|
||||
get value() {
|
||||
return [...this.tags].join()
|
||||
}
|
||||
get isValid() {
|
||||
return this.tags.size
|
||||
}
|
||||
focusIn() {
|
||||
this.input.focus()
|
||||
}
|
||||
reset(){
|
||||
reset() {
|
||||
this.input.value = ''
|
||||
this.tags.clear()
|
||||
while (this.input.previousElementSibling) {
|
||||
this.input.previousElementSibling.remove()
|
||||
}
|
||||
}
|
||||
handleInput(e){
|
||||
handleInput(e) {
|
||||
const inputValueLength = e.target.value.trim().length
|
||||
e.target.setAttribute('size', inputValueLength ? inputValueLength : '3')
|
||||
if (inputValueLength) {
|
||||
@ -128,7 +131,7 @@ customElements.define('tags-input', class extends HTMLElement {
|
||||
this.placeholder.classList.remove('hide')
|
||||
}
|
||||
}
|
||||
handleKeydown(e){
|
||||
handleKeydown(e) {
|
||||
if (e.key === ',' || e.key === '/') {
|
||||
e.preventDefault()
|
||||
}
|
||||
@ -179,7 +182,7 @@ customElements.define('tags-input', class extends HTMLElement {
|
||||
}
|
||||
}
|
||||
}
|
||||
handleClick(e){
|
||||
handleClick(e) {
|
||||
if (e.target.closest('.tag')) {
|
||||
this.removeTag(e.target.closest('.tag'))
|
||||
}
|
||||
@ -187,7 +190,7 @@ customElements.define('tags-input', class extends HTMLElement {
|
||||
this.input.focus()
|
||||
}
|
||||
}
|
||||
removeTag(tag){
|
||||
removeTag(tag) {
|
||||
this.tags.delete(tag.dataset.value)
|
||||
tag.remove()
|
||||
if (!this.tags.size) {
|
||||
|
||||
2
components/dist/tags-input.min.js
vendored
2
components/dist/tags-input.min.js
vendored
@ -1 +1 @@
|
||||
const tagsInput=document.createElement("template");tagsInput.innerHTML='\n <style>\n *{\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n :host{\n\t--accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --danger-color: red;\n --border-radius: 0.3rem;\n\t--background: rgba(var(--text-color), 0.06);\n }\n.hide{\n display: none !important;\n}\n.tags-wrapper{\n position: relative;\n display: flex;\n cursor: text;\n flex-wrap: wrap;\n justify-items: flex-start;\n align-items: center;\n padding: 0.5rem 0.5rem 0 0.5rem;\n border-radius: var(--border-radius);\n background: var(--background);\n }\n .tags-wrapper:focus-within{\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset !important;\n }\n \n .tag {\n cursor: pointer;\n user-select: none;\n align-items: center;\n display: inline-flex;\n border-radius: 0.3rem;\n padding: 0.3rem 0.5rem;\n margin: 0 0.5rem 0.5rem 0;\n background-color: rgba(var(--text-color), 0.06);\n }\n \n .icon {\n height: 1.2rem;\n width: 1.2rem;\n margin-left: 0.3rem;\n fill: rgba(var(--text-color), 0.8);\n }\n \n input,\n input:focus {\n outline: none;\n border: none;\n }\n \n input {\n display: inline-flex;\n width: auto;\n color: inherit;\n max-width: inherit;\n font-size: inherit;\n font-family: inherit;\n padding: 0.4rem 0.5rem;\n margin: 0 0.5rem 0.5rem 0;\n background-color: transparent;\n }\n .placeholder{\n position: absolute;\n padding: 0 0.5rem;\n top: 50%;\n font-weight: 500;\n transform: translateY(-50%);\n color: rgba(var(--text-color), 0.6);\n }\n </style>\n <div class="tags-wrapper">\n <input type="text" size="3"/>\n <p class="placeholder"></p>\n </div>\n',customElements.define("tags-input",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(tagsInput.content.cloneNode(!0)),this.input=this.shadowRoot.querySelector("input"),this.tagsWrapper=this.shadowRoot.querySelector(".tags-wrapper"),this.placeholder=this.shadowRoot.querySelector(".placeholder"),this.reflectedAttributes=["placeholder","limit"],this.limit=void 0,this.tags=new Set,this.reset=this.reset.bind(this),this.handleInput=this.handleInput.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleClick=this.handleClick.bind(this),this.removeTag=this.removeTag.bind(this)}static get observedAttributes(){return["placeholder","limit"]}get value(){return[...this.tags].join()}focusIn(){this.input.focus()}reset(){for(this.input.value="",this.tags.clear();this.input.previousElementSibling;)this.input.previousElementSibling.remove()}handleInput(t){const e=t.target.value.trim().length;t.target.setAttribute("size",e||"3"),e?this.placeholder.classList.add("hide"):e||this.tags.size||this.placeholder.classList.remove("hide")}handleKeydown(t){if(","!==t.key&&"/"!==t.key||t.preventDefault(),""!==t.target.value.trim()){if("Enter"===t.key||","===t.key||"/"===t.key||"Space"===t.code){const e=t.target.value.trim();if(this.tags.has(e))this.tagsWrapper.querySelector(`[data-value="${e}"]`).animate([{backgroundColor:"initial"},{backgroundColor:"var(--accent-color)"},{backgroundColor:"initial"}],{duration:300,easing:"ease"});else{const t=document.createElement("span");t.dataset.value=e,t.className="tag",t.innerHTML=`\n <span class="tag-text">${e}</span>\n <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></svg>\n `,this.input.before(t),this.tags.add(e)}if(t.target.value="",t.target.setAttribute("size","3"),this.limit&&this.limit<this.tags.size+1)return void(this.input.readOnly=!0)}}else"Backspace"===t.key&&this.input.previousElementSibling&&this.removeTag(this.input.previousElementSibling),this.limit&&this.limit>this.tags.size&&(this.input.readOnly=!1)}handleClick(t){t.target.closest(".tag")?this.removeTag(t.target.closest(".tag")):this.input.focus()}removeTag(t){this.tags.delete(t.dataset.value),t.remove(),this.tags.size||this.placeholder.classList.remove("hide")}connectedCallback(){this.input.addEventListener("input",this.handleInput),this.input.addEventListener("keydown",this.handleKeydown),this.tagsWrapper.addEventListener("click",this.handleClick)}attributeChangedCallback(t,e,n){"placeholder"===t&&(this.placeholder.textContent=n),"limit"===t&&(this.limit=parseInt(n))}disconnectedCallback(){this.input.removeEventListener("input",this.handleInput),this.input.removeEventListener("keydown",this.handleKeydown),this.tagsWrapper.removeEventListener("click",this.handleClick)}});
|
||||
const tagsInput=document.createElement("template");tagsInput.innerHTML='\n <style>\n *{\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n :host{\n\t--accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --danger-color: red;\n --border-radius: 0.3rem;\n\t--background: rgba(var(--text-color), 0.06);\n }\n.hide{\n display: none !important;\n}\n.tags-wrapper{\n position: relative;\n display: flex;\n cursor: text;\n flex-wrap: wrap;\n justify-items: flex-start;\n align-items: center;\n padding: 0.5rem 0.5rem 0 0.5rem;\n border-radius: var(--border-radius);\n background: var(--background);\n }\n .tags-wrapper:focus-within{\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset !important;\n }\n \n .tag {\n cursor: pointer;\n user-select: none;\n align-items: center;\n display: inline-flex;\n border-radius: 0.3rem;\n padding: 0.3rem 0.5rem;\n margin: 0 0.5rem 0.5rem 0;\n background-color: rgba(var(--text-color), 0.06);\n }\n \n .icon {\n height: 1.2rem;\n width: 1.2rem;\n margin-left: 0.3rem;\n fill: rgba(var(--text-color), 0.8);\n }\n \n input,\n input:focus {\n outline: none;\n border: none;\n }\n \n input {\n display: inline-flex;\n width: auto;\n color: inherit;\n max-width: inherit;\n font-size: inherit;\n font-family: inherit;\n padding: 0.4rem 0.5rem;\n margin: 0 0.5rem 0.5rem 0;\n background-color: transparent;\n }\n .placeholder{\n position: absolute;\n padding: 0 0.5rem;\n top: 50%;\n font-weight: 500;\n transform: translateY(-50%);\n color: rgba(var(--text-color), 0.6);\n }\n </style>\n <div class="tags-wrapper">\n <input type="text" size="3"/>\n <p class="placeholder"></p>\n </div>\n',customElements.define("tags-input",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(tagsInput.content.cloneNode(!0)),this.input=this.shadowRoot.querySelector("input"),this.tagsWrapper=this.shadowRoot.querySelector(".tags-wrapper"),this.placeholder=this.shadowRoot.querySelector(".placeholder"),this.reflectedAttributes=["placeholder","limit"],this.limit=void 0,this.tags=new Set,this.reset=this.reset.bind(this),this.handleInput=this.handleInput.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleClick=this.handleClick.bind(this),this.removeTag=this.removeTag.bind(this)}static get observedAttributes(){return["placeholder","limit"]}get value(){return[...this.tags].join()}get isValid(){return this.tags.size}focusIn(){this.input.focus()}reset(){for(this.input.value="",this.tags.clear();this.input.previousElementSibling;)this.input.previousElementSibling.remove()}handleInput(t){const e=t.target.value.trim().length;t.target.setAttribute("size",e||"3"),e?this.placeholder.classList.add("hide"):e||this.tags.size||this.placeholder.classList.remove("hide")}handleKeydown(t){if(","!==t.key&&"/"!==t.key||t.preventDefault(),""!==t.target.value.trim()){if("Enter"===t.key||","===t.key||"/"===t.key||"Space"===t.code){const e=t.target.value.trim();if(this.tags.has(e))this.tagsWrapper.querySelector(`[data-value="${e}"]`).animate([{backgroundColor:"initial"},{backgroundColor:"var(--accent-color)"},{backgroundColor:"initial"}],{duration:300,easing:"ease"});else{const t=document.createElement("span");t.dataset.value=e,t.className="tag",t.innerHTML=`\n <span class="tag-text">${e}</span>\n <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></svg>\n `,this.input.before(t),this.tags.add(e)}if(t.target.value="",t.target.setAttribute("size","3"),this.limit&&this.limit<this.tags.size+1)return void(this.input.readOnly=!0)}}else"Backspace"===t.key&&this.input.previousElementSibling&&this.removeTag(this.input.previousElementSibling),this.limit&&this.limit>this.tags.size&&(this.input.readOnly=!1)}handleClick(t){t.target.closest(".tag")?this.removeTag(t.target.closest(".tag")):this.input.focus()}removeTag(t){this.tags.delete(t.dataset.value),t.remove(),this.tags.size||this.placeholder.classList.remove("hide")}connectedCallback(){this.input.addEventListener("input",this.handleInput),this.input.addEventListener("keydown",this.handleKeydown),this.tagsWrapper.addEventListener("click",this.handleClick)}attributeChangedCallback(t,e,n){"placeholder"===t&&(this.placeholder.textContent=n),"limit"===t&&(this.limit=parseInt(n))}disconnectedCallback(){this.input.removeEventListener("input",this.handleInput),this.input.removeEventListener("keydown",this.handleKeydown),this.tagsWrapper.removeEventListener("click",this.handleClick)}});
|
||||
112
components/dist/text-field.js
vendored
112
components/dist/text-field.js
vendored
@ -16,7 +16,6 @@ textField.innerHTML = `
|
||||
align-items: center;
|
||||
}
|
||||
.text{
|
||||
padding: 0.6rem 0;
|
||||
transition: background-color 0.3s;
|
||||
border-bottom: 0.15rem solid transparent;
|
||||
overflow-wrap: break-word;
|
||||
@ -38,44 +37,38 @@ textField.innerHTML = `
|
||||
.editable{
|
||||
border-bottom: 0.15rem solid rgba(var(--text-color), 0.6);
|
||||
}
|
||||
.icon-container{
|
||||
.edit-button{
|
||||
display: grid;
|
||||
position: relative;
|
||||
margin-left: 0.5rem;
|
||||
height: 1.8rem;
|
||||
width: 1.8rem;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
:host([disabled]) .icon-container{
|
||||
:host([disabled]) .edit-button{
|
||||
display: none;
|
||||
}
|
||||
.icon{
|
||||
position: absolute;
|
||||
grid-area: 1/-1;
|
||||
cursor: pointer;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
padding: 0.3rem;
|
||||
height: 1.2rem;
|
||||
width: 1.2rem;
|
||||
fill: rgba(var(--text-color), 1);
|
||||
}
|
||||
.hide{
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
<div class="text-field">
|
||||
<div class="text" part="text"></div>
|
||||
<div tabindex="0" class="icon-container">
|
||||
<svg class="edit-button icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<title>Edit</title>
|
||||
<path fill="none" d="M0 0h24v24H0z"/><path d="M12.9 6.858l4.242 4.243L7.242 21H3v-4.243l9.9-9.9zm1.414-1.414l2.121-2.122a1 1 0 0 1 1.414 0l2.829 2.829a1 1 0 0 1 0 1.414l-2.122 2.121-4.242-4.242z"/>
|
||||
</svg>
|
||||
<svg class="save-button icon hide" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<title>Save</title>
|
||||
<path fill="none" d="M0 0h24v24H0z"/><path d="M10 15.172l9.192-9.193 1.415 1.414L10 18l-6.364-6.364 1.414-1.414z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<button class="edit-button">
|
||||
<svg class="icon" title="edit" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg>
|
||||
<svg class="icon hide" title="Save" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
`
|
||||
|
||||
customElements.define('text-field', class extends HTMLElement{
|
||||
constructor(){
|
||||
customElements.define('text-field', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
@ -85,36 +78,34 @@ customElements.define('text-field', class extends HTMLElement{
|
||||
this.textContainer = this.textField.children[0]
|
||||
this.iconsContainer = this.textField.children[1]
|
||||
this.editButton = this.textField.querySelector('.edit-button')
|
||||
this.saveButton = this.textField.querySelector('.save-button')
|
||||
this.isTextEditable = false
|
||||
this.isDisabled = false
|
||||
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
this.setEditable = this.setEditable.bind(this)
|
||||
this.setNonEditable = this.setNonEditable.bind(this)
|
||||
this.toggleEditable = this.toggleEditable.bind(this)
|
||||
this.revert = this.revert.bind(this)
|
||||
}
|
||||
|
||||
static get observedAttributes(){
|
||||
return ['disabled']
|
||||
static get observedAttributes() {
|
||||
return ['disabled', 'value']
|
||||
}
|
||||
|
||||
get value(){
|
||||
get value() {
|
||||
return this.text
|
||||
}
|
||||
set value(val) {
|
||||
this.text = val
|
||||
this.textContainer.textContent = val
|
||||
this.setAttribute('value', val)
|
||||
}
|
||||
set disabled(val) {
|
||||
this.isDisabled = val
|
||||
if(this.isDisabled)
|
||||
if (this.isDisabled)
|
||||
this.setAttribute('disabled', '')
|
||||
else
|
||||
this.removeAttribute('disabled')
|
||||
}
|
||||
fireEvent(value){
|
||||
fireEvent(value) {
|
||||
let event = new CustomEvent('change', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
@ -125,60 +116,68 @@ customElements.define('text-field', class extends HTMLElement{
|
||||
});
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
setEditable(){
|
||||
if(this.isTextEditable) return
|
||||
|
||||
setEditable() {
|
||||
if (this.isTextEditable) return
|
||||
this.textContainer.contentEditable = true
|
||||
this.textContainer.classList.add('editable')
|
||||
this.textContainer.focus()
|
||||
document.execCommand('selectAll', false, null);
|
||||
this.editButton.animate(this.rotateOut, this.animOptions).onfinish = () => {
|
||||
this.editButton.classList.add('hide')
|
||||
this.editButton.children[0].animate(this.rotateOut, this.animOptions).onfinish = () => {
|
||||
this.editButton.children[0].classList.add('hide')
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.saveButton.classList.remove('hide')
|
||||
this.saveButton.animate(this.rotateIn, this.animOptions)
|
||||
this.editButton.children[1].classList.remove('hide')
|
||||
this.editButton.children[1].animate(this.rotateIn, this.animOptions)
|
||||
}, 100);
|
||||
this.isTextEditable = true
|
||||
}
|
||||
setNonEditable(){
|
||||
setNonEditable() {
|
||||
if (!this.isTextEditable) return
|
||||
this.textContainer.contentEditable = false
|
||||
this.textContainer.classList.remove('editable')
|
||||
|
||||
if (this.text !== this.textContainer.textContent.trim()) {
|
||||
const newValue = this.textContainer.textContent.trim()
|
||||
if (this.text !== newValue && newValue !== '') {
|
||||
this.setAttribute('value', this.textContainer.textContent)
|
||||
this.text = this.textContainer.textContent.trim()
|
||||
this.fireEvent(this.text)
|
||||
} else {
|
||||
this.value = this.text
|
||||
}
|
||||
this.saveButton.animate(this.rotateOut, this.animOptions).onfinish = () => {
|
||||
this.saveButton.classList.add('hide')
|
||||
this.editButton.children[1].animate(this.rotateOut, this.animOptions).onfinish = () => {
|
||||
this.editButton.children[1].classList.add('hide')
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.editButton.classList.remove('hide')
|
||||
this.editButton.animate(this.rotateIn, this.animOptions)
|
||||
this.editButton.children[0].classList.remove('hide')
|
||||
this.editButton.children[0].animate(this.rotateIn, this.animOptions)
|
||||
}, 100);
|
||||
this.isTextEditable = false
|
||||
}
|
||||
toggleEditable() {
|
||||
if (this.isTextEditable)
|
||||
this.setNonEditable()
|
||||
else
|
||||
this.setEditable()
|
||||
}
|
||||
|
||||
revert(){
|
||||
revert() {
|
||||
if (this.textContainer.isContentEditable) {
|
||||
this.value = this.text
|
||||
this.setNonEditable()
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback(){
|
||||
connectedCallback() {
|
||||
this.text
|
||||
if (this.hasAttribute('value')) {
|
||||
this.text = this.getAttribute('value')
|
||||
this.textContainer.textContent = this.text
|
||||
}
|
||||
if(this.hasAttribute('disable'))
|
||||
if (this.hasAttribute('disabled'))
|
||||
this.isDisabled = true
|
||||
else
|
||||
this.isDisabled = false
|
||||
|
||||
|
||||
this.rotateOut = [
|
||||
{
|
||||
transform: 'rotate(0)',
|
||||
@ -207,28 +206,27 @@ customElements.define('text-field', class extends HTMLElement{
|
||||
if (!this.isDisabled) {
|
||||
this.iconsContainer.classList.remove('hide')
|
||||
this.textContainer.addEventListener('dblclick', this.setEditable)
|
||||
this.editButton.addEventListener('click', this.setEditable)
|
||||
this.saveButton.addEventListener('click', this.setNonEditable)
|
||||
this.editButton.addEventListener('click', this.toggleEditable)
|
||||
}
|
||||
}
|
||||
attributeChangedCallback(name) {
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
if (name === 'disabled') {
|
||||
if (this.hasAttribute('disabled')) {
|
||||
this.textContainer.removeEventListener('dblclick', this.setEditable)
|
||||
this.editButton.removeEventListener('click', this.setEditable)
|
||||
this.saveButton.removeEventListener('click', this.setNonEditable)
|
||||
this.editButton.removeEventListener('click', this.toggleEditable)
|
||||
this.revert()
|
||||
}
|
||||
else {
|
||||
this.textContainer.addEventListener('dblclick', this.setEditable)
|
||||
this.editButton.addEventListener('click', this.setEditable)
|
||||
this.saveButton.addEventListener('click', this.setNonEditable)
|
||||
this.editButton.addEventListener('click', this.toggleEditable)
|
||||
}
|
||||
} else if (name === 'value') {
|
||||
this.text = newValue
|
||||
this.textContainer.textContent = newValue
|
||||
}
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.textContainer.removeEventListener('dblclick', this.setEditable)
|
||||
this.editButton.removeEventListener('click', this.setEditable)
|
||||
this.saveButton.removeEventListener('click', this.setNonEditable)
|
||||
this.editButton.removeEventListener('click', this.toggleEditable)
|
||||
}
|
||||
})
|
||||
2
components/dist/text-field.min.js
vendored
2
components/dist/text-field.min.js
vendored
File diff suppressed because one or more lines are too long
18
components/dist/textarea.js
vendored
18
components/dist/textarea.js
vendored
@ -79,8 +79,8 @@ textarea{
|
||||
position: absolute;
|
||||
margin: 0.7rem 1rem;
|
||||
opacity: .7;
|
||||
font-weight: 400;
|
||||
font-size: 1rem;
|
||||
font-weight: inherit;
|
||||
font-size: inherit;
|
||||
line-height: 1.5;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
@ -121,7 +121,7 @@ customElements.define('sm-textarea',
|
||||
this.textareaBox = this.shadowRoot.querySelector('.textarea')
|
||||
this.placeholder = this.shadowRoot.querySelector('.placeholder')
|
||||
this.reflectedAttributes = ['disabled', 'required', 'readonly', 'rows', 'minlength', 'maxlength']
|
||||
|
||||
|
||||
this.reset = this.reset.bind(this)
|
||||
this.focusIn = this.focusIn.bind(this)
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
@ -142,21 +142,21 @@ customElements.define('sm-textarea',
|
||||
}
|
||||
set disabled(val) {
|
||||
if (val) {
|
||||
this.setAttribute('disabled', '')
|
||||
this.setAttribute('disabled', '')
|
||||
} else {
|
||||
this.removeAttribute('disabled')
|
||||
this.removeAttribute('disabled')
|
||||
}
|
||||
}
|
||||
get isValid() {
|
||||
return this.textarea.checkValidity()
|
||||
}
|
||||
reset(){
|
||||
reset() {
|
||||
this.setAttribute('value', '')
|
||||
}
|
||||
focusIn(){
|
||||
focusIn() {
|
||||
this.textarea.focus()
|
||||
}
|
||||
fireEvent(){
|
||||
fireEvent() {
|
||||
let event = new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
@ -164,7 +164,7 @@ customElements.define('sm-textarea',
|
||||
});
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
checkInput(){
|
||||
checkInput() {
|
||||
if (!this.hasAttribute('placeholder') || this.getAttribute('placeholder') === '')
|
||||
return;
|
||||
if (this.textarea.value !== '') {
|
||||
|
||||
2
components/dist/textarea.min.js
vendored
2
components/dist/textarea.min.js
vendored
@ -1 +1 @@
|
||||
const smTextarea=document.createElement("template");smTextarea.innerHTML='\n<style>\n*,\n*::before,\n*::after { \n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n::-moz-focus-inner{\n border: none;\n}\n.hide{\n opacity: 0 !important;\n}\n:host{\n display: grid;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --danger-color: red;\n --border-radius: 0.3rem;\n --background: rgba(var(--text-color), 0.06);\n --padding: initial;\n --max-height: 8rem;\n}\n:host([variant="outlined"]) .textarea {\n box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 0.4) inset;\n background: rgba(var(--background-color), 1);\n}\n.textarea{\n display: grid;\n position: relative;\n cursor: text;\n min-width: 0;\n text-align: left;\n overflow: hidden auto;\n grid-template-columns: 1fr;\n align-items: stretch;\n max-height: var(--max-height);\n background: var(--background);\n border-radius: var(--border-radius);\n padding: var(--padding);\n}\n.textarea::after,\ntextarea{\n padding: 0.7rem 1rem;\n width: 100%;\n min-width: 1em;\n font: inherit;\n color: inherit;\n resize: none;\n grid-area: 2/1;\n justify-self: stretch;\n background: none;\n appearance: none;\n border: none;\n outline: none;\n line-height: 1.5;\n overflow: hidden;\n}\n.textarea::after{\n content: attr(data-value) \' \';\n visibility: hidden;\n white-space: pre-wrap;\n overflow-wrap: break-word;\n word-wrap: break-word;\n hyphens: auto;\n}\n.readonly{\n pointer-events: none;\n}\n.textarea:focus-within:not(.readonly){\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n}\n.placeholder{\n position: absolute;\n margin: 0.7rem 1rem;\n opacity: .7;\n font-weight: 400;\n font-size: 1rem;\n line-height: 1.5;\n pointer-events: none;\n user-select: none;\n}\n:host([disabled]) .textarea{\n cursor: not-allowed;\n opacity: 0.6;\n}\n@media (any-hover: hover){\n ::-webkit-scrollbar{\n width: 0.5rem;\n height: 0.5rem;\n }\n \n ::-webkit-scrollbar-thumb{\n background: rgba(var(--text-color), 0.3);\n border-radius: 1rem;\n &:hover{\n background: rgba(var(--text-color), 0.5);\n }\n }\n}\n</style>\n<label class="textarea" part="textarea">\n <span class="placeholder"></span>\n <textarea rows="1"></textarea>\n</label>\n',customElements.define("sm-textarea",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smTextarea.content.cloneNode(!0)),this.textarea=this.shadowRoot.querySelector("textarea"),this.textareaBox=this.shadowRoot.querySelector(".textarea"),this.placeholder=this.shadowRoot.querySelector(".placeholder"),this.reflectedAttributes=["disabled","required","readonly","rows","minlength","maxlength"],this.reset=this.reset.bind(this),this.focusIn=this.focusIn.bind(this),this.fireEvent=this.fireEvent.bind(this),this.checkInput=this.checkInput.bind(this)}static get observedAttributes(){return["disabled","value","placeholder","required","readonly","rows","minlength","maxlength"]}get value(){return this.textarea.value}set value(e){this.setAttribute("value",e),this.fireEvent()}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get isValid(){return this.textarea.checkValidity()}reset(){this.setAttribute("value","")}focusIn(){this.textarea.focus()}fireEvent(){let e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e)}checkInput(){this.hasAttribute("placeholder")&&""!==this.getAttribute("placeholder")&&(""!==this.textarea.value?this.placeholder.classList.add("hide"):this.placeholder.classList.remove("hide"))}connectedCallback(){this.textarea.addEventListener("input",e=>{this.textareaBox.dataset.value=this.textarea.value,this.checkInput()})}attributeChangedCallback(e,t,n){this.reflectedAttributes.includes(e)?this.hasAttribute(e)?this.textarea.setAttribute(e,this.getAttribute(e)?this.getAttribute(e):""):this.textContent.removeAttribute(e):"placeholder"===e?this.placeholder.textContent=this.getAttribute("placeholder"):"value"===e&&(this.textarea.value=n,this.textareaBox.dataset.value=n,this.checkInput())}});
|
||||
const smTextarea=document.createElement("template");smTextarea.innerHTML='\n<style>\n*,\n*::before,\n*::after { \n padding: 0;\n margin: 0;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n} \n::-moz-focus-inner{\n border: none;\n}\n.hide{\n opacity: 0 !important;\n}\n:host{\n display: grid;\n --accent-color: #4d2588;\n --text-color: 17, 17, 17;\n --background-color: 255, 255, 255;\n --danger-color: red;\n --border-radius: 0.3rem;\n --background: rgba(var(--text-color), 0.06);\n --padding: initial;\n --max-height: 8rem;\n}\n:host([variant="outlined"]) .textarea {\n box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 0.4) inset;\n background: rgba(var(--background-color), 1);\n}\n.textarea{\n display: grid;\n position: relative;\n cursor: text;\n min-width: 0;\n text-align: left;\n overflow: hidden auto;\n grid-template-columns: 1fr;\n align-items: stretch;\n max-height: var(--max-height);\n background: var(--background);\n border-radius: var(--border-radius);\n padding: var(--padding);\n}\n.textarea::after,\ntextarea{\n padding: 0.7rem 1rem;\n width: 100%;\n min-width: 1em;\n font: inherit;\n color: inherit;\n resize: none;\n grid-area: 2/1;\n justify-self: stretch;\n background: none;\n appearance: none;\n border: none;\n outline: none;\n line-height: 1.5;\n overflow: hidden;\n}\n.textarea::after{\n content: attr(data-value) \' \';\n visibility: hidden;\n white-space: pre-wrap;\n overflow-wrap: break-word;\n word-wrap: break-word;\n hyphens: auto;\n}\n.readonly{\n pointer-events: none;\n}\n.textarea:focus-within:not(.readonly){\n box-shadow: 0 0 0 0.1rem var(--accent-color) inset;\n}\n.placeholder{\n position: absolute;\n margin: 0.7rem 1rem;\n opacity: .7;\n font-weight: inherit;\n font-size: inherit;\n line-height: 1.5;\n pointer-events: none;\n user-select: none;\n}\n:host([disabled]) .textarea{\n cursor: not-allowed;\n opacity: 0.6;\n}\n@media (any-hover: hover){\n ::-webkit-scrollbar{\n width: 0.5rem;\n height: 0.5rem;\n }\n \n ::-webkit-scrollbar-thumb{\n background: rgba(var(--text-color), 0.3);\n border-radius: 1rem;\n &:hover{\n background: rgba(var(--text-color), 0.5);\n }\n }\n}\n</style>\n<label class="textarea" part="textarea">\n <span class="placeholder"></span>\n <textarea rows="1"></textarea>\n</label>\n',customElements.define("sm-textarea",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smTextarea.content.cloneNode(!0)),this.textarea=this.shadowRoot.querySelector("textarea"),this.textareaBox=this.shadowRoot.querySelector(".textarea"),this.placeholder=this.shadowRoot.querySelector(".placeholder"),this.reflectedAttributes=["disabled","required","readonly","rows","minlength","maxlength"],this.reset=this.reset.bind(this),this.focusIn=this.focusIn.bind(this),this.fireEvent=this.fireEvent.bind(this),this.checkInput=this.checkInput.bind(this)}static get observedAttributes(){return["disabled","value","placeholder","required","readonly","rows","minlength","maxlength"]}get value(){return this.textarea.value}set value(e){this.setAttribute("value",e),this.fireEvent()}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get isValid(){return this.textarea.checkValidity()}reset(){this.setAttribute("value","")}focusIn(){this.textarea.focus()}fireEvent(){let e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e)}checkInput(){this.hasAttribute("placeholder")&&""!==this.getAttribute("placeholder")&&(""!==this.textarea.value?this.placeholder.classList.add("hide"):this.placeholder.classList.remove("hide"))}connectedCallback(){this.textarea.addEventListener("input",e=>{this.textareaBox.dataset.value=this.textarea.value,this.checkInput()})}attributeChangedCallback(e,t,n){this.reflectedAttributes.includes(e)?this.hasAttribute(e)?this.textarea.setAttribute(e,this.getAttribute(e)?this.getAttribute(e):""):this.textContent.removeAttribute(e):"placeholder"===e?this.placeholder.textContent=this.getAttribute("placeholder"):"value"===e&&(this.textarea.value=n,this.textareaBox.dataset.value=n,this.checkInput())}});
|
||||
81
components/dist/theme-toggle.js
vendored
81
components/dist/theme-toggle.js
vendored
@ -1,4 +1,4 @@
|
||||
const themeToggle = document.createElement('template')
|
||||
const themeToggle = document.createElement('template');
|
||||
themeToggle.innerHTML = `
|
||||
<style>
|
||||
*{
|
||||
@ -45,37 +45,30 @@ themeToggle.innerHTML = `
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
fill: rgba(var(--text-color), 1);
|
||||
transition: transform 0.6s;
|
||||
transition: transform 0.3s, opacity 0.1s;
|
||||
}
|
||||
|
||||
.theme-switcher__checkbox {
|
||||
display: none;
|
||||
}
|
||||
:host([checked]) .moon-icon {
|
||||
transform: scale(0) rotate(90deg);
|
||||
transform: translateY(50%);
|
||||
opacity: 0;
|
||||
}
|
||||
:host(:not([checked])) .sun-icon {
|
||||
transform: scale(0) rotate(-90deg);
|
||||
transform: translateY(50%);
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
<label class="theme-toggle" title="Change theme" tabindex="0">
|
||||
<slot name="light-mode-icon">
|
||||
<svg class="icon moon-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24"
|
||||
height="24">
|
||||
<path fill="none" d="M0 0h24v24H0z" />
|
||||
<path
|
||||
d="M10 6a8 8 0 0 0 11.955 6.956C21.474 18.03 17.2 22 12 22 6.477 22 2 17.523 2 12c0-5.2 3.97-9.474 9.044-9.955A7.963 7.963 0 0 0 10 6zm-6 6a8 8 0 0 0 8 8 8.006 8.006 0 0 0 6.957-4.045c-.316.03-.636.045-.957.045-5.523 0-10-4.477-10-10 0-.321.015-.64.045-.957A8.006 8.006 0 0 0 4 12zm14.164-9.709L19 2.5v1l-.836.209a2 2 0 0 0-1.455 1.455L16.5 6h-1l-.209-.836a2 2 0 0 0-1.455-1.455L13 3.5v-1l.836-.209A2 2 0 0 0 15.29.836L15.5 0h1l.209.836a2 2 0 0 0 1.455 1.455zm5 5L24 7.5v1l-.836.209a2 2 0 0 0-1.455 1.455L21.5 11h-1l-.209-.836a2 2 0 0 0-1.455-1.455L18 8.5v-1l.836-.209a2 2 0 0 0 1.455-1.455L20.5 5h1l.209.836a2 2 0 0 0 1.455 1.455z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon moon-icon" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><rect fill="none" height="24" width="24"/><path d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"/></svg>
|
||||
</slot>
|
||||
<slot name="dark-mode-icon">
|
||||
<svg class="icon sun-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path fill="none" d="M0 0h24v24H0z" />
|
||||
<path
|
||||
d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon sun-icon" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><rect fill="none" height="24" width="24"/><path d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"/></svg>
|
||||
</slot>
|
||||
</label>
|
||||
`
|
||||
`;
|
||||
|
||||
class ThemeToggle extends HTMLElement {
|
||||
constructor() {
|
||||
@ -83,47 +76,47 @@ class ThemeToggle extends HTMLElement {
|
||||
|
||||
this.attachShadow({
|
||||
mode: 'open'
|
||||
}).append(themeToggle.content.cloneNode(true))
|
||||
}).append(themeToggle.content.cloneNode(true));
|
||||
|
||||
this.isChecked = false
|
||||
this.hasTheme = 'light'
|
||||
this.isChecked = false;
|
||||
this.hasTheme = 'light';
|
||||
|
||||
this.toggleState = this.toggleState.bind(this)
|
||||
this.fireEvent = this.fireEvent.bind(this)
|
||||
this.handleThemeChange = this.handleThemeChange.bind(this)
|
||||
this.toggleState = this.toggleState.bind(this);
|
||||
this.fireEvent = this.fireEvent.bind(this);
|
||||
this.handleThemeChange = this.handleThemeChange.bind(this);
|
||||
}
|
||||
static get observedAttributes() {
|
||||
return ['checked'];
|
||||
}
|
||||
|
||||
daylight() {
|
||||
this.hasTheme = 'light'
|
||||
document.body.dataset.theme = 'light'
|
||||
this.setAttribute('aria-checked', 'false')
|
||||
this.hasTheme = 'light';
|
||||
document.body.dataset.theme = 'light';
|
||||
this.setAttribute('aria-checked', 'false');
|
||||
}
|
||||
|
||||
|
||||
nightlight() {
|
||||
this.hasTheme = 'dark'
|
||||
document.body.dataset.theme = 'dark'
|
||||
this.setAttribute('aria-checked', 'true')
|
||||
this.hasTheme = 'dark';
|
||||
document.body.dataset.theme = 'dark';
|
||||
this.setAttribute('aria-checked', 'true');
|
||||
}
|
||||
|
||||
toggleState() {
|
||||
this.toggleAttribute('checked')
|
||||
this.fireEvent()
|
||||
this.toggleAttribute('checked');
|
||||
this.fireEvent();
|
||||
}
|
||||
handleKeyDown(e) {
|
||||
if (e.code === 'Space') {
|
||||
this.toggleState()
|
||||
this.toggleState();
|
||||
}
|
||||
}
|
||||
handleThemeChange(e) {
|
||||
if (e.detail.theme !== this.hasTheme) {
|
||||
if (e.detail.theme === 'dark') {
|
||||
this.setAttribute('checked', '')
|
||||
this.setAttribute('checked', '');
|
||||
}
|
||||
else {
|
||||
this.removeAttribute('checked')
|
||||
this.removeAttribute('checked');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,37 +130,37 @@ class ThemeToggle extends HTMLElement {
|
||||
theme: this.hasTheme
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.setAttribute('role', 'switch')
|
||||
this.setAttribute('aria-label', 'theme toggle')
|
||||
this.setAttribute('role', 'switch');
|
||||
this.setAttribute('aria-label', 'theme toggle');
|
||||
if (localStorage.getItem(`${window.location.hostname}-theme`) === "dark") {
|
||||
this.nightlight();
|
||||
this.setAttribute('checked', '')
|
||||
this.setAttribute('checked', '');
|
||||
} else if (localStorage.getItem(`${window.location.hostname}-theme`) === "light") {
|
||||
this.daylight();
|
||||
this.removeAttribute('checked')
|
||||
this.removeAttribute('checked');
|
||||
}
|
||||
else {
|
||||
if (window.matchMedia(`(prefers-color-scheme: dark)`).matches) {
|
||||
this.nightlight();
|
||||
this.setAttribute('checked', '')
|
||||
this.setAttribute('checked', '');
|
||||
} else {
|
||||
this.daylight();
|
||||
this.removeAttribute('checked')
|
||||
this.removeAttribute('checked');
|
||||
}
|
||||
}
|
||||
this.addEventListener("click", this.toggleState);
|
||||
this.addEventListener("keydown", this.handleKeyDown);
|
||||
document.addEventListener('themechange', this.handleThemeChange)
|
||||
document.addEventListener('themechange', this.handleThemeChange);
|
||||
}
|
||||
|
||||
|
||||
disconnectedCallback() {
|
||||
this.removeEventListener("click", this.toggleState);
|
||||
this.removeEventListener("keydown", this.handleKeyDown);
|
||||
document.removeEventListener('themechange', this.handleThemeChange)
|
||||
document.removeEventListener('themechange', this.handleThemeChange);
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
|
||||
2
components/dist/theme-toggle.min.js
vendored
2
components/dist/theme-toggle.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user