forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-picker.js
126 lines (115 loc) · 3.64 KB
/
browser-picker.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
121
122
123
124
125
import '../node_modules/@polymer/paper-dropdown-menu/paper-dropdown-menu.js';
import '../node_modules/@polymer/paper-item/paper-icon-item.js';
import '../node_modules/@polymer/paper-checkbox/paper-checkbox.js';
import '../node_modules/@polymer/paper-listbox/paper-listbox.js';
import '../node_modules/@polymer/polymer/lib/elements/dom-repeat.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
import './display-logo.js';
import { DefaultBrowserNames, DefaultProducts, ProductInfo } from './product-info.js';
// A component allowing the user to select one of a list of browsers.
class BrowserPicker extends ProductInfo(PolymerElement) {
static get is() {
return 'browser-picker';
}
static get template() {
return html`
<paper-dropdown-menu label="Browser" no-animations>
<paper-listbox slot="dropdown-content" selected="{{ browser }}" attr-for-selected="value">
<template is="dom-repeat" items="[[products]]" as="product">
<paper-icon-item value="[[product.browser_name]]">
<display-logo slot="item-icon" product="[[product]]" small></display-logo>
[[displayName(product.browser_name)]]
</paper-icon-item>
</template>
</paper-listbox>
</paper-dropdown-menu>
`;
}
static get properties() {
return {
browser: {
type: String,
value: DefaultBrowserNames[0],
notify: true,
},
products: {
type: Array,
value: DefaultProducts.map(p => Object.assign({}, p)),
},
};
}
}
window.customElements.define(BrowserPicker.is, BrowserPicker);
export { BrowserPicker };
// A component allowing the user to select multiple browsers from a list. The
// choice of browsers (passed in as |products|) is rendered as a list of
// checkboxes, which are all selected initially.
class BrowserMultiPicker extends ProductInfo(PolymerElement) {
static get is() {
return 'browser-multi-picker';
}
static get template() {
return html`
<style>
paper-checkbox {
margin-left: 16px;
}
paper-checkbox div {
display: flex;
align-items: center;
}
paper-checkbox display-logo {
margin-right: 8px;
}
</style>
<template is="dom-repeat" items="[[products]]" as="product">
<paper-checkbox checked value="[[product.browser_name]]">
<div>
<display-logo product="[[product]]" small></display-logo>
[[displayName(product.browser_name)]]
</div>
</paper-checkbox>
</template>
`;
}
static get properties() {
return {
browser: {
type: String,
value: DefaultBrowserNames[0],
notify: true,
},
products: {
type: Array,
value: DefaultProducts.map(p => Object.assign({}, p)),
observer: 'productsChanged'
},
selected: {
type: Array,
notify: true,
value: DefaultProducts.map(p => p.browser_name),
}
};
}
ready() {
super.ready();
this.shadowRoot.querySelector('dom-repeat').render();
this.shadowRoot.querySelectorAll('paper-checkbox').forEach(c => {
c.addEventListener('change', e => this.selectedChanged(c.value, e));
});
}
productsChanged(products) {
this.selected = products.map(p => p.browser_name);
}
selectedChanged(browser, e) {
if (e.srcElement.checked) {
if (!this.selected.includes(browser)) {
this.splice('selected', this.selected.length, 0, browser);
}
} else {
this.selected = this.selected.filter(b => b !== browser);
}
}
}
window.customElements.define(BrowserMultiPicker.is, BrowserMultiPicker);
export { BrowserMultiPicker };