Copy
KCopy is a component that displays provided text and allows a user to copy it to their clipboard.
<KCopy :text="text" />
Props
text
The copyable text.
format
Determines the display format of the copyable text. The component can take the following format
values:
default
hidden
redacted
deleted
default
Displays regular copyable text.
<KCopy :text="text" />
hidden
Displays just a copy button without text.
<KCopy
format="hidden"
:text="text"
/>
redacted
Displays *****
.
<KCopy
format="redacted"
:text="text"
/>
deleted
Displays *<first-5-chars-of-copyable-text>
.
<KCopy
format="deleted"
:text="text"
/>
badge
Whether or not to display as a badge. Defaults to false
.
<KCopy
badge
truncate
:text="text"
/>
badgeLabel
Text displayed before the copyable text when badge
is true.
<KCopy
badge
badge-label="Service ID:"
:text="text"
/>
truncate
Whether or not the text should be truncated. Defaults to false
. If truncate is false
the text will be truncated only when badge
is true
.
<KCopy
truncate
:text="text"
/>
truncationLimit
Number of characters to truncate at. Defaults to 8
.
<KCopy
truncate
:text="text"
:truncation-limit="15"
/>
If you specify 'auto'
for the truncationLimit
the text will only truncate if there is not enough space for it to be fully displayed.
<KCopy
badge
badge-label="Truncated(auto):"
truncate
:text="longUrl"
truncation-limit="auto"
/>
<KCopy
badge
badge-label="Truncated(20ch):"
truncate
:text="longUrl"
:truncation-limit="20"
/>
copyTooltip
Tooltip text displayed on hover copy button. If the badgeLabel
prop has a value, then the copy tooltip text is Copy {badgeLabel}
and the trailing colon from label if one exists will be stripped; otherwise the copy tooltip text is Copy
.
<KCopy
:text="text"
badge
badge-label="Service ID:"
copy-tooltip="Copy to clipboard"
/>
textTooltip
Tooltip text displayed on hover over the text
.
<KCopy
truncate
:text="text"
text-tooltip="Hello!"
/>
successTooltip
Tooltip text displayed on successful copy. Defaults to Copied!
.
monospace
When badge
is true
, use this prop to control whether the copyable text has JetBrains Mono
font or not. Defaults to false
.
<KCopy badge monospace :text="text" />
Usage
copy
KCopy exposes copy
method that can be used to trigger copy from outside the component. Here is an example of KCopy inside of KButton, clicking on which will trigger KCopy to copy the text.
<template>
<KButton @click="onButtonClick">
<KCopy format="hidden" ref="kCopyElement" :text="text" />
</KButton>
</template>
<script setup lang="ts">
import { KCopy } from '@kong/kongponents'
const text = '12345-6789-ABCD-EFGH-PQRSTUV-WXYZ'
const kCopyElement = ref<InstanceType<typeof KCopy> | null>(null)
const onButtonClick = (): void => {
kCopyElement.value?.copy()
}
</script>