Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 2553b3d

Browse files
committed
Added an add/remove content section to the demo.
1 parent e57c0ed commit 2553b3d

File tree

5 files changed

+105
-7
lines changed

5 files changed

+105
-7
lines changed

demo/assets/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
2-
padding-bottom: 100px;
2+
padding-bottom: 300px;
33
}
44

55
.page-head {

demo/assets/transitions.css

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
}
77
.cross-fade-leave.cross-fade-leave-active {
88
opacity: 0;
9-
transition: opacity 1s ease-in;
9+
transition: opacity 1s ease-in-out;
1010
}
1111

1212
.cross-fade-enter {
1313
opacity: 0;
1414
}
1515
.cross-fade-enter.cross-fade-enter-active {
1616
opacity: 1;
17-
transition: opacity 1s ease-in;
17+
transition: opacity 1s ease-in-out;
1818
}
1919

2020
.cross-fade-height {
@@ -67,3 +67,30 @@
6767
.carousel-swap-height {
6868
transition: height .3s ease-in-out;
6969
}
70+
71+
72+
/* Roll-up transition */
73+
74+
.roll-up-leave {
75+
transform: translate(0, 0);
76+
opacity: 1;
77+
}
78+
.roll-up-leave.roll-up-leave-active {
79+
transform: translate(-100%, 0);
80+
opacity: 0;
81+
transition: opacity .8s ease-in-out, transform .8s ease-in-out;
82+
}
83+
84+
.roll-up-enter {
85+
transform: translate(-100%, 0);
86+
opacity: 0;
87+
}
88+
.roll-up-enter.roll-up-enter-active {
89+
transform: translate(0, 0);
90+
opacity: 1;
91+
transition: opacity .8s ease-in-out, transform .8s ease-in-out;
92+
}
93+
94+
.roll-up-height {
95+
transition: height .8s ease-in-out;
96+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import ReactCSSTransitionReplace from '../../src/ReactCSSTransitionReplace.jsx';
3+
4+
5+
class ContentAddRemove extends React.Component {
6+
7+
state = {added: false};
8+
9+
handleClick = () => {
10+
this.setState({added: !this.state.added});
11+
}
12+
13+
render() {
14+
const { style = {} } = this.props;
15+
16+
style.cursor = 'pointer';
17+
18+
return (
19+
<div style={style} onClick={this.handleClick}>
20+
<a>Click to {this.state.added ? 'remove' : 'add'} content</a><br/>
21+
<br/>
22+
<ReactCSSTransitionReplace {...this.props} onClick={this.handleClick}>
23+
{this.state.added ? this.props.children : null}
24+
</ReactCSSTransitionReplace>
25+
</div>
26+
);
27+
}
28+
}
29+
30+
export default ContentAddRemove;

demo/components/Demo.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Navbar, NavBrand, Nav, NavItem, Grid } from 'react-bootstrap';
33

44
import PageHead from './PageHead.jsx';
55
import ContentSwapper from './ContentSwapper.jsx';
6+
import ContentAddRemove from './ContentAddRemove.jsx';
67

78
import ContentLong from './ContentLong.jsx';
89
import ContentShort from './ContentShort.jsx';
@@ -40,7 +41,7 @@ class Demo extends React.Component {
4041
<h2>Examples</h2>
4142
<p className="text-danger"><em>Click any content to trigger the transition.</em></p>
4243

43-
<h3>Cross-fade transition</h3>
44+
<h3 id="cross-fade">Cross-fade transition</h3>
4445
<p>The <code>opacity</code> transitions for <code>enter</code> and <code>leave</code> are started
4546
at the same time. View the <a
4647
href="https://github.com/marnusw/react-css-transition-replace#cross-fading-two-components"
@@ -51,8 +52,8 @@ class Demo extends React.Component {
5152
<img key="img2" src="img/vista2.jpg" width="600" height="280"/>
5253
</ContentSwapper>
5354

54-
<h3>Fade out, then fade in transition</h3>
55-
<p>The <code>opacity</code> transitions for <code>enter</code> animation is delayed until after
55+
<h3 id="fade-wait">Fade out, then fade in transition</h3>
56+
<p>The <code>opacity</code> transition for <code>enter</code> animation is delayed until after
5657
the <code>leave</code> transition completes. View the <a
5758
href="https://github.com/marnusw/react-css-transition-replace#fade-out-then-fade-in"
5859
target="_blank">CSS</a>.</p>
@@ -62,7 +63,7 @@ class Demo extends React.Component {
6263
<ContentShort key="short"/>
6364
</ContentSwapper>
6465

65-
<h3>Carousel transition</h3>
66+
<h3 id="carousel-swap">Carousel transition</h3>
6667
<p>The slide animation is realised with a 2D CSS <code>transform</code>. View the <a
6768
href="transitions.css" target="_blank">CSS source</a>. To ensure the entering/leaving
6869
images are properly hidden the carousel width can be set directly on the container:
@@ -75,6 +76,17 @@ class Demo extends React.Component {
7576
<img key="img4" src="img/vista4.jpg" width="600" height="280"/>
7677
</ContentSwapper>
7778

79+
<h3 id="roll-up">Add/Remove Content</h3>
80+
<p>The child component may be removed (i.e. <code>ReactCSSTransitionReplace</code> left with no children)
81+
which will animate the <code>height</code> going to zero along with the <code>leave</code> transition.
82+
A single child can subsequently be added again, triggering the inverse animation.
83+
View the <a href="transitions.css" target="_blank">CSS source</a> of the `roll-up` transition.
84+
</p>
85+
86+
<ContentAddRemove transitionName="roll-up" transitionEnterTimeout={800} transitionLeaveTimeout={800}>
87+
<img key="img1" src="img/vista1.jpg" width="600" height="235"/>
88+
</ContentAddRemove>
89+
7890
</div>
7991
</Grid>
8092
</div>

demo/components/TimedSwapper.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import ReactCSSTransitionReplace from '../../src/ReactCSSTransitionReplace.jsx';
3+
4+
5+
class ContentSwapper extends React.Component {
6+
7+
state = {
8+
count: React.Children.count(this.props.children),
9+
index: 0
10+
};
11+
12+
componentDidMount() {
13+
this.interval = setInterval(() => {
14+
this.setState({index: this.state.index + 1 >= this.state.count ? 0 : this.state.index + 1});
15+
}, 4000);
16+
}
17+
18+
render() {
19+
const content = React.Children.toArray(this.props.children);
20+
21+
return (
22+
<ReactCSSTransitionReplace {...this.props}>
23+
{content[this.state.index]}
24+
</ReactCSSTransitionReplace>
25+
);
26+
}
27+
}
28+
29+
export default ContentSwapper;

0 commit comments

Comments
 (0)