-
Notifications
You must be signed in to change notification settings - Fork 322
/
ContextTest.demo.vue
207 lines (197 loc) · 5.23 KB
/
ContextTest.demo.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<template>
<VbDemo>
<VbCard title="Global">
<va-test>No props</va-test>
<va-test color="green">
Prop set
</va-test>
</VbCard>
<VbCard title="Local context component">
<va-test>no context</va-test>
<span style="font-size: 12px;">context 1</span>
<va-context :config="{ VaTest: { color: 'warning' } }">
<div style="border: 1px solid gray; padding: 4px;">
<va-test>No props</va-test>
<span style="font-size: 12px;">context 2</span>
<va-context :config="{ VaTest: { color: 'danger' } }">
<div style="border: 1px solid gray; padding: 4px;">
<va-test>No props</va-test>
<va-test color="green">
Prop set
</va-test>
</div>
</va-context>
</div>
</va-context>
</VbCard>
<VbCard title="Empty values">
<va-context :config="{ VaTest: { label: 'my label' } }">
<div>
Default:
<va-test />
Empty label (should be empty):
<br>
<br>
<va-test label="" />
undefined (should be same as default):
<va-test :label="undefined" />
</div>
</va-context>
</VbCard>
<VbCard title="Reactive update from local context">
<div>
Should change color on change and refresh.
</div>
<span style="font-size: 12px;">dynamic context</span>
<va-context :config="dynamicContextConfig">
<div style="border: 1px solid gray; padding: 4px;">
<va-test>No props</va-test>
<va-test color="green">
Prop set
</va-test>
</div>
</va-context>
<label>
<input
type="checkbox"
v-model="redOrange"
>
red / orange
</label>
</VbCard>
<VbCard title="Override button props">
<va-button>Global config</va-button>
<br>
<span style="font-size: 12px;">context 1</span>
<va-context :config="{ VaButton: { color: 'warning' } }">
<div style="border: 1px solid gray; padding: 4px;">
<va-button>Local config 1 (only color)</va-button>
<br>
<span style="font-size: 12px;">context 2</span>
<va-context :config="{ VaButton: buttonConfig }">
<div style="border: 1px solid gray; padding: 4px;">
<va-button>Local config 2 (override)</va-button>
</div>
</va-context>
</div>
</va-context>
</VbCard>
<VbCard title="Partial rewriting global config">
<div>
Should change global config button color on change and refresh.
</div>
<button @click="overrideButtonsColor('info')">
Make button color blue
</button>
<br>
<button @click="overrideButtonsColor('danger')">
Make button color red
</button>
<br>
<va-button>Vuestic-ui button</va-button>
</VbCard>
<VbCard title="Rewriting global config">
<va-badge />
<va-test>va test component</va-test>
<va-button>Vuestic-ui button</va-button>
<button @click="overrideConfig()">
Override config
</button>
</VbCard>
</VbDemo>
</template>
<script>
import VaTest from './ContextTest'
import VaContext from './context-provide/VaContext'
import VaButton from '../vuestic-components/va-button/VaButton'
import VaBadge from '../vuestic-components/va-badge/VaBadge'
import { overrideContextConfig } from './context-provide/ContextPlugin'
import { getContext } from '../context-test/context-provide/context'
export default {
components: {
VaTest,
VaContext,
VaButton,
VaBadge,
},
beforeCreate () {
overrideContextConfig(this, {
VaTest: {
color: 'blue',
},
VaBadge: {
color: 'info',
label: 'default label',
},
VaButton: {
size: 'small',
icon: 'room',
color: 'info',
outline: true,
},
VaIcon: {
font: 'md',
config: {
room: {
code: 'room',
},
schedule: {
code: 'schedule',
},
},
},
})
},
beforeRouteUpdate (to, from, next) {
overrideContextConfig(this, getContext())
next()
},
data () {
return {
dynamicContextConfig: { VaTest: { color: 'orange' } },
buttonConfig: {
size: 'large',
icon: 'schedule',
iconRight: '',
flat: true,
color: 'success',
outline: false,
},
}
},
computed: {
redOrange: {
get () {
return this.dynamicContextConfig.VaTest.color === 'red'
},
set (value) {
this.dynamicContextConfig.VaTest.color = value ? 'red' : 'orange'
},
},
},
methods: {
overrideButtonsColor (color) {
this.$vaContextConfig.VaButton.color = color
},
overrideConfig () {
const newConfig = {
VaTest: {
color: 'red',
},
VaBadge: {
color: 'danger',
label: 'new label',
},
VaButton: {
large: true,
small: false,
outline: false,
icon: 'star',
color: 'danger',
},
}
overrideContextConfig(this, newConfig)
},
},
}
</script>