simple.tsx 849 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import styled from 'styled-components';
  4. import { PhotoSlider } from '../src';
  5. const Container = styled.div`
  6. font-size: 32px;
  7. `;
  8. const Header = styled.header`
  9. padding: 40px;
  10. font-size: 32px;
  11. border-bottom: 1px solid #ccc;
  12. `;
  13. class Example extends React.Component {
  14. state = {
  15. photoImages: ['1.png', '2.jpg'],
  16. photoVisible: true,
  17. };
  18. handlePhotoClose = () => {
  19. this.setState({
  20. photoVisible: false,
  21. });
  22. }
  23. render() {
  24. const { photoImages, photoVisible } = this.state;
  25. return (
  26. <Container>
  27. <Header>React 图片预览组件</Header>
  28. <PhotoSlider images={photoImages} visible={photoVisible} onClose={this.handlePhotoClose} />
  29. </Container>
  30. );
  31. }
  32. }
  33. ReactDOM.render(<Example />, document.getElementById('root'));