|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// Style preference for leading underscores. |
| 8 | +// tslint:disable:strip-private-property-underscore |
| 9 | + |
| 10 | +import {IconButtonBase} from '@material/mwc-icon-button/mwc-icon-button-base'; |
| 11 | +import {html, TemplateResult} from 'lit'; |
| 12 | +import {property} from 'lit/decorators.js'; |
| 13 | +import {ifDefined} from 'lit/directives/if-defined.js'; |
| 14 | + |
| 15 | +// Note that we cast `linkTarget` to this type, below. The Lit compiler |
| 16 | +// enforces the `target` attribute value to be of this type, but this is not |
| 17 | +// compatible with the generated Wit Soy/JS, which expects `linkTarget` |
| 18 | +// to be a string type. |
| 19 | +type LinkTarget = '_blank'|'_parent'|'_self'|'_top'; |
| 20 | + |
| 21 | +/** @soyCompatible */ |
| 22 | +export class LinkIconButton extends IconButtonBase { |
| 23 | + @property({type: String}) linkHref = ''; |
| 24 | + |
| 25 | + // Default to empty string so that in the generated Wit Soy template, by |
| 26 | + // default `linkTarget` is falsy and the `target` attribute is not printed. |
| 27 | + @property({type: String}) linkTarget = ''; |
| 28 | + |
| 29 | + /** @soyTemplate */ |
| 30 | + protected override render(): TemplateResult { |
| 31 | + return html`<div |
| 32 | + class="mdc-icon-button mdc-icon-button--display-flex" |
| 33 | + @focus="${this.handleRippleFocus}" |
| 34 | + @blur="${this.handleRippleBlur}" |
| 35 | + @mousedown="${this.handleRippleMouseDown}" |
| 36 | + @mouseenter="${this.handleRippleMouseEnter}" |
| 37 | + @mouseleave="${this.handleRippleMouseLeave}" |
| 38 | + @touchstart="${this.handleRippleTouchStart}" |
| 39 | + @touchend="${this.handleRippleDeactivate}" |
| 40 | + @touchcancel="${this.handleRippleDeactivate}" |
| 41 | + >${this.renderRipple()} |
| 42 | + <i class="material-icons">${this.icon}</i> |
| 43 | + <span |
| 44 | + ><slot></slot |
| 45 | + ></span> |
| 46 | + <a class="mdc-icon-button__link" href="${this.linkHref}" |
| 47 | + target="${ifDefined(this.linkTarget) as LinkTarget}" aria-label="${ |
| 48 | + this.ariaLabel || this.icon}"></a> |
| 49 | + </div>`; |
| 50 | + } |
| 51 | +} |
0 commit comments