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

Commit 1be5f8d

Browse files
committed
feat(docs): add tabs for vue script (option/composition)
1 parent 18c31fd commit 1be5f8d

File tree

12 files changed

+294
-205
lines changed

12 files changed

+294
-205
lines changed

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@vueuse/core": "^6.0.0",
2121
"balm-ui": "9.36.0",
2222
"gitart-vue-dialog": "^0.2.0-alpha.3",
23+
"markdown-it-container": "^3.0.0",
2324
"prismjs": "^1.24.1",
2425
"sass": "^1.38.0"
2526
}

docs/src/.vitepress/config.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const path = require('path')
3+
const mdContainerPlugin = require('markdown-it-container')
4+
5+
console.log('🚀 ~ file: config.js ~ line 4 ~ mdContainerPlugin', mdContainerPlugin)
36

47
module.exports = {
58
vite: {
@@ -26,6 +29,55 @@ module.exports = {
2629
['link', { rel: 'icon', href: '/favicon.png' }],
2730
],
2831

32+
markdown: {
33+
config: md => {
34+
35+
/**
36+
* ::: vue-slot composition
37+
* CONTENT
38+
* :::
39+
*/
40+
md.use(mdContainerPlugin, 'vue-slot', {
41+
render(tokens, idx) {
42+
const token = tokens[idx]
43+
44+
if (token.nesting === 1) {
45+
const slotName = token.info.split(' ')[2]
46+
47+
return `<template #${slotName}>`
48+
}
49+
50+
return '</template>'
51+
},
52+
})
53+
54+
/**
55+
* ))) method-switch
56+
*
57+
* ::: vue-slot composition
58+
* CONTENT
59+
* :::
60+
* ::: vue-slot option
61+
* CONTENT
62+
* :::
63+
*
64+
* )))
65+
*/
66+
md.use(mdContainerPlugin, 'method-switch', {
67+
marker: ')',
68+
render(tokens, idx) {
69+
const token = tokens[idx]
70+
71+
if (token.nesting === 1) {
72+
return '<MethodSwitch>'
73+
}
74+
75+
return '</MethodSwitch>'
76+
},
77+
})
78+
},
79+
},
80+
2981
themeConfig: {
3082
lastUpdated: 'Last Updated',
3183
displayAllHeaders: true,
@@ -78,7 +130,8 @@ function getGuideSidebar() {
78130
text: 'Components',
79131
children: [
80132
{ text: 'GDialog', link: '/docs/components/g-dialog' },
133+
{ text: 'GDialogRoot', link: '/docs/components/g-dialog-root' },
81134
],
82135
},
83136
]
84-
}
137+
}

docs/src/.vitepress/includes/minumal-working-example/YourComponent.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/src/.vitepress/includes/minumal-working-example/YourComponent.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/src/.vitepress/includes/minumal-working-example/main.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import './custom.scss'
1818

1919
import ButtonWrapper from '@/components/Components/ButtonWrapper.vue'
2020
import Example from '@/components/Components/Example/Example.vue'
21+
import MethodSwitch from '@/components/Components/MethodSwitch.vue'
2122

2223
export default {
2324
...DefaultTheme,
@@ -36,5 +37,6 @@ export default {
3637
app.component('GDialog', GDialog)
3738
app.component('ButtonWrapper', ButtonWrapper)
3839
app.component('Example', Example)
40+
app.component('MethodSwitch', MethodSwitch)
3941
},
4042
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<template>
2+
<div class="method-switch">
3+
<UiTabBar
4+
v-model="activeTab"
5+
align="start"
6+
>
7+
<UiTab
8+
v-for="({key, label}) in tabs"
9+
:key="key"
10+
min-width
11+
>
12+
{{ label }}
13+
</UiTab>
14+
</UiTabBar>
15+
16+
<div class="method-switch__slot">
17+
<slot :name="activeTabKey" />
18+
</div>
19+
</div>
20+
</template>
21+
22+
<script lang="ts">
23+
import { computed, defineComponent, ref } from 'vue'
24+
25+
export default defineComponent({
26+
name: 'MethodSwitch',
27+
28+
setup() {
29+
const activeTab = ref(0)
30+
const tabs = [
31+
{
32+
label: 'Composition API',
33+
key: 'composition',
34+
},
35+
{
36+
label: 'Option API',
37+
key: 'option',
38+
},
39+
]
40+
41+
const activeTabKey = computed(() => tabs[activeTab.value].key)
42+
43+
return {
44+
tabs,
45+
activeTab,
46+
activeTabKey,
47+
}
48+
},
49+
})
50+
</script>
51+
52+
<style lang="scss">
53+
.method-switch {
54+
border: 1px solid rgba(0, 0, 0, 0.12);
55+
margin: 1em 0;
56+
border-radius: 6px;
57+
overflow: hidden;
58+
59+
.language-js {
60+
margin: 0;
61+
border-top-left-radius: 0;
62+
border-top-right-radius: 0;
63+
}
64+
}
65+
</style>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# GDialogRoot
2+
3+
```js
4+
import { GDialogRoot } from 'gitart-vue-dialog'
5+
```
6+
7+
Put `GDialogRoot` into your root component (App.vue)
8+
9+
::: warning
10+
Remember GDialogRoot just render dialogs added by `$dialog.addDialog()`.
11+
No props, no slots, no events
12+
:::

docs/src/docs/components/g-dialog.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
11
# GDialog
22

3-
...
3+
```js
4+
import { GDialog } from 'gitart-vue-dialog'
5+
```
6+
7+
## Props
8+
9+
| Name | Type | Default | Description |
10+
|:---|:---|:---|:---|
11+
| model-value | `boolean` | `false` | v-model props to activate and deactivate the dialog |
12+
| persistent | `boolean` | `false` | Makes clicking outside of the element will not deactivate the dialog |
13+
| max-width | `string,` `number` | `'none'` | Sets max-width for the dialog |
14+
| width | `string,` `number` | `'auto'` | Sets width for the dialog |
15+
| height | `string`, `number` | `'auto'` | Sets height for the dialog |
16+
| depressed | `boolean` | `false` | Disables default box-shadow |
17+
| contentClass | `string` | `''` | Applies to the div that wraps the main slot |
18+
19+
## Slots
20+
21+
| Name | Description |
22+
|:---|:---|
23+
| default | The default Vue slot
24+
25+
26+
## Events
27+
28+
| Name | Payload | Description |
29+
|:---|:---|:---|
30+
| `update:modelValue` | `boolean` | runs with `false` after clicking outside

0 commit comments

Comments
 (0)