-
Notifications
You must be signed in to change notification settings - Fork 26
/
example.html
157 lines (146 loc) · 5.2 KB
/
example.html
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
<!DOCTYPE html>
<html>
<head>
<title>Round-slider demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!--<script src="https://unpkg.com/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="https://unpkg.com/@thomasloven/round-slider" type="module"></script>-->
<script src="round-slider.bundle.js" type="module"></script>
</head>
<body style="margin-left: 24px">
<style>
round-slider {
max-width: 200px;
transition: all 1.3s ease-out 0s;
}
round-slider.scaling:hover {
max-width: 400px;
}
</style>
<h2>Default (<span class="value">50</span>)</h2>
<round-slider value="50" valueLabel="Temperature"></round-slider>
<h2>Styling (<span class="value">50</span>)</h2>
<round-slider
value="50"
style="--round-slider-path-color: red"
></round-slider>
<round-slider
value="50"
style="--round-slider-bar-color: red"
></round-slider>
<round-slider
value="50"
style="--round-slider-handle-color: red"
></round-slider>
<h2>
High/Low sliders (<span class="low">20</span>-<span class="high">70</span>)
</h2>
<round-slider
low="20"
high="70"
class="highlow"
highLabel="High"
lowLabel="Low"
></round-slider>
<round-slider
low="20"
high="70"
style="
--round-slider-low-handle-color: red;
--round-slider-high-handle-color: green;
"
class="highlow"
></round-slider>
<h2>Disabled</h2>
<round-slider value="50" disabled></round-slider>
<h2>Start Angle (<span class="value">50</span>)</h2>
<round-slider value="50" startAngle="0"></round-slider>
<round-slider value="50" startAngle="90"></round-slider>
<round-slider value="50" startAngle="180"></round-slider>
<round-slider value="50" startAngle="270"></round-slider>
<h2>Arc Length (<span class="value">50</span>)</h2>
<round-slider value="50" arcLength="90" startAngle="180"></round-slider>
<round-slider value="50" arcLength="180" startAngle="180"></round-slider>
<round-slider value="50" arcLength="360" startAngle="180"></round-slider>
<h2>Dynamic scaling (<span class="value">50</span>)</h2>
<round-slider value="50" class="scaling"></round-slider>
<h2>Right-to-Left (<span class="value">50</span>)</h2>
<round-slider value="50" rtl></round-slider>
<h2>Outside-in (<span class="low">20</span>-<span class="high">70</span>)</h2>
<round-slider
low="20"
high="70"
class="highlow"
highLabel="High"
lowLabel="Low"
outside="true"
></round-slider>
<round-slider
low="20"
high="70"
style="
--round-slider-low-handle-color: red;
--round-slider-low-bar-color: red;
--round-slider-high-handle-color: green;
--round-slider-high-bar-color: green;
"
class="highlow"
outside="true"
></round-slider>
<h2>Used as a gauge (<span class="value">50</span>)</h2>
<round-slider
value="50"
readonly
startAngle="180"
arcLength="180"
style="--round-slider-path-width: 30px; --round-slider-linecap: butt"
></round-slider>
<script>
const setValue = function (value, active) {
document.querySelectorAll("round-slider").forEach(function (el) {
if (el.value === undefined) return;
el.value = value;
});
const span = document.querySelectorAll("span.value").forEach(function (el) {
el.innerHTML = value;
if (active) el.style.color = "red";
else el.style.color = "black";
});
};
const setLow = function (value, active) {
document.querySelectorAll("round-slider").forEach(function (el) {
if (el.low === undefined) return;
el.low = value;
});
const span = document.querySelectorAll("span.low").forEach(function (el) {
el.innerHTML = value;
if (active) el.style.color = "red";
else el.style.color = "black";
});
};
const setHigh = function (value, active) {
document.querySelectorAll("round-slider").forEach(function (el) {
if (el.high === undefined) return;
el.high = value;
});
const span = document.querySelectorAll("span.high").forEach(function (el) {
el.innerHTML = value;
if (active) el.style.color = "red";
else el.style.color = "black";
});
};
document.querySelectorAll("round-slider").forEach(function (el) {
el.addEventListener("value-changed", function (ev) {
if (ev.detail.value !== undefined) setValue(ev.detail.value, false);
else if (ev.detail.low !== undefined) setLow(ev.detail.low, false);
else if (ev.detail.high !== undefined) setHigh(ev.detail.high, false);
});
el.addEventListener("value-changing", function (ev) {
if (ev.detail.value !== undefined) setValue(ev.detail.value, true);
else if (ev.detail.low !== undefined) setLow(ev.detail.low, true);
else if (ev.detail.high !== undefined) setHigh(ev.detail.high, true);
});
});
</script>
</body>
</html>