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

Commit a4cf16a

Browse files
committed
Improve docs
1 parent 89d3b29 commit a4cf16a

19 files changed

+335
-138
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/docs/src/examples/**

docs/src/app.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CSSTransition, CSSTransitionProps, transit } from "react-css-transition
66
import { Demo, Logo, SyntaxHighlighter, Button, Quote } from "./components";
77

88
import {
9+
IntroExample,
910
InlineExample, inlineExampleSource,
1011
ClassExample, classExampleSource,
1112
CompletionExample, completionExampleSource,
@@ -25,10 +26,11 @@ import {
2526
initStyleSnippet,
2627
groupTreeSnippet,
2728
groupTranistionSnippet,
29+
groupSnippet,
30+
groupExampleSnippet,
2831
cssSnippet,
2932
componentSnippet,
3033
introSnippet,
31-
groupSnippet,
3234
delaySnippet,
3335
delayObjectSnippet,
3436
} from "./snippets";
@@ -133,6 +135,7 @@ const App: StatelessComponent<void> = () => (
133135

134136
<section className={classes.mainSection}>
135137
<h3>How It Looks Like</h3>
138+
<IntroExample />
136139
<SyntaxHighlighter language="javascript">
137140
{introSnippet}
138141
</SyntaxHighlighter>
@@ -320,21 +323,27 @@ const App: StatelessComponent<void> = () => (
320323
<SyntaxHighlighter language="bash">
321324
{groupTreeSnippet}
322325
</SyntaxHighlighter>
323-
<div className={classes.block}>
324-
<Demo title="Transition Group Example" component={GroupExample} source={groupExampleSource} />
325-
</div>
326326
<p>
327327
Let's predefine a <code>CSSTransition</code>:
328328
</p>
329329
<SyntaxHighlighter language="javascript">
330330
{groupTranistionSnippet}
331331
</SyntaxHighlighter>
332332
<p>
333-
Finally create a component that fades in and out its children:
333+
Then create a component that fades in and out its children:
334334
</p>
335335
<SyntaxHighlighter language="javascript">
336336
{groupSnippet}
337337
</SyntaxHighlighter>
338+
<p>
339+
Finally we put it into use:
340+
</p>
341+
<SyntaxHighlighter language="javascript">
342+
{groupExampleSnippet}
343+
</SyntaxHighlighter>
344+
<div className={classes.block}>
345+
<Demo title="Transition Group Example" component={GroupExample} source={groupExampleSource} />
346+
</div>
338347

339348
<section className={classes.mainSection}>
340349
<h4>Appear on Initial Mount</h4>

docs/src/components/syntaxHighlighter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ registerLanguage("bash", bash);
1111

1212
const customStyle = {
1313
padding: "16px",
14-
fontSize: "14px",
14+
fontSize: "13px",
1515
};
1616

1717
const codeTagProps = {

docs/src/examples/appearExample.jsx

+25-28
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,57 @@
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';
33

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";
67

78
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-
},
179
defaultStyle: {
1810
opacity: 0,
1911
},
2012
enterStyle: {
21-
opacity: transit(1.0, 500, "ease-in-out"),
13+
opacity: transit(1.0, 500, 'ease-in-out'),
2214
},
2315
leaveStyle: {
24-
opacity: transit(0, 500, "ease-in-out"),
16+
opacity: transit(0, 500, 'ease-in-out'),
2517
},
2618
activeStyle: {
2719
opacity: 1,
2820
},
2921
});
3022

3123
class AppearExample extends React.Component {
32-
3324
constructor(props) {
3425
super(props);
3526
this.state = {mounted: 1};
27+
this.handleClickMount = this.handleClickMount.bind(this);
28+
this.handleClickUnmount = this.handleClickUnmount.bind(this);
3629
}
3730

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+
}
4040

4141
render() {
4242
return (
4343
<div>
44-
<div style={prefix({ display: "flex", marginBottom: "32px", height: "20px" })}>
44+
<div style={prefix({ display: 'flex', marginBottom: '32px', height: '20px' })}>
4545
{
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>
5350
)
5451
}
5552
</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>
5855
</div>
5956
);
6057
}

docs/src/examples/circle.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from "react";
2+
3+
import { prefix } from "../theme";
4+
5+
const style = prefix({
6+
boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)",
7+
borderRadius: "50%",
8+
marginBottom: "32px",
9+
background: "#dc7d16",
10+
height: "20px",
11+
width: "20px",
12+
marginRight: "8px",
13+
});
14+
15+
const Circle = () => <div style={ style } />;
16+
17+
export default Circle;

docs/src/examples/classExample.css.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { createClassRules, accentColor } from "../theme";
1+
import { createClassRules } from "../theme";
22

33
export default createClassRules({
4-
className: {
5-
boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)",
6-
borderRadius: "50%",
7-
marginBottom: "32px",
8-
background: accentColor.default,
9-
height: "20px",
10-
width: "20px",
11-
},
124
defaultClassName: {
135
transform: "translate(0, 0)",
146
},

docs/src/examples/classExample.jsx

+9-15
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ import * as React from "react";
22
import { CSSTransition } from "react-css-transition";
33

44
import { Button } from "../components";
5+
import Circle from "./circle";
56

67
/*
78
CSS defined using CSS-Modules.
89
9-
.className: {
10-
boxShadow: "1px 1px 5px 0px rgba(0,0,0,0.25)",
11-
borderRadius: "50%",
12-
marginBottom: "32px",
13-
background: "#dc7d16",
14-
height: "20px",
15-
width: "20px",
16-
},
1710
.defaultClassName: {
1811
transform: "translate(0, 0)",
1912
},
@@ -33,22 +26,23 @@ import { Button } from "../components";
3326
import classes from "./classExample.css";
3427

3528
class ClassExample extends React.Component {
36-
3729
constructor(props) {
3830
super(props);
3931
this.state = {active: false};
32+
this.handleClick = this.handleClick.bind(this);
4033
}
4134

42-
onClick = () => this.setState({active: !this.state.active});
35+
handleClick() {
36+
this.setState({active: !this.state.active});
37+
}
4338

4439
render() {
4540
return (
4641
<div>
47-
<CSSTransition
48-
{...classes}
49-
active={this.state.active}
50-
/>
51-
<Button onClick={this.onClick}>Trigger</Button>
42+
<CSSTransition {...classes} active={this.state.active}>
43+
<Circle />
44+
</CSSTransition>
45+
<Button onClick={this.handleClick}>Trigger</Button>
5246
</div>
5347
);
5448
}

docs/src/examples/completionExample.jsx

+17-15
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@ import { CSSTransition, transit } from "react-css-transition";
33

44
import { prefix } from "../theme";
55
import { Button } from "../components";
6+
import Circle from "./circle";
67

78
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-
},
159
defaultStyle: {
1610
transform: "translate(0, 0)",
1711
},
@@ -26,29 +20,37 @@ const styles = prefix({
2620
},
2721
});
2822

29-
class InlineExample extends React.Component {
30-
23+
class CompletionExample extends React.Component {
3124
constructor(props) {
3225
super(props);
3326
this.state = {active: false, count: 0};
27+
this.handleClick = this.handleClick.bind(this);
28+
this.handleTransitionComplete = this.handleTransitionComplete.bind(this);
3429
}
3530

36-
onClick = () => this.setState({active: !this.state.active});
37-
onTransitionComplete = () => this.setState({count: this.state.count + 1});
31+
handleClick() {
32+
this.setState({active: !this.state.active});
33+
}
34+
35+
handleTransitionComplete() {
36+
this.setState({count: this.state.count + 1});
37+
}
3838

3939
render() {
4040
return (
4141
<div>
4242
<CSSTransition
4343
{...styles}
44-
onTransitionComplete={this.onTransitionComplete}
44+
onTransitionComplete={this.handleTransitionComplete}
4545
active={this.state.active}
46-
/>
46+
>
47+
<Circle />
48+
</CSSTransition>
4749
<p><code>onTransitionComplete calls: {this.state.count}</code></p>
48-
<Button onClick={this.onClick}>Trigger</Button>
50+
<Button onClick={this.handleClick}>Trigger</Button>
4951
</div>
5052
);
5153
}
5254
}
5355

54-
export default InlineExample;
56+
export default CompletionExample;

docs/src/examples/groupExample.css.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createClassRules, accentColor, timing } from "../theme";
2+
3+
export default createClassRules({
4+
container: {
5+
width: "100%",
6+
maxWidth: "240px",
7+
marginBottom: "32px",
8+
},
9+
10+
item: {
11+
padding: "8px 16px",
12+
borderBottom: 0,
13+
cursor: "pointer",
14+
boxShadow: "1px 1px 5px #ccc",
15+
borderLeft: `4px solid ${accentColor.default}`,
16+
background: "#fff",
17+
position: "relative",
18+
fontSize: "15px",
19+
lineHeight: "1.5",
20+
color: "#666",
21+
marginBottom: "16px",
22+
userSelect: "none",
23+
touchAction: "manipulation",
24+
WebkitTapHighlightColor: "rgba(0, 0, 0, 0) !important",
25+
transition: `background 400ms ${timing.easeInOut}`,
26+
27+
"&:hover": {
28+
background: "#eee",
29+
},
30+
"&:active": {
31+
transition: 0,
32+
background: "#ddd",
33+
},
34+
},
35+
});

0 commit comments

Comments
 (0)