From 36f1a1a0b34dba43d4a859a19d30070b9998ca9a Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 11 Jan 2023 16:03:55 -0800 Subject: [PATCH] refactor(iconbutton)!: remove icon properties, use slots instead PiperOrigin-RevId: 501403118 --- iconbutton/icon-button_test.ts | 20 +++++++------ iconbutton/lib/icon-button-toggle.ts | 43 ++++++++-------------------- iconbutton/lib/icon-button.ts | 9 +----- 3 files changed, 25 insertions(+), 47 deletions(-) diff --git a/iconbutton/icon-button_test.ts b/iconbutton/icon-button_test.ts index bbc971a59e..461aa43708 100644 --- a/iconbutton/icon-button_test.ts +++ b/iconbutton/icon-button_test.ts @@ -16,16 +16,19 @@ import {IconButtonHarness} from './harness.js'; import {MdStandardIconButtonToggle} from './standard-icon-button-toggle.js'; const ICON_BUTTON_TEMPLATE = html` - + + star `; const LINK_ICON_BUTTON_TEMPLATE = html` - + + star `; const ICON_BUTTON_TOGGLE_TEMPLATE = html` - + + star + star_border `; @@ -163,8 +166,8 @@ describe('icon button tests', () => { it('if `flipsIconInRtl=true`, flips icon in an RTL context', async () => { const template = html`
- + + star
`; const element = @@ -178,8 +181,9 @@ describe('icon button tests', () => { async () => { const template = html`
- + + star
`; const element = diff --git a/iconbutton/lib/icon-button-toggle.ts b/iconbutton/lib/icon-button-toggle.ts index 35cf3c8343..3f527ca395 100644 --- a/iconbutton/lib/icon-button-toggle.ts +++ b/iconbutton/lib/icon-button-toggle.ts @@ -11,10 +11,9 @@ import '../../focus/focus-ring.js'; import '../../icon/icon.js'; import '../../ripple/ripple.js'; -import {html, LitElement, TemplateResult} from 'lit'; +import {html, LitElement, nothing, TemplateResult} from 'lit'; import {property, queryAsync, state} from 'lit/decorators.js'; import {ClassInfo, classMap} from 'lit/directives/class-map.js'; -import {ifDefined} from 'lit/directives/if-defined.js'; import {when} from 'lit/directives/when.js'; import {ariaProperty} from '../../decorators/aria-property.js'; @@ -36,20 +35,6 @@ export class IconButtonToggle extends LitElement { */ @property({type: Boolean, reflect: true}) disabled = false; - /** - * The glyph of the icon to display from the applied icon font when toggle - * button is selected or "on". See the associated typography tokens for more - * info. - */ - @property({type: String}) onIcon = ''; - - /** - * The glyph of the icon to display from the applied icon font when toggle - * button is not selected or "off". See the associated typography tokens for - * more info. - */ - @property({type: String}) offIcon = ''; - /** * The `aria-label` of the button when the toggle button is selected or "on". */ @@ -85,14 +70,14 @@ export class IconButtonToggle extends LitElement { protected override render(): TemplateResult { const hasToggledAriaLabel = this.ariaLabelOn && this.ariaLabelOff; - const ariaPressedValue = hasToggledAriaLabel ? undefined : this.selected; + const ariaPressedValue = hasToggledAriaLabel ? nothing : this.selected; const ariaLabelValue = hasToggledAriaLabel ? (this.selected ? this.ariaLabelOn : this.ariaLabelOff) : this.ariaLabel; return html``; } @@ -117,15 +102,11 @@ export class IconButtonToggle extends LitElement { }; } - protected renderIcon(icon: string): TemplateResult|string { - return icon ? html`${icon}` : ''; - } - - protected renderTouchTarget(): TemplateResult { + protected renderTouchTarget() { return html``; } - protected renderFocusRing(): TemplateResult { + protected renderFocusRing() { return html``; } diff --git a/iconbutton/lib/icon-button.ts b/iconbutton/lib/icon-button.ts index da6eb4461f..5426cc45a2 100644 --- a/iconbutton/lib/icon-button.ts +++ b/iconbutton/lib/icon-button.ts @@ -28,12 +28,6 @@ import {ARIAHasPopup} from '../../types/aria.js'; export class IconButton extends LitElement { @property({type: Boolean, reflect: true}) disabled = false; - /** - * The glyph of the icon to display from the applied icon font. See the - * associated typography tokens for more info. - */ - @property({type: String}) icon = ''; - /** * Flips the icon if it is in an RTL context at startup. */ @@ -92,8 +86,7 @@ export class IconButton extends LitElement { protected renderIcon(): TemplateResult { // Note, it's important not to render the icon property as a slot fallback // to avoid any whitespace from overridding it. - return html`${ - this.icon ? this.icon : html``}`; + return html``; } protected renderTouchTarget(): TemplateResult {