[Enhancement] Add CopyToClipboard action in code component (#329)
* Add CopyToClipboard action in websiteWidgetCode component * Fix codeclimate issues
This commit is contained in:
48
app/javascript/dashboard/components/Code.vue
Normal file
48
app/javascript/dashboard/components/Code.vue
Normal file
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<div class="code--container">
|
||||
<button class="button small button--copy-code" @click="onCopy">
|
||||
{{ $t('COMPONENTS.CODE.BUTTON_TEXT') }}
|
||||
</button>
|
||||
<highlight-code :lang="lang">
|
||||
{{ script }}
|
||||
</highlight-code>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* global bus */
|
||||
import 'highlight.js/styles/default.css';
|
||||
import copy from 'copy-text-to-clipboard';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
script: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
lang: {
|
||||
type: String,
|
||||
default: 'javascript',
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onCopy() {
|
||||
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>
|
||||
@@ -1,26 +1,28 @@
|
||||
/* eslint no-plusplus: 0 */
|
||||
/* eslint-env browser */
|
||||
|
||||
import Bar from './widgets/chart/BarChart';
|
||||
import Code from './Code';
|
||||
import LoadingState from './widgets/LoadingState';
|
||||
import Modal from './Modal';
|
||||
import ModalHeader from './ModalHeader';
|
||||
import ReportStatsCard from './widgets/ReportStatsCard';
|
||||
import Spinner from './Spinner';
|
||||
import SubmitButton from './buttons/FormSubmitButton';
|
||||
import Tabs from './ui/Tabs/Tabs';
|
||||
import TabsItem from './ui/Tabs/TabsItem';
|
||||
import LoadingState from './widgets/LoadingState';
|
||||
import ReportStatsCard from './widgets/ReportStatsCard';
|
||||
import Bar from './widgets/chart/BarChart';
|
||||
import ModalHeader from './ModalHeader';
|
||||
|
||||
const WootUIKit = {
|
||||
Bar,
|
||||
Code,
|
||||
LoadingState,
|
||||
Modal,
|
||||
ModalHeader,
|
||||
ReportStatsCard,
|
||||
Spinner,
|
||||
SubmitButton,
|
||||
Tabs,
|
||||
TabsItem,
|
||||
LoadingState,
|
||||
ReportStatsCard,
|
||||
Bar,
|
||||
ModalHeader,
|
||||
install(Vue) {
|
||||
const keys = Object.keys(this);
|
||||
keys.pop(); // remove 'install' from keys
|
||||
|
||||
Reference in New Issue
Block a user