Skip to content

Commit 483beed

Browse files
authored
Merge pull request #88 from umbraco/fix/refactor-css-custom-properties-story
2 parents 936adad + 190b493 commit 483beed

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

packages/uui-css/lib/custom-properties.story.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { html, svg } from 'lit-html';
33
// eslint-disable-next-line -- // @typescript-eslint/ban-ts-comment // @ts-ignore
44
import customProperties from '../custom-properties.module.js'; // eslint-disable-line
55
// @ts-ignore-end
6-
76
const properties = Object.keys(customProperties.customProperties).map(
87
// @ts-ignore
98
key => ({ key: key, value: customProperties.customProperties[key] })
@@ -17,22 +16,24 @@ export default {
1716
title: 'Design/Custom properties',
1817
};
1918

20-
const copyToClipboard = (text: string) => {
21-
navigator.clipboard.writeText(text);
19+
const copyToClipboard = (e: Event) => {
20+
const button = e.target as any;
21+
const text = button.dataset.copyToClipboard;
22+
if (text) {
23+
navigator.clipboard.writeText(text);
24+
button.state = 'success';
25+
}
2226
};
2327

2428
const propertyColorTemplate = (property: any) => html` <uui-table-row>
2529
<uui-table-cell
2630
><div
2731
style="display: flex; justify-content: space-between; align-items: center;">
2832
${property.key}<uui-button
29-
title="Copy to clipboard"
33+
data-copy-to-clipboard=${property.key}
34+
title="Copy custom property to clipboard"
35+
label="Copy custom property to clipboard"
3036
compact
31-
@click=${(e: MouseEvent) => {
32-
copyToClipboard(property.key);
33-
const button = e.target as any;
34-
button.state = 'success';
35-
}}
3637
>${copyIcon}</uui-button
3738
>
3839
</div></uui-table-cell
@@ -42,13 +43,10 @@ const propertyColorTemplate = (property: any) => html` <uui-table-row>
4243
style="display: flex; justify-content: space-between; align-items: center;">
4344
<code>${property.value}</code
4445
><uui-button
45-
title="Copy to clipboard"
46+
data-copy-to-clipboard=${property.value}
47+
title="Copy color value to clipboard"
48+
label="Copy color value to clipboard"
4649
compact
47-
@click=${(e: MouseEvent) => {
48-
copyToClipboard(property.value);
49-
const button = e.target as any;
50-
button.state = 'success';
51-
}}
5250
>${copyIcon}</uui-button
5351
>
5452
</div>
@@ -64,13 +62,10 @@ const propertySizeTemplate = (property: any) => html` <uui-table-row>
6462
><div
6563
style="display: flex; justify-content: space-between; align-items: center;">
6664
${property.key}<uui-button
67-
title="Copy to clipboard"
65+
data-copy-to-clipboard=${property.key}
66+
title="Copy custom property to clipboard"
67+
label="Copy custom property to clipboard"
6868
compact
69-
@click=${(e: MouseEvent) => {
70-
copyToClipboard(property.key);
71-
const button = e.target as any;
72-
button.state = 'success';
73-
}}
7469
>${copyIcon}</uui-button
7570
>
7671
</div></uui-table-cell
@@ -80,13 +75,10 @@ const propertySizeTemplate = (property: any) => html` <uui-table-row>
8075
style="display: flex; justify-content: space-between; align-items: center;">
8176
<code>${property.value}</code
8277
><uui-button
83-
title="Copy to clipboard"
78+
data-copy-to-clipboard=${property.value}
79+
title="Copy size value to clipboard"
80+
label="Copy size value to clipboard"
8481
compact
85-
@click=${(e: MouseEvent) => {
86-
copyToClipboard(property.value);
87-
const button = e.target as any;
88-
button.state = 'success';
89-
}}
9082
>${copyIcon}</uui-button
9183
>
9284
</div>
@@ -100,7 +92,7 @@ export const Looks = () => html` <h2>Looks</h2>
10092
</p>
10193
10294
<h3>Primary Look</h3>
103-
<uui-table>
95+
<uui-table @click=${copyToClipboard}>
10496
<uui-table-head>
10597
<uui-table-head-cell>Custom property name</uui-table-head-cell>
10698
<uui-table-head-cell>Value</uui-table-head-cell>
@@ -190,7 +182,7 @@ export const InterfaceColors = () => html`
190182
properties. The fallback values are inserted automatically during build.
191183
</p>
192184
193-
<uui-table>
185+
<uui-table @click=${copyToClipboard}>
194186
<uui-table-head>
195187
<uui-table-head-cell>Custom property name</uui-table-head-cell>
196188
<uui-table-head-cell>Value</uui-table-head-cell>
@@ -209,7 +201,7 @@ export const BrandColors = () => html`<h2>Colors</h2>
209201
interface color properties. Here is an overview of colors:
210202
</p>
211203
212-
<uui-table>
204+
<uui-table @click=${copyToClipboard}>
213205
<uui-table-head>
214206
<uui-table-head-cell>Custom property name</uui-table-head-cell>
215207
<uui-table-head-cell>Value</uui-table-head-cell>
@@ -223,7 +215,7 @@ export const BrandColors = () => html`<h2>Colors</h2>
223215
export const Sizing = () => html`
224216
<h2>Sizing</h2>
225217
226-
<uui-table>
218+
<uui-table @click=${copyToClipboard}>
227219
<uui-table-head>
228220
<uui-table-head-cell>Custom property name</uui-table-head-cell>
229221
<uui-table-head-cell>Value</uui-table-head-cell>

0 commit comments

Comments
 (0)