blob: 2fc05b68d26344f7a84978e6562bde35b82861ca [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {LitElement, html, css} from 'lit-element';
6import {equalsIgnoreCase} from 'shared/helpers.js';
7
8/**
9 * `<mr-grid-dropdown>`
10 *
11 * Component used by the user to select what grid options to use.
12 */
13export class MrGridDropdown extends LitElement {
14 /** @override */
15 render() {
16 return html`
17 ${this.text}:
18 <select
19 class="drop-down"
20 @change=${this._optionChanged}
21 >
22 ${(this.items).map((item) => html`
23 <option .selected=${equalsIgnoreCase(item, this.selection)}>
24 ${item}
25 </option>
26 `)}
27 </select>
28 `;
29 }
30
31 /** @override */
32 static get properties() {
33 return {
34 text: {type: String},
35 items: {type: Array},
36 selection: {type: String},
37 };
38 };
39
40 /** @override */
41 constructor() {
42 super();
43 this.items = [];
44 this.selection = 'None';
45 };
46
47 /** @override */
48 static get styles() {
49 return css`
50 :host {
51 font-size: var(--chops-large-font-size);
52 }
53 .drop-down {
54 font-size: var(--chops-large-font-size);
55 }
56 `;
57 };
58
59 /**
60 * Syncs values when the user updates their selection.
61 * @param {Event} e
62 * @fires CustomEvent#change
63 * @private
64 */
65 _optionChanged(e) {
66 this.selection = e.target.value;
67 this.dispatchEvent(new CustomEvent('change'));
68 };
69};
70
71customElements.define('mr-grid-dropdown', MrGridDropdown);
72