Skip to content

Commit d1875c9

Browse files
joyzhongcopybara-github
authored andcommitted
feat(iconbutton): Add link icon button Sass.
PiperOrigin-RevId: 404609786
1 parent 6833a5c commit d1875c9

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 {customElement} from 'lit/decorators.js';
11+
12+
import {styles} from '../../icon_button/mwc-icon-button.css';
13+
14+
import {LinkIconButton} from './lib/link-icon-button';
15+
16+
declare global {
17+
interface HTMLElementTagNameMap {
18+
'md-link-icon-button': MdLinkIconButton;
19+
}
20+
}
21+
22+
@customElement('md-link-icon-button')
23+
export class MdLinkIconButton extends LinkIconButton {
24+
static override styles = [styles];
25+
}

0 commit comments

Comments
 (0)