forked from discordjs/guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add branch version selector dropdown to user settings (discordjs#218)
* Update vuepress-theme-yuu to v1.1.0 * Install semver package * Add branch selector dropdown to user settings * Move localStorage usage to inside the mounted hook * Add ".x" to master branch version label * Lint Branch Vue component * Add `inline` prop to Branch component * Add section about how to use the Branch component * Add quotes around `default` object key * Revert "Add quotes around `default` object key" This reverts commit a3a8050. Not needed right now because of the current eslint config.
- Loading branch information
Showing
8 changed files
with
170 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default [ | ||
{ label: 'v11.x', version: '11.x' }, | ||
{ label: 'v11.5 (stable)', version: '11.5' }, | ||
{ label: 'v12.x (master)', version: '12.x' }, | ||
]; |
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,55 @@ | ||
<template> | ||
<span v-show="displayContent" :style="{ display: inline ? 'inline-block' : 'block' }"> | ||
<slot></slot> | ||
</span> | ||
</template> | ||
|
||
<script> | ||
import semver from 'semver'; | ||
import branches from '../branches.js'; | ||
import eventBus from '../eventBus.js'; | ||
const [defaultBranch] = branches; | ||
export default { | ||
name: 'Branch', | ||
props: { | ||
version: { | ||
type: String, | ||
required: true, | ||
}, | ||
inline: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
selectedBranch: defaultBranch.version, | ||
}; | ||
}, | ||
computed: { | ||
displayContent() { | ||
return semver.satisfies(semver.coerce(this.version), this.selectedBranch); | ||
}, | ||
}, | ||
mounted() { | ||
this.selectedBranch = localStorage.getItem('branch-version') || defaultBranch.version; | ||
eventBus.$on('branch-update', this.updateBranch); | ||
}, | ||
destroyed() { | ||
eventBus.$off('branch-update', this.updateBranch); | ||
}, | ||
methods: { | ||
updateBranch(branch) { | ||
this.selectedBranch = branch; | ||
}, | ||
}, | ||
}; | ||
</script> |
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,56 @@ | ||
<template> | ||
<div> | ||
<label for="branch-selector">Discord.js Version:</label> | ||
<select id="branch-selector" v-model="selectedBranch" @change="updateBranch"> | ||
<option v-for="branch in branches" :key="branch.version" :value="branch.version"> | ||
{{ branch.label }} | ||
</option> | ||
</select> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import branches from '../branches.js'; | ||
import eventBus from '../eventBus.js'; | ||
const [defaultBranch] = branches; | ||
export default { | ||
name: 'BranchSelector', | ||
data() { | ||
return { | ||
branches, | ||
selectedBranch: defaultBranch.version, | ||
}; | ||
}, | ||
mounted() { | ||
this.selectedBranch = localStorage.getItem('branch-version') || defaultBranch.version; | ||
}, | ||
methods: { | ||
updateBranch() { | ||
localStorage.setItem('branch-version', this.selectedBranch); | ||
eventBus.$emit('branch-update', this.selectedBranch); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style> | ||
#branch-selector { | ||
display: block; | ||
width: 100%; | ||
border-color: #eaecef; | ||
padding: 5px; | ||
box-sizing: border-box; | ||
border-radius: 4px; | ||
} | ||
.yuu-theme-dark #branch-selector { | ||
color: #f3f3f3; | ||
background-color: #1a1a1a; | ||
border-color: rgba(255, 255, 255, 0.1); | ||
} | ||
</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
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,2 @@ | ||
import Vue from 'vue'; | ||
export default new 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
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