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

Commit 89d3b29

Browse files
committed
Use plain es6 classes in examples
1 parent c99e937 commit 89d3b29

12 files changed

+233
-208
lines changed

docs/src/components/demo.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const enhance = assemble<DemoInnerProps, DemoProps>(
4444
);
4545

4646
const DemoInner: StatelessComponent<DemoInnerProps> =
47-
({title, source, component: Component, onClick, active}) => (
47+
({title, source, component: Example, onClick, active}) => (
4848
<section className={classes.root}>
4949
<div className={classes.bar}>
5050
<h3>{title}</h3>
@@ -57,7 +57,7 @@ const DemoInner: StatelessComponent<DemoInnerProps> =
5757
</SyntaxHighlighter>
5858
</CSSTransition>
5959
<div className={classes.main}>
60-
<Component />
60+
<Example />
6161
</div>
6262
</section>
6363
);

docs/src/examples/appearExample.tsx renamed to docs/src/examples/appearExample.jsx

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from "react";
22
import { CSSTransition, transit } from "react-css-transition";
3-
import { assemble, withState, withHandlers } from "reassemble";
43

54
import { prefix } from "../theme";
65
import { Button } from "../components";
@@ -29,22 +28,22 @@ const styles = prefix({
2928
},
3029
});
3130

32-
// This example uses reassemble to handle internal state.
33-
// See: https://github.com/wikiwi/reassemble.
34-
const enhance = assemble(
35-
withState("count", "setCount", 1),
36-
withHandlers({
37-
onClickMount: ({count, setCount}) => () => setCount(count < 6 ? count + 1 : 6),
38-
onClickUnmount: ({count, setCount}) => () => setCount(count > 0 ? count - 1 : 0),
39-
}),
40-
);
31+
class AppearExample extends React.Component {
4132

42-
export const AppearExample = enhance(
43-
({active, onClickMount, onClickUnmount, count}) => (
33+
constructor(props) {
34+
super(props);
35+
this.state = {mounted: 1};
36+
}
37+
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});
40+
41+
render() {
42+
return (
4443
<div>
4544
<div style={prefix({ display: "flex", marginBottom: "32px", height: "20px" })}>
4645
{
47-
Array(count).fill("").map((_, idx) =>
46+
Array(this.state.mounted).fill("").map((_, idx) =>
4847
<CSSTransition
4948
{...styles}
5049
key={idx}
@@ -54,8 +53,11 @@ export const AppearExample = enhance(
5453
)
5554
}
5655
</div>
57-
<Button style={{ marginRight: "16px" }} onClick={onClickMount}>Mount</Button>
58-
<Button onClick={onClickUnmount}>Unmount</Button>
59-
</div >
60-
),
61-
);
56+
<Button style={{ marginRight: "16px" }} onClick={this.onClickMount}>Mount</Button>
57+
<Button onClick={this.onClickUnmount}>Unmount</Button>
58+
</div>
59+
);
60+
}
61+
}
62+
63+
export default AppearExample;

docs/src/examples/classExample.tsx renamed to docs/src/examples/classExample.jsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from "react";
22
import { CSSTransition } from "react-css-transition";
3-
import { assemble, withState, withHandlers } from "reassemble";
43

54
import { Button } from "../components";
65

@@ -33,22 +32,26 @@ import { Button } from "../components";
3332

3433
import classes from "./classExample.css";
3534

36-
// This example uses reassemble to handle internal state.
37-
// See: https://github.com/wikiwi/reassemble.
38-
const enhance = assemble(
39-
withState("active", "setActive", false),
40-
withHandlers({
41-
onClick: ({active, setActive}) => () => setActive(!active),
42-
}),
43-
);
44-
45-
export const ClassExample = enhance(
46-
({active, onClick}) => (
47-
<div>
48-
<CSSTransition
49-
{...classes}
50-
active={active}
51-
/>
52-
<Button onClick={onClick}>Trigger</Button>
53-
</div>
54-
));
35+
class ClassExample extends React.Component {
36+
37+
constructor(props) {
38+
super(props);
39+
this.state = {active: false};
40+
}
41+
42+
onClick = () => this.setState({active: !this.state.active});
43+
44+
render() {
45+
return (
46+
<div>
47+
<CSSTransition
48+
{...classes}
49+
active={this.state.active}
50+
/>
51+
<Button onClick={this.onClick}>Trigger</Button>
52+
</div>
53+
);
54+
}
55+
}
56+
57+
export default ClassExample;
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from "react";
2+
import { CSSTransition, transit } from "react-css-transition";
3+
4+
import { prefix } from "../theme";
5+
import { Button } from "../components";
6+
7+
const styles = prefix({
8+
style: {
9+
boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)",
10+
borderRadius: "50%",
11+
background: "#dc7d16",
12+
height: "20px",
13+
width: "20px",
14+
},
15+
defaultStyle: {
16+
transform: "translate(0, 0)",
17+
},
18+
enterStyle: {
19+
transform: transit("translate(175px, 0)", 500, "ease-in-out"),
20+
},
21+
leaveStyle: {
22+
transform: transit("translate(0, 0)", 500, "ease-in-out"),
23+
},
24+
activeStyle: {
25+
transform: "translate(175px, 0)",
26+
},
27+
});
28+
29+
class InlineExample extends React.Component {
30+
31+
constructor(props) {
32+
super(props);
33+
this.state = {active: false, count: 0};
34+
}
35+
36+
onClick = () => this.setState({active: !this.state.active});
37+
onTransitionComplete = () => this.setState({count: this.state.count + 1});
38+
39+
render() {
40+
return (
41+
<div>
42+
<CSSTransition
43+
{...styles}
44+
onTransitionComplete={this.onTransitionComplete}
45+
active={this.state.active}
46+
/>
47+
<p><code>onTransitionComplete calls: {this.state.count}</code></p>
48+
<Button onClick={this.onClick}>Trigger</Button>
49+
</div>
50+
);
51+
}
52+
}
53+
54+
export default InlineExample;

docs/src/examples/completionExample.tsx

-55
This file was deleted.

docs/src/examples/groupExample.jsx

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import * as React from "react";
2+
import { CSSTransition, CSSTransitionGroup, transit } from "react-css-transition";
3+
4+
import { prefix } from "../theme";
5+
import { Button } from "../components";
6+
7+
const circleStyle = prefix({
8+
display: "inline-box",
9+
boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)",
10+
borderRadius: "50%",
11+
background: "#dc7d16",
12+
height: "20px",
13+
width: "20px",
14+
marginRight: "8px",
15+
});
16+
17+
const Circle = () => <div style={circleStyle} />;
18+
19+
const fadeInOutStyles = prefix({
20+
defaultStyle: {
21+
opacity: 0,
22+
},
23+
enterStyle: {
24+
opacity: transit(1.0, 500, "ease-in-out"),
25+
},
26+
leaveStyle: {
27+
opacity: transit(0, 500, "ease-in-out"),
28+
},
29+
activeStyle: {
30+
opacity: 1,
31+
},
32+
});
33+
34+
const FadeInOut = (props) => (
35+
<CSSTransition
36+
{...props}
37+
{...fadeInOutStyles}
38+
/>
39+
);
40+
41+
export const FadeInOutGroup = (props) => (
42+
<CSSTransitionGroup {...props}>
43+
{React.Children.map(props.children, (child) => <FadeInOut>{child}</FadeInOut>)}
44+
</CSSTransitionGroup >
45+
);
46+
47+
class GroupExample extends React.Component {
48+
49+
constructor(props) {
50+
super(props);
51+
this.state = {mounted: 1};
52+
}
53+
54+
onClickMount = () => this.setState({mounted: this.state.mounted < 6 ? this.state.mounted + 1 : 6});
55+
onClickUnmount = () => this.setState({mounted: this.state.mounted > 0 ? this.state.mounted - 1 : 0});
56+
57+
render() {
58+
return (
59+
<div>
60+
<FadeInOutGroup
61+
style={prefix({ display: "flex", marginBottom: "32px", height: "20px" })}
62+
>
63+
{
64+
Array(this.state.mounted).fill(null).map((_, idx) =>
65+
<Circle key={idx} />,
66+
)
67+
}
68+
</FadeInOutGroup>
69+
<Button style={{ marginRight: "16px" }} onClick={this.onClickMount}>Mount</Button>
70+
<Button onClick={this.onClickUnmount}>Unmount</Button>
71+
</div >
72+
);
73+
}
74+
}
75+
76+
export default GroupExample;

docs/src/examples/groupExample.tsx

-62
This file was deleted.

0 commit comments

Comments
 (0)