You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tagline: A button that allows easy copying of text to the clipboard.
4
+
thumbnail: "./thumbnails/modal.png"
5
+
---
6
+
7
+
The `<hyperkit-copyable />` element provides an easy way to copy specified text to the user's clipboard. It wraps a button element, which, when clicked, copies the provided text value to the clipboard. Additionally, it fires a `copied` event when the action is successful and sets a `data-copied` attribute on the button.
8
+
9
+
{% example hero=true %}{% copyable / %}{% /example %}
10
+
11
+
## Usage
12
+
13
+
Import the JS:
14
+
```js
15
+
import "@hyperkitxyz/elements/copyable";
16
+
```
17
+
18
+
Tag:
19
+
```html
20
+
<hyperkit-copyable value="Text to copy">
21
+
<button>Copy</button>
22
+
</hyperkit-copyable>
23
+
```
24
+
25
+
### Options
26
+
27
+
{% table %}
28
+
* Attribute
29
+
* Value
30
+
*
31
+
---
32
+
* `value`
33
+
* String _(required)_
34
+
* Specifies the text that will be copied to the clipboard when the button is clicked.
35
+
---
36
+
{% /table %}
37
+
38
+
### Children
39
+
40
+
```html
41
+
<hyperkit-copyable value="Text to copy">
42
+
<button>Copy</button>
43
+
</hyperkit-copyable>
44
+
```
45
+
46
+
#### `<button />`
47
+
* The button that triggers the copy action when clicked.
48
+
* Can be styled according to your needs and can contain any text or content.
49
+
50
+
## JavaScript API
51
+
52
+
The `hyperkit-copyable` element provides a simple JavaScript API to interact with its functionality and listen for events.
53
+
54
+
### Listening for the `copied` Event
55
+
56
+
The element emits a `copied` event whenever the text is successfully copied to the clipboard. You can listen for this event to respond to the copy action:
0 commit comments