Index.stories.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. export default {
  26. title: '基本操作',
  27. };
  28. storiesOf('基本操作', module)
  29. .add('默认预览', () => (
  30. <PhotoProvider>
  31. <ImageList>
  32. {photoImages.map((item, index) => (
  33. <PhotoConsumer key={index} src={item} intro={item}>
  34. <SmallImage src={item} />
  35. </PhotoConsumer>
  36. ))}
  37. </ImageList>
  38. </PhotoProvider>
  39. ))
  40. .add('只展示两张图片', () => (
  41. <PhotoProvider>
  42. <ImageList>
  43. {photoImages.map((item, index) => (
  44. <PhotoConsumer key={index} src={item} intro={item}>
  45. {index < 2 ? <SmallImage src={item} /> : undefined}
  46. </PhotoConsumer>
  47. ))}
  48. </ImageList>
  49. </PhotoProvider>
  50. ));