Skip to content

Commit

Permalink
fix(button)!: remove BaseButton
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Apr 11, 2024
1 parent 71107fd commit 4576285
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 202 deletions.
4 changes: 4 additions & 0 deletions .changeset/remove-basebutton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/elements": major
---
`<pf-button>`: Removed `BaseButton` class. Reimplement (recommended) or extend `PfButton`.
14 changes: 14 additions & 0 deletions elements/custom-elements-manifest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { pfeCustomElementsManifestConfig } from '@patternfly/pfe-tools/custom-elements-manifest/config.js';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';

// HACK: cem runs from `./elements` in a monorepo
const rootDir = dirname(dirname(fileURLToPath(import.meta.url)));

export default pfeCustomElementsManifestConfig({
rootDir,
globs: [
'./*/pf-*.ts',
'./*/Base*.ts'
],
});
1 change: 0 additions & 1 deletion elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"./pf-background-image/pf-background-image.js": "./pf-background-image/pf-background-image.js",
"./pf-badge/pf-badge.js": "./pf-badge/pf-badge.js",
"./pf-banner/pf-banner.js": "./pf-banner/pf-banner.js",
"./pf-button/BaseButton.js": "./pf-button/BaseButton.js",
"./pf-button/pf-button.js": "./pf-button/pf-button.js",
"./pf-card/BaseCard.js": "./pf-card/BaseCard.js",
"./pf-card/pf-card.js": "./pf-card/pf-card.js",
Expand Down
68 changes: 0 additions & 68 deletions elements/pf-button/BaseButton.css

This file was deleted.

106 changes: 0 additions & 106 deletions elements/pf-button/BaseButton.ts

This file was deleted.

61 changes: 34 additions & 27 deletions elements/pf-button/pf-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,39 @@ export type ButtonVariant = (
export class PfButton extends LitElement {
static readonly formAssociated = true;

static override readonly shadowRootOptions = {
...LitElement.shadowRootOptions,
delegatesFocus: true,
};

static readonly styles = [
tokensStyles,
iconStyles,
styles,
];

/** Represents the state of a stateful button */
@property({ type: Boolean, reflect: true }) loading = false;
@property({ reflect: true }) type?: 'button' | 'submit' | 'reset';

/** Applies plain styles */
@property({ type: Boolean, reflect: true }) plain = false;
/** Accessible name for the button, use when the button does not have slotted text */
@property() label?: string;

/** Not as urgent as danger */
@property({ type: Boolean, reflect: true }) warning = false;
/** Form value for the button */
@property() value?: string;

/** Form element name for the button */
@property() name?: string;

/** Disables the button */
@property({ reflect: true, type: Boolean }) disabled = false;

/** Represents the state of a stateful button */
@property({ type: Boolean, reflect: true }) loading = false;

/** Changes the size of the button. */
@property({ reflect: true }) size?: 'small' | 'large';

/** Icon set for the `icon` property */
@property({ attribute: 'icon-set' }) iconSet?: string;
/** Not as urgent as danger */
@property({ type: Boolean, reflect: true }) warning = false;

/**
* Use danger buttons for actions a user can take that are potentially
Expand All @@ -171,6 +184,9 @@ export class PfButton extends LitElement {
*/
@property({ type: Boolean, reflect: true }) danger = false;

/** Applies plain styles */
@property({ type: Boolean, reflect: true }) plain = false;

/**
* Changes the style of the button.
* - Primary: Used for the most important call to action on a page. Try to
Expand All @@ -187,21 +203,12 @@ export class PfButton extends LitElement {

@property({ reflect: true, type: Boolean }) block = false;

/** Disables the button */
@property({ reflect: true, type: Boolean }) disabled = false;

@property({ reflect: true }) type?: 'button' | 'submit' | 'reset';

/** Accessible name for the button, use when the button does not have slotted text */
@property() label?: string;

@property() value?: string;

@property() name?: string;

/** Shorthand for the `icon` slot, the value is icon name */
@property() icon?: string;

/** Icon set for the `icon` property */
@property({ attribute: 'icon-set' }) iconSet?: string;

#internals = InternalsController.of(this, { role: 'button' });

#slots = new SlotController(this, 'icon', null);
Expand All @@ -222,7 +229,12 @@ export class PfButton extends LitElement {
this.#internals.ariaDisabled = String(!!this.disabled);
}

protected override render() {
async formDisabledCallback() {
await this.updateComplete;
this.requestUpdate();
}

override render() {
const hasIcon = !!this.icon || !!this.loading || this.#slots.hasSlotted('icon');
const { warning, variant, danger, loading, plain, inline, block, size } = this;
const disabled = this.#disabled;
Expand All @@ -244,7 +256,7 @@ export class PfButton extends LitElement {
<pf-icon role="presentation"
icon="${ifDefined(this.icon)}"
set="${ifDefined(this.iconSet)}"
?hidden="${!this.icon}"></pf-icon>
?hidden="${!this.icon || this.loading}"></pf-icon>
<pf-spinner size="md"
?hidden="${!this.loading}"
aria-label="${this.getAttribute('loading-label') ?? 'loading'}"></pf-spinner>
Expand All @@ -254,11 +266,6 @@ export class PfButton extends LitElement {
`;
}

async formDisabledCallback() {
await this.updateComplete;
this.requestUpdate();
}

#onClick() {
if (!this.#disabled) {
switch (this.type) {
Expand Down

0 comments on commit 4576285

Please sign in to comment.