|
1 |
| -import * as React from "react"; |
2 |
| -import { CSSTransition, transit } from "react-css-transition"; |
| 1 | +import * as React from 'react'; |
| 2 | +import { CSSTransition, transit } from 'react-css-transition'; |
3 | 3 |
|
4 |
| -import { prefix } from "../theme"; |
5 |
| -import { Button } from "../components"; |
| 4 | +import { prefix } from '../theme'; |
| 5 | +import { Button } from '../components'; |
| 6 | +import Circle from "./circle"; |
6 | 7 |
|
7 | 8 | const styles = prefix({
|
8 |
| - style: { |
9 |
| - display: "inline-box", |
10 |
| - boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)", |
11 |
| - borderRadius: "50%", |
12 |
| - background: "#dc7d16", |
13 |
| - height: "20px", |
14 |
| - width: "20px", |
15 |
| - marginRight: "8px", |
16 |
| - }, |
17 | 9 | defaultStyle: {
|
18 | 10 | opacity: 0,
|
19 | 11 | },
|
20 | 12 | enterStyle: {
|
21 |
| - opacity: transit(1.0, 500, "ease-in-out"), |
| 13 | + opacity: transit(1.0, 500, 'ease-in-out'), |
22 | 14 | },
|
23 | 15 | leaveStyle: {
|
24 |
| - opacity: transit(0, 500, "ease-in-out"), |
| 16 | + opacity: transit(0, 500, 'ease-in-out'), |
25 | 17 | },
|
26 | 18 | activeStyle: {
|
27 | 19 | opacity: 1,
|
28 | 20 | },
|
29 | 21 | });
|
30 | 22 |
|
31 | 23 | class AppearExample extends React.Component {
|
32 |
| - |
33 | 24 | constructor(props) {
|
34 | 25 | super(props);
|
35 | 26 | this.state = {mounted: 1};
|
| 27 | + this.handleClickMount = this.handleClickMount.bind(this); |
| 28 | + this.handleClickUnmount = this.handleClickUnmount.bind(this); |
36 | 29 | }
|
37 | 30 |
|
38 |
| - onClickMount = () => this.setState({mounted: this.state.mounted < 6 ? this.state.mounted + 1 : 6}); |
39 |
| - onClickUnmount = () => this.setState({mounted: this.state.mounted > 0 ? this.state.mounted - 1 : 0}); |
| 31 | + handleClickMount() { |
| 32 | + const mounted = this.state.mounted; |
| 33 | + this.setState({mounted: mounted < 6 ? mounted + 1 : 6}); |
| 34 | + } |
| 35 | + |
| 36 | + handleClickUnmount() { |
| 37 | + const mounted = this.state.mounted; |
| 38 | + this.setState({mounted: mounted > 0 ? mounted - 1 : 0}); |
| 39 | + } |
40 | 40 |
|
41 | 41 | render() {
|
42 | 42 | return (
|
43 | 43 | <div>
|
44 |
| - <div style={prefix({ display: "flex", marginBottom: "32px", height: "20px" })}> |
| 44 | + <div style={prefix({ display: 'flex', marginBottom: '32px', height: '20px' })}> |
45 | 45 | {
|
46 |
| - Array(this.state.mounted).fill("").map((_, idx) => |
47 |
| - <CSSTransition |
48 |
| - {...styles} |
49 |
| - key={idx} |
50 |
| - active={true} |
51 |
| - transitionAppear |
52 |
| - />, |
| 46 | + Array(this.state.mounted).fill('').map((_, idx) => |
| 47 | + <CSSTransition {...styles} key={idx} active={true} transitionAppear> |
| 48 | + <Circle /> |
| 49 | + </CSSTransition> |
53 | 50 | )
|
54 | 51 | }
|
55 | 52 | </div>
|
56 |
| - <Button style={{ marginRight: "16px" }} onClick={this.onClickMount}>Mount</Button> |
57 |
| - <Button onClick={this.onClickUnmount}>Unmount</Button> |
| 53 | + <Button style={{ marginRight: '16px' }} onClick={this.handleClickMount}>Mount</Button> |
| 54 | + <Button onClick={this.handleClickUnmount}>Unmount</Button> |
58 | 55 | </div>
|
59 | 56 | );
|
60 | 57 | }
|
|
0 commit comments