-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimelineTooltip.vue
99 lines (84 loc) · 2.04 KB
/
TimelineTooltip.vue
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
<template>
<div v-if="this.contents" id="tooltip">
<header>
<div class="header-description">
<div>
<strong>{{ this.contents.where }}</strong>
</div>
<div>{{ this.contents.title }} - {{ this.contents.type }}</div>
<div class="time-period">
{{ this.getFormattedPeriod() }}
<span class="time-duration">({{ this.getDuration() }})</span>
</div>
</div>
<img v-if="this.contents.logoUrl" :src="this.contents.logoUrl" />
</header>
<hr v-if="this.hasActivities()" />
<ul v-for="activity in this.contents.activities" :key="activity">
<li>{{ activity }}</li>
</ul>
</div>
</template>
<script>
import { intervalToDuration, formatDuration } from "date-fns";
export default {
props: ["contents"],
methods: {
hasActivities() {
return this.contents.activities && this.contents.activities.length;
},
formatDate(dateString) {
return dateString.replace(/-/g, "/");
},
getFormattedPeriod() {
const { begin, end } = this.contents.period;
return `${this.formatDate(begin)} - ${this.formatDate(end || "Ongoing")}`;
},
getDuration() {
const { begin, end } = this.contents.period;
const duration = intervalToDuration({
start: new Date(begin),
end: end ? new Date(end) : new Date(),
});
return formatDuration(duration, { format: ['years', 'months'] });
},
},
};
</script>
<style scoped>
hr {
border: 1px dashed;
opacity: 0.5;
margin-bottom: 1rem;
}
img {
float: right;
}
header {
clear: both;
/* height: 100px; */
}
header:after {
content: "";
display: table;
clear: both;
}
.header-description {
float: left;
}
.time-period {
font-size: 12px;
}
.time-duration {
opacity: 0.6;
}
#tooltip {
border-left: 5px solid indigo;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
padding: 1em;
-webkit-box-shadow: 0px 0px 40px 10px rgba(0, 0, 0, 0.4);
box-shadow: 0px 0px 40px 10px rgba(0, 0, 0, 0.4);
}
</style>