Convert CopyCode component to Composition API (#124)

* Convert CopyCode component to Composition API

* ^^/
This commit is contained in:
Mysterious_Dev 2023-11-13 21:08:28 +01:00 committed by GitHub
parent 92116273b0
commit 06d6cb6d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,35 +6,24 @@
</button> </button>
</template> </template>
<script setup> <script setup lang="ts">
import { ref } from 'vue'
import { CheckIcon, ClipboardCopyIcon } from '@' import { CheckIcon, ClipboardCopyIcon } from '@'
import { useVIntl, defineMessage } from '@vintl/vintl' import { useVIntl, defineMessage } from '@vintl/vintl'
const copiedMessage = defineMessage({ const copiedMessage = defineMessage({
id: 'omorphia.component.copy.action.copy', id: 'omorphia.component.copy.action.copy',
defaultMessage: 'Copy code to clipboard', defaultMessage: 'Copy code to clipboard',
}) })
const { formatMessage } = useVIntl() const { formatMessage } = useVIntl()
</script>
<script> const props = defineProps<{ text: string }>()
export default {
props: { const copied = ref(false)
text: {
type: String, async function copyText() {
required: true, await navigator.clipboard.writeText(props.text)
}, copied.value = true
},
data() {
return {
copied: false,
}
},
methods: {
async copyText() {
await navigator.clipboard.writeText(this.text)
this.copied = true
},
},
} }
</script> </script>