diff --git a/packages/components/calendar/__tests__/calendar.spec.ts b/packages/components/calendar/__tests__/calendar.spec.ts index dffacf47aa..453a07aa5f 100644 --- a/packages/components/calendar/__tests__/calendar.spec.ts +++ b/packages/components/calendar/__tests__/calendar.spec.ts @@ -1,6 +1,6 @@ import { nextTick } from 'vue' import { mount } from '@vue/test-utils' -import Calendar from '../src/index.vue' +import Calendar from '../src/calendar.vue' const _mount = (template: string, data?, otherObj?) => mount({ diff --git a/packages/components/calendar/index.ts b/packages/components/calendar/index.ts index ec5b3e2e71..075d3773f3 100644 --- a/packages/components/calendar/index.ts +++ b/packages/components/calendar/index.ts @@ -1,12 +1,7 @@ -import Calendar from './src/index.vue' -import type { App } from 'vue' -import type { SFCWithInstall } from '@element-plus/utils/types' +import { withInstall } from '@element-plus/utils/with-install' +import Calendar from './src/calendar.vue' -Calendar.install = (app: App): void => { - app.component(Calendar.name, Calendar) -} +export const ElCalendar = withInstall(Calendar) +export default ElCalendar -const _Calendar = Calendar as SFCWithInstall - -export default _Calendar -export const ElCalendar = _Calendar +export * from './src/calendar' diff --git a/packages/components/calendar/src/calendar.ts b/packages/components/calendar/src/calendar.ts new file mode 100644 index 0000000000..fa9afaf518 --- /dev/null +++ b/packages/components/calendar/src/calendar.ts @@ -0,0 +1,23 @@ +import { buildProps, definePropType } from '@element-plus/utils/props' +import { UPDATE_MODEL_EVENT } from '@element-plus/utils/constants' +import type { ExtractPropTypes } from 'vue' + +export const calendarProps = buildProps({ + modelValue: { + type: Date, + }, + range: { + type: definePropType<[Date, Date]>(Array), + validator: (range: unknown): range is [Date, Date] => + Array.isArray(range) && + range.length === 2 && + range.every((item) => item instanceof Date), + }, +} as const) +export type CalendarProps = ExtractPropTypes + +export const calendarEmits = { + [UPDATE_MODEL_EVENT]: (value: Date) => value instanceof Date, + input: (value: Date) => value instanceof Date, +} +export type CalendarEmits = typeof calendarEmits diff --git a/packages/components/calendar/src/index.vue b/packages/components/calendar/src/calendar.vue similarity index 90% rename from packages/components/calendar/src/index.vue rename to packages/components/calendar/src/calendar.vue index 176754038b..3760319943 100644 --- a/packages/components/calendar/src/index.vue +++ b/packages/components/calendar/src/calendar.vue @@ -49,13 +49,13 @@