import React from 'react' import moment from 'moment' import { observable } from 'mobx' import DatePicker from './date_picker' const datePickerStatus = { date: new Date('2020-11-15 23:32:22'), setDate(date: Date | null) { console.log('selected date', date) this.date = date as any }, } const commonStore = observable(datePickerStatus) const inputValueRenderStore = observable(datePickerStatus) const disabledStore1 = observable(datePickerStatus) const disabledStore2 = observable(datePickerStatus) const disabledStore3 = observable(datePickerStatus) const withNoInputStatus = observable(datePickerStatus) const addTimeStore = observable(datePickerStatus) export const ComDatePicker = () => { return ( <>
normal
commonStore.setDate(date)} />
自定义日期展示形式
inputValueRenderStore.setDate(date)} renderDate={(begin) => `${begin.getMonth() + 1}月-${begin.getDate()}日`} /> ) } export const ComDatePickerWithDisabled = () => { return ( <>
禁止点击选择
disabledStore1.setDate(date)} />
自定义禁止选择的日期段
只能选择非周五的日期
{ return moment(m).get('day') === 5 }} onChange={(date) => disabledStore2.setDate(date)} />
只能选择今天之后的日期
disabledStore3.setDate(date)} />
) } export const ComDatePickerWithCustomChildren = () => ( <>
自定义children
withNoInputStatus.setDate(date)} > {withNoInputStatus.date ? moment(withNoInputStatus.date!).format('YYYY-MM-DD') : '请点击选择'} ) export const ComDatePickerWithTimeSelect = () => ( <>
增加时间选择
{ addTimeStore.setDate(date) }} enabledTimeSelect /> ) export default { title: '表单/DatePicker', }