Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f3789
commit eeb65ed
Showing
24 changed files
with
1,395 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Vant Doc | ||
|
||
UI components of Vant document site | ||
|
||
#### NPM | ||
|
||
```shell | ||
npm i @vant/doc -D | ||
``` | ||
|
||
#### YARN | ||
|
||
```shell | ||
yarn add @vant/doc --dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('path'); | ||
const baseWebpackConfig = require('../../../build/webpack.dev'); | ||
|
||
module.exports = Object.assign(baseWebpackConfig, { | ||
mode: 'production', | ||
entry: { | ||
index: './src/index.js' | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, '../lib'), | ||
filename: '[name].js', | ||
libraryTarget: 'commonjs2' | ||
}, | ||
externals: { | ||
vue: { | ||
root: 'Vue', | ||
commonjs: 'vue', | ||
commonjs2: 'vue', | ||
amd: 'vue' | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@vant/doc", | ||
"version": "2.5.1", | ||
"description": "vant document template", | ||
"main": "./lib/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "webpack --progress --config ./build/webpack.config.js", | ||
"release": "npm run build && npm publish" | ||
}, | ||
"license": "MIT", | ||
"repository": "https://github.com/youzan/vant/tree/dev/packages/vant-doc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<template> | ||
<div class="van-doc"> | ||
<van-doc-header | ||
:lang="lang" | ||
:github="github" | ||
:versions="versions" | ||
:config="config.header" | ||
:search-config="searchConfig" | ||
@switch-version="$emit('switch-version', $event)" | ||
/> | ||
<van-doc-nav :base="base" :nav-config="config.nav" /> | ||
<van-doc-container :has-simulator="!!(simulator || simulators.length)"> | ||
<van-doc-content> | ||
<slot /> | ||
</van-doc-content> | ||
</van-doc-container> | ||
<van-doc-simulator v-if="simulator" :src="simulator" /> | ||
<van-doc-simulator | ||
v-for="(url, index) in simulators" | ||
v-show="index === currentSimulator" | ||
:src="url" | ||
:key="url" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'van-doc', | ||
props: { | ||
lang: String, | ||
github: String, | ||
versions: Array, | ||
searchConfig: Object, | ||
currentSimulator: Number, | ||
simulator: String, | ||
config: { | ||
type: Object, | ||
required: true | ||
}, | ||
simulators: { | ||
type: Array, | ||
default: () => [] | ||
}, | ||
base: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
data() { | ||
return { | ||
nav: [], | ||
currentPath: null, | ||
leftNav: null, | ||
rightNav: null | ||
}; | ||
}, | ||
watch: { | ||
// eslint-disable-next-line | ||
'$route.path'() { | ||
this.setNav(); | ||
this.updateNav(); | ||
} | ||
}, | ||
created() { | ||
this.setNav(); | ||
this.updateNav(); | ||
this.keyboardHandler(); | ||
}, | ||
methods: { | ||
setNav() { | ||
const { nav } = this.config; | ||
for (let i = 0; i < nav.length; i++) { | ||
const navItem = nav[i]; | ||
if (!navItem.groups) { | ||
this.nav.push(nav[i]); | ||
} else { | ||
for (let j = 0; j < navItem.groups.length; j++) { | ||
this.nav = this.nav.concat(navItem.groups[j].list); | ||
} | ||
} | ||
} | ||
}, | ||
updateNav() { | ||
let currentIndex; | ||
this.currentPath = '/' + this.$route.path.split('/').pop(); | ||
for (let i = 0, len = this.nav.length; i < len; i++) { | ||
if (this.nav[i].path === this.currentPath) { | ||
currentIndex = i; | ||
break; | ||
} | ||
} | ||
this.leftNav = this.nav[currentIndex - 1]; | ||
this.rightNav = this.nav[currentIndex + 1]; | ||
}, | ||
handleNavClick(direction) { | ||
const nav = direction === 'prev' ? this.leftNav : this.rightNav; | ||
if (nav.path) { | ||
this.$router.push(this.base + nav.path); | ||
} else if (nav.link) { | ||
window.location.href = nav.link; | ||
} | ||
}, | ||
keyboardHandler() { | ||
window.addEventListener('keyup', event => { | ||
switch (event.keyCode) { | ||
case 37: // left | ||
this.handleNavClick('prev'); | ||
break; | ||
case 39: // right | ||
this.handleNavClick('next'); | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="less"> | ||
@import './style/index'; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<div class="van-doc-block"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'van-doc-block' | ||
}; | ||
</script> | ||
|
||
<style lang="less"> | ||
@import '../style/variable'; | ||
.van-doc-block { | ||
display: flex; | ||
margin-bottom: 20px; | ||
.highlight { | ||
flex: 1; | ||
box-sizing: border-box; | ||
pre { | ||
word-break: break-all; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<div | ||
class="van-doc-container van-doc-row" | ||
:class="{ 'van-doc-container--with-simulator': hasSimulator }" | ||
> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'van-doc-container', | ||
props: { | ||
hasSimulator: Boolean | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="less"> | ||
@import '../style/variable'; | ||
.van-doc-container { | ||
box-sizing: border-box; | ||
padding-left: @van-doc-nav-width; | ||
overflow: hidden; | ||
&--with-simulator { | ||
padding-right: @van-doc-simulator-width + @van-doc-padding; | ||
@media (max-width: 1300px) { | ||
padding-right: @van-doc-simulator-small-width + @van-doc-padding; | ||
} | ||
} | ||
} | ||
</style> |
Oops, something went wrong.