-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTimer.vue
More file actions
37 lines (34 loc) · 901 Bytes
/
BaseTimer.vue
File metadata and controls
37 lines (34 loc) · 901 Bytes
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
<script setup lang="ts">
import { oneOf, integer } from 'vue-types';
import { computed } from 'vue';
import {
formatTime,
getIntervalTypeColor,
getMinutes,
getSeconds,
} from '@/utils';
import { IntervalType } from '@/types';
const props = defineProps({
type: oneOf(['none', ...Object.values(IntervalType)] as const).def('none'),
duration: integer().def(0),
});
const time = computed(() => formatTime(props.duration));
const label = computed(() => {
const mins = getMinutes(props.duration);
const secs = getSeconds(props.duration);
return `${mins} minutes ${secs ? secs + ' seconds ' : ''}left`;
});
const classes = computed(() =>
getIntervalTypeColor(props.type as IntervalType),
);
</script>
<template>
<div
role="timer"
class="rounded-lg border-4 px-8 py-4 text-4xl tabular-nums"
:class="classes"
:aria-label="label"
>
{{ time }}
</div>
</template>