UNPKG

14 kBJavaScriptView Raw
1/**
2 * @module prama/theme/flat
3 *
4 * Control-panel theme on steroids
5 */
6'use strict';
7
8const px = require('add-px-to-style');
9const fonts = require('google-fonts');
10const color = require('tinycolor2');
11const scopeCss = require('scope-css');
12const none = require('./none');
13const interpolate = require('color-interpolate');
14
15module.exports = flat;
16
17//uses reflective scheme
18flat.palette = ['black', '#fff'];
19flat.palette = ['#272727', '#f95759', '#fff'];
20// flat.active = '#f95759';
21
22flat.fontSize = '14px';
23flat.fontFamily = '"Roboto", sans-serif';
24flat.labelWidth = '33.3%';
25flat.inputHeight = 2;
26flat.padding = 1/5;
27
28fonts.add({
29 'Roboto': 500,
30 'Material Icons': 400
31});
32
33
34function flat (opts) {
35 opts = opts || {};
36 let fs = opts.fontSize || flat.fontSize;
37 let font = opts.fontFamily || flat.fontFamily;
38 let h = opts.inputHeight || flat.inputHeight;
39 let labelWidth = opts.labelWidth || flat.labelWidth;
40 let padding = opts.padding || flat.padding;
41
42 let palette = opts.palette || flat.palette;
43 let pick = interpolate(palette);
44
45 //NOTE: this is in case of scaling palette to black/white range
46 let white = tone(1);
47 let black = tone(0);
48 let active = opts.active || tone(.5);
49
50 function tone (amt) {
51 return color(pick(amt)).toString();
52 }
53
54 //none theme defines sizes, the rest (ours) is up to style
55 return none({
56 fontSize: fs,
57 fontFamily: font,
58 inputHeight: h,
59 labelWidth: labelWidth,
60 padding: padding
61 }) + `
62 :host {
63 background: ${white};
64 color: ${black};
65 font-family: ${font};
66 font-weight: 500;
67 -webkit-text-size-adjust: 100%;
68 -webkit-font-smoothing: antialiased;
69 }
70 :host a {
71 text-decoration: none;
72 border-bottom: 1px solid ${alpha(tone(.0), .2)};
73 }
74 :host a:hover {
75 text-decoration: none;
76 border-bottom: 1px solid ${alpha(tone(.0), 1)};
77 }
78
79 .settings-panel-title {
80 color: ${tone(.0)};
81 font-family: ${font};
82 font-weight: 500;
83 }
84
85 .settings-panel-label {
86 color: ${alpha(tone(.0), .666)};
87 font-weight: 500;
88 }
89
90 /** Text */
91 .settings-panel-text,
92 .settings-panel-textarea,
93 .settings-panel-color-value {
94 -webkit-appearance: none;
95 -moz-appearance: none;
96 -o-appearance: none;
97 appearance: none;
98 outline: none;
99 border: 0;
100 width: auto;
101 border-radius: 0;
102 font-weight: 500;
103 background: none;
104 color: ${active};
105 box-shadow: 0 1px ${alpha(tone(.0), .2)};
106 }
107 .settings-panel-text:hover,
108 .settings-panel-color-value:hover,
109 .settings-panel-textarea:hover {
110 color: ${active};
111 }
112 .settings-panel-text:focus,
113 .settings-panel-color-value:focus,
114 .settings-panel-textarea:focus {
115 box-shadow: 0 1px ${active};
116
117 }
118
119
120 /** Sliders */
121 .settings-panel-range {
122 -webkit-appearance: none;
123 -moz-appearance: none;
124 appearance: none;
125 background: none;
126 color: ${tone(0)};
127 border: 0;
128 width: 85%;
129 margin-right: ${h/4}em;
130 }
131 .settings-panel-range + .settings-panel-value {
132 width: calc(15% - ${h/4}em);
133 padding-left: 0;
134 }
135 .settings-panel-field--range:hover .settings-panel-range,
136 .settings-panel-range:focus {
137 outline: none;
138 }
139 .settings-panel-range::-webkit-slider-runnable-track {
140 background: none;
141 height: 2px;
142 background: ${active};
143 }
144 .settings-panel-field--range:hover .settings-panel-range::-webkit-slider-runnable-track,
145 .settings-panel-range:focus::-webkit-slider-runnable-track {
146 /* background: ${active}; */
147 }
148 .settings-panel-range::-moz-range-track {
149 background: none;
150 height: 2px;
151 background: ${active};
152 }
153 .settings-panel-field--range:hover .settings-panel-range::-moz-range-track,
154 .settings-panel-range:focus::-moz-range-track {
155 /* background: ${active}; */
156 }
157
158 .settings-panel-range::-ms-track {
159 height: 2px;
160 color: transparent;
161 border: none;
162 outline: none;
163 }
164 .settings-panel-range::-ms-fill-lower {
165 background: ${active};
166 }
167 .settings-panel-range::-ms-fill-upper {
168 background: ${alpha(active, .2)};
169 }
170
171 @supports (--css: variables) {
172 .settings-panel-range {
173 --active: ${active};
174 --bg: ${alpha(active, .2)};
175 --track-background: linear-gradient(to right, var(--active) 0, var(--active) var(--value), var(--bg) 0) no-repeat;
176 }
177 .settings-panel-range::-webkit-slider-runnable-track {
178 background: var(--track-background);
179 }
180 .settings-panel-range::-moz-range-track {
181 background: var(--track-background);
182 }
183 .settings-panel-field--range:hover .settings-panel-range,
184 .settings-panel-range:focus {
185 --bg: ${alpha(active, .2)};
186 --active: ${active};
187 }
188 }
189
190 .settings-panel-range::-webkit-slider-thumb {
191 background: ${active};
192 height: ${h/2}em;
193 width: ${h/2}em;
194 border-radius: ${h/2}em;
195 margin-top: -${h/4}em;
196 border: 0;
197 position: relative;
198 top: 1px;
199 -webkit-appearance: none;
200 appearance: none;
201 transition: .05s ease-in transform;
202 transform: scale(1, 1);
203 transform-origin: center center;
204 }
205 .settings-panel-range:focus::-webkit-slider-thumb,
206 .settings-panel-range::-webkit-slider-thumb:hover {
207 box-shadow: 0 0 0 0;
208 transform: scale(1.2, 1.2);
209 }
210 .settings-panel-range[value="0"]::-webkit-slider-thumb {
211 background: ${white};
212 box-shadow: inset 0 0 0 1.5px ${active};
213 }
214 .settings-panel-range::-moz-range-thumb {
215 background: ${active};
216 height: ${h/2}em;
217 width: ${h/2}em;
218 border-radius: ${h/2}em;
219 margin-top: -${h/4}em;
220 border: 0;
221 position: relative;
222 top: 1px;
223 -moz-appearance: none;
224 appearance: none;
225 transition: .05s ease-in transform;
226 transform: scale(1, 1);
227 transform-origin: center center;
228 }
229 .settings-panel-range:focus::-moz-range-thumb,
230 .settings-panel-range::-moz-range-thumb:hover {
231 box-shadow: 0 0 0 0;
232 transform: scale(1.2, 1.2);
233 }
234 .settings-panel-range[value="0"]::-moz-range-thumb {
235 background: ${white};
236 box-shadow: inset 0 0 0 1.5px ${active};
237 }
238 .settings-panel-range::-ms-thumb {
239 background: ${active};
240 height: ${h/2}em;
241 width: ${h/2}em;
242 border-radius: ${h/2}em;
243 border: 0;
244 position: relative;
245 top: 1px;
246 appearance: none;
247 transition: .05s ease-in transform;
248 transform: scale(1, 1);
249 transform-origin: center center;
250 }
251 .settings-panel-range:focus::-ms-thumb,
252 .settings-panel-range::-ms-thumb:hover {
253 box-shadow: 0 0 0 0;
254 transform: scale(1.2, 1.2);
255 }
256 .settings-panel-range[value="0"]::-ms-thumb {
257 background: ${white};
258 box-shadow: inset 0 0 0 1.5px ${active};
259 }
260
261 /** Interval */
262 .settings-panel-interval {
263 background: none;
264 }
265 .settings-panel-interval:after {
266 content: '';
267 position: absolute;
268 width: 100%;
269 left: 0;
270 bottom: 0;
271 top: 0;
272 background: ${alpha(active, .2)};
273 height: 2px;
274 margin-top: auto;
275 margin-bottom: auto;
276 }
277 .settings-panel-interval-handle {
278 position: absolute;
279 z-index: 1;
280 height: 2px;
281 top: 0;
282 bottom: 0;
283 margin-top: auto;
284 margin-bottom: auto;
285 background: ${active};
286 }
287 .settings-panel-field--interval:hover .settings-panel-interval:after {
288 background: ${alpha(active, .2)};
289 }
290 .settings-panel-field--interval:hover .settings-panel-interval-handle {
291 background: ${active};
292 }
293 .settings-panel-field--interval:hover .settings-panel-value {
294 color: ${black};
295 font-weight: 500;
296 }
297 .settings-panel-interval-handle:after,
298 .settings-panel-interval-handle:before {
299 content: '';
300 position: absolute;
301 right: -${h/4}em;
302 top: 0;
303 bottom: 0;
304 margin: auto;
305 height: ${h/2}em;
306 width: ${h/2}em;
307 border-radius: ${h/2}em;
308 background: inherit;
309 transform: scale(1, 1);
310 transform-origin: center center;
311 transition: .05s ease-in transform;
312 }
313 .settings-panel-interval-handle:before {
314 left: -${h/4}em;
315 right: auto;
316 }
317 .settings-panel-interval-dragging .settings-panel-interval-handle:after,
318 .settings-panel-interval-dragging .settings-panel-interval-handle:before,
319 .settings-panel-interval:hover .settings-panel-interval-handle:after,
320 .settings-panel-interval:hover .settings-panel-interval-handle:before {
321 transform: scale(1.2, 1.2);
322 }
323
324
325 /** Values */
326 .settings-panel-value {
327 color: ${tone(0)};
328 font-weight: 500;
329 }
330 .settings-panel-value:first-child {
331 margin-left: 0;
332 }
333 .settings-panel-value:hover,
334 .settings-panel-value:focus {
335 }
336
337
338 /** Select */
339 .settings-panel-select {
340 font-family: inherit;
341 color: inherit;
342 border-radius: 0;
343 outline: none;
344 border: none;
345 -webkit-appearance: none;
346 -moz-appearance: none;
347 -o-appearance:none;
348 appearance:none;
349 font-weight: 500;
350 padding-right: 2em;
351 margin-right: -1em;
352 color: ${active};
353 background: none;
354 line-height: ${h}em;
355 box-shadow: 0 1px ${alpha(tone(.0), .2)};
356 width: auto;
357 }
358 .settings-panel-select:hover,
359 .settings-panel-select:focus {
360 }
361 .settings-panel-select::-ms-expand {
362 display: none;
363 }
364 .settings-panel-select-triangle {
365 content: '';
366 border-right: .3em solid transparent;
367 border-left: .3em solid transparent;
368 line-height: 2em;
369 position: relative;
370 z-index: 1;
371 vertical-align: middle;
372 display: inline-block;
373 width: 0;
374 text-align: center;
375 pointer-events: none;
376 }
377 .settings-panel-select-triangle--down {
378 top: 0em;
379 left: .5em;
380 border-top: .3em solid ${active};
381 border-bottom: .0 transparent;
382 }
383 .settings-panel-select-triangle--up {
384 display: none;
385 }
386 .settings-panel-field--select:hover .settings-panel-select,
387 .settings-panel-select:focus {
388 }
389
390
391 /** Checkbox */
392 .settings-panel-checkbox {
393 display: none;
394 }
395 .settings-panel-checkbox-label {
396 display: inline-block;
397 color: ${tone(0)};
398 position: relative;
399 margin-right: ${h}em;
400 /* margin-bottom: ${h/2}em; */
401 }
402 .settings-panel-checkbox-label:before {
403 /*content: '✓';*/
404 font-family: "Material Icons";
405 content: '';
406 font-weight: bolder;
407 color: ${alpha(white, 0)};
408 display: block;
409 float: left;
410 width: ${h*.5}em;
411 height: ${h*.5}em;
412 border-radius: .5px;
413 position: relative;
414 margin-right: ${h/3}em;
415 margin-left: 2px;
416 box-shadow: 0 0 0 2px ${alpha(tone(0), .9)};
417 line-height: ${h/2}em;
418 margin-top: 1px;
419 text-align: center;
420 }
421 .settings-panel-checkbox-label:hover:before {
422 box-shadow: 0 0 0 2px ${tone(0)};
423 }
424 .settings-panel-checkbox:checked + .settings-panel-checkbox-label {
425 color: ${active};
426 }
427 .settings-panel-checkbox:checked + .settings-panel-checkbox-label:before {
428 box-shadow: 0 0 0 2px ${active};
429 background: ${active};
430 color: ${tone(1)};
431 }
432 .settings-panel-checkbox-label:after {
433 content: '';
434 z-index: 1;
435 position: absolute;
436 width: ${h*1.5}em;
437 height: ${h*1.5}em;
438 background: ${tone(.1)};
439 border-radius: ${h}em;
440 top: -${h*.45}em;
441 left: -${h*.5}em;
442 opacity: 0;
443 margin-left: 2px;
444 transform-origin: center center;
445 transform: scale(.5, .5);
446 transition: .1s ease-out;
447 }
448 .settings-panel-checkbox-label:active:after {
449 transform: scale(1, 1);
450 opacity: .08;
451 }
452 .settings-panel-checkbox:checked + .settings-panel-checkbox-label:after {
453 background: ${active};
454 }
455
456
457 /** Color */
458 .settings-panel-color {
459 height: ${h*.5}em;
460 width: ${h*.5}em;
461 display: inline-block;
462 vertical-align: baseline;
463 }
464 .settings-panel-color-value {
465 border: none;
466 font-family: inherit;
467 border-radius: 0;
468 padding-left: ${h*.75}em;
469 }
470 .settings-panel-color-value:hover,
471 .settings-panel-color-value:focus {
472 outline: none;
473 }
474
475
476 /** Button */
477 .settings-panel-button {
478 text-align: center;
479 border: none;
480 text-transform: uppercase;
481 color: ${tone(0)};
482 font-weight: 500;
483 background: none;
484 width: auto;
485 padding: ${h/3}em ${h/3}em;
486 min-width: ${h*3}em;
487 margin-top: -${h/4}em;
488 margin-bottom: -${h/4}em;
489 }
490 .settings-panel-button:focus {
491 outline: none;
492 }
493 .settings-panel-button:hover {
494 background: ${alpha(tone(0), .08)};
495 }
496 .settings-panel-button:active {
497 background: ${alpha(tone(0), .333)};
498 }
499
500
501 /** Switch style */
502 .settings-panel-switch {
503 }
504 .settings-panel-switch-input {
505 display: none;
506 }
507 .settings-panel-switch-label {
508 position: relative;
509 display: inline-block;
510 margin: 0;
511 margin-right: ${h*.75}em;
512 z-index: 2;
513 text-align: center;
514 padding: 0 0;
515 color: ${tone(0)};
516 }
517 .settings-panel-switch-input:checked + .settings-panel-switch-label {
518 color: ${active};
519 }
520 .settings-panel-switch-input + .settings-panel-switch-label:hover {
521 }
522 .settings-panel-switch-label:hover {
523 color: ${tone(0)};
524 }
525 .settings-panel-switch-label:active {
526 color: ${tone(0)};
527 }
528 .settings-panel-switch-label:after {
529 content: '';
530 z-index: 1;
531 position: absolute;
532 width: ${h*2}em;
533 height: ${h*2}em;
534 min-width: 100%;
535 min-height: 100%;
536 background: ${tone(.1)};
537 border-radius: ${h}em;
538 top: 50%;
539 left: 50%;
540 margin-left: -${h}em;
541 margin-top: -${h}em;
542 opacity: 0;
543 transform-origin: center center;
544 transform: scale(.5, .5);
545 transition: .1s ease-out;
546 }
547 .settings-panel-switch-label:active:after {
548 transform: scale(1, 1);
549 opacity: .08;
550 }
551 .settings-panel-checkbox:checked + .settings-panel-switch-label:after {
552 background: ${active};
553 }
554
555 /** Decorations */
556 ::-webkit-input-placeholder {
557 color: ${alpha(active, .5)};
558 }
559 ::-moz-placeholder {
560 color: ${alpha(active, .5)};
561 }
562 :-ms-input-placeholder {
563 color: ${alpha(active, .5)};
564 }
565 :-moz-placeholder {
566 color: ${alpha(active, .5)};
567 }
568 ::-moz-selection {
569 background: ${active};
570 color: ${white};
571 }
572 ::selection {
573 background: ${active};
574 color: ${white};
575 }
576 :host hr {
577 opacity: 1;
578 border-bottom: 1px solid ${alpha(tone(.0), .2)};
579 margin-left: -${h*.666}em;
580 margin-right: -${h*.666}em;
581 margin-top: ${h*.75}em;
582 }
583 :host a {
584 }
585 :host a:hover {
586 }
587`};
588
589
590function alpha (c, value) {
591 return color(c).setAlpha(value).toString();
592}
593
\No newline at end of file