Skip to content

Commit

Permalink
[core] Normalize transitions API
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 12, 2019
1 parent 752cde5 commit 9cdb582
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
6 changes: 6 additions & 0 deletions packages/material-ui/src/Collapse/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const styles = theme => ({
height: 'auto',
overflow: 'visible',
},
/* Styles applied to the container element when the transition has exited. */
exited: {
visibility: 'hidden',
},
/* Styles applied to the outer wrapper element. */
wrapper: {
// Hack to get children with a negative margin to not falsify the height computation.
Expand Down Expand Up @@ -152,10 +156,12 @@ class Collapse extends React.Component {
>
{(state, childProps) => (
<Component
aria-hidden={state === 'exited'}
className={clsx(
classes.container,
{
[classes.entered]: state === 'entered',
[classes.exited]: state === 'exited',
},
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Fade/Fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Fade.propTypes = {
/**
* A single child content element.
*/
children: PropTypes.element.isRequired,
children: PropTypes.element,
/**
* If `true`, the component will transition in.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/material-ui/src/Grow/Grow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const styles = {
// Use translateZ to scrolling issue on Chrome.
transform: `${getScale(1)} translateZ(0)`,
},
exited: {
visibility: 'hidden',
},
};

/**
Expand Down Expand Up @@ -121,6 +124,7 @@ class Grow extends React.Component {
>
{(state, childProps) =>
React.cloneElement(children, {
'aria-hidden': state === 'exited',
style: {
opacity: 0,
transform: getScale(0.75),
Expand Down
32 changes: 13 additions & 19 deletions packages/material-ui/src/Slide/Slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ class Slide extends React.Component {

updatePosition() {
if (this.transitionRef) {
this.transitionRef.style.visibility = 'inherit';
setTranslateValue(this.props, this.transitionRef);
}
}
Expand All @@ -197,21 +196,6 @@ class Slide extends React.Component {
...other
} = this.props;

let style = {};

// We use this state to handle the server-side rendering.
// We don't know the width of the children ahead of time.
// We need to render it.
if (!this.props.in && !this.mounted) {
style.visibility = 'hidden';
}

style = {
...style,
...styleProp,
...(React.isValidElement(children) ? children.props.style : {}),
};

return (
<EventListener target="window" onResize={this.handleResize}>
<Transition
Expand All @@ -220,13 +204,23 @@ class Slide extends React.Component {
onExit={this.handleExit}
onExited={this.handleExited}
appear
style={style}
ref={ref => {
this.transitionRef = ReactDOM.findDOMNode(ref);
}}
{...other}
>
{children}
{state => {
const style = {
visibility: state === 'exited' ? 'hidden' : undefined,
...styleProp,
...children.props.style,
};

return React.cloneElement(children, {
'aria-hidden': state === 'exited',
style,
});
}}
</Transition>
</EventListener>
);
Expand All @@ -237,7 +231,7 @@ Slide.propTypes = {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
children: PropTypes.element,
/**
* Direction the child node will enter from.
*/
Expand Down
8 changes: 6 additions & 2 deletions packages/material-ui/src/Zoom/Zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const styles = {
entered: {
transform: 'scale(1)',
},
exited: {
visibility: 'hidden',
},
};

/**
Expand Down Expand Up @@ -55,13 +58,14 @@ class Zoom extends React.Component {

const style = {
...styleProp,
...(React.isValidElement(children) ? children.props.style : {}),
...children.props.style,
};

return (
<Transition appear onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
{(state, childProps) =>
React.cloneElement(children, {
'aria-hidden': state === 'exited',
style: {
transform: 'scale(0)',
...styles[state],
Expand All @@ -79,7 +83,7 @@ Zoom.propTypes = {
/**
* A single child content element.
*/
children: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
children: PropTypes.element.isRequired,
/**
* If `true`, the component will transition in.
*/
Expand Down
1 change: 1 addition & 0 deletions pages/api/collapse.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This property accepts the following keys:
|:-----|:------------|
| <span class="prop-name">container</span> | Styles applied to the container element.
| <span class="prop-name">entered</span> | Styles applied to the container element when the transition has entered.
| <span class="prop-name">exited</span> | Styles applied to the container element when the transition has exited.
| <span class="prop-name">wrapper</span> | Styles applied to the outer wrapper element.
| <span class="prop-name">wrapperInner</span> | Styles applied to the inner wrapper element.

Expand Down
2 changes: 1 addition & 1 deletion pages/api/fade.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `aria-hidden` prop will be set on the child according to the `in` prop.

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name required">children *</span> | <span class="prop-type">element</span> |   | A single child content element. |
| <span class="prop-name">children</span> | <span class="prop-type">element</span> |   | A single child content element. |
| <span class="prop-name">in</span> | <span class="prop-type">bool</span> |   | If `true`, the component will transition in. |
| <span class="prop-name">timeout</span> | <span class="prop-type">union:&nbsp;number&nbsp;&#124;<br>&nbsp;{ enter?: number, exit?: number }<br></span> | <span class="prop-default">{ enter: duration.enteringScreen, exit: duration.leavingScreen,}</span> | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. |

Expand Down
2 changes: 1 addition & 1 deletion pages/api/slide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It uses [react-transition-group](https://github.com/reactjs/react-transition-gro

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">children</span> | <span class="prop-type">union:&nbsp;element&nbsp;&#124;<br>&nbsp;func<br></span> |   | A single child content element. |
| <span class="prop-name">children</span> | <span class="prop-type">element</span> |   | A single child content element. |
| <span class="prop-name">direction</span> | <span class="prop-type">enum:&nbsp;'left'&nbsp;&#124;<br>&nbsp;'right'&nbsp;&#124;<br>&nbsp;'up'&nbsp;&#124;<br>&nbsp;'down'<br></span> | <span class="prop-default">'down'</span> | Direction the child node will enter from. |
| <span class="prop-name">in</span> | <span class="prop-type">bool</span> |   | If `true`, show the component; triggers the enter or exit animation. |
| <span class="prop-name">timeout</span> | <span class="prop-type">union:&nbsp;number&nbsp;&#124;<br>&nbsp;{ enter?: number, exit?: number }<br></span> | <span class="prop-default">{ enter: duration.enteringScreen, exit: duration.leavingScreen,}</span> | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. |
Expand Down
2 changes: 1 addition & 1 deletion pages/api/zoom.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It uses [react-transition-group](https://github.com/reactjs/react-transition-gro

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">children</span> | <span class="prop-type">union:&nbsp;element&nbsp;&#124;<br>&nbsp;func<br></span> |   | A single child content element. |
| <span class="prop-name required">children *</span> | <span class="prop-type">element</span> |   | A single child content element. |
| <span class="prop-name">in</span> | <span class="prop-type">bool</span> |   | If `true`, the component will transition in. |
| <span class="prop-name">timeout</span> | <span class="prop-type">union:&nbsp;number&nbsp;&#124;<br>&nbsp;{ enter?: number, exit?: number }<br></span> | <span class="prop-default">{ enter: duration.enteringScreen, exit: duration.leavingScreen,}</span> | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. |

Expand Down

0 comments on commit 9cdb582

Please sign in to comment.