Skip to content

KClipboardProvider

<KClipboardProvider /> Provide clipboard functionality to components.

html
<template>
  <KInput :model-value="dataToCopy" @input="newValue => dataToCopy = newValue" type="text" />
  <KClipboardProvider v-slot="{ copyToClipboard }">
    <KButton @click="() => { if (copyToClipboard(dataToCopy)) alert(`Copied '${dataToCopy}'`) }">
      copy to clipboard
    </KButton>
  </KClipboardProvider>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const dataToCopy = ref('copy this to the clipboard')

    const alert = (msg: string): void => {
      window.alert(msg)
    }

    return { dataToCopy, alert }
  }
})
</script>

Slots

  • default - content to toggle.

Slot Props

PropsTypeDescription
copyToClipboardFunctioncopy to clipboard @returns {Boolean}

Released under the Apache-2.0 License.