ant-design/components/date-picker/demo/date-render.md

57 lines
1.3 KiB
Markdown
Raw Normal View History

---
order: 12
title:
zh-CN: 定制日期单元格
en-US: Customized Date Rendering
---
## zh-CN
使用 `dateRender` 可以自定义日期单元格的内容和样式。
## en-US
We can customize the rendering of date cells in the calendar by providing a `dateRender` function to `DatePicker`.
```tsx
import { DatePicker, Space } from 'antd';
2022-05-21 22:14:15 +08:00
import React from 'react';
2018-06-27 15:55:04 +08:00
const { RangePicker } = DatePicker;
const App: React.FC = () => (
<Space direction="vertical" size={12}>
<DatePicker
2019-05-07 14:57:32 +08:00
dateRender={current => {
const style: React.CSSProperties = {};
if (current.date() === 1) {
style.border = '1px solid #1890ff';
style.borderRadius = '50%';
}
return (
<div className="ant-picker-cell-inner" style={style}>
{current.date()}
</div>
);
}}
/>
<RangePicker
2019-05-07 14:57:32 +08:00
dateRender={current => {
const style: React.CSSProperties = {};
if (current.date() === 1) {
style.border = '1px solid #1890ff';
style.borderRadius = '50%';
}
return (
<div className="ant-picker-cell-inner" style={style}>
{current.date()}
</div>
);
}}
/>
</Space>
2018-11-28 15:00:03 +08:00
);
export default App;
2019-05-07 14:57:32 +08:00
```