-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntervalSquare.vue
More file actions
55 lines (51 loc) · 1.56 KB
/
IntervalSquare.vue
File metadata and controls
55 lines (51 loc) · 1.56 KB
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
<script setup lang="ts">
import { computed } from 'vue';
import { oneOf, integer, bool } from 'vue-types';
import { formatTime, formatTimeDuration, toTitleCase } from '@/utils';
import { IntervalType } from '@/types';
const props = defineProps({
type: oneOf(Object.values(IntervalType)).isRequired,
duration: integer().def(0),
current: bool().def(false),
});
const abbr = computed(() =>
props.type.replace(/(\w).+?($|-)/g, (_: string, v: string) =>
v.toUpperCase(),
),
);
const classes = computed(() => {
if (props.type === IntervalType.Work) {
return 'text-amber-300';
}
if (props.type === IntervalType.ShortBreak) {
return 'text-green-300';
}
if (props.type === IntervalType.LongBreak) {
return 'text-green-300';
}
return 'text-blue-100';
});
const durationFormatted = computed(() => formatTime(props.duration));
const durationAttr = computed(() => formatTimeDuration(props.duration));
const typeFormatted = computed(() => toTitleCase(props.type));
</script>
<template>
<li
class="grid rounded-md border px-2 py-1 text-center transition-colors duration-150 ease-out *:text-gray-700"
:class="[
classes,
{
'bg-current *:dark:text-stone-800': current,
'*:dark:text-inherit': !current,
},
]"
:aria-current="current ? 'time' : undefined"
>
<b class="text-sm" aria-hidden="true">{{ abbr }}</b>
<span class="sr-only">{{ typeFormatted }}</span>
<time class="text-xs" :datetime="durationAttr">
{{ durationFormatted }}
<span class="sr-only">minutes</span>
</time>
</li>
</template>