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

35 lines
743 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"
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
export let value
export let label
export let width = "medium"
export let size = "small"
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="uk-margin">
2020-02-03 10:50:30 +01: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 11:35:57 +02:00
</div>