Index.stories.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import * as React from 'react';
  2. import styled from 'styled-components';
  3. import { storiesOf } from '@storybook/react';
  4. import { PhotoProvider, PhotoConsumer } from 'react-photo-view';
  5. import 'react-photo-view/dist/index.css';
  6. import image1 from './static/1.png';
  7. import image2 from './static/2.jpg';
  8. import image3 from './static/3.jpg';
  9. import image4 from './static/4.jpg';
  10. import image5 from './static/5.jpg';
  11. const photoImages = [image1, image2, image3, image4, image5];
  12. const ImageList = styled.div`
  13. padding: 40px;
  14. display: flex;
  15. flex-wrap: wrap;
  16. align-items: center;
  17. `;
  18. const SmallImage = styled.img`
  19. margin-right: 20px;
  20. margin-bottom: 20px;
  21. width: 100px;
  22. height: 100px;
  23. cursor: pointer;
  24. `;
  25. const Button = styled.button`
  26. padding: 6px 10px;
  27. border: 1px solid #ccc;
  28. border-radius: 2px;
  29. cursor: pointer;
  30. `;
  31. storiesOf('基本操作', module)
  32. .add('默认预览', () => (
  33. <PhotoProvider>
  34. <ImageList>
  35. {photoImages.map((item, index) => (
  36. <PhotoConsumer key={index} src={item} intro={item}>
  37. <SmallImage src={item} />
  38. </PhotoConsumer>
  39. ))}
  40. </ImageList>
  41. </PhotoProvider>
  42. ))
  43. .add('只展示两张', () => (
  44. <PhotoProvider>
  45. <ImageList>
  46. {photoImages.map((item, index) => (
  47. <PhotoConsumer key={index} src={item} intro={item}>
  48. {index < 2 ? <SmallImage src={item} /> : undefined}
  49. </PhotoConsumer>
  50. ))}
  51. </ImageList>
  52. </PhotoProvider>
  53. ))
  54. .add('错误图片地址', () => (
  55. <PhotoProvider>
  56. <ImageList>
  57. <PhotoConsumer src={null}>
  58. <SmallImage src={image1} />
  59. </PhotoConsumer>
  60. </ImageList>
  61. </PhotoProvider>
  62. ))
  63. .add('按钮触发', () => (
  64. <PhotoProvider>
  65. <ImageList>
  66. <PhotoConsumer src={image4}>
  67. <Button>打开预览</Button>
  68. </PhotoConsumer>
  69. </ImageList>
  70. </PhotoProvider>
  71. ));