Skip to content

Commit df55fcf

Browse files
committed
feat(Rating): support custom display of rating grade
1 parent f90a747 commit df55fcf

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

docs/rating/demo/grade.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,18 @@ Rating component display grade tips when you set `showGrade` attribute.
1717
````jsx
1818
import { Rating } from '@alifd/next';
1919

20-
ReactDOM.render(<Rating defaultValue={2} showGrade />, mountNode);
20+
const starMap = {
21+
1: 'Bad',
22+
2: 'OK',
23+
3: 'Good',
24+
4: 'Great',
25+
5: 'Perfect'
26+
};
27+
28+
ReactDOM.render(
29+
<Rating
30+
defaultValue={2}
31+
showGrade
32+
readAs={(val) => starMap[val]}
33+
/>, mountNode);
2134
````

docs/rating/index.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ Rating component is usually used for customer feedback.
2626
| onChange | callback function on click star<br><br>**signatures**:<br>Function(value: String) => void<br>**params**:<br>_value_: {String} score | Function | func.noop |
2727
| onHoverChange | callback function on hover star<br><br>**signatures**:<br>Function(value: String) => void<br>**params**:<br>_value_: {String} score | Function | func.noop |
2828
| disabled | disabled rate or not | Boolean | false |
29-
| readAs | make sense when you set id and enable accessibility<br><br>**signatures**:<br>Function() => void | Function | val => val |
29+
| readAs | custom display of grade<br><br>**signatures**:<br>Function() => void | Function | val => val |

docs/rating/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
| onChange | 用户点击评分时触发的回调<br><br>**签名**:<br>Function(value: String) => void<br>**参数**:<br>_value_: {String} 评分值 | Function | func.noop |
2727
| onHoverChange | 用户hover评分时触发的回调<br><br>**签名**:<br>Function(value: String) => void<br>**参数**:<br>_value_: {String} 评分值 | Function | func.noop |
2828
| disabled | 是否禁用 | Boolean | false |
29-
| readAs | 传入id支持无障碍时,参数才有意义<br><br>**签名**:<br>Function() => void | Function | val => val |
29+
| readAs | 评分文案生成方法,传入id支持无障碍时,读屏软件可读<br><br>**签名**:<br>Function() => void | Function | val => val |

src/rating/rating.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class Rating extends Component {
5858
*/
5959
disabled: PropTypes.bool,
6060
/**
61-
* 传入id支持无障碍时,参数才有意义
61+
* 评分文案生成方法,传入id支持无障碍时,读屏软件可读
6262
*/
6363
readAs: PropTypes.func,
6464
// 实验属性: 自定义评分icon
@@ -374,7 +374,7 @@ export default class Rating extends Component {
374374
</div>
375375
</div>
376376
{
377-
showGrade ? <div className={`${prefix}rating-info`} style={infoStyle}>{value}</div> : null
377+
showGrade ? <div className={`${prefix}rating-info`} style={infoStyle}>{readAs(value)}</div> : null
378378
}
379379
</div>
380380
);

0 commit comments

Comments
 (0)