Skip to content
This repository was archived by the owner on Jan 9, 2022. It is now read-only.

Commit af6cf6d

Browse files
committed
refactor: make dynamic import for examples
1 parent 95f74e9 commit af6cf6d

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<div>
3+
<Component
4+
:is="component"
5+
v-if="component"
6+
v-bind="{
7+
...$attrs,
8+
}"
9+
/>
10+
</div>
11+
</template>
12+
13+
<script>
14+
import { defineComponent, shallowRef } from 'vue'
15+
16+
export default defineComponent({
17+
name: 'Example',
18+
props: {
19+
file: {
20+
type: String,
21+
required: true,
22+
},
23+
},
24+
25+
data: () => ({
26+
component: null,
27+
}),
28+
29+
created() {
30+
this.load()
31+
},
32+
33+
methods: {
34+
async load() {
35+
try {
36+
const res = await import(`../Examples/${this.file}.vue`)
37+
console.log('🚀 ~ file: Example.vue ~ line 38 ~ load ~ res2', res2)
38+
39+
this.component = shallowRef(res.default)
40+
} catch (error) {
41+
console.log('🚀 ~ file: Example.vue ~ line 32 ~ load ~ error', error)
42+
}
43+
},
44+
},
45+
})
46+
</script>

docs/src/.vitepress/components/GettingStartedExample.vue renamed to docs/src/.vitepress/components/Examples/Introduction/GettingStartedExample.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import { ref, computed } from 'vue'
1515
1616
export default {
17-
name: 'BaseDialog',
17+
name: 'GettingStartedExample',
1818
1919
setup() {
2020
const dialogState = ref(false)

docs/src/.vitepress/components/GettingStartedExampleStyled.vue renamed to docs/src/.vitepress/components/Examples/Introduction/GettingStartedExampleStyled.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { ref, computed } from 'vue'
1717
1818
export default {
19-
name: 'BaseDialog',
19+
name: 'GettingStartedExampleStyled',
2020
2121
setup() {
2222
const dialogState = ref(false)

docs/src/.vitepress/theme/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import DefaultTheme from 'vitepress/theme'
2-
import { GDialog } from 'gitart-vue-dialog'
2+
import { GDialog } from 'gitart-vue-dialog/dist/server'
33
import 'gitart-vue-dialog/dist/style.css'
44
import './custom.css'
55

66
import BaseBtn from '@/.vitepress/components/Components/BaseBtn.vue'
77
import BtnWrapper from '@/.vitepress/components/Components/BtnWrapper.vue'
8+
import Example from '@/.vitepress/components/Components/Example.vue'
89

910
export default {
1011
...DefaultTheme,
1112
enhanceApp({ app }) {
1213
app.component('GDialog', GDialog)
1314
app.component('BaseBtn', BaseBtn)
1415
app.component('BtnWrapper', BtnWrapper)
16+
app.component('Example', Example)
1517
},
1618
}

docs/src/docs/introduction/getting-started.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@ Let's use standalone component (without installing plugin)
3131
<<< @/.vitepress/includes/minumal-working-example/YourComponent.js
3232
<<< @/.vitepress/includes/minumal-working-example/YourComponent.html
3333

34-
<script setup>
35-
import GettingStartedExample from '@/.vitepress/components/GettingStartedExample.vue'
36-
import GettingStartedExampleStyled from '@/.vitepress/components/GettingStartedExampleStyled.vue'
37-
</script>
38-
39-
<GettingStartedExample />
34+
<Example file="Introduction/GettingStartedExample" />
4035

4136
Pretty **ugly** dialog, right? Let's add max-width, background and some padding. Take a look:
4237

43-
<GettingStartedExampleStyled />
38+
<Example file="Introduction/GettingStartedExampleStyled" />
4439

45-
Looks better. Here is more advanced [examples](https://michaelgitart.github.io/gitart-vue-dialog)
40+
Looks better. Here is more advanced [examples](https://michaelgitart.github.io/gitart-vue-dialog)

0 commit comments

Comments
 (0)