naive-ui/demo/utils/ComponentDemo.vue

103 lines
2.0 KiB
Vue
Raw Normal View History

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>
2019-12-22 23:19:08 +08:00
<n-card
class="demo-card"
:segmented="{
footer: true
2019-09-17 19:24:39 +08:00
}"
2019-12-22 23:19:08 +08:00
:content-style="contentStyle"
2019-09-17 19:24:39 +08:00
>
2019-12-22 23:19:08 +08:00
<template v-slot:header>
2019-11-17 00:57:30 +08:00
<slot name="title" />
2019-12-22 23:19:08 +08:00
</template>
<template v-slot:header-extra>
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
circle
@click="toggleCodeDisplay"
2019-10-24 18:04:31 +08:00
>
<template v-slot:icon>
<md-code />
</template>
</n-button>
2019-09-21 17:03:37 +08:00
</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-12-22 23:19:08 +08:00
</template>
<slot name="content" />
2019-09-17 19:24:39 +08:00
<div
2019-12-22 23:19:08 +08:00
class="demo-card__view"
2019-09-17 19:24:39 +08:00
>
<slot name="demo" />
</div>
2019-12-22 23:19:08 +08:00
<template v-slot:footer v-if="showCode">
2019-09-27 15:56:33 +08:00
<n-scrollbar>
<slot name="code" />
</n-scrollbar>
2019-12-22 23:19:08 +08:00
</template>
</n-card>
2019-09-17 19:24:39 +08:00
</template>
<script>
2019-10-24 18:04:31 +08:00
import mdCode from '../../packages/icons/md-code'
2019-09-17 19:24:39 +08:00
export default {
2019-10-24 18:04:31 +08:00
components: {
mdCode
},
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,
2019-12-22 23:19:08 +08:00
contentStyle: null,
2019-09-29 19:07:16 +08:00
controller: {}
2019-09-17 19:24:39 +08:00
}
},
2019-09-20 00:22:55 +08:00
watch: {
2019-09-29 19:07:16 +08:00
showCode () {
2019-12-22 23:19:08 +08:00
this.contentStyle = {
transition: 'none'
}
2019-09-29 19:07:16 +08:00
this.$nextTick().then(() => {
this.controller.updatePosition()
2019-12-22 23:19:08 +08:00
this.contentStyle = null
2019-09-29 19:07:16 +08:00
})
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
toggleCodeDisplay () {
2019-09-17 19:24:39 +08:00
this.showCode = !this.showCode
}
}
}
</script>