fix: prop headerRender should be optional for component Calendar

This commit is contained in:
jiang.an 2019-06-12 17:46:21 +08:00
parent 798d050352
commit 180ed017f8
2 changed files with 9 additions and 7 deletions

View File

@ -12,6 +12,8 @@ export interface RenderHeader {
onTypeChange: (type: string) => void;
}
export type HeaderRender = (headerRender: RenderHeader) => React.ReactNode;
export interface HeaderProps {
prefixCls?: string;
locale?: any;
@ -23,7 +25,7 @@ export interface HeaderProps {
onTypeChange?: (type: string) => void;
value: moment.Moment;
validRange?: [moment.Moment, moment.Moment];
headerRender: (header: RenderHeader) => React.ReactNode;
headerRender?: HeaderRender;
}
export default class Header extends React.Component<HeaderProps, any> {
@ -178,8 +180,8 @@ export default class Header extends React.Component<HeaderProps, any> {
);
};
headerRenderCustom = (): React.ReactNode => {
const { headerRender, type, onValueChange, value } = this.props;
headerRenderCustom = (headerRender: HeaderRender): React.ReactNode => {
const { type, onValueChange, value } = this.props;
return headerRender({
value,
@ -194,7 +196,7 @@ export default class Header extends React.Component<HeaderProps, any> {
const typeSwitch = this.getTypeSwitch();
const { yearReactNode, monthReactNode } = this.getMonthYearSelections(getPrefixCls);
return headerRender ? (
this.headerRenderCustom()
this.headerRenderCustom(headerRender)
) : (
<div className={`${prefixCls}-header`} ref={this.getCalenderHeaderNode}>
{yearReactNode}

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import * as PropTypes from 'prop-types';
import * as moment from 'moment';
import FullCalendar from 'rc-calendar/lib/FullCalendar';
import Header, { RenderHeader } from './Header';
import Header, { HeaderRender } from './Header';
import enUS from './locale/en_US';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
@ -41,7 +41,7 @@ export interface CalendarProps {
onChange?: (date?: moment.Moment) => void;
disabledDate?: (current: moment.Moment) => boolean;
validRange?: [moment.Moment, moment.Moment];
headerRender: (header: RenderHeader) => React.ReactNode;
headerRender?: HeaderRender;
}
export interface CalendarState {
@ -56,7 +56,6 @@ class Calendar extends React.Component<CalendarProps, CalendarState> {
onSelect: noop,
onPanelChange: noop,
onChange: noop,
headerRender: null,
};
static propTypes = {
@ -73,6 +72,7 @@ class Calendar extends React.Component<CalendarProps, CalendarState> {
value: PropTypes.object as PropTypes.Requireable<moment.Moment>,
onSelect: PropTypes.func,
onChange: PropTypes.func,
headerRender: PropTypes.func,
};
static getDerivedStateFromProps(nextProps: CalendarProps) {