Skip to content

Commit

Permalink
refactor(iconbutton)!: remove <md-icon>
Browse files Browse the repository at this point in the history
BREAKING CHANGE: font icons require using <md-icon> directly

PiperOrigin-RevId: 530673789
  • Loading branch information
asyncLiz authored and copybara-github committed May 9, 2023
1 parent 48ac6ef commit ec47f9b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
92 changes: 60 additions & 32 deletions docs/components/icon-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ the icon font.
![A row of icon buttons](images/iconbutton/usage.png "Icon buttons can be used within other components, such as a bottom app bar")

```html
<md-standard-icon-button>check</md-standard-icon-button>
<md-filled-icon-button>check</md-filled-icon-button>
<md-filled-tonal-icon-button>check</md-filled-tonal-icon-button>
<md-outlined-icon-button>check</md-outlined-icon-button>
<md-standard-icon-button>
<md-icon>check</md-icon>
</md-standard-icon-button>
<md-filled-icon-button>
<md-icon>check</md-icon>
</md-filled-icon-button>
<md-filled-tonal-icon-button>
<md-icon>check</md-icon>
</md-filled-tonal-icon-button>
<md-outlined-icon-button>
<md-icon>check</md-icon>
</md-outlined-icon-button>
```

### Links
Expand All @@ -62,7 +70,9 @@ and optionally a
attribute to turn the icon button into a link.

```html
<md-standard-icon-button href="https://google.com">check</md-standard-icon-button>
<md-standard-icon-button href="https://google.com">
<md-icon>check</md-icon>
</md-standard-icon-button>
```

### Toggle
Expand All @@ -77,38 +87,38 @@ adding or removing something from favorites.
```html
<div>
<md-standard-icon-button toggle>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-standard-icon-button>
<md-filled-icon-button toggle>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-filled-icon-button>
<md-filled-tonal-icon-button toggle>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-filled-tonal-icon-button>
<md-outlined-icon-button toggle>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-outlined-icon-button>
</div>
<div>
<md-standard-icon-button toggle selected>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-standard-icon-button>
<md-filled-icon-button toggle selected>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-filled-icon-button>
<md-filled-tonal-icon-button toggle selected>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-filled-tonal-icon-button>
<md-outlined-icon-button toggle selected>
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-outlined-icon-button>
</div>
```
Expand All @@ -120,7 +130,9 @@ Add an
attribute to buttons whose labels need a more descriptive label.

```html
<md-standard-icon-button aria-label="Search for Contact">search</md-standard-icon-button>
<md-standard-icon-button aria-label="Search for Contact">
<md-icon>search</md-icon>
</md-standard-icon-button>
```

### Toggle
Expand All @@ -132,8 +144,8 @@ descriptive label when selected.
<md-standard-icon-button toggle
aria-label="Unselected"
selected-aria-label="Selected">
<span>close</span>
<span slot="selectedIcon">check</span>
<md-icon>close</md-icon>
<md-icon slot="selectedIcon">check</md-icon>
</md-standard-icon-button>
```

Expand All @@ -152,7 +164,9 @@ Icon buttons can be grouped together or they can stand alone.
![A check icon](images/iconbutton/usage-standard.png "Standard Icon Button with Check icon")

```html
<md-standard-icon-button>check</md-standard-icon-button>
<md-standard-icon-button>
<md-icon>check</md-icon>
</md-standard-icon-button>
```

## Filled Icon Button
Expand All @@ -165,7 +179,9 @@ Filled icon buttons have higher visual impact and are best for high emphasis
actions.

```html
<md-filled-icon-button>check</md-filled-icon-button>
<md-filled-icon-button>
<md-icon>check</md-icon>
</md-filled-icon-button>
```

## Filled Tonal Icon Button
Expand All @@ -180,7 +196,9 @@ emphasis than an outline would give, such as a secondary action paired with a
high emphasis action.

```html
<md-filled-tonal-icon-button>check</md-filled-tonal-icon-button>
<md-filled-tonal-icon-button>
<md-icon>check</md-icon>
</md-filled-tonal-icon-button>
```

## Outlined Icon Button
Expand All @@ -194,7 +212,9 @@ button needs more emphasis than a standard icon button but less than a filled or
filled tonal icon button.

```html
<md-outlined-icon-button>check</md-outlined-icon-button>
<md-outlined-icon-button>
<md-icon>check</md-icon>
</md-outlined-icon-button>
```

## Theming
Expand Down Expand Up @@ -225,7 +245,9 @@ Token | Default value
}
</style>

<md-standard-icon-button></md-standard-icon-button>
<md-standard-icon-button>
<md-icon>check</md-icon>
</md-standard-icon-button>
```

### Filled Icon Button tokens
Expand Down Expand Up @@ -253,7 +275,9 @@ Token | Default value
--md-sys-color-primary: #dc362e;
}
</style>
<md-filled-icon-button></md-filled-icon-button>
<md-filled-icon-button>
<md-icon>check</md-icon>
</md-filled-icon-button>
```

### Filled Tonal Icon Button tokens
Expand All @@ -278,7 +302,9 @@ Token | Default value
--md-sys-color-secondary-container: #006A6A;
}
</style>
<md-filled-tonal-icon-button></md-filled-tonal-icon-button>
<md-filled-tonal-icon-button>
<md-icon>check</md-icon>
</md-filled-tonal-icon-button>
```

### Outlined Icon Button tokens
Expand All @@ -305,5 +331,7 @@ Token | Default value
--md-sys-color-outline: #006A6A;
}
</style>
<md-outlined-icon-button></md-outlined-icon-button>
<md-outlined-icon-button>
<md-icon>check</md-icon>
</md-outlined-icon-button>
```
9 changes: 5 additions & 4 deletions iconbutton/icon-button_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import '../icon/icon.js';
import './standard-icon-button.js';

import {html} from 'lit';
Expand All @@ -14,18 +15,18 @@ import {IconButtonHarness} from './harness.js';

const ICON_BUTTON_TEMPLATE = html`
<md-standard-icon-button aria-label="Star">
star
<md-icon>star</md-icon>
</md-standard-icon-button>
`;
const LINK_ICON_BUTTON_TEMPLATE = html`
<md-standard-icon-button aria-label="Star" href="https://google.com">
star
<md-icon>star</md-icon>
</md-standard-icon-button>
`;
const ICON_BUTTON_TOGGLE_TEMPLATE = html`
<md-standard-icon-button toggle aria-label="Star">
<md-icon slot="onIcon">star</md-icon>
<md-icon slot="offIcon">star_border</md-icon>
<md-icon slot="onIcon">star</md-icon>
<md-icon slot="offIcon">star_border</md-icon>
</md-standard-icon-button>
`;

Expand Down
3 changes: 3 additions & 0 deletions iconbutton/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
}

.icon {
height: var(--_icon-size);
width: var(--_icon-size);

@include icon.theme(
(
size: var(--_icon-size),
Expand Down
5 changes: 2 additions & 3 deletions iconbutton/lib/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import '../../focus/focus-ring.js';
import '../../icon/icon.js';
import '../../ripple/ripple.js';

import {html, LitElement, nothing} from 'lit';
Expand Down Expand Up @@ -145,12 +144,12 @@ export class IconButton extends LitElement {
}

private renderIcon() {
return html`<md-icon class="icon"><slot></slot></md-icon>`;
return html`<span class="icon"><slot></slot></span>`;
}

private renderSelectedIcon() {
// Use default slot as fallback to not require specifying multiple icons
return html`<md-icon class="icon icon--selected"><slot name="selectedIcon"><slot></slot></slot></md-icon>`;
return html`<span class="icon icon--selected"><slot name="selectedIcon"><slot></slot></slot></span>`;
}

private renderTouchTarget() {
Expand Down

0 comments on commit ec47f9b

Please sign in to comment.