Skip to content

Commit d06740b

Browse files
author
Christopher Mühl
committed
Initial commit
0 parents  commit d06740b

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
yarn.lock
3+
package-lock.json

components/CodeSwitcher.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div class="code-switcher">
3+
<div class="tab-header">
4+
<ul>
5+
<li v-for="(name, shorthand) in languages"
6+
@click="selectedLanguage = shorthand"
7+
:class="{ active: selectedLanguage === shorthand }"
8+
> {{ name }}
9+
</li>
10+
</ul>
11+
</div>
12+
13+
<div class="tab-content"
14+
v-for="(name, shorthand) in languages"
15+
v-show="shorthand === selectedLanguage"
16+
>
17+
<slot :name="shorthand"></slot>
18+
</div>
19+
</div>
20+
</template>
21+
22+
<script>
23+
export default {
24+
props: {
25+
languages: Object
26+
},
27+
28+
data () {
29+
return {
30+
selectedLanguage: 'js'
31+
}
32+
}
33+
}
34+
</script>
35+
36+
<style>
37+
38+
</style>

enhanceAppFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './switcher.styl'

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { resolve } = require('path')
2+
3+
module.exports = (options, ctx) => ({
4+
5+
name: 'vuepress-plugin-code-switcher',
6+
7+
enhanceAppFiles: resolve(__dirname, 'enhanceAppFile.js'),
8+
9+
plugins: [
10+
[
11+
'@vuepress/register-components',
12+
{
13+
componentsDir: resolve(__dirname, './components')
14+
}
15+
]
16+
]
17+
18+
})

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "vuepress-plugin-code-switcher",
3+
"author": {
4+
"name": "Christopher Mühl",
5+
"email": "[email protected]",
6+
"url": "https://padarom.io"
7+
},
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/padarom/vuepress-plugin-code-switcher"
11+
},
12+
"version": "1.0.0",
13+
"main": "index.js",
14+
"license": "MIT",
15+
"dependencies": {
16+
"@vuepress/plugin-register-components": "^1.0.0-alpha.0"
17+
}
18+
}

switcher.styl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.code-switcher
2+
div[class*="language-"]::before
3+
content ""
4+
5+
.tab-header
6+
ul
7+
padding 0
8+
9+
li
10+
display inline-block
11+
padding 0 10px
12+
cursor pointer
13+
14+
&.active
15+
font-weight bold

0 commit comments

Comments
 (0)