hongluan-ui
Version:
Hongluan Component Library for Vue 3
99 lines (96 loc) • 3.4 kB
JavaScript
import { defineComponent, provide, reactive, toRef, ref, computed, createVNode, mergeProps } from 'vue';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
import advancedFormat from 'dayjs/plugin/advancedFormat.js';
import localeData from 'dayjs/plugin/localeData.js';
import weekOfYear from 'dayjs/plugin/weekOfYear.js';
import weekYear from 'dayjs/plugin/weekYear.js';
import dayOfYear from 'dayjs/plugin/dayOfYear.js';
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter.js';
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
import '../../time-picker/index.mjs';
import '../../../tokens/index.mjs';
import '../../../hooks/index.mjs';
import { datePickerProps } from './props/date-picker.mjs';
import { getPanel } from './panel-utils.mjs';
import { ROOT_PICKER_INJECTION_KEY } from '../../../tokens/date-picker.mjs';
import { DEFAULT_FORMATS_DATEPICKER, DEFAULT_FORMATS_DATE } from '../../time-picker/src/constants.mjs';
import { useConsistentProp } from '../../../hooks/use-consistent-prop/index.mjs';
import _sfc_main from '../../time-picker/src/common/picker.mjs';
dayjs.extend(localeData);
dayjs.extend(advancedFormat);
dayjs.extend(customParseFormat);
dayjs.extend(weekOfYear);
dayjs.extend(weekYear);
dayjs.extend(dayOfYear);
dayjs.extend(isSameOrAfter);
dayjs.extend(isSameOrBefore);
var DatePicker = defineComponent({
name: "DatePicker",
install: null,
props: datePickerProps,
emits: ["update:modelValue"],
setup(props, {
expose,
emit,
slots
}) {
provide("PopperOptions", reactive(toRef(props, "popperOptions")));
provide(ROOT_PICKER_INJECTION_KEY, {
slots
});
const commonPicker = ref();
const refProps = {
focus: (focusStartInput = true) => {
var _a;
(_a = commonPicker.value) == null ? void 0 : _a.focus(focusStartInput);
},
handleOpen: () => {
var _a;
(_a = commonPicker.value) == null ? void 0 : _a.handleOpen();
},
handleClose: () => {
var _a;
(_a = commonPicker.value) == null ? void 0 : _a.handleClose();
},
popperPaneRef: computed(() => {
var _a;
return (_a = commonPicker.value) == null ? void 0 : _a.popperPaneRef;
})
};
expose(refProps);
const onModelValueUpdated = (val) => {
emit("update:modelValue", val);
};
return () => {
var _a;
const format = (_a = props.format) != null ? _a : DEFAULT_FORMATS_DATEPICKER[props.type] || DEFAULT_FORMATS_DATE;
const {
size,
disabled,
fill
} = useConsistentProp();
const Component = getPanel(props.type);
return createVNode(_sfc_main, mergeProps(props, {
"format": format,
"type": props.type,
"size": size.value,
"disabled": disabled.value,
"fill": fill.value,
"ref": commonPicker,
"onUpdate:modelValue": onModelValueUpdated
}), {
default: (scopedProps) => createVNode(Component, scopedProps, {
"prev-month": slots["prev-month"],
"next-month": slots["next-month"],
"prev-year": slots["prev-year"],
"next-year": slots["next-year"]
}),
icon: slots.icon,
"range-separator": slots["range-separator"]
});
};
}
});
export { DatePicker as default };
//# sourceMappingURL=date-picker.mjs.map