Skip to content

Commit dc47efe

Browse files
committed
feat(DateTime): click to toggle relative
1 parent 243b23a commit dc47efe

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

app/components/DateTime.vue

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const props = withDefaults(
3131
3232
const { locale } = useI18n()
3333
34+
const { settings } = useSettings()
3435
const relativeDates = useRelativeDates()
3536
3637
const dateFormatter = new Intl.DateTimeFormat(locale.value, {
@@ -51,27 +52,18 @@ const titleValue = computed(() => {
5152
</script>
5253

5354
<template>
54-
<span>
55-
<ClientOnly>
56-
<NuxtTime
57-
v-if="relativeDates"
58-
:datetime="datetime"
59-
:title="titleValue"
60-
relative
61-
:locale="locale"
62-
/>
63-
<NuxtTime
64-
v-else
65-
:datetime="datetime"
66-
:title="titleValue"
67-
:date-style="dateStyle"
68-
:year="year"
69-
:month="month"
70-
:day="day"
71-
:locale="locale"
72-
/>
73-
<template #fallback>
55+
<button @click="settings.relativeDates = !settings.relativeDates">
56+
<span>
57+
<ClientOnly>
7458
<NuxtTime
59+
v-if="relativeDates"
60+
:datetime="datetime"
61+
:title="titleValue"
62+
relative
63+
:locale="locale"
64+
/>
65+
<NuxtTime
66+
v-else
7567
:datetime="datetime"
7668
:title="titleValue"
7769
:date-style="dateStyle"
@@ -80,7 +72,18 @@ const titleValue = computed(() => {
8072
:day="day"
8173
:locale="locale"
8274
/>
83-
</template>
84-
</ClientOnly>
85-
</span>
75+
<template #fallback>
76+
<NuxtTime
77+
:datetime="datetime"
78+
:title="titleValue"
79+
:date-style="dateStyle"
80+
:year="year"
81+
:month="month"
82+
:day="day"
83+
:locale="locale"
84+
/>
85+
</template>
86+
</ClientOnly>
87+
</span>
88+
</button>
8689
</template>

0 commit comments

Comments
 (0)