feat: add demo edit link

This commit is contained in:
Justineo 2021-10-25 20:18:05 +08:00
parent e69f8fcc3c
commit a3d118cdbd
No known key found for this signature in database
GPG Key ID: B73F0979CF18A0EA
4 changed files with 72 additions and 28 deletions

View File

@ -49,6 +49,11 @@
:name="localExpanded ? 'one-demo-code-off' : 'one-demo-code'" :name="localExpanded ? 'one-demo-code-off' : 'one-demo-code'"
/> />
</veui-button> </veui-button>
<one-edit-link
class="edit"
variant="quiet"
:path="path"
/>
</section> </section>
<section <section
v-if="$slots.source" v-if="$slots.source"
@ -68,6 +73,7 @@ import i18n from 'veui/mixins/i18n'
import { BrowserWindow } from 'vue-windows' import { BrowserWindow } from 'vue-windows'
import { getLocale } from '../common/i18n' import { getLocale } from '../common/i18n'
import { play } from '../common/play' import { play } from '../common/play'
import OneEditLink from './OneEditLink'
export default { export default {
name: 'one-demo', name: 'one-demo',
@ -77,12 +83,14 @@ export default {
components: { components: {
'veui-button': Button, 'veui-button': Button,
'veui-icon': Icon, 'veui-icon': Icon,
BrowserWindow BrowserWindow,
OneEditLink
}, },
mixins: [i18n], mixins: [i18n],
props: { props: {
expanded: Boolean, expanded: Boolean,
browser: String browser: String,
path: String
}, },
data () { data () {
return { return {
@ -193,4 +201,11 @@ Icon.register({
.veui-button + .veui-button .veui-button + .veui-button
margin-left 12px margin-left 12px
.edit
position absolute
right 30px
top 50%
transform translateY(-50%)
font-size 12px
</style> </style>

View File

@ -1,15 +1,24 @@
<template> <template>
<a <a
class="one-edit-link" class="one-edit-link"
:class="
variant
? {
[`one-edit-link-${variant}`]: true,
}
: {}
"
:href="href" :href="href"
target="_blank" target="_blank"
rel="noopener" rel="noopener"
> >
{{ t('editOnGitHub') }} <slot :label="t('editOnGitHub')">
{{ t("editOnGitHub") }}
<veui-icon <veui-icon
class="icon" class="icon"
name="external-link" name="external-link"
/> />
</slot>
</a> </a>
</template> </template>
@ -27,6 +36,10 @@ export default {
}, },
mixins: [i18n], mixins: [i18n],
props: { props: {
variant: {
type: String,
default: 'default'
},
path: String path: String
}, },
computed: { computed: {
@ -39,6 +52,10 @@ export default {
<style lang="stylus" scoped> <style lang="stylus" scoped>
.one-edit-link .one-edit-link
text-decoration none
transition background 0.2s, color 0.2s, border-color 0.2s
&-default
display inline-flex display inline-flex
align-items center align-items center
padding 4px 6px padding 4px 6px
@ -46,8 +63,6 @@ export default {
background-color #fff background-color #fff
color #848b99 color #848b99
border 1px solid #e2e6f0 border 1px solid #e2e6f0
transition background 0.2s, color 0.2s, border-color 0.2s
text-decoration none
&:hover &:hover
&[data-focus-visible-added] &[data-focus-visible-added]
@ -62,4 +77,14 @@ export default {
.icon .icon
margin-left 4px margin-left 4px
&-quiet
color #282c33
&:hover
&[data-focus-visible-added]
color #545b66
&:active
color #000
</style> </style>

View File

@ -8,14 +8,15 @@ export default function attacher () {
let { tagName } = node let { tagName } = node
let [name] = tagName.match(RE_DEMO) || [] let [name] = tagName.match(RE_DEMO) || []
if (name) { if (name) {
let { code, desc, browser } = data.demos[name] || {} let { code, desc, browser, path } = data.demos[name] || {}
if (!code) { if (!code) {
return return
} }
let demo = h('one-demo', let demo = h('one-demo',
{ {
browser browser,
path
}, },
[ [
node, node,

View File

@ -40,6 +40,8 @@ export default function attacher () {
? resolve(DOCS_DIR, src.slice(1)) ? resolve(DOCS_DIR, src.slice(1))
: resolve(dirname(path), src) : resolve(dirname(path), src)
let demoRelativePath = relative(DOCS_DIR, demoPath)
if (!existsSync(demoPath)) { if (!existsSync(demoPath)) {
console.warn(`Demo not found at '${demoPath}'`) console.warn(`Demo not found at '${demoPath}'`)
return return
@ -55,7 +57,8 @@ export default function attacher () {
let { content, doc } = extractDoc(demoPath, { locale }) let { content, doc } = extractDoc(demoPath, { locale })
fileData.demos[name] = { fileData.demos[name] = {
path: demoPath, filePath: demoPath,
path: demoRelativePath,
browser, browser,
code: render('```vue\n' + content + '\n```', demoPath).contents, code: render('```vue\n' + content + '\n```', demoPath).contents,
desc: render(doc, demoPath).contents desc: render(doc, demoPath).contents