CopyButton
A button component that copies text to the clipboard when clicked.
Component
Props
| Props | Required | Default | Type |
|---|---|---|---|
textToCopy | true | Sample text to copy | string |
copySuccessText | — | Copied to clipboard! | string |
copyErrorText | — | Failed to copy to clipboard. | string |
showToast | — | true | boolean |
resetAfter | — | 1500 | number |
buttonType | — | ButtonType.ACTION_ICON_BUTTON | ButtonTypeAllowed types: All except DELETE styles. |
styleType | — | ButtonStyleType.NEUTRAL_OUTLINED | ButtonStyleType |
text | — | Copy | string |
size | — | ButtonSize.LG | ButtonSize |
icon | — | mdi:content-copy | string |
iconPosition | — | IconPosition.RIGHT | IconPosition |
disabled | — | false | boolean |
Usage
textToCopy
The textToCopy prop defines the text that will be copied to the clipboard when the button is clicked.
<template>
<CopyButton textToCopy="This is the text to be copied!" />
</template>
copySuccessText
The copySuccessText prop defines the message displayed when the text is successfully copied to the clipboard.
It only works when showToast is set to true or when using the ButtonType.ACTION_BUTTON button type.
<template>
<CopyButton copySuccessText="Text copied successfully!" />
</template>
copyErrorText
The copyErrorText prop defines the message displayed when there is an error copying the text to the clipboard.
It only works when showToast is set to true or when using the ButtonType.ACTION_BUTTON button type.
<template>
<CopyButton copyErrorText="Unable to copy text." />
</template>
showToast
The showToast prop determines whether a toast notification is displayed when the text is copied successfully or if there is an error.
<template>
<CopyButton showToast />
</template>
resetAfter
The resetAfter prop defines the time in milliseconds after which the button resets to its original state after a copy action.
<template>
<CopyButton :resetAfter="2000" />
</template>
buttonType
The buttonType prop defines the type of the copy button using the ButtonType enum.
<template>
<CopyButton :buttonType="ButtonType.ACTION_BUTTON" />
</template>
Options
| Value | Description |
|---|---|
ACTION_ICON_BUTTON | A square button with an icon for copy action. |
ACTION_BUTTON | A standard action button with text and optional icon. |
styleType
The styleType prop controls the visual style of the button using the ButtonStyleType enum.
Important: The DELETE styles are not available for this component.
<template>
<CopyButton :styleType="ButtonStyleType.PRIMARY_BRAND_FILLED" />
</template>
Options
| Value | Description |
|---|---|
PRIMARY_BRAND_FILLED | Primary brand filled |
PRIMARY_BRAND_TRANSPARENT | Primary brand transparent |
PRIMARY_BRAND_SOFT | Primary brand soft |
SECONDARY_BRAND_FILLED | Secondary brand filled |
NEUTRAL_OUTLINED | Neutral outlined |
NEUTRAL_TRANSPARENT | Neutral transparent |
NEUTRAL_TRANSPARENT_SUBTLE | Neutral transparent subtle |
NEUTRAL_FILLED | Neutral filled |
text
The text prop defines the label displayed on the copy button.
<template>
<CopyButton text="Copy Text" />
</template>
size
The size prop controls the size of the button using the ButtonSize enum.
<template>
<CopyButton :size="ButtonSize.SM" />
</template>
Options
| Value | Description |
|---|---|
XS | xs |
SM | sm |
MD | md |
LG | lg |
XL | xl |
XXL | 2xl |
icon
The icon prop specifies the Material Design Icon to be displayed on the button.
<template>
<CopyButton icon="mdi:content-copy" />
</template>
iconPosition
The iconPosition prop determines the position of the icon relative to the button text using the IconPosition enum.
<template>
<CopyButton
icon="mdi:content-copy"
:iconPosition="IconPosition.RIGHT"
/>
</template>
Options
| Value | Description |
|---|---|
LEFT | left |
RIGHT | right |
NONE | none (icon does not appear at all) |
disabled
The disabled prop disables the copy button when set to true.
<template>
<CopyButton disabled />
</template>
Emits
| Value | Description |
|---|---|
@success | Emitted when the text is successfully copied to the clipboard. |
@error | Emitted when there is an error copying the text to the clipboard. |
Example
<template>
<CopyButton
@success="handleSuccess"
@error="handleError"
/>
</template>
<script setup lang="ts">
const handleSuccess = () => {
console.log("Text copied successfully")
}
const handleError = () => {
console.log("Error copying text")
}
</script>