ant-design/components/calendar/Notes.jsx

45 lines
1.1 KiB
React
Raw Normal View History

2015-11-11 12:22:14 +08:00
import React, {PropTypes, Component} from 'react';
import NoteList from './NoteList';
import Tooltip from '../tooltip';
import {PREFIX_CLS} from './Constants';
class Notes extends Component {
render() {
2015-11-11 14:30:15 +08:00
const {listData, threshold, prefixCls} = this.props;
2015-11-11 12:22:14 +08:00
const classNames = [prefixCls];
let items;
2015-11-11 14:30:15 +08:00
if (listData.length > threshold) {
2015-11-11 12:22:14 +08:00
items = new Array(threshold).fill('gray');
classNames.push(`${prefixCls}-overflow`);
} else {
2015-11-11 14:30:15 +08:00
items = listData.map(item => item.type);
2015-11-11 12:22:14 +08:00
}
const el = (<div className={classNames.join(' ')}>
{
items.map((type, i) => (
<span key={`item-${i}`}
className={`${prefixCls}-node-${type}`}></span>
)
)
}
</div>);
return (
2015-11-11 14:30:15 +08:00
<Tooltip placement="right" trigger={['hover']} overlay={<NoteList listData={listData} />}>{el}</Tooltip>
2015-11-11 12:22:14 +08:00
);
}
}
Notes.propTypes = {
2015-11-11 14:30:15 +08:00
listData: PropTypes.array,
2015-11-11 12:22:14 +08:00
threshold: PropTypes.number,
prefixCls: PropTypes.string,
};
Notes.defaultProps = {
2015-11-11 14:30:15 +08:00
listData: null,
2015-11-11 12:22:14 +08:00
threshold: 3,
prefixCls: `${PREFIX_CLS}-notes`,
};
export default Notes;