code-snippet.vue
2.56 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<template>
<div class="eagle-code-snippet">
<div class="eagle-code-snippet--demo">
<slot name="source"></slot>
</div>
<div class="eagle-code-snippet--desc">
<slot name="desc"></slot>
<span class="eagle-code-snippet--icon-code"
@click="showCode = !showCode"
title="查看代码"
>
<img v-if="showCode"
src="@/assets/images/icon/code-open.svg" />
<img v-else
src="@/assets/images/icon/code-close.svg" />
</span>
</div>
<eagle-code-collapse>
<div v-show="showCode"
class="eagle-code-snippet--code">
<slot name="code"></slot>
</div>
</eagle-code-collapse>
</div>
</template>
<script>
import EagleCodeCollapse from "./code-collapse"
export default {
components: { EagleCodeCollapse },
data() {
return {
showCode: false
};
}
};
</script>
<style lang="scss">
.eagle-code-snippet {
position: relative;
box-sizing: border-box;
width: 100%;
margin: 0 0 16px;
border-radius: 4px;
transition: all 0.2s;
@include themify($themes) {
border: 1px solid themed('border');
}
background-color: inherit;
text-align: left;
// element-ui样式冲突
ul > li {
list-style-type: none !important;
margin: 0px !important;
padding: 0px !important;
}
.el-pagination.is-background .el-pager li {
margin: 0 5px !important;
}
}
.eagle-code-snippet--demo {
box-sizing: border-box;
padding: 30px 35px;
color: inherit;
@include themify($themes) {
border-bottom: 1px solid themed('border');
}
}
.eagle-code-snippet--desc {
position: relative;
box-sizing: border-box;
width: 100%;
padding: 0 20px;
font-size: 14px;
transition: background-color 0.4s;
line-height: 1.5;
display: flex;
align-items: center;
justify-content: space-between;
}
.eagle-code-snippet--icon-code {
cursor: pointer;
min-width: 18px;
width: 18px;
height: 18px;
text-align: center;
> img {
transition: all 0.4s;
user-select: none;
max-width: 100%;
width: 100%;
vertical-align: baseline;
box-shadow: none;
}
}
.eagle-code-snippet--code {
box-sizing: border-box;
@include themify($themes) {
border-top: 1px solid themed('border');
}
code {
@include themify($themes) {
background-color: themed('background');
}
font-family: Consolas, Menlo, Courier, monospace;
border: none;
display: block;
font-size: 14px;
padding: 16px 32px;
line-height: 1.5;
}
.hljs {
padding: 0;
margin: 0;
code {
margin: 0;
}
}
}
</style>