skeleton.stories.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import { storiesOf } from '@storybook/react';
  3. import Skeleton from '../index';
  4. import Button from '../../button';
  5. import Switch from '../../switch';
  6. import Avatar from '../../avatar';
  7. const stories = storiesOf('Skeleton', module);
  8. interface IProps {
  9. [x:string]: any;
  10. }
  11. interface IState {
  12. loading: boolean;
  13. }
  14. class Demo extends React.Component<IProps, IState> {
  15. constructor(props:any) {
  16. super(props);
  17. this.state = {loading: true};
  18. }
  19. showContent() {
  20. const {loading} = this.state;
  21. this.setState({
  22. loading: !loading
  23. });
  24. }
  25. render() {
  26. const {loading} = this.state;
  27. return (
  28. <>
  29. <span style={{display: 'flex', alignItems: 'center'}}>
  30. <Switch onChange={() => this.showContent()}/>
  31. <span style={{marginLeft: '10px' }}>显示加载内容</span>
  32. </span>
  33. <br/>
  34. <Skeleton placeholder={(<Skeleton.Avatar size="medium" />)} loading={loading}>
  35. <Avatar color='blue' style={{marginBottom: 10}}>U</Avatar>
  36. </Skeleton>
  37. <br/>
  38. <Skeleton style={{width: 200, height: 150}} placeholder={(<Skeleton.Image />)} loading={loading}>
  39. <img src="https://sf3-cdn-tos.douyinstatic.com/obj/eden-cn/slepweh7nupqpognuhbo/semi/831f8189f564e79c25769884c9d3d5f6.jpg" height='150' />
  40. </Skeleton>
  41. <br/>
  42. <Skeleton style={{width: 80}} placeholder={(<Skeleton.Title style={{marginBottom: 10}}/>)} loading={loading}>
  43. <h4 style={{marginBottom: 0}}>Semi UI</h4>
  44. </Skeleton>
  45. <Skeleton style={{width: 240}} placeholder={(<Skeleton.Paragraph rows={2}/>)} loading={loading}>
  46. <p style={{width: 240}} >精心打磨每一个组件的用户体验,从用户的角度考虑每个组件的使用场景。</p>
  47. </Skeleton>
  48. <br/>
  49. <Skeleton placeholder={(<Skeleton.Button />)} loading={loading}>
  50. <Button>Button</Button>
  51. </Skeleton>
  52. </>
  53. );
  54. }
  55. }
  56. stories.add('Skeleton', () => (<Demo />
  57. ));