提交 081be0c8 编写于 作者: A afc163

Add notice calendar demo

上级 077f7de4
# 自定义渲染 # 自定义渲染
- order: 2 - order: 1
`dateCellRender``monthCellRender` 函数来自定义需要渲染的数据。 `dateCellRender``monthCellRender` 函数来自定义需要渲染的数据。
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
import { Calendar } from 'antd'; import { Calendar } from 'antd';
function dateCellRender(value) { function dateCellRender(value) {
return <div>date</div>; return <div>自定义日数据</div>;
} }
function monthCellRender(value) { function monthCellRender(value) {
return <div>month</div>; return <div>自定义月数据</div>;
} }
ReactDOM.render( ReactDOM.render(
......
# 通知事项日历演示
- order: 2
一个复杂的应用实例。
---
````jsx
import { Calendar } from 'antd';
function getListData(value) {
console.log(value.getDayOfMonth());
var listData;
switch (value.getDayOfMonth()) {
case 8:
listData = [
{ type: 'warn', content: '这里是警告事项.' },
{ type: 'normal', content: '这里是普通事项.' }
]; break;
case 10:
listData = [
{ type: 'warn', content: '这里是警告事项.' },
{ type: 'normal', content: '这里是普通事项.' },
{ type: 'error', content: '这里是错误事项.' }
]; break;
case 15:
listData = [
{ type: 'warn', content: '这里是警告事项.' },
{ type: 'normal', content: '这里是普通事项好长啊。。....' },
{ type: 'error', content: '这里是错误事项.' },
{ type: 'error', content: '这里是错误事项.' },
{ type: 'error', content: '这里是错误事项.' },
{ type: 'error', content: '这里是错误事项.' }
]; break;
}
return listData || [];
}
function dateCellRender(value) {
let listData = getListData(value);
return <ul className="events">
{listData.map((item, index) =>
<li key={index}>
<span className={`event-${item.type}`}></span>
{item.content}
</li>
)}
</ul>;
}
function getMonthData(value) {
if (value.getMonth() === 8) {
return 1394;
}
}
function monthCellRender(value) {
let num = getMonthData(value);
return num ? <div className="notes-month">
<section>{num}</section>
<span>待办事项数</span>
</div> : null;
}
ReactDOM.render(
<Calendar dateCellRender={dateCellRender} monthCellRender={monthCellRender} />
, document.getElementById('components-calendar-demo-notice-calendar'));
````
````css
.events {
line-height: 24px;
list-style: none;
margin: 0;
padding: 0;
}
.events li {
color: #999;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.events li span {
vertical-align: middle;
}
.events li span:first-child {
font-size: 9px;
margin-right: 4px;
}
.event-warn {
color: #fac450;
}
.event-normal {
color: #2db7f5;
}
.event-error {
color: #f60;
}
.notes-month {
text-align: center;
}
.notes-month section {
font-size: 28px;
}
````
...@@ -32,7 +32,9 @@ class Calendar extends Component { ...@@ -32,7 +32,9 @@ class Calendar extends Component {
<div className={`${prefixCls}-value`}> <div className={`${prefixCls}-value`}>
{locale.format.shortMonths[month]} {locale.format.shortMonths[month]}
</div> </div>
{this.props.monthCellRender(value)} <div className={`${prefixCls}-content`}>
{this.props.monthCellRender(value)}
</div>
</div>; </div>;
} }
dateCellRender(value) { dateCellRender(value) {
...@@ -41,7 +43,9 @@ class Calendar extends Component { ...@@ -41,7 +43,9 @@ class Calendar extends Component {
<div className={`${prefixCls}-value`}> <div className={`${prefixCls}-value`}>
{zerofixed(value.getDayOfMonth())} {zerofixed(value.getDayOfMonth())}
</div> </div>
{this.props.dateCellRender(value)} <div className={`${prefixCls}-content`}>
{this.props.dateCellRender(value)}
</div>
</div>; </div>;
} }
setValue(value) { setValue(value) {
......
...@@ -51,6 +51,10 @@ ...@@ -51,6 +51,10 @@
border: none; border: none;
} }
td {
position: relative;
}
&-calendar-table { &-calendar-table {
border-spacing: 0; border-spacing: 0;
margin-bottom: 0; margin-bottom: 0;
...@@ -73,6 +77,11 @@ ...@@ -73,6 +77,11 @@
} }
} }
&-month,
&-date {
text-align: center;
}
&-value { &-value {
display: block; display: block;
margin: 0 auto; margin: 0 auto;
...@@ -83,7 +92,6 @@ ...@@ -83,7 +92,6 @@
padding: 0; padding: 0;
background: transparent; background: transparent;
line-height: 22px; line-height: 22px;
text-align: center;
&:hover { &:hover {
background: tint(@primary-color, 90%); background: tint(@primary-color, 90%);
...@@ -139,7 +147,7 @@ ...@@ -139,7 +147,7 @@
width: 46px; width: 46px;
margin: 0 auto; margin: 0 auto;
color: @text-color; color: @text-color;
border-radius: 4px 4px; border-radius: 4px;
height: 36px; height: 36px;
padding: 0; padding: 0;
background: transparent; background: transparent;
...@@ -171,10 +179,10 @@ ...@@ -171,10 +179,10 @@
} }
} }
&-notes-wrapper { &-content {
position: absolute; position: absolute;
width: 100%; width: 100%;
left:0; left: 0;
bottom: -9px; bottom: -9px;
} }
...@@ -198,6 +206,7 @@ ...@@ -198,6 +206,7 @@
&-fullscreen &-month, &-fullscreen &-month,
&-fullscreen &-date { &-fullscreen &-date {
text-align: left;
margin: 0 4px; margin: 0 4px;
display: block; display: block;
color: @text-color; color: @text-color;
...@@ -245,15 +254,12 @@ ...@@ -245,15 +254,12 @@
color: #ccc; color: #ccc;
} }
&-fullscreen &-note-list-wrapper { &-fullscreen &-content {
height: 90px; height: 90px;
overflow-y: auto; overflow-y: auto;
} position: static;
width: auto;
&-fullscreen &-notes-month { left: auto;
text-align: center; bottom: auto;
> section {
font-size: 28px;
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册