budibase/packages/builder/src/components/common/DatePicker.svelte

33 lines
755 B
Svelte
Raw Normal View History

2019-07-13 11:35:57 +02:00
<script>
2020-02-03 10:50:30 +01:00
import flatpickr from "flatpickr"
import "flatpickr/dist/flatpickr.css"
import { onMount } from "svelte"
2020-09-01 23:00:30 +02:00
import { Label, Input } from "@budibase/bbui"
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
export let value
export let label
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
let input
let fpInstance
2020-02-03 10:50:30 +01:00
$: if (fpInstance) fpInstance.setDate(value)
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
onMount(() => {
fpInstance = flatpickr(input, {})
2019-07-13 11:35:57 +02:00
fpInstance.config.onChange.push(selectedDates => {
2020-02-03 10:50:30 +01:00
if (selectedDates.length > 0) value = new Date(selectedDates[0])
})
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
return fpInstance
})
2019-07-13 11:35:57 +02:00
</script>
<div class="bb-margin-m">
<Label small forAttr={'datepicker-label'}>{label}</Label>
2020-09-01 23:00:30 +02:00
<Input thin bind:this={input} />
2019-07-13 11:35:57 +02:00
</div>
2020-09-01 23:00:30 +02:00
<!-- TODO: Verify DatePicker Input works as expected when datetime property used again
in CreateEditColumn -->