Skip to content

Commit 56eaf90

Browse files
committed
refactor(light): rewrite dev component
1 parent 128128d commit 56eaf90

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

light/src/App.vue

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
v-model="value"
55
v-model:period="period"
66
format="crontab"
7-
locale="en"
7+
:locale="locale"
8+
:key="locale"
89
@error="error = $event"
910
>
1011
</cron-light>
@@ -14,46 +15,45 @@
1415
</div>
1516
<br />
1617
Error: {{ error }}
17-
<div>
18-
<button @click="toggleDarkMode" class="cl-btn" style="margin-top: 1em">
18+
<div style="margin-top: 1em">
19+
<button @click="toggleDarkMode" class="cl-btn">
1920
Switch to {{ isDark ? 'Light' : 'Dark' }} Mode
2021
</button>
22+
<button @click="switchLocale" class="cl-btn">Locale: {{ locale }}</button>
2123
</div>
2224
</div>
2325
</template>
2426

25-
<script lang="ts">
27+
<script lang="ts" setup>
2628
import CronLight from '@/components/cron-light.vue'
29+
import { ref, watch } from 'vue'
30+
31+
const value = ref(undefined)
32+
const period = ref('month')
33+
const error = ref('')
34+
const isDark = ref(false)
35+
const locale = ref('en')
36+
37+
watch(value, (value) => {
38+
console.log('value changed: ' + value)
39+
})
40+
watch(period, (value) => {
41+
console.log('period changed: ' + value)
42+
})
43+
44+
function updateValue(evt: any) {
45+
value.value = evt.target.value
46+
}
47+
48+
function toggleDarkMode() {
49+
const body = document.querySelector('body')
50+
isDark.value = body?.classList.toggle('dark') ?? false
51+
}
2752
28-
export default {
29-
components: {
30-
CronLight,
31-
},
32-
data: () => {
33-
return {
34-
value: undefined,
35-
period: 'month',
36-
error: '',
37-
isDark: false,
38-
}
39-
},
40-
watch: {
41-
value: function (value) {
42-
console.log('value changed: ' + value)
43-
},
44-
period: function (value) {
45-
console.log('period changed: ' + value)
46-
},
47-
},
48-
methods: {
49-
updateValue(evt: any) {
50-
this.value = evt.target.value
51-
},
52-
toggleDarkMode() {
53-
const body = document.querySelector('body')
54-
this.isDark = body?.classList.toggle('dark') ?? false
55-
},
56-
},
53+
function switchLocale() {
54+
const locales = ['en', 'de']
55+
const i = (locales.indexOf(locale.value) + 1) % locales.length
56+
locale.value = locales[i]
5757
}
5858
</script>
5959

0 commit comments

Comments
 (0)