Skip to content

Commit

Permalink
fix(button): allow overriding padding and gap
Browse files Browse the repository at this point in the history
More customization and necessary prep to move styles to host for host aria and text wrapping customization.

PiperOrigin-RevId: 580565272
  • Loading branch information
asyncLiz authored and Copybara-Service committed Nov 8, 2023
1 parent 1852238 commit 5bb4a42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
18 changes: 9 additions & 9 deletions button/internal/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@

@mixin styles() {
:host {
box-sizing: border-box;
cursor: pointer;
display: inline-flex;
gap: 8px;
height: var(--_container-height);
min-width: 64px;
outline: none;
padding-inline-start: var(--_leading-space);
padding-inline-end: var(--_trailing-space);
position: relative;
font-family: var(--_label-text-font);
font-size: var(--_label-text-size);
line-height: var(--_label-text-line-height);
Expand Down Expand Up @@ -64,23 +69,19 @@
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
border: none;
outline: none;
-webkit-appearance: none;
vertical-align: middle;
background: transparent;
text-decoration: none;
width: 100%;
position: relative;
z-index: 0; // Place content on top of elevation and ripple
height: 100%;
font: inherit;
color: var(--_label-text-color);
// TODO(b/181413732): Verify token below are named correctly
padding-inline-start: var(--_leading-space);
padding-inline-end: var(--_trailing-space);
gap: 8px;
padding: 0;
gap: inherit;

&::-moz-focus-inner {
padding: 0;
Expand Down Expand Up @@ -139,13 +140,12 @@
z-index: -1; // Place behind content
}

// TODO(b/181413732): Verify token below are named correctly
.icon-leading {
:host([has-icon]:not([trailing-icon])) {
padding-inline-start: var(--_with-leading-icon-leading-space);
padding-inline-end: var(--_with-leading-icon-trailing-space);
}

.icon-trailing {
:host([has-icon][trailing-icon]) {
padding-inline-start: var(--_with-trailing-icon-leading-space);
padding-inline-end: var(--_with-trailing-icon-trailing-space);
}
Expand Down
16 changes: 5 additions & 11 deletions button/internal/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../../ripple/ripple.js';

import {html, isServer, LitElement, nothing} from 'lit';
import {property, query, queryAssignedElements} from 'lit/decorators.js';
import {classMap} from 'lit/directives/class-map.js';
import {literal, html as staticHtml} from 'lit/static-html.js';

import {ARIAMixinStrict} from '../../internal/aria/aria.js';
Expand Down Expand Up @@ -71,12 +70,14 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
*
* _Note:_ Link buttons cannot have trailing icons.
*/
@property({type: Boolean, attribute: 'trailing-icon'}) trailingIcon = false;
@property({type: Boolean, attribute: 'trailing-icon', reflect: true})
trailingIcon = false;

/**
* Whether to display the icon or not.
*/
@property({type: Boolean, attribute: 'has-icon'}) hasIcon = false;
@property({type: Boolean, attribute: 'has-icon', reflect: true}) hasIcon =
false;

@property() type: FormSubmitterType = 'submit';

Expand Down Expand Up @@ -125,7 +126,7 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;
return staticHtml`
<${button}
class="button ${classMap(this.getRenderClasses())}"
class="button"
?disabled=${isDisabled}
aria-label="${ariaLabel || nothing}"
aria-haspopup="${ariaHasPopup || nothing}"
Expand All @@ -135,13 +136,6 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
>${this.renderContent()}</${button}>`;
}

protected getRenderClasses() {
return {
'icon-leading': !this.trailingIcon && this.hasIcon,
'icon-trailing': this.trailingIcon && this.hasIcon,
};
}

protected renderElevation?(): unknown;

protected renderOutline?(): unknown;
Expand Down

0 comments on commit 5bb4a42

Please sign in to comment.