-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange-slider.js
100 lines (88 loc) · 2.02 KB
/
range-slider.js
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
import { html, css, LitElement } from 'https://unpkg.com/lit-element?module';
class RangeSlider extends LitElement {
static styles = css`
:host {
display: block;
}
.slider-container {
display: flex;
align-items: center;
}
.slider {
flex: 1;
-webkit-appearance: none;
width: 100%;
height: 5px;
background-color: #ddd;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
background-color: #4CAF50;
cursor: pointer;
z-index: 2;
}
.slider::-moz-range-thumb {
width: 15px;
height: 15px;
background-color: #4CAF50;
cursor: pointer;
z-index: 2;
}
.slider::-moz-range-track {
z-index: 1;
}
`;
static properties = {
min: { type: Number },
max: { type: Number },
from: { type: Number },
to: { type: Number },
currency: { type: String },
};
constructor() {
super();
this.min = 0;
this.max = 100;
this.from = 0;
this.to = 100;
this.currency = '$'; // Default currency symbol is $
}
handleMinChange(event) {
this.from = parseInt(event.target.value);
}
handleMaxChange(event) {
this.to = parseInt(event.target.value);
}
render() {
return html`
<div class="slider-container">
<input
type="range"
class="slider"
min="${this.min}"
max="${this.max}"
value="${this.from}"
@input="${this.handleMinChange}"
/>
<input
type="range"
class="slider"
min="${this.min}"
max="${this.max}"
value="${this.to}"
@input="${this.handleMaxChange}"
/>
</div>
<p>From: ${this.currency} ${this.from}</p>
<p>To: ${this.currency} ${this.to}</p>
`;
}
}
customElements.define('range-slider', RangeSlider);