Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ __markdown content__

~~~

### With options
If you have a lot of tabbed sections in your documentation you might want
to see all of them switch together when one is changed.
To enable this behavior, just set the `sync` option to `true`:

```js
module.exports = {
// Your remaining configuration ...
plugins: [
[
'vuepress-plugin-element-tabs',
{
sync: true,
},
],
],
}
```

## Documents
> Accepted Value Like That
~~~md
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const path = require('path')

module.exports = (options, context) => ({
extendPageData($page) {
$page.elementTabsOptions = options
},
enhanceAppFiles: [
path.resolve(__dirname, './lib/client.js')
],
Expand All @@ -9,8 +12,8 @@ module.exports = (options, context) => ({
},
chainMarkdown (config) {
config
.plugin('@superbiger/tabs')
.use(require('./lib/markdownItPlugin'), [options])
.end()
.plugin('@superbiger/tabs')
.use(require('./lib/markdownItPlugin'), [options])
.end()
}
})
24 changes: 23 additions & 1 deletion lib/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
},
props: {
type: String,
activeName: String,
activeName: {
type: String,
default () {
if (typeof localStorage !== 'undefined') {
return localStorage.getItem('vuepress-plugin-element-tabs@activeId');
}
}
},
closable: Boolean,
addable: Boolean,
value: {},
Expand Down Expand Up @@ -65,7 +72,15 @@
handleTabClick(tab, tabName, event) {
if (tab.disabled) return;
this.setCurrentName(tabName);
if (Array.every([
this.$page.elementTabsOptions,
this.$page.elementTabsOptions.sync,
typeof localStorage !== 'undefined'
])) {
localStorage.setItem('vuepress-plugin-element-tabs@activeId', tabName);
}
this.$emit('tab-click', tab, event);
this.$root.$emit('tab-change', tabName, tab, event);
},
handleTabRemove(pane, ev) {
if (pane.disabled) return;
Expand Down Expand Up @@ -162,6 +177,13 @@
},

created() {
if (this.$page.elementTabsOptions.sync) {
this.$root.$on('tab-change', (tabName, tab, event) => {
this.setCurrentName(tabName)
});
} else if (typeof localStorage !== 'undefined') {
localStorage.removeItem('vuepress-plugin-element-tabs@activeId')
}
if (!this.currentName) {
this.setCurrentName('0');
}
Expand Down