Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {LitElement, html, css} from 'lit-element'; |
| 6 | |
| 7 | import 'elements/framework/mr-dropdown/mr-dropdown.js'; |
| 8 | |
| 9 | import 'shared/typedef.js'; |
| 10 | |
| 11 | /** Button bar containing table controls. */ |
| 12 | export 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 | */ |
| 78 | function _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 | |
| 100 | customElements.define('mr-button-bar', MrButtonBar); |