Skip to content

Commit

Permalink
fix(button)!: merge standard and link buttons
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 520365410
  • Loading branch information
asyncLiz authored and copybara-github committed Mar 29, 2023
1 parent 123c1e0 commit acfdbb4
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 434 deletions.
46 changes: 0 additions & 46 deletions button/elevated-link-button.ts

This file was deleted.

43 changes: 0 additions & 43 deletions button/filled-link-button.ts

This file was deleted.

50 changes: 35 additions & 15 deletions button/lib/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {html, LitElement, nothing, TemplateResult} from 'lit';
import {property, query, queryAssignedElements, queryAsync, state} from 'lit/decorators.js';
import {ClassInfo, classMap} from 'lit/directives/class-map.js';
import {when} from 'lit/directives/when.js';
import {html as staticHtml, literal} from 'lit/static-html.js';

import {dispatchActivationClick, isActivationClick} from '../../controller/events.js';
import {ariaProperty} from '../../decorators/aria-property.js';
Expand All @@ -24,7 +25,9 @@ import {ARIAExpanded, ARIAHasPopup} from '../../types/aria.js';

import {ButtonState} from './state.js';

// tslint:disable-next-line:enforce-comments-on-exported-symbols
/**
* A button component.
*/
export abstract class Button extends LitElement implements ButtonState {
static override shadowRootOptions:
ShadowRootInit = {mode: 'open', delegatesFocus: true};
Expand All @@ -46,6 +49,17 @@ export abstract class Button extends LitElement implements ButtonState {
*/
@property({type: Boolean, reflect: true}) disabled = false;

/**
* The URL that the link button points to.
*/
@property({type: String}) href?: string;

/**
* Where to display the linked `href` URL for a link button. Common options
* include `_blank` to open in a new tab.
*/
@property({type: String}) target?: string;

/**
* Whether to render the icon at the inline end of the label rather than the
* inline start.
Expand Down Expand Up @@ -112,19 +126,25 @@ export abstract class Button extends LitElement implements ButtonState {
};

protected override render(): TemplateResult {
// TODO(b/237283903): Replace ifDefined(... || undefined) with ifTruthy(...)
return html`
<button
class="md3-button ${classMap(this.getRenderClasses())}"
?disabled="${this.disabled}"
aria-label="${this.ariaLabel || nothing}"
aria-haspopup="${this.ariaHasPopup || nothing}"
aria-expanded="${this.ariaExpanded || nothing}"
@pointerdown="${this.handlePointerDown}"
@focus="${this.handleFocus}"
@blur="${this.handleBlur}"
@click="${this.handleClick}"
${ripple(this.getRipple)}>
// Link buttons may not be disabled
const isDisabled = this.disabled && !this.href;

const button = this.href ? literal`a` : literal`button`;
return staticHtml`
<${button}
class="md3-button ${classMap(this.getRenderClasses())}"
?disabled=${isDisabled}
aria-label="${this.ariaLabel || nothing}"
aria-haspopup="${this.ariaHasPopup || nothing}"
aria-expanded="${this.ariaExpanded || nothing}"
href=${this.href || nothing}
target=${this.target || nothing}
@pointerdown="${this.handlePointerDown}"
@focus="${this.handleFocus}"
@blur="${this.handleBlur}"
@click="${this.handleClick}"
${ripple(this.getRipple)}
>
${this.renderFocusRing()}
${this.renderElevation()}
${when(this.showRipple, this.renderRipple)}
Expand All @@ -133,7 +153,7 @@ export abstract class Button extends LitElement implements ButtonState {
${this.renderLeadingIcon()}
${this.renderLabel()}
${this.renderTrailingIcon()}
</button>`;
</${button}}>`;
}

protected getRenderClasses(): ClassInfo {
Expand Down
4 changes: 3 additions & 1 deletion button/lib/elevated-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {ClassInfo} from 'lit/directives/class-map.js';

import {Button} from './button.js';

// tslint:disable-next-line:enforce-comments-on-exported-symbols
/**
* An elevated button component.
*/
export class ElevatedButton extends Button {
protected override getRenderClasses(): ClassInfo {
return {
Expand Down
26 changes: 0 additions & 26 deletions button/lib/elevated-link-button.ts

This file was deleted.

5 changes: 3 additions & 2 deletions button/lib/filled-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {ClassInfo} from 'lit/directives/class-map.js';

import {Button} from './button.js';

// tslint:disable-next-line:enforce-comments-on-exported-symbols
/**
* A filled button component.
*/
export class FilledButton extends Button {
protected override getRenderClasses(): ClassInfo {
return {
Expand All @@ -20,7 +22,6 @@ export class FilledButton extends Button {
};
}

/** @soyTemplate */
protected override renderElevation(): TemplateResult {
return html`<md-elevation shadow surface></md-elevation>`;
}
Expand Down
27 changes: 0 additions & 27 deletions button/lib/filled-link-button.ts

This file was deleted.

70 changes: 0 additions & 70 deletions button/lib/link-button.ts

This file was deleted.

4 changes: 3 additions & 1 deletion button/lib/outlined-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {ClassInfo} from 'lit/directives/class-map.js';

import {Button} from './button.js';

// tslint:disable-next-line:enforce-comments-on-exported-symbols
/**
* An outlined button component.
*/
export class OutlinedButton extends Button {
protected override getRenderClasses(): ClassInfo {
return {
Expand Down
24 changes: 0 additions & 24 deletions button/lib/outlined-link-button.ts

This file was deleted.

4 changes: 3 additions & 1 deletion button/lib/text-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {ClassInfo} from 'lit/directives/class-map.js';

import {Button} from './button.js';

// tslint:disable-next-line:enforce-comments-on-exported-symbols
/**
* A text button component.
*/
export class TextButton extends Button {
protected override getRenderClasses(): ClassInfo {
return {
Expand Down
19 changes: 0 additions & 19 deletions button/lib/text-link-button.ts

This file was deleted.

Loading

0 comments on commit acfdbb4

Please sign in to comment.