2019-09-29 17:54:20 +08:00
|
|
|
<i18n>
|
|
|
|
{
|
|
|
|
"zh-cn": {
|
|
|
|
"show": "显示代码",
|
|
|
|
"hide": "收起代码"
|
|
|
|
},
|
|
|
|
"en-us": {
|
|
|
|
"show": "Show Code",
|
|
|
|
"hide": "Hide Code"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</i18n>
|
|
|
|
|
2019-09-17 19:24:39 +08:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="n-code-box"
|
|
|
|
:class="{
|
|
|
|
[`n-${synthesizedTheme}-theme`]: synthesizedTheme
|
|
|
|
}"
|
2019-10-10 23:01:25 +08:00
|
|
|
n-dark-theme-background-color-hint="#1e2437"
|
2019-09-20 00:22:55 +08:00
|
|
|
n-light-theme-background-color-hint="white"
|
2019-09-17 19:24:39 +08:00
|
|
|
>
|
|
|
|
<div class="n-code-box__title">
|
|
|
|
<slot name="title" />
|
2019-09-21 17:03:37 +08:00
|
|
|
<n-tooltip
|
2019-09-28 13:47:54 +08:00
|
|
|
:delay="300"
|
2019-09-21 17:03:37 +08:00
|
|
|
:placement="'top'"
|
|
|
|
:arrow="true"
|
2019-09-29 19:07:16 +08:00
|
|
|
:controller="controller"
|
2019-09-21 17:03:37 +08:00
|
|
|
>
|
|
|
|
<template v-slot:activator>
|
|
|
|
<n-button
|
|
|
|
size="tiny"
|
|
|
|
ghost
|
|
|
|
icon="md-code"
|
|
|
|
circle
|
|
|
|
@click="toggleCodeDisplay"
|
|
|
|
/>
|
|
|
|
</template>
|
2019-09-29 17:54:20 +08:00
|
|
|
{{ !showCode ? $t('show') : $t('hide') }}
|
2019-09-21 17:03:37 +08:00
|
|
|
</n-tooltip>
|
2019-09-17 19:24:39 +08:00
|
|
|
</div>
|
2019-09-22 22:59:11 +08:00
|
|
|
<div class="n-code-box__content markdown">
|
2019-09-17 19:24:39 +08:00
|
|
|
<slot name="content" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="n-code-box__view"
|
|
|
|
>
|
|
|
|
<slot name="demo" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="showCode"
|
|
|
|
class="n-code-box__code"
|
|
|
|
>
|
2019-09-27 15:56:33 +08:00
|
|
|
<n-scrollbar>
|
|
|
|
<slot name="code" />
|
|
|
|
</n-scrollbar>
|
2019-09-17 19:24:39 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-09-23 15:04:57 +08:00
|
|
|
import withapp from '../../packages/mixins/withapp'
|
|
|
|
import themeable from '../../packages/mixins/themeable'
|
2019-09-17 19:24:39 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [withapp, themeable],
|
2019-10-14 17:49:23 +08:00
|
|
|
inject: {
|
|
|
|
NDocumentation: {
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
2019-09-17 19:24:39 +08:00
|
|
|
data () {
|
|
|
|
return {
|
2019-09-20 00:22:55 +08:00
|
|
|
showCode: false,
|
|
|
|
lightThemeCSSRef: null,
|
2019-09-29 19:07:16 +08:00
|
|
|
defaultThemeCSSRef: null,
|
|
|
|
controller: {}
|
2019-09-17 19:24:39 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-20 00:22:55 +08:00
|
|
|
watch: {
|
|
|
|
synthesizedTheme (value) {
|
|
|
|
|
2019-09-29 19:07:16 +08:00
|
|
|
},
|
|
|
|
showCode () {
|
|
|
|
this.$nextTick().then(() => {
|
|
|
|
this.controller.updatePosition()
|
|
|
|
})
|
2019-09-20 00:22:55 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
2019-10-14 17:49:23 +08:00
|
|
|
const map = this.NDocumentation.anchorLinkMap
|
|
|
|
map.set(this.$el.id, String(this.$scopedSlots.title()[0].text).trim())
|
|
|
|
this.NDocumentation.anchorLinkMap = new Map(map, this.$scopedSlots.title()[0].text.trim())
|
2019-09-20 00:22:55 +08:00
|
|
|
},
|
2019-09-17 19:24:39 +08:00
|
|
|
methods: {
|
2019-09-20 00:22:55 +08:00
|
|
|
switchHighlightStyle () {
|
|
|
|
|
|
|
|
},
|
|
|
|
toggleCodeDisplay () {
|
2019-09-17 19:24:39 +08:00
|
|
|
this.showCode = !this.showCode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|