2019-11-30 12:03:42 +00:00
|
|
|
<template>
|
|
|
|
<div class="code--container">
|
|
|
|
<button class="button small button--copy-code" @click="onCopy">
|
|
|
|
{{ $t('COMPONENTS.CODE.BUTTON_TEXT') }}
|
|
|
|
</button>
|
2021-02-08 11:09:15 +00:00
|
|
|
<highlightjs v-if="script" :language="lang" :code="script" />
|
2019-11-30 12:03:42 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import 'highlight.js/styles/default.css';
|
|
|
|
import copy from 'copy-text-to-clipboard';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
script: {
|
|
|
|
type: String,
|
2021-02-08 11:09:15 +00:00
|
|
|
default: '',
|
2019-11-30 12:03:42 +00:00
|
|
|
},
|
|
|
|
lang: {
|
|
|
|
type: String,
|
|
|
|
default: 'javascript',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2020-03-10 18:32:15 +00:00
|
|
|
onCopy(e) {
|
|
|
|
e.preventDefault();
|
2019-11-30 12:03:42 +00:00
|
|
|
copy(this.script);
|
|
|
|
bus.$emit('newToastMessage', this.$t('COMPONENTS.CODE.COPY_SUCCESSFUL'));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.code--container {
|
|
|
|
position: relative;
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
.button--copy-code {
|
|
|
|
margin-top: 0;
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|