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

35 lines
743 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"
2019-07-13 21:35:57 +12:00
2020-02-03 22:50:30 +13:00
export let value
export let label
export let width = "medium"
export let size = "small"
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="uk-margin">
2020-02-03 22:50:30 +13:00
<label class="uk-form-label">{label}</label>
<div class="uk-form-controls">
<input
class="uk-input uk-form-width-{width} uk-form-{size}"
bind:this={input} />
</div>
2019-07-13 21:35:57 +12:00
</div>