ora/src/dashboard/components/RangeChooser.svelte

46 lines
1.1 KiB
Svelte
Raw Normal View History

2020-09-19 01:16:43 +02:00
<script>
2020-09-20 22:24:57 +02:00
import { onMount } from 'svelte'
2020-09-19 01:16:43 +02:00
import dj from 'dayjs'
import DateInput from './DateInput.svelte'
2020-09-20 22:24:57 +02:00
export let start = new Date()
export let end = new Date()
2020-09-19 01:16:43 +02:00
function set(interval, amount = 1) {
return () => {
2020-09-20 18:24:22 +02:00
start = dj().subtract(amount, interval).startOf('day').toDate()
end = dj().endOf('day').toDate()
2020-09-19 01:16:43 +02:00
}
}
function all() {
start = new Date(0)
end = new Date()
}
2020-09-19 01:30:42 +02:00
// Init
2020-09-20 22:24:57 +02:00
onMount(() => set('day', 0)())
2020-09-19 01:16:43 +02:00
</script>
<style>
.spacer {
width: 0.5em;
}
</style>
<div class="flex items-center">
<div class="btn-group">
<button class="btn btn-sm" on:click={all}>All</button>
2020-09-20 18:37:02 +02:00
<button class="btn btn-sm" on:click={set('month', 1)}>Month</button>
<button class="btn btn-sm" on:click={set('week', 1)}>Week</button>
<button class="btn btn-sm" on:click={set('day', 3)}>3 Days</button>
<button class="btn btn-sm" on:click={set('day', 0)}>Today</button>
2020-09-19 01:16:43 +02:00
</div>
<div class="spacer" />
<div class="input-group">
<DateInput bind:date={start} />
<DateInput bind:date={end} />
</div>
</div>