Files
tauri-plugins-workspace/examples/api/src/views/Clipboard.svelte
T
Lucas Fernandes Nogueira 5015132ece feat: add API example (#317)
2023-05-05 09:41:17 -03:00

33 lines
715 B
Svelte

<script>
import { writeText, readText } from 'tauri-plugin-clipboard-api'
export let onMessage
let text = 'clipboard message'
function write() {
writeText(text)
.then(() => {
onMessage('Wrote to the clipboard')
})
.catch(onMessage)
}
function read() {
readText()
.then((contents) => {
onMessage(`Clipboard contents: ${contents}`)
})
.catch(onMessage)
}
</script>
<div class="flex gap-1">
<input
class="grow input"
placeholder="Text to write to the clipboard"
bind:value={text}
/>
<button class="btn" type="button" on:click={write}>Write</button>
<button class="btn" type="button" on:click={read}>Read</button>
</div>