date-picker.mjs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { UPDATE_MODEL_EVENT } from "../../../constants/event.mjs";
  2. import { DEFAULT_FORMATS_DATE, DEFAULT_FORMATS_DATEPICKER, PICKER_POPPER_OPTIONS_INJECTION_KEY } from "../../time-picker/src/constants.mjs";
  3. import picker_default from "../../time-picker/src/common/picker.mjs";
  4. import { ROOT_PICKER_IS_DEFAULT_FORMAT_INJECTION_KEY } from "../../date-picker-panel/src/constants.mjs";
  5. import { ElDatePickerPanel } from "../../date-picker-panel/index.mjs";
  6. import { datePickerProps } from "./props.mjs";
  7. import { computed, createVNode, defineComponent, isVNode, mergeProps, provide, reactive, ref, toRef } from "vue";
  8. //#region ../../packages/components/date-picker/src/date-picker.tsx
  9. function _isSlot(s) {
  10. return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
  11. }
  12. var date_picker_default = /* @__PURE__ */ defineComponent({
  13. name: "ElDatePicker",
  14. install: null,
  15. props: datePickerProps,
  16. emits: [UPDATE_MODEL_EVENT],
  17. setup(props, { expose, emit, slots }) {
  18. provide(ROOT_PICKER_IS_DEFAULT_FORMAT_INJECTION_KEY, computed(() => {
  19. return !props.format;
  20. }));
  21. provide(PICKER_POPPER_OPTIONS_INJECTION_KEY, reactive(toRef(props, "popperOptions")));
  22. const commonPicker = ref();
  23. expose({
  24. focus: () => {
  25. commonPicker.value?.focus();
  26. },
  27. blur: () => {
  28. commonPicker.value?.blur();
  29. },
  30. handleOpen: () => {
  31. commonPicker.value?.handleOpen();
  32. },
  33. handleClose: () => {
  34. commonPicker.value?.handleClose();
  35. }
  36. });
  37. const onModelValueUpdated = (val) => {
  38. emit(UPDATE_MODEL_EVENT, val);
  39. };
  40. return () => {
  41. const format = props.format ?? (DEFAULT_FORMATS_DATEPICKER[props.type] || DEFAULT_FORMATS_DATE);
  42. return createVNode(picker_default, mergeProps(props, {
  43. "format": format,
  44. "type": props.type,
  45. "ref": commonPicker,
  46. "onUpdate:modelValue": onModelValueUpdated
  47. }), {
  48. default: (scopedProps) => createVNode(ElDatePickerPanel, mergeProps({
  49. "disabled": props.disabled,
  50. "editable": props.editable,
  51. "border": false
  52. }, scopedProps), _isSlot(slots) ? slots : { default: () => [slots] }),
  53. "range-separator": slots["range-separator"]
  54. });
  55. };
  56. }
  57. });
  58. //#endregion
  59. export { date_picker_default as default };
  60. //# sourceMappingURL=date-picker.mjs.map