diff --git a/packages/components/calendar/src/calendar.ts b/packages/components/calendar/src/calendar.ts index bd22c8dbf5..9de46e68e4 100644 --- a/packages/components/calendar/src/calendar.ts +++ b/packages/components/calendar/src/calendar.ts @@ -6,7 +6,7 @@ import { } from '@element-plus/utils' import { INPUT_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants' -import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue' +import type { ExtractPublicPropTypes } from 'vue' export type CalendarDateType = | 'prev-month' @@ -18,6 +18,29 @@ export type CalendarDateType = const isValidRange = (range: unknown): range is [Date, Date] => isArray(range) && range.length === 2 && range.every((item) => isDate(item)) +export interface CalendarProps { + /** + * @description binding value + */ + modelValue?: Date + /** + * @description time range, including start time and end time. + * Start time must be start day of week, end time must be end day of week, the time span cannot exceed two months. + */ + range?: [Date, Date] + /** + * @description type of the controller for the Calendar header + */ + controllerType?: 'button' | 'select' + /** + * @description format label when `controller-type` is 'select' + */ + formatter?: (value: number, type: 'year' | 'month') => string | number +} + +/** + * @deprecated Removed after 3.0.0, Use `CalendarProps` instead. + */ export const calendarProps = buildProps({ /** * @description binding value @@ -50,7 +73,9 @@ export const calendarProps = buildProps({ >(Function), }, } as const) -export type CalendarProps = ExtractPropTypes +/** + * @deprecated Removed after 3.0.0, Use `CalendarProps` instead. + */ export type CalendarPropsPublic = ExtractPublicPropTypes export const calendarEmits = { diff --git a/packages/components/calendar/src/calendar.vue b/packages/components/calendar/src/calendar.vue index f93a4f9de8..f865e4b1da 100644 --- a/packages/components/calendar/src/calendar.vue +++ b/packages/components/calendar/src/calendar.vue @@ -62,9 +62,11 @@ import { ElButton, ElButtonGroup } from '@element-plus/components/button' import { useLocale, useNamespace } from '@element-plus/hooks' import DateTable from './date-table.vue' import { useCalendar } from './use-calendar' -import { calendarEmits, calendarProps } from './calendar' +import { calendarEmits } from './calendar' import SelectController from './select-controller.vue' +import type { CalendarProps } from './calendar' + const ns = useNamespace('calendar') const COMPONENT_NAME = 'ElCalendar' @@ -72,7 +74,9 @@ defineOptions({ name: COMPONENT_NAME, }) -const props = defineProps(calendarProps) +const props = withDefaults(defineProps(), { + controllerType: 'button', +}) const emit = defineEmits(calendarEmits) const { diff --git a/packages/components/calendar/src/date-table.ts b/packages/components/calendar/src/date-table.ts index 69f608235e..ba52764911 100644 --- a/packages/components/calendar/src/date-table.ts +++ b/packages/components/calendar/src/date-table.ts @@ -1,7 +1,7 @@ import { buildProps, definePropType, isObject } from '@element-plus/utils' import { rangeArr } from '@element-plus/components/time-picker' -import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue' +import type { ExtractPublicPropTypes } from 'vue' import type { Dayjs } from 'dayjs' export type CalendarDateCellType = 'next' | 'prev' | 'current' @@ -26,6 +26,16 @@ export const toNestedArr = (days: CalendarDateCell[]) => return days.slice(start, start + 7) }) +export interface DateTableProps { + selectedDay?: Dayjs + range?: [Dayjs, Dayjs] + date: Dayjs + hideHeader?: boolean +} + +/** + * @deprecated Removed after 3.0.0, Use `DateTableProps` instead. + */ export const dateTableProps = buildProps({ selectedDay: { type: definePropType(Object), @@ -41,7 +51,9 @@ export const dateTableProps = buildProps({ type: Boolean, }, } as const) -export type DateTableProps = ExtractPropTypes +/** + * @deprecated Removed after 3.0.0, Use `DateTableProps` instead. + */ export type DateTablePropsPublic = ExtractPublicPropTypes export const dateTableEmits = { diff --git a/packages/components/calendar/src/date-table.vue b/packages/components/calendar/src/date-table.vue index b5801efd8d..bdf116b40e 100644 --- a/packages/components/calendar/src/date-table.vue +++ b/packages/components/calendar/src/date-table.vue @@ -38,16 +38,16 @@