Add Number, Radio and Dropdown setting types

This commit is contained in:
samfun123 2018-02-04 11:12:38 -05:00
parent 4480458bd6
commit 75410b4ce9
6 changed files with 321 additions and 6 deletions

View File

@ -96,6 +96,7 @@
.bd-form-textinput,
.bd-form-fileinput,
.bd-form-numberinput,
.bd-setting-switch {
.bd-title {
display: flex;
@ -121,8 +122,8 @@
}
}
.bd-form-textinput {
input[type="text"] {
.bd-form-textinput, .bd-form-numberinput {
input[type="text"], input[type="number"] {
background: transparent;
border: none;
color: #b9bbbe;
@ -179,3 +180,155 @@
}
}
}
.bd-number {
position: relative;
input[type=number] {
&::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
.bd-number-spinner {
position: absolute;
top: 0;
right: 0;
height: 100%;
justify-content: space-around;
.bd-arrow {
padding: 3px 5px;
cursor: pointer;
font-size: 0;
.bd-up-arrow {
border-color: transparent transparent rgb(153, 153, 153);
border-style: solid;
border-width: 2.5px 5px 5px;
}
&:hover .bd-up-arrow {
border-color: transparent transparent rgb(200, 200, 200);
}
.bd-down-arrow {
border-color: rgb(153, 153, 153) transparent transparent;
border-style: solid;
border-width: 5px 5px 2.5px;
}
&:hover .bd-down-arrow {
border-color: rgb(200, 200, 200) transparent transparent;
}
}
}
}
.bd-radio-option {
background: rgb(50, 50, 50);
border: 2px solid rgb(39, 39, 39);
border-radius: 5px;
padding: 3px;
align-items: center;
input[type="radio"] {
display: none;
&:checked + .bd-radio {
background-color: white;
}
}
.bd-radio {
background: rgb(50, 50, 50);
border: 1px solid rgb(114, 118, 125);
border-radius: 50%;
width: 12px;
height: 12px;
transition: background-color .1s;
}
span {
color: white;
margin: 0px 5px;
}
&:not(:last-child) {
margin-bottom: 5px;
}
}
.bd-dropdown {
position: relative;
.bd-dropdown-current {
color: white;
background: rgb(50, 50, 50);
border: 2px solid rgb(39, 39, 39);
border-radius: 5px;
padding: 8px;
.bd-dropdown-arrow {
border-color: rgb(153, 153, 153) transparent transparent;
border-style: solid;
border-width: 5px 5px 2.5px;
display: inline-block;
margin-left: 10px;
}
}
.bd-dropdown-options {
position: absolute;
top: calc(100% - 2.5px);
width: 100%;
max-height: 100px;
box-sizing: border-box;
background: rgb(50, 50, 50);
border: 2px solid rgb(39, 39, 39);
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
overflow-y: scroll;
div {
color: white;
padding: 5px;
&:hover {
background: rgb(59, 59, 59);
}
&:last-child {
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
}
&::-webkit-scrollbar {
width: 14px;
}
&::-webkit-scrollbar-thumb {
background-color: #1e2124;
border-color: #36393e;
border-color: transparent;
}
&::-webkit-scrollbar-thumb,
&::-webkit-scrollbar-track-piece {
background-clip: padding-box;
border-width: 3px;
border-style: solid;
border-radius: 7px;
border-color: transparent;
}
&::-webkit-scrollbar-track-piece {
background-color: #2f3136;
border-color: #36393e;
border-color: transparent;
}
}
}

View File

@ -0,0 +1,51 @@
/**
* BetterDiscord Plugin Setting Dropdown Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<template>
<div class="bd-setting-switch">
<div class="bd-title">
<h3>{{setting.text}}</h3>
<div class="bd-dropdown">
<div class="bd-dropdown-current" @click="expanded = true">{{getOptionText(setting.value)}}<span class="bd-dropdown-arrow"></span></div>
<div class="bd-dropdown-options bd-flex bd-flex-col" ref="options" v-if="expanded">
<div v-for="option in setting.options" @click="selectOption(setting.id, option.value)">{{option.text}}</div>
</div>
</div>
</div>
<div class="bd-hint">{{setting.hint}}</div>
</div>
</template>
<script>
export default {
props: ['setting', 'change'],
data() {
return { expanded: false }
},
methods: {
getOptionText(value) {
let matching = this.setting.options.filter(opt => opt.value == value);
if (matching.length == 0) return "";
else return matching[0].text;
},
selectOption(settingID, value) {
this.expanded = false;
this.change(settingID, value)
}
},
mounted() {
document.addEventListener("click", e => {
let options = this.$refs.options;
if (options && !options.contains(e.target) && options !== e.target) {
this.expanded = false;
}
});
}
}
</script>

View File

@ -0,0 +1,39 @@
/**
* BetterDiscord Plugin Setting Number Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<template>
<div class="bd-form-numberinput">
<div class="bd-title">
<h3>{{setting.text}}</h3>
<div class="bd-number">
<input type="number" :value="setting.value" :min="setting.min" :max="setting.max" :step="setting.step" @keyup.stop @change="change"/>
<div class="bd-number-spinner bd-flex bd-flex-col">
<div class="bd-arrow" @click="changeBy(true)"><div class="bd-up-arrow"></div></div>
<div class="bd-arrow" @click="changeBy(false)"><div class="bd-down-arrow"></div></div>
</div>
</div>
</div>
<div class="bd-hint">{{setting.hint}}</div>
</div>
</template>
<script>
export default {
props: ['setting', 'change'],
methods: {
input(e) {
this.change(this.setting.id, parseFloat(e.target.value));
},
changeBy(positive) {
let step = this.setting.step == undefined ? 1 : this.settings.step;
this.change(this.setting.id, this.setting.value + (positive ? step : -step));
}
}
}
</script>

View File

@ -11,6 +11,9 @@
<template>
<div class="bd-form-item">
<BoolSetting v-if="setting.type === 'bool'" :setting="setting" :change="change"/>
<DropdownSetting v-if="setting.type === 'dropdown'" :setting="setting" :change="change"/>
<NumberSetting v-if="setting.type === 'number'" :setting="setting" :change="change"/>
<RadioSetting v-if="setting.type === 'radio'" :setting="setting" :change="change"/>
<StringSetting v-if="setting.type === 'text'" :setting="setting" :change="change"/>
<FileSetting v-if="setting.type === 'file'" :setting="setting" :change="change"/>
<div class="bd-form-divider"></div>
@ -19,6 +22,9 @@
<script>
// Imports
import BoolSetting from './Bool.vue';
import DropdownSetting from './Dropdown.vue';
import NumberSetting from './Number.vue';
import RadioSetting from './Radio.vue';
import StringSetting from './String.vue';
import FileSetting from './File.vue';
@ -29,6 +35,9 @@
],
components: {
BoolSetting,
DropdownSetting,
NumberSetting,
RadioSetting,
StringSetting,
FileSetting
}

View File

@ -0,0 +1,35 @@
/**
* BetterDiscord Plugin Setting Radio Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<template>
<div class="bd-setting-switch">
<div class="bd-title">
<h3>{{setting.text}}</h3>
<div class="bd-flex bd-flex-col">
<label class="bd-radio-option bd-flex" v-for="option in setting.options">
<input type="radio" :value="option.value" :name="setting.id" :checked="setting.value == option.value" @change="input">
<div class="bd-radio"></div>
<span>{{option.text}}</span>
</label>
</div>
</div>
<div class="bd-hint">{{setting.hint}}</div>
</div>
</template>
<script>
export default {
props: ['setting', 'change'],
methods: {
input(e) {
this.change(this.setting.id, e.target.value);
}
}
}
</script>

View File

@ -27,10 +27,38 @@
},
{
"id": "default-2",
"type": "bool",
"value": false,
"text": "Bool Test Setting 3",
"hint": "Bool Test Setting Hint 3"
"type": "dropdown",
"value": "opt1",
"text": "Dropdown Test Setting",
"hint": "Dropdown Test Setting Hint",
"options": [
{"value": "opt1", "text": "Option 1"},
{"value": "opt2", "text": "Option 2"},
{"value": "opt3", "text": "Option 3"},
{"value": "opt4", "text": "Option 4"},
{"value": "opt5", "text": "Option 5"}
]
},
{
"id": "default-5",
"type": "radio",
"value": "opt1",
"text": "Radio Test Setting",
"hint": "Radio Test Setting Hint",
"options": [
{"value": "opt1", "text": "Option 1"},
{"value": "opt2", "text": "Option 2"},
{"value": "opt3", "text": "Option 3"},
{"value": "opt4", "text": "Option 4"},
{"value": "opt5", "text": "Option 5"}
]
},
{
"id": "default-6",
"type": "number",
"value": 0,
"text": "Number Test Setting",
"hint": "Number Test Setting Hint"
},
{
"id": "default-3",