File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,25 @@ __markdown content__
4747
4848~~~
4949
50+ ### With options
51+ If you have a lot of tabbed sections in your documentation you might want
52+ to see all of them switch together when one is changed.
53+ To enable this behavior, just set the ` sync ` option to ` true ` :
54+
55+ ``` js
56+ module .exports = {
57+ // Your remaining configuration ...
58+ plugins: [
59+ [
60+ ' vuepress-plugin-element-tabs' ,
61+ {
62+ sync: true ,
63+ },
64+ ],
65+ ],
66+ }
67+ ```
68+
5069## Documents
5170> Accepted Value Like That
5271~~~ md
Original file line number Diff line number Diff line change 11const path = require ( 'path' )
22
33module . exports = ( options , context ) => ( {
4+ extendPageData ( $page ) {
5+ $page . elementTabsOptions = options
6+ } ,
47 enhanceAppFiles : [
58 path . resolve ( __dirname , './lib/client.js' )
69 ] ,
@@ -9,8 +12,8 @@ module.exports = (options, context) => ({
912 } ,
1013 chainMarkdown ( config ) {
1114 config
12- . plugin ( '@superbiger/tabs' )
13- . use ( require ( './lib/markdownItPlugin' ) , [ options ] )
14- . end ( )
15+ . plugin ( '@superbiger/tabs' )
16+ . use ( require ( './lib/markdownItPlugin' ) , [ options ] )
17+ . end ( )
1518 }
1619} )
Original file line number Diff line number Diff line change 77 },
88 props: {
99 type: String ,
10- activeName: String ,
10+ activeName: {
11+ type: String ,
12+ default () {
13+ if (typeof localStorage !== ' undefined' ) {
14+ return localStorage .getItem (' vuepress-plugin-element-tabs@activeId' );
15+ }
16+ }
17+ },
1118 closable: Boolean ,
1219 addable: Boolean ,
1320 value: {},
6572 handleTabClick (tab , tabName , event ) {
6673 if (tab .disabled ) return ;
6774 this .setCurrentName (tabName);
75+ if (Array .every ([
76+ this .$page .elementTabsOptions ,
77+ this .$page .elementTabsOptions .sync ,
78+ typeof localStorage !== ' undefined'
79+ ])) {
80+ localStorage .setItem (' vuepress-plugin-element-tabs@activeId' , tabName);
81+ }
6882 this .$emit (' tab-click' , tab, event );
83+ this .$root .$emit (' tab-change' , tabName, tab, event );
6984 },
7085 handleTabRemove (pane , ev ) {
7186 if (pane .disabled ) return ;
162177 },
163178
164179 created () {
180+ if (this .$page .elementTabsOptions .sync ) {
181+ this .$root .$on (' tab-change' , (tabName , tab , event ) => {
182+ this .setCurrentName (tabName)
183+ });
184+ } else if (typeof localStorage !== ' undefined' ) {
185+ localStorage .removeItem (' vuepress-plugin-element-tabs@activeId' )
186+ }
165187 if (! this .currentName ) {
166188 this .setCurrentName (' 0' );
167189 }
You can’t perform that action at this time.
0 commit comments