generated from lit/lit-element-starter-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwh-input.js
More file actions
166 lines (158 loc) · 4.46 KB
/
wh-input.js
File metadata and controls
166 lines (158 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @license
* Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import { LitElement, html, css } from 'lit-element';
/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
export class WhInput extends LitElement {
static get styles() {
return css`
:host {
display: block;
padding: 8px 0;
}
:host([disabled]) .fieldInputLabel {
background-color: transparent;
}
* {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
.inputContainer {
position: relative;
}
.fieldInput {
box-sizing: border-box;
padding: 0 16px;
width: 100%;
height: 56px;
background: #fff;
border: 1px solid #bdbdbd;
border-radius: 4px;
position: relative;
font-size: 16pt;
z-index: 1;
-webkit-appearance: none;
transition: border 0.2s cubic-bezier(1, 0, 0, 1);
}
.fieldInput:focus {
outline: none;
border: 2px solid #6200ee;
}
.fieldInput:not(:focus):hover:not(:disabled) {
border: 1px solid #000000de;
}
.fieldInput:focus ~ .fieldInputLabel {
color: #6200ee;
font-weight: 500;
}
.fieldInput:disabled {
color: #8a8a8a;
background-color: #e6e6e6;
}
@media (prefers-color-scheme: dark) {
.fieldInput {
background-color: #202020;
color: white;
border: 1px solid #b3b3b3;
}
.fieldInput:focus {
outline: none;
border: 2px solid #bb86fc;
}
.fieldInput:not(:focus):hover:not(:disabled) {
border: 1px solid white;
}
.fieldInput:disabled {
color: #b3b3b3;
background-color: #313131;
}
}
.fieldInputLabel {
z-index: 2;
position: absolute;
top: 16px;
left: 2px;
color: #222;
background: #fff;
transition: transform 0.2s cubic-bezier(1, 0, 0, 1), font-size 0.2s cubic-bezier(1, 0, 0, 1), color 0.2s cubic-bezier(1, 0, 0, 1);
transform: translate(4px, -27px);
font-size: 12px;
pointer-events: none;
}
.fieldInputLabel,
.fieldInputLabel supports:placeholder-shown {
transform: translate(16px, 0px);
font-size: 1rem;
color: #8a8a8a;
padding: 0 4px;
}
.fieldInput:focus ~ .fieldInputLabel,
.fieldInput:not(:placeholder-shown) ~ .fieldInputLabel {
transform: translate(16px, -25px);
font-size: 12px;
font-weight: 500;
}
@media (prefers-color-scheme: dark) {
.fieldInputLabel {
background-color: #202020;
color: #b3b3b3;
}
}
@media (prefers-color-scheme: dark) {
.fieldInput:focus ~ .fieldInputLabel {
color: #bb86fc;
}
}
`;
}
static get properties() {
return {
name: { type: String },
count: { type: Number },
autocomplete: { type: String },
type: { type: String },
value: { type: String },
disabled: { type: Boolean, reflect: true }
};
}
constructor() {
super();
if (this.value == undefined) {
this.value = '';
}
this.name = 'input';
this.disabled = false;
}
render() {
return html`
<div class="inputContainer">
<input value=${this.value} @input=${(e) => {
this.value = e.target.value;
this.event();
}} @change=${(e) => this.dispatchEvent(new Event('change'))} class="fieldInput"
name=${this.name} id=${this.name} placeholder=" " type="${this.type}" autocomplete="${this.autocomplete}" ?disabled="${this.disabled}">
<label class="fieldInputLabel" for=${this.name}>
<slot></slot>
</label>
</div>
`;
}
event() {
console.log(this.value);
}
}
window.customElements.define('wh-input', WhInput);