feat(components): [date-picker] extract props (#7893)

- Extract props from basic-month-table.
- Extract common props to shared.
This commit is contained in:
JeremyWuuuuu 2022-05-25 22:39:30 +08:00 committed by GitHub
parent e4bb98102c
commit 607819c54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 65 deletions

View File

@ -36,9 +36,7 @@ import dayjs from 'dayjs'
import { useLocale } from '@element-plus/hooks'
import { rangeArr } from '@element-plus/components/time-picker'
import { castArray, hasClass } from '@element-plus/utils'
import type { PropType } from 'vue'
import type { Dayjs } from 'dayjs'
import { basicMonthTableProps } from '../props/basic-month-table'
const datesInMonth = (year: number, month: number, lang: string) => {
const firstDay = dayjs().locale(lang).startOf('month').month(month).year(year)
@ -47,34 +45,7 @@ const datesInMonth = (year: number, month: number, lang: string) => {
}
export default defineComponent({
props: {
disabledDate: {
type: Function as PropType<(_: Date) => void>,
},
selectionMode: {
type: String,
default: 'month',
},
minDate: {
type: Object as PropType<Dayjs>,
},
maxDate: {
type: Object as PropType<Dayjs>,
},
date: {
type: Object as PropType<Dayjs>,
},
parsedValue: {
type: Object as PropType<Dayjs>,
},
rangeState: {
type: Object,
default: () => ({
endDate: null,
selecting: false,
}),
},
},
props: basicMonthTableProps,
emits: ['changerange', 'pick', 'select'],
expose: ['focus'],

View File

@ -1,44 +1,15 @@
import { buildProps, definePropType } from '@element-plus/utils'
import { datePickerSharedProps, selectionModeWithDefault } from './shared'
import type { ExtractPropTypes } from 'vue'
import type { Dayjs } from 'dayjs'
type RangeState = {
endDate: null
selecting: boolean
}
export const basicDateTableProps = buildProps({
date: {
type: definePropType<Dayjs>(Object),
},
minDate: {
type: definePropType<Dayjs>(Object),
},
maxDate: {
type: definePropType<Dayjs>(Object),
},
parsedValue: {
type: definePropType<Dayjs | Dayjs[]>([Object, Array]),
},
selectionMode: {
type: String,
default: 'date',
...datePickerSharedProps,
cellClassName: {
type: definePropType<(date: Date) => string>(Function),
},
showWeekNumber: Boolean,
disabledDate: {
type: Function,
},
cellClassName: {
type: Function,
},
rangeState: {
type: definePropType<RangeState>(Object),
default: () => ({
endDate: null,
selecting: false,
}),
},
selectionMode: selectionModeWithDefault('date'),
} as const)
export type BasicDateTableProps = ExtractPropTypes<typeof basicDateTableProps>

View File

@ -0,0 +1,11 @@
import { buildProps } from '@element-plus/utils'
import { datePickerSharedProps, selectionModeWithDefault } from './shared'
import type { ExtractPropTypes } from 'vue'
export const basicMonthTableProps = buildProps({
...datePickerSharedProps,
selectionMode: selectionModeWithDefault('month'),
})
export type BasicMonthTableProps = ExtractPropTypes<typeof basicMonthTableProps>

View File

@ -0,0 +1,46 @@
import { buildProps, definePropType } from '@element-plus/utils'
import type { Dayjs } from 'dayjs'
const selectionModes = ['date', 'dates', 'year', 'month', 'week']
type RangeState = {
endDate: null | Dayjs
selecting: boolean
}
export const datePickerSharedProps = buildProps({
disabledDate: {
type: definePropType<(date: Date) => boolean>(Function),
},
date: {
type: definePropType<Dayjs>(Object),
required: true,
},
minDate: {
type: definePropType<Dayjs | null>(Object),
},
maxDate: {
type: definePropType<Dayjs | null>(Object),
},
parsedValue: {
type: definePropType<Dayjs | Dayjs[]>([Object, Array]),
},
rangeState: {
type: definePropType<RangeState>(Object),
default: () => ({
endDate: null,
selecting: false,
}),
},
} as const)
export const selectionModeWithDefault = (
mode: typeof selectionModes[number]
) => {
return {
type: String,
values: selectionModes,
default: mode,
}
}