skeleton.stories.jsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, { useMemo } from 'react';
  2. // import { withKnobs, text, boolean } from '@storybook/addon-knobs';
  3. import withPropsCombinations from 'react-storybook-addon-props-combinations';
  4. import { Table } from '@douyinfe/semi-ui/';
  5. import Skeleton from '../index';
  6. import Avatar from '../../avatar';
  7. export default {
  8. title: 'Skeleton'
  9. }
  10. export const _Skeleton = () => (
  11. <div>
  12. <Skeleton placeholder={<Skeleton.Avatar />} loading={true}>
  13. <Avatar>U</Avatar>
  14. </Skeleton>
  15. <Skeleton placeholder={<Skeleton.Image />} loading={true}>
  16. <Avatar>U</Avatar>
  17. </Skeleton>
  18. <Skeleton placeholder={<Skeleton.Paragraph row={6} />} loading={true}>
  19. <Avatar>U</Avatar>
  20. </Skeleton>
  21. <Skeleton placeholder={<Skeleton.Button />} loading={true}>
  22. <Avatar>U</Avatar>
  23. </Skeleton>
  24. <Skeleton placeholder={<Skeleton.Title />} loading={true}>
  25. <Avatar>U</Avatar>
  26. </Skeleton>
  27. </div>
  28. );
  29. export const _Table = () => {
  30. const Demo = () => {
  31. const phArray = [1, 2, 1, 1, 1, 1, 2, 1];
  32. const columns = useMemo(
  33. () =>
  34. phArray.map((key, idx) => {
  35. const item = {};
  36. item.title = <Skeleton.Title style={{ width: '0' }} />;
  37. item.dataIndex = key;
  38. item.key = idx;
  39. return item;
  40. }),
  41. phArray
  42. );
  43. const dataSource = useMemo(
  44. () =>
  45. [1, 2, 3, 4, 5].map(key => {
  46. const item = {};
  47. item.key = key;
  48. phArray.forEach(i => {
  49. const width = 50 * i;
  50. item[i] = <Skeleton.Paragraph style={{ width }} rows={1} />;
  51. });
  52. return item;
  53. }),
  54. []
  55. );
  56. const placeholder = (
  57. <div style={{ position: 'relative' }}>
  58. <Table
  59. style={{ backgroundColor: 'var(--semi-color-bg-1)' }}
  60. columns={columns}
  61. dataSource={dataSource}
  62. pagination={false}
  63. />
  64. <div style={{ position: 'absolute', left: 0, right: 0, top: 0, bottom: 0 }} />
  65. </div>
  66. );
  67. return <Skeleton placeholder={placeholder} loading={true} />;
  68. };
  69. return <Demo />;
  70. };
  71. _Table.story = {
  72. name: 'table',
  73. };