Skip to content

Commit

Permalink
fix(clipboard-copy)!: remove BaseClipboardCopy
Browse files Browse the repository at this point in the history
Closes #2611
  • Loading branch information
bennypowers committed Mar 31, 2024
1 parent cf4723b commit 67f8ed4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .changeset/remove-base-clipboard-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@patternfly/elements": major
---
`<pf-clipboard-copy>`: Removed `BaseClipboardCopy` class. Reimplement (recommended) or extend `PfClipboardCopy`.

1 change: 0 additions & 1 deletion elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"./pf-card/pf-card.js": "./pf-card/pf-card.js",
"./pf-chip/pf-chip.js": "./pf-chip/pf-chip.js",
"./pf-chip/pf-chip-group.js": "./pf-chip/pf-chip-group.js",
"./pf-clipboard-copy/BaseClipboardCopy.js": "./pf-clipboard-copy/BaseClipboardCopy.js",
"./pf-clipboard-copy/pf-clipboard-copy.js": "./pf-clipboard-copy/pf-clipboard-copy.js",
"./pf-code-block/BaseCodeBlock.js": "./pf-code-block/BaseCodeBlock.js",
"./pf-code-block/pf-code-block.js": "./pf-code-block/pf-code-block.js",
Expand Down
6 changes: 0 additions & 6 deletions elements/pf-clipboard-copy/BaseClipboardCopy.css

This file was deleted.

29 changes: 0 additions & 29 deletions elements/pf-clipboard-copy/BaseClipboardCopy.ts

This file was deleted.

6 changes: 6 additions & 0 deletions elements/pf-clipboard-copy/pf-clipboard-copy.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
flex-direction: column;
}

[hidden],
[inert],
[inert]::slotted(*) {
display: none !important;
}

#input-group,
#wrapper,
pf-tooltip,
Expand Down
56 changes: 36 additions & 20 deletions elements/pf-clipboard-copy/pf-clipboard-copy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { html } from 'lit';
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';

import { BaseClipboardCopy } from './BaseClipboardCopy.js';

import styles from './pf-clipboard-copy.css';

import '@patternfly/elements/pf-button/pf-button.js';
Expand All @@ -14,51 +12,65 @@ import '@patternfly/elements/pf-tooltip/pf-tooltip.js';

const sleep = (ms?: number) => new Promise(r => setTimeout(r, ms));

export class ClipboardCopyCopiedEvent extends Event {
constructor(public text: string) {
super('copy', { bubbles: true });
}
}

/**
* The **clipboard copy** component allows users to quickly and easily copy content to their clipboard.
*
* @slot - Place content to copy here, or use the `value` attribute
* @slot actions - Place additional action buttons here
*/
@customElement('pf-clipboard-copy')
export class PfClipboardCopy extends BaseClipboardCopy {
static readonly styles = [...BaseClipboardCopy.styles, styles];
export class PfClipboardCopy extends LitElement {
static readonly styles = [styles];

static shadowRootOptions: ShadowRootInit = { ...BaseClipboardCopy.shadowRootOptions, delegatesFocus: true };
static shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };

@property({ attribute: 'click-tip' }) clickTip = 'Copied';
/** Tooltip message to display when clicking the copy button */
@property({ attribute: 'click-tip' }) clickTip = 'Successfully copied to clipboard!';

@property({ attribute: 'hover-tip' }) hoverTip = 'Copy';
/** Tooltip message to display when hover the copy button */
@property({ attribute: 'hover-tip' }) hoverTip = 'Copy to clipboard';

@property({ attribute: 'text-label' }) textAriaLabel = 'Copyable input';
/** Accessible label to use on the text input. */
@property({ attribute: 'accessible-text-label' }) accessibleTextLabel = 'Copyable input';

@property({ attribute: 'toggle-label' }) toggleAriaLabel = 'Show content';
/** Accessible label to use on the toggle button. */
@property({ attribute: 'accessible-toggle-label' }) accessibleToggleLabel = 'Show content';

/** Delay in ms before the tooltip appears. */
@property({ type: Number, attribute: 'entry-delay' }) entryDelay = 300;

/** Delay in ms before the tooltip disappears. */
@property({ type: Number, attribute: 'exit-delay' }) exitDelay = 1500;

/** Flag to determine if inline clipboard copy should be block styling */
@property({ type: Boolean, reflect: true }) block = false;

/** Flag to determine if clipboard copy content includes code */
@property({ type: Boolean, reflect: true }) code = false;

/** Flag to determine if clipboard copy is in the expanded state */
@property({ type: Boolean, reflect: true }) expanded = false;

/**
* Implies not `inline`.
*/
/** Implies not `inline`. */
@property({ type: Boolean, reflect: true }) expandable = false;

/** Flag to show if the input is read only. */
@property({ type: Boolean, reflect: true }) readonly = false;

/**
* Implies not expandable. Overrules `expandable`.
*/
/** Implies not expandable. Overrules `expandable`. */
@property({ type: Boolean, reflect: true }) inline = false;

/** Flag to determine if inline clipboard copy should have compact styling */
@property({ type: Boolean, reflect: true }) compact = false;

@property() override value = '';
/** String to copy */
@property() value = '';

#copied = false;

Expand Down Expand Up @@ -96,7 +108,7 @@ export class PfClipboardCopy extends BaseClipboardCopy {
?disabled="${expanded || readonly}"
.value="${this.value}"
@input="${this.#onChange}"
aria-label="${this.textAriaLabel}">
aria-label="${this.accessibleTextLabel}">
<pf-tooltip>
<pf-button id="copy-button"
plain
Expand Down Expand Up @@ -142,8 +154,12 @@ export class PfClipboardCopy extends BaseClipboardCopy {
return match ? stripped.replace(new RegExp(`^${match[0]}`, 'gm'), '') : str;
}

override async copy() {
await super.copy();
/**
* Copy the current value to the clipboard.
*/
async copy() {
await navigator.clipboard.writeText(this.value);
this.dispatchEvent(new ClipboardCopyCopiedEvent(this.value));
await sleep(this.entryDelay);
this.#copied = true;
this.requestUpdate();
Expand Down

0 comments on commit 67f8ed4

Please sign in to comment.