Skip to content

Commit

Permalink
refactor(button): Use flex gap for internal layout
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 500845959
  • Loading branch information
dfreedm authored and copybara-github committed Jan 10, 2023
1 parent f3383cd commit 4974ede
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 42 deletions.
38 changes: 14 additions & 24 deletions button/lib/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,31 @@
// The icon CSS class overrides styles defined in the .material-icons CSS
// class, which is loaded separately so the order of CSS definitions is not
// guaranteed. Therefore, increase specifity to ensure overrides apply.
.md3-button__icon-slot-container {
display: inline-flex;

::slotted([slot='icon']) {
::slotted([slot='icon']) {
.md3-button & {
display: inline-flex;
position: relative;
writing-mode: horizontal-tb;
color: var(--_with-icon-icon-color);
font-size: var(--_with-icon-icon-size);
inline-size: var(--_with-icon-icon-size);
block-size: var(--_with-icon-icon-size);
}

.md3-button:hover & {
color: var(--_with-icon-hover-icon-color);
}

.md3-button:focus & {
color: var(--_with-icon-focus-icon-color);
}

.md3-button:active & {
color: var(--_with-icon-pressed-icon-color);
}
.md3-button:hover & {
color: var(--_with-icon-hover-icon-color);
}

.md3-button:disabled & {
color: var(--_with-icon-disabled-icon-color);
}
.md3-button:focus & {
color: var(--_with-icon-focus-icon-color);
}
}

.md3-button__icon--leading ::slotted([slot='icon']) {
margin-inline-end: 8px;
}
.md3-button:active & {
color: var(--_with-icon-pressed-icon-color);
}

.md3-button__icon--trailing ::slotted([slot='icon']) {
margin-inline-start: 8px;
.md3-button:disabled & {
color: var(--_with-icon-disabled-icon-color);
}
}
}
1 change: 1 addition & 0 deletions button/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
// TODO(b/181413732): Verify token below are named correctly
padding-inline-start: var(--_spacing-leading);
padding-inline-end: var(--_spacing-trailing);
gap: 8px;

&::-moz-focus-inner {
padding: 0;
Expand Down
14 changes: 2 additions & 12 deletions button/lib/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ export abstract class Button extends LitElement implements ButtonState {
};
}

protected getIconContainerClasses(): ClassInfo {
return {
'md3-button__icon--leading': !this.trailingIcon,
'md3-button__icon--trailing': this.trailingIcon,
};
}

protected renderTouchTarget(): TemplateResult {
return html`
<span class="md3-button__touch"></span>
Expand Down Expand Up @@ -181,11 +174,8 @@ export abstract class Button extends LitElement implements ButtonState {
}

protected renderIcon(): TemplateResult {
return html`<span class="md3-button__icon-slot-container ${
classMap(this.getIconContainerClasses())}">
<slot name="icon" @slotchange="${this.handleSlotChange}">
</slot>
</span>`;
return html`<slot name="icon" @slotchange="${
this.handleSlotChange}"></slot>`;
}

protected handlePointerDown(e: PointerEvent) {
Expand Down
6 changes: 0 additions & 6 deletions button/lib/link-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ export abstract class LinkButton extends Button {
};
}

protected override getIconContainerClasses(): ClassInfo {
return {
'md3-button__icon--leading': true,
};
}

protected override render(): TemplateResult {
return html`
<span class="md3-link-button-wrapper">
Expand Down

0 comments on commit 4974ede

Please sign in to comment.