/
ViewCode.vue
52 lines (45 loc) · 1.1 KB
/
ViewCode.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
<template>
<button v-if="isActive" class="button is-small is-primary" @click="open" :title="url">
<i class="fa fa-code"></i> {{ label || text }}
</button>
</template>
<script>
import { actions, dispatch } from 'codesandbox-api';
export default {
props: {
src: String,
label: String
},
computed: {
isActive () {
return this.src
},
isCodeSandbox () {
return window.location.href.includes('codesandbox')
},
url () {
return this.isCodeSandbox
? `/src/${this.src}`
: `${this.$site.repo}/tree/master/${this.src}`
},
text () {
const action = this.isCodeSandbox
? 'Edit'
: 'View'
const object = this.src.includes('.vue')
? 'component'
: this.src.includes('/vuex')
? 'store'
: 'code'
return `${action} ${object}`
}
},
methods: {
open() {
this.isCodeSandbox
? dispatch(actions.editor.openModule(this.url))
: window.open(this.url, '_github')
},
}
}
</script>