ant-design/components/calendar/index.jsx

95 lines
3.0 KiB
React
Raw Normal View History

2015-11-11 00:15:12 +08:00
import React, {PropTypes, Component} from 'react';
import CalendarLocale from 'rc-calendar/lib/locale/zh_CN';
import FullCalendar from 'rc-calendar/lib/FullCalendar';
2015-11-11 12:22:14 +08:00
import Notes from './Notes';
import NoteList from './NoteList';
import {PREFIX_CLS} from './Constants';
2015-11-11 00:15:12 +08:00
function noop () { return null; }
function zerofixed (v) {
if (v < 10) return '0' + v;
return v + '';
}
2015-11-11 12:22:14 +08:00
const MonthCellNoteNum = ({num, prefixCls}) => {
return (
<div className={`${prefixCls}-month-cell`}>
<section>{num}</section>
<span>待办事项数</span>
</div>
);
};
2015-11-11 00:15:12 +08:00
class NoticeCalendar extends Component {
monthCellRender(value, locale) {
2015-11-11 12:22:14 +08:00
const prefixCls = this.props.prefixCls;
2015-11-11 00:15:12 +08:00
const month = value.getMonth();
const noteNum = this.props.getMonthData(value);
if (noteNum > 0) {
return (
2015-11-11 12:22:14 +08:00
<a className={`${prefixCls}-month-panel-month`}>
2015-11-11 00:15:12 +08:00
<span>{locale.format.shortMonths[month]}</span>
2015-11-11 12:22:14 +08:00
<MonthCellNoteNum num={noteNum} prefixCls={`${prefixCls}-notes`} />
2015-11-11 00:15:12 +08:00
</a>
);
}
return (
2015-11-11 12:22:14 +08:00
<a className={`${prefixCls}-month-panel-month`}>{locale.format.shortMonths[month]}</a>
2015-11-11 00:15:12 +08:00
);
}
fullscreenDateCellRender(value) {
2015-11-11 12:22:14 +08:00
const prefixCls = this.props.prefixCls;
2015-11-11 14:30:15 +08:00
let listData = this.props.getDateData(value);
2015-11-11 00:15:12 +08:00
return (
2015-11-11 12:22:14 +08:00
<span className={`${prefixCls}-date ${prefixCls}-notes-date-full`}>
2015-11-11 00:15:12 +08:00
<span>{ zerofixed(value.getDayOfMonth()) }</span>
2015-11-11 14:30:15 +08:00
<NoteList listData={listData} />
2015-11-11 00:15:12 +08:00
</span>
);
}
dateCellRender(value) {
2015-11-11 12:22:14 +08:00
const prefixCls = this.props.prefixCls;
const el = (<span className={`${prefixCls}-date ${prefixCls}-notes-date`}>{ zerofixed(value.getDayOfMonth()) }</span>);
2015-11-11 14:30:15 +08:00
const listData = this.props.getDateData(value);
2015-11-11 00:15:12 +08:00
return (
<div style={{position: 'relative', height: 32}}>
{ el }
2015-11-11 14:30:15 +08:00
{ (listData && listData.length > 0) ? <Notes listData={listData} /> : null }
2015-11-11 00:15:12 +08:00
</div>
);
}
render() {
const props = this.props;
const {fullscreen, monthCellRender, dateCellRender, fullscreenDateCellRender} = props;
const _monthCellRender = monthCellRender ? monthCellRender : this.monthCellRender;
const _dateCellRender = dateCellRender ? dateCellRender : this.dateCellRender;
const _fullscreenDateCellRender = fullscreenDateCellRender ? fullscreenDateCellRender : this.fullscreenDateCellRender;
return (<FullCalendar
{...props}
monthCellRender={ fullscreen ? _monthCellRender.bind(this) : null }
dateCellRender={ fullscreen ? _fullscreenDateCellRender.bind(this) : _dateCellRender.bind(this) }/>);
}
}
NoticeCalendar.propTypes = {
monthCellRender: PropTypes.func,
dateCellRender: PropTypes.func,
fullDateCellRender: PropTypes.func,
getMonthData: PropTypes.func,
getDateData: PropTypes.func,
fullscreen: PropTypes.bool,
locale: PropTypes.object,
2015-11-11 12:22:14 +08:00
prefixCls: PropTypes.string,
2015-11-11 00:15:12 +08:00
};
NoticeCalendar.defaultProps = {
locale: CalendarLocale,
getMonthData: noop,
getDateData: noop,
fullscreen: false,
2015-11-11 12:22:14 +08:00
prefixCls: PREFIX_CLS,
2015-11-11 00:15:12 +08:00
};
export default NoticeCalendar;