forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display-logo.js
120 lines (110 loc) · 3 KB
/
display-logo.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Copyright 2018 The WPT Dashboard Project. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
import '../node_modules/@polymer/paper-tooltip/paper-tooltip.js';
import '../node_modules/@polymer/polymer/lib/elements/dom-if.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
import { ProductInfo, Platforms, Sources } from './product-info.js';
class DisplayLogo extends ProductInfo(PolymerElement) {
static get template() {
return html`
<style>
:host {
--browser-size: 32px;
--source-size: 16px;
}
.icon {
/*Avoid (unwanted) space between images.*/
font-size: 0;
}
img.browser {
height: var(--browser-size);
width: var(--browser-size);
}
img.source,
img.platform {
height: var(--source-size);
width: var(--source-size);
margin-top: var(--browser-size);
}
:host([overlap]) img.source {
margin-left: calc(-0.5 * var(--source-size));
}
:host([overlap]) img.platform {
margin-right: calc(-0.5 * var(--source-size));
}
.small {
--browser-size: 24px;
--source-size: 12px;
}
</style>
<div class\$="icon [[containerClass(small)]]">
<template is="dom-if" if="[[platform]]" restamp>
<img class="platform" src="/static/[[platform]].svg" alt="[[platform]] logo">
</template>
<img class="browser"
src="[[displayLogo(product.browser_name, product.labels)]]"
alt="[[product.browser_name]] [[product.labels]] logo">
<template is="dom-if" if="[[source]]" restamp>
<img class="source" src="/static/[[source]].svg" alt="[[source]] logo">
</template>
</div>
`;
}
static get is() {
return 'display-logo';
}
static get properties() {
return {
small: {
type: Boolean,
value: false,
},
product: {
type: Object, /* {
browser_name: String,
os_name: String,
labels: Array|Set,
}*/
value: {}
},
showSource: {
type: Boolean,
value: false
},
source: {
computed: 'computeSource(product, showSource)',
},
showPlatform: {
type: Boolean,
value: false
},
platform: {
computed: 'computePlatform(product, showPlatform)',
},
overlap: {
type: Boolean,
reflectToAttribute: true,
}
};
}
containerClass(small) {
return small ? 'small' : '';
}
computeSource(product, showSource) {
if (!showSource || !product.labels) {
return '';
}
return product.labels.find(s => Sources.has(s));
}
computePlatform(product, showPlatform) {
if (!showPlatform || !Platforms.has(product.os_name)) {
return '';
}
return product.os_name;
}
}
window.customElements.define(DisplayLogo.is, DisplayLogo);
export { DisplayLogo };