2020-06-11 14:11:21 +08:00
|
|
|
---
|
|
|
|
order: 6
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义字符
|
|
|
|
en-US: Customize character
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2020-06-18 15:48:48 +08:00
|
|
|
可以使用 `(RateProps) => ReactNode` 的方式自定义每一个字符。
|
2020-06-11 14:11:21 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2020-06-18 15:48:48 +08:00
|
|
|
Can customize each character using `(RateProps) => ReactNode`.
|
2020-06-11 14:11:21 +08:00
|
|
|
|
|
|
|
```jsx
|
|
|
|
import { Rate } from 'antd';
|
|
|
|
import { FrownOutlined, MehOutlined, SmileOutlined } from '@ant-design/icons';
|
|
|
|
|
|
|
|
const customIcons = {
|
|
|
|
1: <FrownOutlined />,
|
|
|
|
2: <FrownOutlined />,
|
|
|
|
3: <MehOutlined />,
|
|
|
|
4: <SmileOutlined />,
|
|
|
|
5: <SmileOutlined />,
|
|
|
|
};
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<>
|
|
|
|
<Rate
|
2020-06-18 15:48:48 +08:00
|
|
|
defaultValue={2}
|
2020-06-11 14:11:21 +08:00
|
|
|
character={({ index }) => {
|
|
|
|
return index + 1;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<Rate
|
2020-06-18 15:48:48 +08:00
|
|
|
defaultValue={3}
|
2020-06-11 14:11:21 +08:00
|
|
|
character={({ index }) => {
|
|
|
|
return customIcons[index + 1];
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
mountNode,
|
|
|
|
);
|
|
|
|
```
|