blob: d586042cfce2b12ab006b74ef0099ca8b90bfdf8 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2020 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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';
6
7import 'elements/framework/mr-dropdown/mr-dropdown.js';
8
9import 'shared/typedef.js';
10
11/** Button bar containing table controls. */
12export class MrButtonBar extends LitElement {
13 /** @override */
14 static get styles() {
15 return css`
16 :host {
17 display: flex;
18 }
19 button {
20 background: none;
21 color: var(--chops-link-color);
22 cursor: pointer;
23 font-size: var(--chops-normal-font-size);
24 font-weight: var(--chops-link-font-weight);
25
26 line-height: 24px;
27 padding: 4px 16px;
28
29 border: none;
30
31 align-items: center;
32 display: inline-flex;
33 }
34 button:hover {
35 background: var(--chops-active-choice-bg);
36 }
37 i.material-icons {
38 font-size: 20px;
39 margin-right: 4px;
40 vertical-align: middle;
41 }
42 mr-dropdown {
43 --mr-dropdown-anchor-padding: 6px 4px;
44 --mr-dropdown-icon-color: var(--chops-link-color);
45 }
46 `;
47 }
48
49 /** @override */
50 render() {
51 return html`
52 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
53 ${this.items.map(_renderItem)}
54 `;
55 }
56
57 /** @override */
58 static get properties() {
59 return {
60 items: {type: Array},
61 };
62 };
63
64 /** @override */
65 constructor() {
66 super();
67
68 /** @type {Array<MenuItem>} */
69 this.items = [];
70 }
71};
72
73/**
74 * Renders one item.
75 * @param {MenuItem} item
76 * @return {TemplateResult}
77 */
78function _renderItem(item) {
79 if (item.items) {
80 return html`
81 <mr-dropdown
82 icon=${item.icon}
83 menuAlignment="left"
84 label=${item.text}
85 .items=${item.items}
86 ></mr-dropdown>
87 `;
88 } else {
89 return html`
90 <button @click=${item.handler}>
91 <i class="material-icons" ?hidden=${!item.icon}>
92 ${item.icon}
93 </i>
94 ${item.text}
95 </button>
96 `;
97 }
98}
99
100customElements.define('mr-button-bar', MrButtonBar);