Skip to content

Commit

Permalink
Merge pull request #3201 from newoga/#2852/popover
Browse files Browse the repository at this point in the history
[Popover] Remove style-propable mixin
  • Loading branch information
oliviertassinari committed Feb 6, 2016
2 parents 4cf79f4 + 6bc221f commit ea4afa7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 115 deletions.
79 changes: 34 additions & 45 deletions src/popover/popover-animation-from-top.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import Transitions from '../styles/transitions';
import React from 'react';
import PropTypes from '../utils/prop-types';
import StylePropable from '../mixins/style-propable';
import getMuiTheme from '../styles/getMuiTheme';
import Paper from '../paper';
import Transitions from '../styles/transitions';
import getMuiTheme from '../styles/getMuiTheme';
import PropTypes from '../utils/prop-types';

function getStyles(props, state) {
const {
targetOrigin,
} = props;

const {
open,
muiTheme: {
zIndex,
},
} = state;

const horizontal = targetOrigin.horizontal.replace('middle', 'vertical');

return {
root: {
opacity: open ? 1 : 0,
transform: open ? 'scaleY(1)' : 'scaleY(0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
position: 'fixed',
zIndex: zIndex.popover,
transition: Transitions.easeOut('450ms', ['transform', 'opacity']),
maxHeight: '100%',
},
};
}

const PopoverAnimationFromTop = React.createClass({

Expand All @@ -24,15 +50,10 @@ const PopoverAnimationFromTop = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
StylePropable,
],

getDefaultProps() {
return {
style: {},
Expand All @@ -58,56 +79,24 @@ const PopoverAnimationFromTop = React.createClass({
},

componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;

this.setState({
open: nextProps.open,
muiTheme: newMuiTheme,
muiTheme: nextContext.muiTheme || this.state.muiTheme,
});
},

getStyles() {
let {targetOrigin} = this.props;
let horizontal = targetOrigin.horizontal.replace('middle', 'vertical');

return {
base: {
opacity: 0,
transform: 'scaleY(0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
position: 'fixed',
zIndex: this.state.muiTheme.zIndex.popover,
transition: Transitions.easeOut('450ms', ['transform', 'opacity']),
maxHeight: '100%',
},

};
},

getOpenStyles() {
return {
base: {
opacity: 1,
transform: 'scaleY(1)',
},
};
},

render() {
let {
const {
className,
style,
zDepth,
} = this.props;

let styles = this.getStyles();
let openStyles = {};
if (this.state.open)
openStyles = this.getOpenStyles();
const styles = getStyles(this.props, this.state);

return (
<Paper
style={this.mergeStyles(styles.base, style, openStyles.base)}
style={Object.assign(styles.root, style)}
zDepth={zDepth}
className={className}
>
Expand Down
118 changes: 51 additions & 67 deletions src/popover/popover-default-animation.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
import Transitions from '../styles/transitions';
import React from 'react';
import PropTypes from '../utils/prop-types';
import StylePropable from '../mixins/style-propable';
import getMuiTheme from '../styles/getMuiTheme';
import Paper from '../paper';

function getStyles(props, state) {
const {
targetOrigin,
} = props;

const {
open,
muiTheme: {
zIndex,
},
} = state;

const horizontal = targetOrigin.horizontal.replace('middle', 'vertical');

return {
root: {
opacity: open ? 1 : 0,
transform: open ? 'scale(1, 1)' : 'scale(0, 0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
position: 'fixed',
zIndex: zIndex.popover,
transition: Transitions.easeOut('250ms', ['transform', 'opacity']),
maxHeight: '100%',
},
horizontal: {
maxHeight: '100%',
overflowY: 'auto',
transform: open ? 'scaleX(1)' : 'scaleX(0)',
opacity: open ? 1 : 0,
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: Transitions.easeOut('250ms', ['transform', 'opacity']),
},
vertical: {
opacity: open ? 1 : 0,
transform: open ? 'scaleY(1)' : 'scaleY(0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: Transitions.easeOut('500ms', ['transform', 'opacity']),
},
};
}

const PopoverDefaultAnimation = React.createClass({

propTypes: {
Expand All @@ -28,15 +68,10 @@ const PopoverDefaultAnimation = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
StylePropable,
],

getDefaultProps() {
return {
style: {},
Expand All @@ -62,84 +97,33 @@ const PopoverDefaultAnimation = React.createClass({
},

componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;

this.setState({
open: nextProps.open,
muiTheme: newMuiTheme,
muiTheme: nextContext.muiTheme || this.state.muiTheme,
});
},


getStyles() {
let {targetOrigin} = this.props;
let horizontal = targetOrigin.horizontal.replace('middle', 'vertical');

return {
base: {
opacity: 0,
transform: 'scale(0, 0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
position: 'fixed',
zIndex: this.state.muiTheme.zIndex.popover,
transition: Transitions.easeOut('250ms', ['transform', 'opacity']),
maxHeight: '100%',

},
horizontal: {
maxHeight: '100%',
overflowY: 'auto',
transform: 'scaleX(0)',
opacity: 0,
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: Transitions.easeOut('250ms', ['transform', 'opacity']),
},
vertical: {
opacity: 0,
transform: 'scaleY(0)',
transformOrigin: `${horizontal} ${targetOrigin.vertical}`,
transition: Transitions.easeOut('500ms', ['transform', 'opacity']),
},
};
},

getOpenStyles() {
return {
base: {
opacity: 1,
transform: 'scale(1, 1)',
},
horizontal: {
opacity: 1,
transform: 'scaleX(1)',
},
vertical: {
opacity: 1,
transform: 'scaleY(1)',
},
};
},

render() {
let {
const {
className,
style,
zDepth,
} = this.props;

let styles = this.getStyles();
let openStyles = {};
if (this.state.open)
openStyles = this.getOpenStyles();
const {
prepareStyles,
} = this.state.muiTheme;

const styles = getStyles(this.props, this.state);

return (
<Paper
style={this.mergeStyles(styles.base, style, openStyles.base)}
style={Object.assign(styles.root, style)}
zDepth={zDepth}
className={className}
>
<div style={this.prepareStyles(styles.horizontal, openStyles.horizontal)}>
<div style={this.prepareStyles(styles.vertical, openStyles.vertical)}>
<div style={prepareStyles(styles.horizontal)}>
<div style={prepareStyles(styles.vertical)}>
{this.props.children}
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/popover/popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import WindowListenable from '../mixins/window-listenable';
import RenderToLayer from '../render-to-layer';
import StylePropable from '../mixins/style-propable';
import PropTypes from '../utils/prop-types';
import Paper from '../paper';
import throttle from 'lodash.throttle';
Expand Down Expand Up @@ -104,13 +103,11 @@ const Popover = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
StylePropable,
WindowListenable,
],

Expand Down

0 comments on commit ea4afa7

Please sign in to comment.