Skip to content

Commit edbc482

Browse files
committed
Add more documentation
1 parent 101ffb9 commit edbc482

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

src/CSSTransition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class CSSTransition extends React.Component {
191191
const { className } = this.getClassNames('exit')
192192

193193
this.removeClasses(node, 'appear');
194-
this.removeClasses(node, 'exit');
194+
this.removeClasses(node, 'enter');
195195
addClass(node, className)
196196

197197
if (this.props.onExit) {

src/Transition.js

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const EXITING = 'exiting';
1313
/**
1414
* The Transition component lets you describe a transition from one component
1515
* state to another _over time_ with a simple declarative API. Most commonly
16-
* It's used to animate the mounting and unmounting of Component, but can also
16+
* it's used to animate the mounting and unmounting of a component, but can also
1717
* be used to describe in-place transition states as well.
1818
*
1919
* By default the `Transition` component does not alter the behavior of the
@@ -50,6 +50,24 @@ export const EXITING = 'exiting';
5050
* );
5151
* ```
5252
*
53+
* As noted the `Transition` component doesn't _do_ anything by itself to its child component.
54+
* What it does do is track transition states over time so you can adjust you
55+
* component (such as adding styles of classes) as it changes states.
56+
*
57+
* There are 4 main states a Transition can be in:
58+
* - `ENTERING`
59+
* - `ENTERED`
60+
* - `EXITING`
61+
* - `EXITED`
62+
*
63+
* Transition state is toggled via the `in` prop. When `true` the component begins the
64+
* "Enter" stage. During this stage, the component will shift from its current transitions state,
65+
* to `'entering'` for the duration of the transition and then to the `'entered'` stage once
66+
* it's complete. So in the following example: `<Transition in timeout={500} />`,
67+
* the component will immediately shift to `'entering'` and stay there for 500ms and switch to `'entered'`.
68+
* When `in` is `false` the same thing happens except the states are `'exiting'` to `'exited'`.
69+
*
70+
* This framework is intentionally
5371
*/
5472
class Transition extends React.Component {
5573
static contextTypes = {
@@ -280,10 +298,7 @@ class Transition extends React.Component {
280298

281299
Transition.propTypes = {
282300
/**
283-
* Generally a React element to animate, all unknown props on Transition are
284-
* transfered to the **single** child element.
285-
*
286-
* For advanced uses a `function` child can be used instead of a React element.
301+
* A `function` child can be used instead of a React element.
287302
* This function is called with the current transition status
288303
* ('entering', 'entered', 'exiting', 'exited', 'unmounted'), which can used
289304
* to apply context specific props to a component.
@@ -307,17 +322,25 @@ Transition.propTypes = {
307322
in: PropTypes.bool,
308323

309324
/**
310-
* Wait until the first "enter" transition to mount the component (add it to the DOM)
325+
* By default the child component is mounted immediately along with
326+
* the parent `Transition` component. If you want to "lazy mount" the component on the
327+
* first `in={true}` you can set `mountOnEnter`. After the first enter transition the component will stay
328+
* mounted even on exit unless you also specify `unmountOnExit`
311329
*/
312330
mountOnEnter: PropTypes.bool,
313331

314332
/**
315-
* Unmount the component (remove it from the DOM) when it is not shown
333+
* By default the child component is mounted in the DOM after it enteres the `'exited'` state.
334+
* If you'd prefer to completely unmonut the component after it exits, set `unmountOnExit`.
316335
*/
317336
unmountOnExit: PropTypes.bool,
318337

319338
/**
320-
* Enable or disable appear (entering on mount) transitions.
339+
* Normally a component is not transitioned on it's initial mount. If you
340+
* want to transition on the first mount set `appear` to `true`, and the
341+
* component will enter the component.
342+
*
343+
* > Note: there are no specific "appear" states. `apprear` only an additional `enter` transition.
321344
*/
322345
appear: PropTypes.bool,
323346

@@ -363,44 +386,47 @@ Transition.propTypes = {
363386
addEndListener: PropTypes.func,
364387

365388
/**
366-
* Callback fired before the "entering" status is applied.
389+
* Callback fired before the "entering" status is applied. An extra parameter
390+
* `isAppearing` is supplied to indicate if the enter stage is occuring on the initial mount
367391
*
368-
* @type Function(node: HtmlElement, isAppearing: bool)
392+
* @type Function(node: HtmlElement, isAppearing: bool) -> void
369393
*/
370394
onEnter: PropTypes.func,
371395

372396
/**
373-
* Callback fired after the "entering" status is applied.
397+
* Callback fired after the "entering" status is applied. An extra parameter
398+
* `isAppearing` is supplied to indicate if the enter stage is occuring on the initial mount
374399
*
375400
* @type Function(node: HtmlElement, isAppearing: bool)
376401
*/
377402
onEntering: PropTypes.func,
378403

379404
/**
380-
* Callback fired after the "enter" status is applied.
405+
* Callback fired after the "enter" status is applied. An extra parameter
406+
* `isAppearing` is supplied to indicate if the enter stage is occuring on the initial mount
381407
*
382-
* @type Function(node: HtmlElement, isAppearing: bool)
408+
* @type Function(node: HtmlElement, isAppearing: bool) -> void
383409
*/
384410
onEntered: PropTypes.func,
385411

386412
/**
387413
* Callback fired before the "exiting" status is applied.
388414
*
389-
* @type Function(node: HtmlElement)
415+
* @type Function(node: HtmlElement) -> void
390416
*/
391417
onExit: PropTypes.func,
392418

393419
/**
394420
* Callback fired after the "exiting" status is applied.
395421
*
396-
* @type Function(node: HtmlElement)
422+
* @type Function(node: HtmlElement) -> void
397423
*/
398424
onExiting: PropTypes.func,
399425

400426
/**
401427
* Callback fired after the "exited" status is applied.
402428
*
403-
* @type Function(node: HtmlElement)
429+
* @type Function(node: HtmlElement) -> void
404430
*/
405431
onExited: PropTypes.func,
406432
};

0 commit comments

Comments
 (0)