Skip to content

Commit f9087d8

Browse files
committed
feat: rename element to uui-button-copy-text
1 parent e4e1ae8 commit f9087d8

File tree

6 files changed

+62
-76
lines changed

6 files changed

+62
-76
lines changed

packages/uui-text-copy/lib/UUITextCopyEvent.ts renamed to packages/uui-text-copy/lib/UUICopyTextEvent.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
2-
import { UUITextCopyElement } from './uui-text-copy.element';
2+
import { UUIButtonCopyTextElement } from './uui-button-copy-text.element';
33

4-
interface UUITextCopyEventInit extends EventInit {
4+
interface UUICopyTextEventInit extends EventInit {
55
detail?: { text: string };
66
}
77

8-
export class UUITextCopyEvent extends UUIEvent<
8+
export class UUICopyTextEvent extends UUIEvent<
99
{ text: string },
10-
UUITextCopyElement
10+
UUIButtonCopyTextElement
1111
> {
1212
public static readonly COPIED: string = 'copied';
1313
public static readonly COPYING: string = 'copying';
1414

15-
constructor(evName: string, eventInit: UUITextCopyEventInit = {}) {
15+
constructor(evName: string, eventInit: UUICopyTextEventInit = {}) {
1616
super(evName, {
1717
...eventInit,
1818
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './uui-text-copy.element';
2-
export * from './UUITextCopyEvent';
1+
export * from './uui-button-copy-text.element';
2+
export * from './UUICopyTextEvent';

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
55
import { UUIButtonElement } from '@umbraco-ui/uui-button/lib';
66
import { UUIInterfaceColor, UUIInterfaceLook } from '@umbraco-ui/uui-base';
77
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
8-
import { UUITextCopyEvent } from './UUITextCopyEvent';
8+
import { UUICopyTextEvent } from './UUICopyTextEvent';
99

1010
/**
1111
* @summary A button to trigger text content to be copied to the clipboard
12-
* @element uui-text-copy
12+
* @element uui-button-copy-text
1313
* @dependency uui-button
1414
* @dependency uui-icon
1515
* @fires {UUITextCopyEvent} 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
1616
* @fires {UUITextCopyEvent} copied - Fires when the content is copied to the clipboard
1717
* @slot - Use to replace the default content of 'Copy' and the copy icon
1818
*/
19-
@defineElement('uui-text-copy')
20-
export class UUITextCopyElement extends LabelMixin('', LitElement) {
19+
@defineElement('uui-button-copy-text')
20+
export class UUIButtonCopyTextElement extends LabelMixin('', LitElement) {
2121
/**
2222
* Set a string you wish to copy to the clipboard
2323
* @type {string}
@@ -118,7 +118,7 @@ export class UUITextCopyElement extends LabelMixin('', LitElement) {
118118
}
119119
}
120120

121-
const beforeCopyEv = new UUITextCopyEvent(UUITextCopyEvent.COPYING, {
121+
const beforeCopyEv = new UUICopyTextEvent(UUICopyTextEvent.COPYING, {
122122
detail: { text: this.#valueToCopy },
123123
});
124124
this.dispatchEvent(beforeCopyEv);
@@ -130,7 +130,7 @@ export class UUITextCopyElement extends LabelMixin('', LitElement) {
130130
try {
131131
await navigator.clipboard.writeText(this.#valueToCopy);
132132
this.dispatchEvent(
133-
new UUITextCopyEvent(UUITextCopyEvent.COPIED, {
133+
new UUICopyTextEvent(UUICopyTextEvent.COPIED, {
134134
detail: { text: this.#valueToCopy },
135135
}),
136136
);
@@ -166,6 +166,6 @@ export class UUITextCopyElement extends LabelMixin('', LitElement) {
166166

167167
declare global {
168168
interface HTMLElementTagNameMap {
169-
'uui-text-copy': UUITextCopyElement;
169+
'uui-button-copy-text': UUIButtonCopyTextElement;
170170
}
171171
}

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

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { Meta, StoryObj } from '@storybook/web-components';
22
import { html } from 'lit';
33

4-
import './uui-text-copy.element';
5-
import type { UUITextCopyElement } from './uui-text-copy.element';
4+
import './uui-text-copy.element.js';
5+
import { UUICopyTextEvent } from './UUICopyTextEvent';
6+
import type { UUIButtonCopyTextElement } from './uui-button-copy-text.element.js';
67
import readme from '../README.md?raw';
78

89
// For the story to show the example of using inside an uui-input
@@ -11,12 +12,10 @@ import '@umbraco-ui/uui-input/lib';
1112
import '@umbraco-ui/uui-button/lib';
1213
import '@umbraco-ui/uui-loader-circle/lib';
1314

14-
import { UUITextCopyEvent } from './UUITextCopyEvent';
15-
16-
const meta: Meta<UUITextCopyElement> = {
17-
id: 'uui-text-copy',
18-
title: 'Buttons/Text Copy',
19-
component: 'uui-text-copy',
15+
const meta: Meta<UUIButtonCopyTextElement> = {
16+
id: 'uui-button-copy-text',
17+
title: 'Buttons/Copy text',
18+
component: 'uui-button-copy-text',
2019
parameters: {
2120
readme: { markdown: readme },
2221
},
@@ -38,7 +37,7 @@ const meta: Meta<UUITextCopyElement> = {
3837
};
3938

4039
export default meta;
41-
type Story = StoryObj<UUITextCopyElement>;
40+
type Story = StoryObj<UUIButtonCopyTextElement>;
4241

4342
export const Overview: Story = {
4443
name: 'Simple Copy',
@@ -48,7 +47,7 @@ export const Overview: Story = {
4847
parameters: {
4948
docs: {
5049
source: {
51-
code: `<uui-text-copy value="Hey stop copying me 🥸"></uui-text-copy>`,
50+
code: `<uui-button-copy-text value="Hey stop copying me 🥸"></uui-button-copy-text>`,
5251
},
5352
},
5453
},
@@ -64,7 +63,7 @@ export const WithLabelSet: Story = {
6463
parameters: {
6564
docs: {
6665
source: {
67-
code: `<uui-text-copy value="Hey stop copying me 🥸" label="This is my A11y label I want"></uui-text-copy>`,
66+
code: `<uui-button-copy-text value="Hey stop copying me 🥸" label="This is my A11y label I want"></uui-button-copy-text>`,
6867
},
6968
},
7069
},
@@ -79,7 +78,7 @@ export const Disabled: Story = {
7978
parameters: {
8079
docs: {
8180
source: {
82-
code: `<uui-text-copy value="You cannot copy this" disabled></uui-text-copy>`,
81+
code: `<uui-button-copy-text value="You cannot copy this" disabled></uui-button-copy-text>`,
8382
},
8483
},
8584
},
@@ -91,12 +90,14 @@ export const CustomSlotContent: Story = {
9190
value: 'Custom slot content',
9291
},
9392
render: args => html`
94-
<uui-text-copy .value=${args.value}> Custom Copy Text </uui-text-copy>
93+
<uui-button-copy-text .value=${args.value}>
94+
Custom Copy Text
95+
</uui-button-copy-text>
9596
`,
9697
parameters: {
9798
docs: {
9899
source: {
99-
code: `<uui-text-copy value="Custom slot content">Custom Copy Text</uui-text-copy>`,
100+
code: `<uui-button-copy-text value="Custom slot content">Custom Copy Text</uui-button-copy-text>`,
100101
},
101102
},
102103
},
@@ -109,19 +110,11 @@ export const ColorAndLook: Story = {
109110
color: 'positive',
110111
look: 'primary',
111112
},
112-
render: args => html`
113-
<uui-text-copy
114-
.value=${args.value}
115-
.color=${args.color || 'default'}
116-
.look=${args.look || 'default'}>
117-
<uui-icon name="copy"></uui-icon> Copy
118-
</uui-text-copy>
119-
`,
120113
parameters: {
121114
docs: {
122115
source: {
123116
code: `
124-
<uui-text-copy value="I have the same look and color props as UUI-Button" color="positive" look="primary"></uui-text-copy>
117+
<uui-button-copy-text value="I have the same look and color props as UUI-Button" color="positive" look="primary"></uui-button-copy-text>
125118
`,
126119
},
127120
},
@@ -134,19 +127,19 @@ export const CopiedEvent: Story = {
134127
value: 'Copy this text',
135128
},
136129
render: args => html`
137-
<uui-text-copy
130+
<uui-button-copy-text
138131
.value=${args.value}
139-
@copied=${(event: UUITextCopyEvent) => {
132+
@copied=${(event: UUICopyTextEvent) => {
140133
alert(`Copied text: ${event.detail.text}`);
141-
}}></uui-text-copy>
134+
}}></uui-button-copy-text>
142135
`,
143136
parameters: {
144137
docs: {
145138
source: {
146139
code: `
147-
<uui-text-copy value="Copy this text"></uui-text-copy>
140+
<uui-button-copy-text value="Copy this text"></uui-button-copy-text>
148141
<script>
149-
document.querySelector('uui-text-copy').addEventListener('copied', (event) => {
142+
document.querySelector('uui-button-copy-text').addEventListener('copied', (event) => {
150143
alert(\`Copied text: \${event.detail.text}\`);
151144
});
152145
</script>
@@ -164,7 +157,7 @@ export const ModifyClipboardContent: Story = {
164157
render: args => html`
165158
<uui-text-copy
166159
.value=${args.value}
167-
@copying=${(event: UUITextCopyEvent) => {
160+
@copying=${(event: UUICopyTextEvent) => {
168161
event.detail.text += ' - Modified before copying';
169162
}}></uui-text-copy>
170163
`,
@@ -189,9 +182,6 @@ export const EmptyValueErrorState: Story = {
189182
args: {
190183
copyFrom: 'idSelectorDoesNotExist',
191184
},
192-
render: args => html`
193-
<uui-text-copy .copyFrom=${args.copyFrom}></uui-text-copy>
194-
`,
195185
parameters: {
196186
docs: {
197187
source: {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { html, fixture, expect } from '@open-wc/testing';
2+
import { UUIButtonCopyTextElement } from './uui-button-copy-text.element';
3+
4+
describe('UUIButtonCopyTextElement', () => {
5+
let element: UUIButtonCopyTextElement;
6+
7+
beforeEach(async () => {
8+
element = await fixture(
9+
html`<uui-button-copy-text value="Oh hi there"></uui-button-copy-text>`,
10+
);
11+
});
12+
13+
it('is defined with its own instance', () => {
14+
expect(element).to.be.instanceOf(UUIButtonCopyTextElement);
15+
});
16+
17+
it('passes the a11y audit', async () => {
18+
await expect(element).shadowDom.to.be.accessible();
19+
});
20+
21+
it('renders correctly', async () => {
22+
expect(element).shadowDom.to.contain(
23+
'<uui-icon name="copy"></uui-icon> Copy',
24+
);
25+
});
26+
});

packages/uui-text-copy/lib/uui-text-copy.test.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)