-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
CodeModal.vue
87 lines (77 loc) 路 2.74 KB
/
CodeModal.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
<Modal :show.sync="show" :on-close="closeModal">
<h3 class="modal__title">
Copy CSS code
</h3>
<div class="modal__content">
<div class="modal__success" v-if="copied">
<p>{{this.showSuccessMessage()}}</p>
</div>
<pre class="codeblock" v-else><code>
<span class="codeblock__property">background</span>: <span class="codeblock__spec">{{ this.gradient.colors[0] | lowercase }}</span>; <span class="codeblock__comment">/* fallback for old browsers */</span>
<span class="codeblock__property">background</span>: -webkit-linear-gradient({{ this.direction }}, <span class="codeblock__spec">{{ [...this.gradient.colors].join(', ') | lowercase }}</span>); <span class="codeblock__comment">/* Chrome 10-25, Safari 5.1-6 */</span>
<span class="codeblock__property">background</span>: linear-gradient({{ this.direction }}, <span class="codeblock__spec">{{ [...this.gradient.colors].join(', ') | lowercase }}</span>); <span class="codeblock__comment">/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */</span>
</code></pre>
</div>
<button
class="btn"
id="js-copy"
v-clipboard="copyData"
@success="handleSuccess"
>
Click to copy
</button>
</Modal>
</template>
<script>
import Modal from '../Modal';
export default {
name: 'codemodal',
props: ['show', 'gradient', 'direction', 'closeModals'],
components: {
Modal,
},
data() {
return {
copied: false,
};
},
filters: {
lowercase(value) {
return (!value) ? '' : value.toString().toLowerCase();
},
},
computed: {
copyData() {
return `background: ${this.gradient.colors[0]}; /* fallback for old browsers */
background: -webkit-linear-gradient(${this.direction}, ${[...this.gradient.colors].reverse().join(', ')}); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(${this.direction}, ${[...this.gradient.colors].reverse().join(', ')}); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
`;
},
},
methods: {
closeModal() {
this.closeModals();
this.copied = false;
},
showSuccessMessage() {
const messages = [
'馃憡 You got it! Go make something awesome.',
'馃憣 Excellent Choice! It\'ll look amazing.',
'馃檶 Very well, master.',
'馃憤 Done. Go for it.',
'鉁岋笍 Nice one! You have good taste.',
];
const { length } = messages;
const randomMessage = Math.round(Math.random() * (length - 1));
return messages[randomMessage];
},
handleSuccess() {
const self = this;
this.$ga.event('copy css', 'click', this.gradient.name);
this.copied = true;
setTimeout(() => { self.copied = false; }, 1000);
},
},
};
</script>