1
0
Fork 0
mirror of synced 2024-07-16 19:56:10 +12:00
budibase/packages/builder/src/components/common/DatePicker.svelte

33 lines
755 B
Svelte
Raw Normal View History

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