mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-13 17:05:47 +08:00
feat(components): [date-picker] extract props (#7893)
- Extract props from basic-month-table. - Extract common props to shared.
This commit is contained in:
parent
e4bb98102c
commit
607819c54a
@ -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'],
|
||||
|
@ -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>
|
||||
|
@ -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>
|
46
packages/components/date-picker/src/props/shared.ts
Normal file
46
packages/components/date-picker/src/props/shared.ts
Normal 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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user