Skip to content

Commit 4da1a03

Browse files
committed
feat(popover): add copy to clipboard for elements
1 parent e108b88 commit 4da1a03

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/components/popover.riot

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</div>
1111
<div each="{ style in Object.keys(props.styleProps) }">
1212
<template if="{ props.styleProps[style] }">
13-
{ style }: <code>{ props.styleProps[style] }</code>
13+
{ style }: <code onclick="{ copyToClipboard }">{ props.styleProps[style] }</code>
1414
<span if="{ style.indexOf('color') > -1}" class="popover-color" color="{ props.styleProps[style] }"></span>
1515
</template>
1616
</div>
@@ -32,6 +32,13 @@
3232
onUpdated(props, state) {
3333
this.updateColors(props, state);
3434
},
35+
copyToClipboard(e) {
36+
navigator.clipboard.writeText(e.target.innerHTML);
37+
e.target.style['background-color'] = '#8bc34a';
38+
setTimeout(() => {
39+
e.target.style['background-color'] = null;
40+
}, 4000);
41+
},
3542
};
3643
</script>
3744
<style>
@@ -93,5 +100,9 @@
93100
height: 0.8rem;
94101
background-color: #fff;
95102
}
103+
code {
104+
cursor: pointer;
105+
transition: background-color 0.5s ease-out;
106+
}
96107
</style>
97108
</popover>

0 commit comments

Comments
 (0)