File size: 1,834 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import { createDatePicker } from "@melt-ui/svelte";
import { getContext, setContext } from "svelte";
import { removeUndefined, getOptionUpdater, createBitAttrs } from "../../internal/index.js";
import { getCalendarData } from "../calendar/ctx.js";
import { getDateFieldData } from "../date-field/ctx.js";
import { getPopoverData } from "../popover/ctx.js";
import { getPositioningUpdater } from "../floating/helpers.js";
function getDatePickerData() {
const NAME = "date-picker";
return {
NAME,
};
}
export function setCtx(props) {
const { NAME } = getDatePickerData();
const { NAME: CALENDAR_NAME, PARTS: CALENDAR_PARTS } = getCalendarData();
const getCalendarAttrs = createBitAttrs(CALENDAR_NAME, CALENDAR_PARTS);
const { NAME: FIELD_NAME, PARTS: FIELD_PARTS } = getDateFieldData();
const getFieldAttrs = createBitAttrs(FIELD_NAME, FIELD_PARTS);
const { NAME: POPOVER_NAME, PARTS: POPOVER_PARTS } = getPopoverData();
const getPopoverAttrs = createBitAttrs(POPOVER_NAME, POPOVER_PARTS);
const datePicker = {
...createDatePicker({ ...removeUndefined(props), forceVisible: true }),
getCalendarAttrs,
getFieldAttrs,
getPopoverAttrs,
};
const updateOption = getOptionUpdater(datePicker.options);
setContext(NAME, { ...datePicker, updateOption });
return {
...datePicker,
updateOption,
};
}
export function getCtx() {
const { NAME } = getDatePickerData();
return getContext(NAME);
}
export function updatePositioning(props) {
const defaultPlacement = {
side: "bottom",
align: "center",
};
const withDefaults = { ...defaultPlacement, ...props };
const { options: { positioning }, } = getCtx();
const updater = getPositioningUpdater(positioning);
updater(withDefaults);
}
|