Skip to content

Commit 8e2bb32

Browse files
committed
Rename from uui-copy to more explicit uui-text-copy-button
1 parent bf86ac4 commit 8e2bb32

14 files changed

+134
-118
lines changed

package-lock.json

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uui-copy/README.md

-31
This file was deleted.

packages/uui-copy/lib/UUICopyEvent.ts

-18
This file was deleted.

packages/uui-copy/lib/index.ts

-1
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# uuui-text-copy-button
2+
3+
![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-text-copy-button?logoColor=%231B264F)
4+
5+
Umbraco style copy component.
6+
7+
## Installation
8+
9+
### ES imports
10+
11+
```zsh
12+
npm i @umbraco-ui/uui-text-copy-button
13+
```
14+
15+
Import the registration of `<uui-text-copy-button>` via:
16+
17+
```javascript
18+
import '@umbraco-ui/uui-text-copy-button';
19+
```
20+
21+
When looking to leverage the `UUITextCopyButtonElement` base class as a type and/or for extension purposes, do so via:
22+
23+
```javascript
24+
import { UUITextCopyButtonElement } from '@umbraco-ui/uui-text-copy-button';
25+
```
26+
27+
## Usage
28+
29+
```html
30+
<uui-text-copy-button
31+
value="I am copied to the clipboard"></uui-text-copy-button>
32+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
2+
import { UUITextCopyButtonElement } from './uui-text-copy-button.element';
3+
4+
interface UUITextCopyButtonEventInit extends EventInit {
5+
detail?: { text: string };
6+
}
7+
8+
export class UUITextCopyButtonEvent extends UUIEvent<
9+
{ text: string },
10+
UUITextCopyButtonElement
11+
> {
12+
public static readonly COPIED: string = 'copied';
13+
public static readonly COPYING: string = 'copying';
14+
15+
constructor(evName: string, eventInit: UUITextCopyButtonEventInit = {}) {
16+
super(evName, {
17+
...{ bubbles: true },
18+
...eventInit,
19+
});
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './uui-text-copy-button.element';
2+
export * from './UUITextCopyButtonEvent';

packages/uui-copy/lib/uui-copy.element.ts renamed to packages/uui-text-copy-button/lib/uui-text-copy-button.element.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
22
import { css, html, LitElement } from 'lit';
33
import { property } from 'lit/decorators.js';
44
import { UUIButtonElement } from '@umbraco-ui/uui-button/lib';
5-
import { UUICopyEvent } from './UUICopyEvent';
5+
import { UUITextCopyButtonEvent } from './UUITextCopyButtonEvent';
66
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
77
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
88

99
/**
1010
* @summary A button to trigger text content to be copied to the clipboard
11-
* @element uui-copy
11+
* @element uui-text-copy-button
1212
* @dependency uui-button
1313
* @dependency uui-icon
1414
* @fires {UUICopyEvent} copying - Fires before the content is about to copied to the clipboard and can be used to transform or modify the data before its added to the clipboard
1515
* @fires {UUICopyEvent} copied - Fires when the content is copied to the clipboard
1616
* @slot - Use to replace the default content of 'Copy' and the copy icon
1717
*/
18-
@defineElement('uui-copy')
19-
export class UUICopyElement extends LabelMixin('', LitElement) {
18+
@defineElement('uui-text-copy-button')
19+
export class UUITextCopyButtonElement extends LabelMixin('', LitElement) {
2020
/**
2121
* Set a string you wish to copy to the clipboard
2222
* @type {string}
@@ -120,9 +120,12 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
120120
}
121121
}
122122

123-
const beforeCopyEv = new UUICopyEvent(UUICopyEvent.COPYING, {
124-
detail: { text: this.#valueToCopy },
125-
});
123+
const beforeCopyEv = new UUITextCopyButtonEvent(
124+
UUITextCopyButtonEvent.COPYING,
125+
{
126+
detail: { text: this.#valueToCopy },
127+
},
128+
);
126129
this.dispatchEvent(beforeCopyEv);
127130

128131
if (beforeCopyEv.detail.text != null) {
@@ -133,7 +136,7 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
133136
.writeText(this.#valueToCopy)
134137
.then(() => {
135138
this.dispatchEvent(
136-
new UUICopyEvent(UUICopyEvent.COPIED, {
139+
new UUITextCopyButtonEvent(UUITextCopyButtonEvent.COPIED, {
137140
detail: { text: this.#valueToCopy },
138141
}),
139142
);
@@ -170,6 +173,6 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
170173

171174
declare global {
172175
interface HTMLElementTagNameMap {
173-
'uui-copy': UUICopyElement;
176+
'uui-text-copy-button': UUITextCopyButtonElement;
174177
}
175178
}

0 commit comments

Comments
 (0)