Updated input and button

This commit is contained in:
sairaj mote 2022-03-02 16:47:39 +05:30
parent eab4b25e80
commit 1d8fc1233e
4 changed files with 30 additions and 69 deletions

View File

@ -8,30 +8,25 @@ smButton.innerHTML = `
box-sizing: border-box; box-sizing: border-box;
} }
:host{ :host{
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex; display: inline-flex;
width: auto; width: auto;
--accent-color: #4d2588;
--text-color: 17, 17, 17;
--background-color: 255, 255, 255; --background-color: 255, 255, 255;
--padding: 0.6rem 1.2rem; --padding: 0.6rem 1.2rem;
--border-radius: 0.3rem; --border-radius: 0.3rem;
--background: rgba(var(--text-color), 0.1); --background: rgba(var(--text-color, (17,17,17)), 0.1);
} }
:host([variant='primary']) .button{ :host([variant='primary']) .button{
background: var(--accent-color); background: var(--accent-color,teal);
color: rgba(var(--background-color), 1); color: rgba(var(--background-color, (255,255,255)), 1);
} }
:host([variant='outlined']) .button{ :host([variant='outlined']) .button{
-webkit-box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset; box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 0.2) inset;
box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset;
background: transparent; background: transparent;
color: var(--accent-color); color: var(--accent-color,teal);
} }
:host([variant='no-outline']) .button{ :host([variant='no-outline']) .button{
background: inherit; background: inherit;
color: var(--accent-color); color: var(--accent-color,teal);
} }
:host([disabled]){ :host([disabled]){
pointer-events: none; pointer-events: none;
@ -39,19 +34,12 @@ smButton.innerHTML = `
} }
.button { .button {
position: relative; position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
width: 100%; width: 100%;
padding: var(--padding); padding: var(--padding);
cursor: pointer; cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none; user-select: none;
border-radius: var(--border-radius); border-radius: var(--border-radius);
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center; justify-content: center;
transition: box-shadow 0.3s, background-color 0.3s; transition: box-shadow 0.3s, background-color 0.3s;
font-family: inherit; font-family: inherit;
@ -69,8 +57,8 @@ smButton.innerHTML = `
pointer-events: none; pointer-events: none;
cursor: not-allowed; cursor: not-allowed;
opacity: 0.6; opacity: 0.6;
color: rgba(var(--text-color), 1); color: rgba(var(--text-color, (17,17,17)), 1);
background-color: rgba(var(--text-color), 0.3); background-color: rgba(var(--text-color, (17,17,17)), 0.3);
} }
@media (hover: hover){ @media (hover: hover){
:host(:not([disabled])) .button:hover, :host(:not([disabled])) .button:hover,
@ -80,8 +68,8 @@ smButton.innerHTML = `
} }
:host([variant='outlined']:not([disabled])) .button:hover, :host([variant='outlined']:not([disabled])) .button:hover,
:host(:focus-within[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); -webkit-box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 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); box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 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);
} }
} }
@media (hover: none){ @media (hover: none){
@ -90,8 +78,8 @@ smButton.innerHTML = `
box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2); box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.8rem rgba(0, 0, 0, 0.2);
} }
:host([variant='outlined']) .button:active{ :host([variant='outlined']) .button:active{
-webkit-box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset, 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.8rem rgba(0, 0, 0, 0.2); -webkit-box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 0.2) inset, 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.8rem rgba(0, 0, 0, 0.2);
box-shadow: 0 0 0 1px rgba(var(--text-color), 0.2) inset, 0 0.1rem 0.1rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.8rem rgba(0, 0, 0, 0.2); box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 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);
} }
} }
</style> </style>

View File

@ -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 :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&&" "!==t.key||(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")))}}); 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: inline-flex;\n width: auto;\n --background-color: 255, 255, 255;\n --padding: 0.6rem 1.2rem;\n --border-radius: 0.3rem;\n --background: rgba(var(--text-color, (17,17,17)), 0.1);\n}\n:host([variant='primary']) .button{\n background: var(--accent-color,teal);\n color: rgba(var(--background-color, (255,255,255)), 1);\n}\n:host([variant='outlined']) .button{\n box-shadow: 0 0 0 1px rgba(var(--text-color, (17,17,17)), 0.2) inset;\n background: transparent; \n color: var(--accent-color,teal);\n}\n:host([variant='no-outline']) .button{\n background: inherit; \n color: var(--accent-color,teal);\n}\n:host([disabled]){\n pointer-events: none;\n cursor: not-allowed;\n}\n.button {\n position: relative;\n display: flex;\n width: 100%;\n padding: var(--padding);\n cursor: pointer;\n user-select: none;\n border-radius: var(--border-radius); \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, (17,17,17)), 1);\n background-color: rgba(var(--text-color, (17,17,17)), 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, (17,17,17)), 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, (17,17,17)), 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, (17,17,17)), 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, (17,17,17)), 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&&" "!==t.key||(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")))}});

View File

@ -34,18 +34,13 @@ input:invalid{
border: none; border: none;
} }
:host{ :host{
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
--accent-color: #4d2588;
--text-color: 17, 17, 17;
--background-color: 255, 255, 255;
--success-color: #00C853; --success-color: #00C853;
--danger-color: red; --danger-color: red;
--width: 100%; --width: 100%;
--icon-gap: 0.5rem; --icon-gap: 0.5rem;
--border-radius: 0.3rem; --border-radius: 0.3rem;
--background: rgba(var(--text-color), 0.06); --background: rgba(var(--text-color, (17,17,17)), 0.06);
} }
.hide{ .hide{
opacity: 0 !important; opacity: 0 !important;
@ -55,7 +50,7 @@ border: none;
display: none; display: none;
} }
.icon { .icon {
fill: rgba(var(--text-color), 0.6); fill: rgba(var(--text-color, (17,17,17)), 0.6);
height: 1.4rem; height: 1.4rem;
width: 1.4rem; width: 1.4rem;
border-radius: 1rem; border-radius: 1rem;
@ -67,22 +62,16 @@ border: none;
border-radius: 10rem; border-radius: 10rem;
} }
.input { .input {
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
cursor: text; cursor: text;
min-width: 0; min-width: 0;
text-align: left; text-align: left;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center; align-items: center;
position: relative; position: relative;
gap: var(--icon-gap); gap: var(--icon-gap);
padding: var(--padding, 0.6rem 0.8rem); padding: var(--padding, 0.6rem 0.8rem);
border-radius: var(--border-radius); border-radius: var(--border-radius);
-webkit-transition: opacity 0.3s; transition: opacity 0.3s, box-shadow 0.2s;
-o-transition: opacity 0.3s;
transition: opacity 0.3s;
background: var(--background); background: var(--background);
width: 100%; width: 100%;
outline: none; outline: none;
@ -96,7 +85,7 @@ border: none;
pointer-events: none; pointer-events: none;
} }
.input:focus-within:not(.readonly){ .input:focus-within:not(.readonly){
box-shadow: 0 0 0 0.1rem var(--accent-color) inset !important; box-shadow: 0 0 0 0.1rem var(--accent-color,teal) inset !important;
} }
.disabled{ .disabled{
pointer-events: none; pointer-events: none;
@ -112,7 +101,7 @@ border: none;
transition: -webkit-transform 0.3s; transition: -webkit-transform 0.3s;
-o-transition: transform 0.3s; -o-transition: transform 0.3s;
transition: transform 0.3s; transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s; transition: transform 0.3s, -webkit-transform 0.3s, color .03;
-webkit-transform-origin: left; -webkit-transform-origin: left;
-ms-transform-origin: left; -ms-transform-origin: left;
transform-origin: left; transform-origin: left;
@ -131,15 +120,9 @@ border: none;
} }
.container{ .container{
width: 100%; width: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
position: relative; position: relative;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center; align-items: center;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1; flex: 1;
} }
input{ input{
@ -147,40 +130,30 @@ input{
border: none; border: none;
background: transparent; background: transparent;
outline: none; outline: none;
color: rgba(var(--text-color), 1); color: rgba(var(--text-color, (17,17,17)), 1);
width: 100%; width: 100%;
} }
:host(:not([variant="outlined"])) .animate-label .container input { :host([animate]) .input:focus-within .container input,
.animate-label .container input {
-webkit-transform: translateY(0.6rem); -webkit-transform: translateY(0.6rem);
-ms-transform: translateY(0.6rem); -ms-transform: translateY(0.6rem);
transform: translateY(0.6rem); transform: translateY(0.6rem);
} }
:host(:not([variant="outlined"])) .animate-label .label { :host([animate]) .input:focus-within .label,
.animate-label .label {
-webkit-transform: translateY(-0.7em) scale(0.8); -webkit-transform: translateY(-0.7em) scale(0.8);
-ms-transform: translateY(-0.7em) scale(0.8); -ms-transform: translateY(-0.7em) scale(0.8);
transform: translateY(-0.7em) scale(0.8); transform: translateY(-0.7em) scale(0.8);
opacity: 1; opacity: 1;
color: var(--accent-color) color: var(--accent-color,teal)
} }
:host([variant="outlined"]) .input { :host([variant="outlined"]) .input {
box-shadow: 0 0 0 0.1rem var(--border-color, rgba(var(--text-color), 0.4)) inset; box-shadow: 0 0 0 1px var(--border-color, rgba(var(--text-color, (17,17,17)), 0.3)) inset;
background: rgba(var(--background-color), 1); background: rgba(var(--background-color, (255,255,255)), 1);
}
:host([variant="outlined"]) .label {
width: max-content;
margin-left: -0.5rem;
padding: 0 0.5rem;
}
:host([variant="outlined"]) .animate-label .label {
-webkit-transform: translate(0.1rem, -1.5rem) scale(0.8);
-ms-transform: translate(0.1rem, -1.5rem) scale(0.8);
transform: translate(0.1rem, -1.5rem) scale(0.8);
opacity: 1;
background: rgba(var(--background-color), 1);
} }
.animate-label:focus-within:not(.readonly) .label{ .animate-label:focus-within:not(.readonly) .label{
color: var(--accent-color) color: var(--accent-color,teal)
} }
.feedback-text:not(:empty){ .feedback-text:not(:empty){
display: flex; display: flex;
@ -189,7 +162,7 @@ input{
font-size: 0.9rem; font-size: 0.9rem;
align-items: center; align-items: center;
padding: 0.8rem 0; padding: 0.8rem 0;
color: rgba(var(--text-color), 0.8); color: rgba(var(--text-color, (17,17,17)), 0.8);
} }
.success{ .success{
color: var(--success-color); color: var(--success-color);
@ -208,7 +181,7 @@ input{
} }
@media (any-hover: hover){ @media (any-hover: hover){
.icon:hover{ .icon:hover{
background: rgba(var(--text-color), 0.1); background: rgba(var(--text-color, (17,17,17)), 0.1);
} }
} }
</style> </style>

File diff suppressed because one or more lines are too long