summaryrefslogtreecommitdiff
path: root/src/client/components/header-clock.vue
blob: 696fd4eb678926b1cf08e440189e60fe98ee426d (plain)
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
<template>
<div class="eqryymyo">
	<div class="header">
		<time ref="time" class="_ghost">
			<span class="yyyymmdd">{{ yyyy }}/{{ mm }}/{{ dd }}</span>
			<br>
			<span class="hhnn">{{ hh }}<span :style="{ visibility: now.getSeconds() % 2 == 0 ? 'visible' : 'hidden' }">:</span>{{ nn }}</span>
		</time>
	</div>
	<div class="content _panel _ghost">
		<mk-clock/>
	</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import MkClock from './analog-clock.vue';

export default Vue.extend({
	components: {
		MkClock
	},
	data() {
		return {
			now: new Date(),
			clock: null
		};
	},
	computed: {
		yyyy(): number {
			return this.now.getFullYear();
		},
		mm(): string {
			return ('0' + (this.now.getMonth() + 1)).slice(-2);
		},
		dd(): string {
			return ('0' + this.now.getDate()).slice(-2);
		},
		hh(): string {
			return ('0' + this.now.getHours()).slice(-2);
		},
		nn(): string {
			return ('0' + this.now.getMinutes()).slice(-2);
		}
	},
	mounted() {
		this.tick();
		this.clock = setInterval(this.tick, 1000);
	},
	beforeDestroy() {
		clearInterval(this.clock);
	},
	methods: {
		tick() {
			this.now = new Date();
		}
	}
});
</script>

<style lang="scss" scoped>
.eqryymyo {
	display: inline-block;
	overflow: visible;

	> .header {
		padding: 0 12px;
		padding-top: 4px;
		text-align: center;
		font-size: 12px;
		font-family: Lucida Console, Courier, monospace;

		&:hover + .content {
			opacity: 1;
		}

		> time {
			display: table-cell;
			vertical-align: middle;
			height: 48px;

			> .yyyymmdd {
				opacity: 0.7;
			}
		}
	}

	> .content {
		opacity: 0;
		display: block;
		position: absolute;
		top: auto;
		right: 0;
		margin: 16px 0 0 0;
		padding: 16px;
		width: 230px;
		transition: opacity 0.2s ease;
	}
}
</style>