Skip to content

Commit 01f5578

Browse files
authored
Merge pull request #518 from openWB/feature-refactor-base-components
Feature refactor base components
2 parents 8f6b15b + c8f69d2 commit 01f5578

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1055
-1250
lines changed

src/App.vue

+8
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,12 @@ export default {
345345
.container[role="main"] {
346346
padding: 60px 15px 30px;
347347
}
348+
349+
.clickable {
350+
cursor: pointer;
351+
}
352+
353+
.not-clickable {
354+
cursor: not-allowed;
355+
}
348356
</style>

src/components/OpenwbBaseArrayInput.vue

+25-47
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
<template>
2-
<div class="form-row mb-1">
3-
<label
4-
class="col-md-4 col-form-label"
5-
@click="toggleHelp"
2+
<openwb-base-setting-element>
3+
<template #title>
4+
<slot name="title">
5+
{{ title }}
6+
</slot>
7+
</template>
8+
<template
9+
v-if="$slots.help"
10+
#help
611
>
7-
{{ title }}
8-
<font-awesome-icon
9-
v-if="$slots.help"
10-
:icon="
11-
showHelp
12-
? ['fas', 'question-circle']
13-
: ['far', 'question-circle']
14-
"
15-
:class="showHelp ? 'text-info' : ''"
16-
/>
17-
</label>
18-
<div class="col-md-8">
19-
<div class="form-row">
12+
<slot name="help" />
13+
</template>
14+
<template #default>
15+
<div class="w-100">
2016
<div class="input-group">
2117
<div class="input-group-prepend">
2218
<div class="input-group-text">
@@ -42,7 +38,7 @@
4238
:class="
4339
newTagValid
4440
? 'bg-success clickable'
45-
: 'notClickable'
41+
: 'not-clickable'
4642
"
4743
@click="addTag"
4844
>
@@ -56,7 +52,7 @@
5652
</div>
5753
</div>
5854
</div>
59-
<div class="form-row tagList mt-1">
55+
<div class="tagList mt-1 w-100">
6056
<span
6157
v-if="value.length == 0"
6258
class="noTag"
@@ -80,31 +76,23 @@
8076
/>
8177
</span>
8278
</div>
83-
<span
84-
v-if="showHelp"
85-
class="form-row alert alert-info my-1 small"
86-
>
87-
<slot name="help" />
88-
</span>
89-
</div>
90-
</div>
79+
</template>
80+
</openwb-base-setting-element>
9181
</template>
9282

9383
<script>
84+
import OpenwbBaseSettingElement from "./OpenwbBaseSettingElement.vue";
85+
9486
import { library } from "@fortawesome/fontawesome-svg-core";
9587
import {
96-
faQuestionCircle as fasQuestionCircle,
9788
faTag as fasTag,
9889
faTimesCircle as fasTimesCircle,
9990
faPlus as fasPlus,
10091
faInfoCircle as fasInfoCircle,
10192
} from "@fortawesome/free-solid-svg-icons";
102-
import { faQuestionCircle as farQuestionCircle } from "@fortawesome/free-regular-svg-icons";
10393
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
10494
10595
library.add(
106-
fasQuestionCircle,
107-
farQuestionCircle,
10896
fasTag,
10997
fasTimesCircle,
11098
fasPlus,
@@ -115,6 +103,7 @@ export default {
115103
name: "OpenwbArrayInput",
116104
components: {
117105
FontAwesomeIcon,
106+
OpenwbBaseSettingElement,
118107
},
119108
inheritAttrs: false,
120109
props: {
@@ -152,27 +141,22 @@ export default {
152141
get() {
153142
return (
154143
this.newTag.length > 0 &&
155-
this.value.indexOf(this.newTag) == -1
144+
!this.value.includes(this.newTag)
156145
);
157146
},
158147
},
159148
},
160149
methods: {
161-
toggleHelp() {
162-
this.showHelp = !this.showHelp && this.$slots.help !== undefined;
163-
},
164150
addTag() {
165151
if (this.newTagValid) {
166-
let tempValue = this.value;
167-
tempValue.push(this.newTag);
168-
tempValue.sort();
152+
const tempValue = [...this.value, this.newTag].sort();
169153
this.value = tempValue;
170154
this.newTag = "";
171155
}
172156
this.$refs.tagInput.focus();
173157
},
174158
removeTag(index) {
175-
let tempValue = this.value;
159+
let tempValue = [...this.value];
176160
tempValue.splice(index, 1);
177161
this.value = tempValue;
178162
},
@@ -181,14 +165,6 @@ export default {
181165
</script>
182166

183167
<style scoped>
184-
.clickable {
185-
cursor: pointer;
186-
}
187-
188-
.notClickable {
189-
cursor: not-allowed;
190-
}
191-
192168
.remove-element:hover {
193169
color: var(--danger);
194170
}
@@ -203,6 +179,8 @@ input:invalid {
203179
border: 1px solid #ced4da;
204180
border-radius: 0.25rem;
205181
padding: 5px 5px 0 5px;
182+
display: flex;
183+
flex-wrap: wrap;
206184
}
207185
208186
.tag,
+46-71
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,65 @@
11
<template>
2-
<div class="form-row mb-1">
3-
<label
4-
class="col-md-4 col-form-label"
5-
@click="toggleHelp"
6-
>
7-
<slot>
2+
<openwb-base-setting-element>
3+
<template #title>
4+
<slot name="title">
85
{{ title }}
96
</slot>
10-
<font-awesome-icon
11-
v-if="$slots.help"
12-
fixed-width
13-
:icon="
14-
showHelp
15-
? ['fas', 'question-circle']
16-
: ['far', 'question-circle']
17-
"
18-
:class="showHelp ? 'text-info' : ''"
19-
/>
20-
</label>
21-
<div class="col-md-8">
22-
<div class="form-row">
23-
<div class="btn-group btn-block btn-group-toggle">
24-
<label
25-
v-for="button in buttons"
26-
:key="button.value"
27-
class="btn"
28-
:class="[
29-
value == button.buttonValue ? 'active' : '',
30-
button.class ? button.class : 'btn-outline-info',
31-
]"
7+
</template>
8+
<template
9+
v-if="$slots.help"
10+
#help
11+
>
12+
<slot name="help" />
13+
</template>
14+
<template #default>
15+
<div class="btn-group btn-block btn-group-toggle">
16+
<label
17+
v-for="button in buttons"
18+
:key="button.value"
19+
class="btn"
20+
:class="[
21+
value == button.buttonValue ? 'active' : '',
22+
button.class ? button.class : 'btn-outline-info',
23+
]"
24+
>
25+
<input
26+
v-model="value"
27+
type="radio"
28+
:value="button.buttonValue"
29+
v-bind="$attrs"
3230
>
33-
<input
34-
v-model="value"
35-
type="radio"
36-
:value="button.buttonValue"
37-
v-bind="$attrs"
38-
>
39-
<slot :name="'label-' + button.buttonValue">
40-
{{ button.text }}
41-
</slot>
42-
<font-awesome-icon
43-
:icon="['fas', 'check']"
44-
:style="[
45-
value == button.buttonValue
46-
? 'visibility: visible'
47-
: 'visibility: hidden',
48-
]"
49-
/>
50-
</label>
51-
</div>
31+
<slot :name="'label-' + button.buttonValue">
32+
{{ button.text }}
33+
</slot>
34+
<font-awesome-icon
35+
fixed-width
36+
:icon="['fas', 'check']"
37+
:style="[
38+
value == button.buttonValue
39+
? 'visibility: visible'
40+
: 'visibility: hidden',
41+
]"
42+
/>
43+
</label>
5244
</div>
53-
<span
54-
v-if="showHelp"
55-
class="form-row alert alert-info my-1 small"
56-
>
57-
<slot name="help" />
58-
</span>
59-
</div>
60-
</div>
45+
</template>
46+
</openwb-base-setting-element>
6147
</template>
6248

6349
<script>
50+
import OpenwbBaseSettingElement from "./OpenwbBaseSettingElement.vue";
51+
6452
import { library } from "@fortawesome/fontawesome-svg-core";
65-
import {
66-
faQuestionCircle as fasQuestionCircle,
67-
faCheck as fasCheck,
68-
} from "@fortawesome/free-solid-svg-icons";
69-
import { faQuestionCircle as farQuestionCircle } from "@fortawesome/free-regular-svg-icons";
53+
import { faCheck as fasCheck } from "@fortawesome/free-solid-svg-icons";
7054
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
7155
72-
library.add(fasQuestionCircle, farQuestionCircle, fasCheck);
56+
library.add(fasCheck);
7357
7458
export default {
7559
name: "OpenwbButtonGroupInput",
7660
components: {
7761
FontAwesomeIcon,
62+
OpenwbBaseSettingElement,
7863
},
7964
inheritAttrs: false,
8065
props: {
@@ -83,11 +68,6 @@ export default {
8368
buttons: { type: Array, required: true },
8469
},
8570
emits: ["update:modelValue"],
86-
data() {
87-
return {
88-
showHelp: false,
89-
};
90-
},
9171
computed: {
9272
value: {
9373
get() {
@@ -98,10 +78,5 @@ export default {
9878
},
9979
},
10080
},
101-
methods: {
102-
toggleHelp() {
103-
this.showHelp = !this.showHelp && this.$slots.help !== undefined;
104-
},
105-
},
10681
};
10782
</script>

0 commit comments

Comments
 (0)