rating.stories.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react';
  2. import Rating from '../index';
  3. import Button from '../../button'
  4. import { IconLikeHeart } from '@douyinfe/semi-icons';
  5. export default {
  6. title: 'Rating',
  7. parameters: {
  8. chromatic: { disableSnapshot: true },
  9. },
  10. }
  11. export const _Rating = () => (
  12. <div style={{ display: 'flex' }}>
  13. <div style={{ width: '50%' }}>
  14. <h5>default</h5>
  15. <Rating />
  16. <br />
  17. <h5>allowHalf</h5>
  18. <Rating allowHalf />
  19. <br />
  20. <h5>disabled</h5>
  21. <Rating disabled defaultValue={4} />
  22. <br />
  23. <h5>allowClear = false</h5>
  24. <Rating allowClear={false} />
  25. <br />
  26. <h5>character</h5>
  27. <Rating size="small" character={<IconLikeHeart />} />
  28. <br />
  29. <Rating character={'好'} defaultValue={2} disabled />
  30. </div>
  31. <div style={{ width: '50%' }}>
  32. <br />
  33. <h5>tooltips</h5>
  34. <Rating tooltips={['terrible', 'bad', 'normal', 'good', 'wonderful']} />
  35. <br />
  36. <h5>defaultValue</h5>
  37. <Rating defaultValue={2} />
  38. <h5>value</h5>
  39. <Rating value={3} />
  40. <br />
  41. <h5>onHoverChange</h5>
  42. <Rating onHoverChange={e => console.log(e)} />
  43. <h5>size</h5>
  44. <Rating size="small" defaultValue={2} />
  45. <Rating size="large" defaultValue={2} />
  46. </div>
  47. </div>
  48. );
  49. _Rating.parameters = {
  50. chromatic: { disableSnapshot: false },
  51. };
  52. class Demo extends React.Component {
  53. constructor(props) {
  54. super();
  55. this.state = {
  56. value: 0,
  57. };
  58. this.handleChange = this.handleChange.bind(this);
  59. }
  60. handleChange(value) {
  61. this.setState({
  62. value,
  63. });
  64. }
  65. render() {
  66. const { value } = this.state;
  67. const desc = ['terrible', 'bad', 'normal', 'good', 'wonderful'];
  68. return (
  69. <div>
  70. <span>How was the help you received: {value ? <span id='rating-result'>{desc[value - 1]}</span> : ''}</span>
  71. <br />
  72. <Rating tooltips={desc} onChange={this.handleChange} value={value} />
  73. </div>
  74. );
  75. }
  76. }
  77. export const TooltipRating = () => <Demo />;
  78. TooltipRating.story = {
  79. name: 'tooltip Rating',
  80. };
  81. const KeyDownDemo = () => {
  82. return <Rating onKeyDown={event => console.log(event)} />;
  83. };
  84. export const Keydown = () => <KeyDownDemo />;
  85. Keydown.story = {
  86. name: 'keydown',
  87. };
  88. const AutoFocusDemo = () => {
  89. return <Rating defaultValue={2} autoFocus />;
  90. }
  91. export const AutoFocus = () => <AutoFocusDemo />;
  92. AutoFocus.story = {
  93. name: 'autofocus',
  94. };