Skip to content

Commit b39b9f8

Browse files
committed
docs: add simple code examples for CSSTransition
Add static code blocks to ease the reader into the CodeSandbox demo.
1 parent e8131ea commit b39b9f8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/CSSTransition.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ const removeClass = (node, classes) => node && classes && classes.split(' ').for
2323
* transition, matching `*-done` class names are applied to persist the
2424
* transition state.
2525
*
26+
* ```jsx
27+
* function App() {
28+
* const [inProp, setInProp] = useState(false);
29+
* return (
30+
* <div>
31+
* <CSSTransition in={inProp} timeout={200} classNames="my-node">
32+
* <div>
33+
* {"I'll receive my-node-* classes"}
34+
* </div>
35+
* </CSSTransition>
36+
* <button type="button" onClick={() => setInProp(true)}>
37+
* Click to Enter
38+
* </button>
39+
* </div>
40+
* );
41+
* }
42+
* ```
43+
*
2644
* When the `in` prop is set to `true`, the child component will first receive
2745
* the class `example-enter`, then the `example-enter-active` will be added in
2846
* the next tick. `CSSTransition` [forces a
@@ -32,6 +50,25 @@ const removeClass = (node, classes) => node && classes && classes.split(' ').for
3250
* `example-enter-active` even though they were added immediately one after
3351
* another. Most notably, this is what makes it possible for us to animate
3452
* _appearance_.
53+
*
54+
* ```css
55+
* .my-node-enter {
56+
* opacity: 0;
57+
* }
58+
* .my-node-enter-active {
59+
* opacity: 1;
60+
* transition: opacity 200ms;
61+
* }
62+
* .my-node-exit {
63+
* opacity: 1;
64+
* }
65+
* .my-node-exit-active {
66+
* opacity: 0;
67+
* transition: opacity: 200ms;
68+
* }
69+
* ```
70+
*
71+
* `*-active` classes represent which styles you want to animate **to**.
3572
*/
3673
class CSSTransition extends React.Component {
3774
onEnter = (node, appearing) => {

0 commit comments

Comments
 (0)