-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.html
173 lines (163 loc) · 5.9 KB
/
colors.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<link rel="stylesheet" href="jrad.css" />
<style>
.dr-menu {
background-color: var(--bg-dropdown-menu);
}
.dr-menu-item {
margin:4px;
}
.dr-menu-active-item {
margin:4px;
background-color: var(--bg-dropdown-menu-active-item);
}
</style>
<script>
const tintColor = (color, percent) => {
// send with hash in front #123456
let R = parseInt(color.substring(1,3),16);
let G = parseInt(color.substring(3,5),16);
let B = parseInt(color.substring(5,7),16);
const p = percent / 100;
R = Math.round(R + (255 - R) * p);
G = Math.round(G + (255 - G) * p);
B = Math.round(B + (255 - B) * p);
R = (R<255)?R:255;
G = (G<255)?G:255;
B = (B<255)?B:255;
const RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
const GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
const BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));
return "#"+RR+GG+BB;
}
const shadeColor = (color, percent) => {
// send with hash in front #123456
let R = parseInt(color.substring(1,3),16);
let G = parseInt(color.substring(3,5),16);
let B = parseInt(color.substring(5,7),16);
const p = percent / 100;
R = Math.round(R * p);
G = Math.round(G * p);
B = Math.round(B * p);
R = (R<255)?R:255;
G = (G<255)?G:255;
B = (B<255)?B:255;
const RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
const GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
const BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));
return "#"+RR+GG+BB;
}
const setVar = (id, val) => {
document.documentElement.style.setProperty('--' + id, val);
}
const getVar = (id) => {
return getComputedStyle(document.documentElement).getPropertyValue('--' + id);
// return document.documentElement.style.getProperty('--' + id);
}
/*
const go = () => {
const val = document.getElementById('col').value;
const arr = [];
const step = 8; // 12
for (var i=0; i < 10; i++) {
setDiv(9 - i, shadeColor(val, 100 - ((i+1) * step )), arr, true);
}
setDiv(10, val, arr);
//for (var i=0; i < 5; i++) {
//setDiv(i + 6, tintColor(val, (i+1) * step), arr);
//}
const p = document.getElementById('prefix').value;
const result = arr.map((x, n) => '--' + p + n + ':' + x + ';').join('\n');
document.getElementById('out').value = result;
}
*/
const adjustLight = (id) => {
const val = document.getElementById(id).value;
const arr = [];
const step = 8; // 12
arr.push(val);
for (var i=1; i < 11; i++) {
arr.push(tintColor(val, (i+1) * step ));
}
arr.forEach((x, n) => {
setVar(id + n, x);
})
}
const adjustDark = (id) => {
const val = document.getElementById(id).value;
const arr = [];
const step = 8; // 12
for (var i=0; i < 10; i++) {
arr.unshift(shadeColor(val, 100 - ((i+1) * step )));
}
arr.unshift(val);
arr.forEach((x, n) => {
setVar(id + n, x);
})
}
setTimeout(() => {
document.getElementById('gray').value = getVar('gray10');
document.getElementById('blue').value = getVar('blue5');
}, 100)
</script>
</head>
<body>
Base Gray: <input type="text" id="gray"/>
<button onclick="adjustDark('gray')">go</button>
Base Blue: <input type="text" id="blue"/>
<button onclick="adjustLight('blue')">go</button>
<hr/>
<div style="display:flex">
<div style="padding:4px; flex:1">
<input class="input" placeholder="some placeholder">
<br/><br/>
<input class="input" placeholder="some placeholder" readonly disabled>
<br/><br/>
dropdown pop-up menu:<br/>
<div class="dr-menu">
<div class="dr-menu-item">item 1</div>
<div class="dr-menu-active-item">active item</div>
<div class="dr-menu-item">item 2</div>
</div>
</div>
<div style="padding:4px; flex:1">
<button class="btn">primary</button>
<br/><br/>
<button class="btn btn-type-secondary">secondary</button>
<br/><br/>
<button class="btn btn-type-link">link</button>
<br/><br/>
<button class="btn btn-type-danger">danger</button>
<br/><br/>
modal:
<div class="bg-header">
Header
</div>
<div class="bg-body">
this is body.
</div>
</div>
<div style="padding:4px; flex:1">
<table class="table">
<thead>
<tr>
<th>header</th>
<th>header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>value 1</td>
<td>value 1</td>
</tr>
<tr>
<td>value 1</td>
<td>value 1</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>