Skip to content

Commit ccce9f2

Browse files
committed
Revised demo implementation for handling image children.
1 parent 674d6b5 commit ccce9f2

File tree

9 files changed

+219
-111
lines changed

9 files changed

+219
-111
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# Override .gitignore so `lib` will be published.
1+
node_modules
2+
demo

demo/assets/app.js

Lines changed: 124 additions & 71 deletions
Large diffs are not rendered by default.

demo/assets/img/vista1.jpg

48.6 KB
Loading

demo/assets/img/vista2.jpg

64 KB
Loading

demo/assets/img/vista3.jpg

74.9 KB
Loading

demo/assets/img/vista4.jpg

89.3 KB
Loading

demo/assets/transitions.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
h2 {
22
margin-top: 50px;
33
}
4+
body {
5+
padding-bottom: 100px;
6+
}
47

58

69
/* Cross-fade transition */
@@ -50,3 +53,26 @@ h2 {
5053

5154

5255
/* Carousel-like transition */
56+
57+
.carousel {
58+
position: relative;
59+
overflow: hidden;
60+
display: block;
61+
width: 100%;
62+
}
63+
64+
.carousel-swap-leave {
65+
transition: transform .3s ease-in-out;
66+
transform: translate(0, 0);
67+
}
68+
.carousel-swap-leave-active {
69+
transform: translate(-100%, 0);
70+
}
71+
72+
.carousel-swap-enter {
73+
transition: transform .3s ease-in-out;
74+
transform: translate(100%, 0);
75+
}
76+
.carousel-swap-enter-active {
77+
transform: translate(0, 0);
78+
}

demo/components/ContentSwapper.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import React from 'react';
22
import ReactCSSTransitionReplace from '../../src/ReactCSSTransitionReplace.jsx';
33

4-
import ContentLong from './ContentLong.jsx';
5-
import ContentShort from './ContentShort.jsx';
6-
74

85
class ContentSwapper extends React.Component {
96

107
static propTypes = {
11-
longContent: React.PropTypes.bool
8+
swapped: React.PropTypes.bool
129
};
1310

14-
state = {longContent: this.props.longContent};
11+
state = {swapped: this.props.swapped};
1512

1613
handleClick = () => {
17-
this.setState({longContent: !this.state.longContent});
14+
this.setState({swapped: !this.state.swapped});
1815
}
1916

2017
render() {
18+
const content = React.Children.toArray(this.props.children);
19+
2120
return (
2221
<div onClick={this.handleClick} style={{cursor: 'pointer'}}>
2322
<ReactCSSTransitionReplace {...this.props}>
24-
{this.state.longContent ? <ContentLong key="long" /> : <ContentShort key="short" />}
23+
{this.state.swapped ? content[1] : content[0]}
2524
</ReactCSSTransitionReplace>
2625
</div>
2726
);

demo/components/Demo.jsx

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,68 @@ import { Navbar, NavBrand, Nav, NavItem, Grid } from 'react-bootstrap';
33

44
import ContentSwapper from './ContentSwapper.jsx';
55

6+
import ContentLong from './ContentLong.jsx';
7+
import ContentShort from './ContentShort.jsx';
68

7-
function Demo() {
8-
const transitionProps = {
9-
transitionEnterTimeout: 500,
10-
transitionLeaveTimeout: 300,
11-
transitionHeight: false
12-
};
13-
14-
return (
15-
<div>
16-
<Navbar>
17-
<NavBrand>ReactCSSTransitionReplace</NavBrand>
18-
<Nav right>
19-
<NavItem href="https://github.com/marnusw/react-css-transition-replace" target="_blank">GitHub</NavItem>
20-
</Nav>
21-
</Navbar>
22-
23-
<Grid>
24-
<br/>
25-
<p className="text-danger"><em>Click any content to trigger the transition.</em></p>
26-
27-
<h2>Cross-fade transition</h2>
28-
<ContentSwapper {...transitionProps} transitionName="cross-fade"/>
29-
30-
<h2>Fade out, then fade in transition</h2>
31-
<ContentSwapper {...transitionProps} transitionName="wait-fade"/>
32-
33-
<h2>Carousel-like transition</h2>
34-
<ContentSwapper {...transitionProps} transitionName="carousel"/>
35-
36-
</Grid>
37-
</div>
38-
);
9+
class Demo extends React.Component {
10+
11+
componentDidMount() {
12+
[
13+
'/img/vista1.jpg',
14+
'/img/vista2.jpg',
15+
'/img/vista3.jpg',
16+
'/img/vista4.jpg'
17+
].forEach(src => {
18+
const img = new window.Image();
19+
img.src = src;
20+
});
21+
}
22+
23+
render() {
24+
const transitionProps = {
25+
transitionEnterTimeout: 500,
26+
transitionLeaveTimeout: 300,
27+
transitionHeight: false
28+
};
29+
30+
return (
31+
<div>
32+
<Navbar>
33+
<NavBrand>ReactCSSTransitionReplace</NavBrand>
34+
<Nav right>
35+
<NavItem href="https://github.com/marnusw/react-css-transition-replace" target="_blank">GitHub</NavItem>
36+
</Nav>
37+
</Navbar>
38+
39+
<Grid>
40+
<br/>
41+
<p className="text-danger"><em>Click any content to trigger the transition.</em></p>
42+
43+
<h2>Cross-fade transition</h2>
44+
<ContentSwapper {...transitionProps} transitionName="cross-fade">
45+
<img key="img1" src="/img/vista1.jpg"/>
46+
<img key="img2" src="/img/vista2.jpg"/>
47+
</ContentSwapper>
48+
49+
<h2>Fade out, then fade in transition</h2>
50+
<ContentSwapper {...transitionProps} transitionName="wait-fade">
51+
<ContentShort key="short"/>
52+
<ContentLong key="long"/>
53+
</ContentSwapper>
54+
55+
<h2>Carousel-like transition</h2>
56+
57+
<div style={{width: 600}}>
58+
<ContentSwapper {...transitionProps} transitionName="carousel-swap" className="carousel">
59+
<img key="img3" src="/img/vista3.jpg"/>
60+
<img key="img4" src="/img/vista4.jpg"/>
61+
</ContentSwapper>
62+
</div>
63+
64+
</Grid>
65+
</div>
66+
);
67+
}
3968
}
4069

4170
export default Demo;

0 commit comments

Comments
 (0)