2022-07-08 15:17:17 +00:00
|
|
|
<script>
|
2022-07-12 10:06:26 +00:00
|
|
|
import { formatDuration } from './lib';
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
2022-07-08 15:17:17 +00:00
|
|
|
export let title;
|
|
|
|
export let subtitle;
|
2022-07-11 09:32:28 +00:00
|
|
|
export let color;
|
2022-07-11 11:15:39 +00:00
|
|
|
export let date;
|
2022-07-12 10:06:26 +00:00
|
|
|
export let since;
|
2022-07-12 09:34:04 +00:00
|
|
|
export let center = false;
|
2022-07-12 10:06:26 +00:00
|
|
|
|
|
|
|
let formattedDuration = '';
|
|
|
|
$: formattedDate = date ? date.toLocaleTimeString('en-GB', {
|
|
|
|
timeStyle: 'short',
|
|
|
|
}) : '';
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
if (since) {
|
|
|
|
function updateDuration() {
|
|
|
|
formattedDuration = formatDuration(
|
|
|
|
new Date().getTime() - since.getTime()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDuration();
|
|
|
|
const interval = setInterval(updateDuration, 100);
|
|
|
|
return () => clearInterval(interval);
|
|
|
|
}
|
|
|
|
});
|
2022-07-08 15:17:17 +00:00
|
|
|
</script>
|
|
|
|
|
2022-07-11 09:32:28 +00:00
|
|
|
<div class="tile {color}">
|
2022-07-11 11:15:39 +00:00
|
|
|
{#if title || subtitle || date}
|
2022-07-11 09:20:44 +00:00
|
|
|
<div class="desc">
|
2022-07-11 11:15:39 +00:00
|
|
|
<div>
|
|
|
|
{#if title}
|
|
|
|
<div class="title">{title}</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if subtitle}
|
|
|
|
<div class="subtitle">{subtitle}</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-12 10:06:26 +00:00
|
|
|
{#if date || since}
|
|
|
|
<div class="time">
|
|
|
|
{formattedDate}
|
|
|
|
{#if date && since}<br />{/if}
|
|
|
|
{formattedDuration}
|
|
|
|
</div>
|
2022-07-11 09:20:44 +00:00
|
|
|
{/if}
|
|
|
|
</div>
|
2022-07-08 15:17:17 +00:00
|
|
|
{/if}
|
2022-07-11 09:20:44 +00:00
|
|
|
|
2022-07-12 09:34:04 +00:00
|
|
|
<div class="content" class:center><slot /></div>
|
2022-07-08 15:17:17 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.tile {
|
|
|
|
padding: 1rem;
|
2022-07-09 09:12:39 +00:00
|
|
|
background-color: var(--tile-bg);
|
2022-07-08 15:17:17 +00:00
|
|
|
border-radius: var(--radius);
|
2022-07-11 09:32:28 +00:00
|
|
|
border: 2px solid var(--tile-bg);
|
2022-07-12 08:18:29 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2022-07-11 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.tile.red {
|
|
|
|
background-color: var(--red);
|
|
|
|
border-color: var(--red);
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tile.green {
|
|
|
|
border-color: var(--green);
|
2022-07-11 13:07:47 +00:00
|
|
|
background-color: var(--green);
|
2022-07-12 10:28:53 +00:00
|
|
|
color: #fff;
|
2022-07-11 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 11:17:26 +00:00
|
|
|
.tile.grey {
|
|
|
|
opacity: 0.5;
|
2022-07-11 11:20:42 +00:00
|
|
|
border-color: var(--grey);
|
2022-07-11 11:17:26 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 11:15:39 +00:00
|
|
|
.tile.grey .content {
|
|
|
|
color: var(--grey);
|
|
|
|
}
|
|
|
|
|
2022-07-11 09:32:28 +00:00
|
|
|
.desc {
|
|
|
|
margin-bottom: 1rem;
|
2022-07-11 11:15:39 +00:00
|
|
|
display: flex;
|
2022-07-08 15:17:17 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 09:32:28 +00:00
|
|
|
.desc .title {
|
2022-07-11 13:09:37 +00:00
|
|
|
font-weight: 300;
|
2022-07-12 09:34:04 +00:00
|
|
|
font-size: 1.7vw;
|
2022-07-08 15:17:17 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 09:32:28 +00:00
|
|
|
.desc .subtitle {
|
2022-07-12 09:34:04 +00:00
|
|
|
font-weight: 200;
|
|
|
|
font-size: 1.5vw;
|
2022-07-08 15:17:17 +00:00
|
|
|
}
|
2022-07-11 11:15:39 +00:00
|
|
|
|
|
|
|
.desc .time {
|
|
|
|
opacity: 0.6;
|
|
|
|
margin-left: auto;
|
2022-07-12 09:34:04 +00:00
|
|
|
font-size: 1.3vw;
|
2022-07-12 10:06:26 +00:00
|
|
|
text-align: right;
|
2022-07-11 11:15:39 +00:00
|
|
|
}
|
2022-07-12 08:18:29 +00:00
|
|
|
|
|
|
|
.content {
|
|
|
|
flex-grow: 1;
|
2022-07-12 09:34:04 +00:00
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
.content.center {
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2022-07-12 08:18:29 +00:00
|
|
|
}
|
2022-07-08 15:17:17 +00:00
|
|
|
</style>
|