Skip to content

Commit

Permalink
[core] Normalize transitions child style implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 9, 2019
1 parent 5082f2f commit af3d812
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
28 changes: 13 additions & 15 deletions packages/material-ui/src/Fade/Fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,22 @@ class Fade extends React.Component {
render() {
const { children, onEnter, onExit, style: styleProp, theme, ...other } = this.props;

const style = {
...styleProp,
...children.props.style,
};

return (
<Transition appear onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
{(state, childProps) =>
React.cloneElement(children, {
style: {
opacity: 0,
...styles[state],
...style,
},
'aria-hidden': state === 'exited',
{(state, childProps) => {
const style = {
opacity: 0,
...styles[state],
...styleProp,
...childProps.style,
};

return React.cloneElement(children, {
...childProps,
})
}
'aria-hidden': state === 'exited',
style,
});
}}
</Transition>
);
}
Expand Down
30 changes: 14 additions & 16 deletions packages/material-ui/src/Grow/Grow.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ class Grow extends React.Component {
render() {
const { children, onEnter, onExit, style: styleProp, theme, timeout, ...other } = this.props;

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

return (
<Transition
appear
Expand All @@ -122,18 +117,21 @@ class Grow extends React.Component {
timeout={timeout === 'auto' ? null : timeout}
{...other}
>
{(state, childProps) =>
React.cloneElement(children, {
'aria-hidden': state === 'exited',
style: {
opacity: 0,
transform: getScale(0.75),
...styles[state],
...style,
},
{(state, childProps) => {
const style = {
opacity: 0,
transform: getScale(0.75),
...styles[state],
...styleProp,
...children.props.style,
};

return React.cloneElement(children, {
...childProps,
})
}
'aria-hidden': state === 'exited',
style,
});
}}
</Transition>
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/Slide/Slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,15 @@ class Slide extends React.Component {
}}
{...other}
>
{state => {
{(state, childProps) => {
const style = {
visibility: state === 'exited' ? 'hidden' : undefined,
...styleProp,
...children.props.style,
};

return React.cloneElement(children, {
...childProps,
'aria-hidden': state === 'exited',
style,
});
Expand Down
28 changes: 13 additions & 15 deletions packages/material-ui/src/Zoom/Zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,22 @@ class Zoom extends React.Component {
render() {
const { children, onEnter, onExit, style: styleProp, theme, ...other } = this.props;

const style = {
...styleProp,
...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],
...style,
},
{(state, childProps) => {
const style = {
transform: 'scale(0)',
...styles[state],
...styleProp,
...children.props.style,
};

return React.cloneElement(children, {
...childProps,
})
}
'aria-hidden': state === 'exited',
style,
});
}}
</Transition>
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/Zoom/Zoom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('<Zoom />', () => {
);
assert.deepEqual(wrapper.find('div').props().style, {
transform: 'scale(0)',
visibility: 'hidden',
});
});

Expand All @@ -98,6 +99,7 @@ describe('<Zoom />', () => {
);
assert.deepEqual(wrapper.find('div').props().style, {
transform: 'scale(0)',
visibility: 'hidden',
});
});
});
Expand Down

0 comments on commit af3d812

Please sign in to comment.