mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
fix(date-picker): load rangePlugin dynamically
This commit is contained in:
parent
48d4c0ba37
commit
77771712f9
3 changed files with 46 additions and 41 deletions
|
@ -128,9 +128,8 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
async function initCalendar() {
|
||||||
if ($hasCalendar && !calendar) {
|
calendar = await createCalendar({
|
||||||
calendar = createCalendar({
|
|
||||||
options: {
|
options: {
|
||||||
appendTo: datePickerRef,
|
appendTo: datePickerRef,
|
||||||
dateFormat,
|
dateFormat,
|
||||||
|
@ -165,6 +164,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterUpdate(() => {
|
||||||
if (calendar) {
|
if (calendar) {
|
||||||
if ($range) {
|
if ($range) {
|
||||||
calendar.setDate([$inputValueFrom, $inputValueTo]);
|
calendar.setDate([$inputValueFrom, $inputValueTo]);
|
||||||
|
@ -189,6 +189,7 @@
|
||||||
$: valueFrom = $inputValueFrom;
|
$: valueFrom = $inputValueFrom;
|
||||||
$: inputValueTo.set(valueTo);
|
$: inputValueTo.set(valueTo);
|
||||||
$: valueTo = $inputValueTo;
|
$: valueTo = $inputValueTo;
|
||||||
|
$: if ($hasCalendar && !calendar && inputRef) initCalendar();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:body
|
<svelte:body
|
||||||
|
|
|
@ -72,9 +72,7 @@
|
||||||
|
|
||||||
add({ id, labelText });
|
add({ id, labelText });
|
||||||
|
|
||||||
onMount(() => {
|
$: if (ref) declareRef({ id, ref });
|
||||||
declareRef({ id, ref });
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import flatpickr from "flatpickr";
|
import flatpickr from "flatpickr";
|
||||||
import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
|
|
||||||
|
|
||||||
let l10n;
|
let l10n;
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ function updateMonthNode(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCalendar({ options, base, input, dispatch }) {
|
async function createCalendar({ options, base, input, dispatch }) {
|
||||||
let locale = options.locale;
|
let locale = options.locale;
|
||||||
|
|
||||||
if (options.locale === "en" && l10n && l10n.en) {
|
if (options.locale === "en" && l10n && l10n.en) {
|
||||||
|
@ -61,6 +60,13 @@ function createCalendar({ options, base, input, dispatch }) {
|
||||||
locale = l10n.en;
|
locale = l10n.en;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let rangePlugin;
|
||||||
|
|
||||||
|
if (options.mode === "range") {
|
||||||
|
const importee = await import("flatpickr/dist/esm/plugins/rangePlugin");
|
||||||
|
rangePlugin = importee.default;
|
||||||
|
}
|
||||||
|
|
||||||
return new flatpickr(base, {
|
return new flatpickr(base, {
|
||||||
...options,
|
...options,
|
||||||
allowInput: true,
|
allowInput: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue