Test.stories.mdx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import styled from 'styled-components';
  2. import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
  3. import { PhotoProvider, PhotoConsumer, PhotoSlider } from 'react-photo-view';
  4. import 'react-photo-view/dist/index.css';
  5. import {
  6. photoImages,
  7. ImageList,
  8. ViewBox,
  9. Button,
  10. DefaultImage,
  11. ControlledView,
  12. } from '../src';
  13. <Meta title="React-photo-view" />
  14. ## 默认展示
  15. <Preview>
  16. <Story name="默认展示">
  17. <PhotoProvider>
  18. <ImageList>
  19. {photoImages.map((item, index) => (
  20. <PhotoConsumer key={index} src={item} intro={item}>
  21. <ViewBox viewImage={item} />
  22. </PhotoConsumer>
  23. ))}
  24. </ImageList>
  25. </PhotoProvider>
  26. </Story>
  27. </Preview>
  28. ## 两张预览
  29. <Preview>
  30. <Story name="两张预览">
  31. <PhotoProvider>
  32. <ImageList>
  33. {photoImages.map((item, index) => (
  34. <PhotoConsumer key={index} src={item}>
  35. {index < 2 ? <ViewBox viewImage={item} /> : undefined}
  36. </PhotoConsumer>
  37. ))}
  38. </ImageList>
  39. </PhotoProvider>
  40. </Story>
  41. </Preview>
  42. ## 通过按钮触发
  43. <Preview>
  44. <Story name="通过按钮触发">
  45. <PhotoProvider>
  46. <ImageList>
  47. <PhotoConsumer src={photoImages[3]}>
  48. <Button>打开预览</Button>
  49. </PhotoConsumer>
  50. </ImageList>
  51. </PhotoProvider>
  52. </Story>
  53. </Preview>
  54. ## 自定义加载失败
  55. <Preview>
  56. <Story name="自定义加载失败">
  57. <ImageList>
  58. <PhotoProvider>
  59. <PhotoConsumer src="">
  60. <Button>无默认图</Button>
  61. </PhotoConsumer>
  62. </PhotoProvider>
  63. <PhotoProvider brokenElement={<DefaultImage src="default-photo.svg" />}>
  64. <PhotoConsumer src="">
  65. <Button>自定义默认图</Button>
  66. </PhotoConsumer>
  67. </PhotoProvider>
  68. </ImageList>
  69. </Story>
  70. </Preview>
  71. ## 受控 PhotoSlider
  72. <Preview>
  73. <Story name="受控 PhotoSlider">
  74. <ControlledView />
  75. </Story>
  76. </Preview>
  77. # Props
  78. <Props of={PhotoSlider} />