Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refractored css into js for dialog and dialog-window. #370

Merged
merged 4 commits into from
Feb 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 78 additions & 38 deletions src/js/dialog-window.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ var React = require('react');
var WindowListenable = require('./mixins/window-listenable');
var CssEvent = require('./utils/css-event');
var KeyCode = require('./utils/key-code');
var Classable = require('./mixins/classable');
var StylePropable = require('./mixins/style-propable');
var Transitions = require('./styles/mixins/transitions');
var CustomVariables = require('./styles/variables/custom-variables');
var FlatButton = require('./flat-button');
var Overlay = require('./overlay');
var Paper = require('./paper');

var DialogWindow = React.createClass({

mixins: [Classable, WindowListenable],
mixins: [WindowListenable, StylePropable],

propTypes: {
actions: React.PropTypes.array,
Expand Down Expand Up @@ -42,24 +44,65 @@ var DialogWindow = React.createClass({
this._positionDialog();
},

componentDidUpdate: function (prevProps, prevState) {
componentDidUpdate: function(prevProps, prevState) {
this._positionDialog();
},

/** Styles */
_main: function() {
var style = {
position: 'fixed',
zIndex: 10,
top: 0,
left: -10000,
width: '100%',
height: '100%',
transition: Transitions.easeOut('0ms', 'left', '450ms'),
};

if (this.state.open) {
style = this.mergeAndPrefix(style, {
left: 0,
transition: Transitions.easeOut('0ms', 'left', '0ms'),
});
}

return this.mergeAndPrefix(style);
},

_contents: function() {
var style = {
transition: Transitions.easeOut(),
position: 'relative',
width: '75%',
maxWidth: (CustomVariables.spacing.desktopKeylineIncrement * 12),
margin: '0 auto',
zIndex: 10,
background: CustomVariables.canvasColor,
opacity: 0,
};

if (this.state.open) {
style = this.mergeAndPrefix(style, {
opacity: 1,
top: 0,
transform: 'translate3d(0, ' + CustomVariables.spacing.desktopKeylineIncrement + 'px, 0)',
});
}

return this.mergeAndPrefix(style);
},

render: function() {
var classes = this.getClasses('mui-dialog-window', {
'mui-is-shown': this.state.open
});
var contentClasses = 'mui-dialog-window-contents';
var actions = this._getActionsContainer(this.props.actions);

if (this.props.contentClassName) {
contentClasses += ' ' + this.props.contentClassName;
}

return (
<div className={classes}>
<Paper ref="dialogWindow" className={contentClasses} zDepth={4}>
<div ref="container" style={this._main()}>
<Paper ref="dialogWindow" style={this._contents()} zDepth={4}>
{this.props.children}
{actions}
</Paper>
Expand Down Expand Up @@ -90,32 +133,34 @@ var DialogWindow = React.createClass({
var body = document.getElementsByTagName('body')[0];
body.style.overflow = 'hidden';
body.style.position = 'fixed';

this.setState({ open: true });
if (this.props.onShow) this.props.onShow();
},

_addClassName: function(reactObject, className) {
var originalClassName = reactObject.props.className;

reactObject.props.className = originalClassName ?
originalClassName + ' ' + className : className;
},

_getAction: function(actionJSON, key) {
var onClickHandler = actionJSON.onClick ? actionJSON.onClick : this.dismiss;
var styles = {marginRight: 8};

return (
<FlatButton
key={key}
secondary={true}
onClick={onClickHandler}
label={actionJSON.text} />
label={actionJSON.text}
style={styles}/>
);
},

_getActionsContainer: function(actions) {
var actionContainer;
var actionObjects = [];
var actionStyle = {
padding: 8,
marginBottom: 8,
width: '100%',
textAlign: 'right',
};

if (actions.length) {
for (var i = 0; i < actions.length; i++) {
Expand All @@ -126,12 +171,11 @@ var DialogWindow = React.createClass({
currentAction = this._getAction(currentAction, i);
}

this._addClassName(currentAction, 'mui-dialog-window-action');
actionObjects.push(currentAction);
};

actionContainer = (
<div className="mui-dialog-window-actions">
<div style={actionStyle}>
{actionObjects}
</div>
);
Expand All @@ -140,28 +184,24 @@ var DialogWindow = React.createClass({
return actionContainer;
},

_positionDialog: function() {
var container, dialogWindow, containerHeight, dialogWindowHeight;

if (this.state.open) {

container = this.getDOMNode(),
dialogWindow = this.refs.dialogWindow.getDOMNode(),
containerHeight = container.offsetHeight,
_positionDialog: function() {

//Reset the height in case the window was resized.
dialogWindow.style.height = '';
dialogWindowHeight = dialogWindow.offsetHeight;
var container = this.getDOMNode();
var dialogWindow = this.refs.dialogWindow.getDOMNode();
var containerHeight = container.offsetHeight;

//Reset the height in case the window was resized.
dialogWindow.style.height = '';
var dialogWindowHeight = dialogWindow.offsetHeight;

//Vertically center the dialog window, but make sure it doesn't
//transition to that position.
if (this.props.repositionOnUpdate || !container.style.paddingTop) {
container.style.paddingTop =
((containerHeight - dialogWindowHeight) / 2) - 64 + 'px';
}

var paddingTop = ((containerHeight - dialogWindowHeight) / 2) - 64;

//Vertically center the dialog window, but make sure it doesn't
//transition to that position.
if (this.props.repositionOnUpdate || !container.style.paddingTop) {
container.style.paddingTop = paddingTop + 'px';
}

},

_handleOverlayTouchTap: function() {
Expand Down
28 changes: 21 additions & 7 deletions src/js/dialog.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
var React = require('react');
var Classable = require('./mixins/classable');
var StylePropable = require('./mixins/style-propable');
var CustomVariables = require('./styles/variables/custom-variables');
var DialogWindow = require('./dialog-window');

var Dialog = React.createClass({

mixins: [Classable],
mixins: [StylePropable],

propTypes: {
title: React.PropTypes.string
},

/** Styles */
title: function() {
var gutter = CustomVariables.spacing.desktopGutter + 'px ';
return {
padding: gutter + gutter + '0 ' + gutter,
marginBottom: 0,
}
},
content: function() {
return {
padding: CustomVariables.spacing.desktopGutter
}
},

render: function() {
var {
className,
title,
...other
} = this.props;
var classes = this.getClasses('mui-dialog');

return (
<DialogWindow
{...other}
ref="dialogWindow"
className={classes}>
style={this.props.style}>

<h3 className="mui-dialog-title">{this.props.title}</h3>
<div ref="dialogContent" className="mui-dialog-content">
<h3 style={this.title()}>{this.props.title}</h3>
<div ref="dialogContent" style={this.content()}>
{this.props.children}
</div>

Expand All @@ -43,4 +57,4 @@ var Dialog = React.createClass({

});

module.exports = Dialog;
module.exports = Dialog;
2 changes: 0 additions & 2 deletions src/less/components/components.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@import "app-bar.less";
@import "card.less";
@import "date-picker/date-picker.less";
@import "dialog-window.less";
@import "dialog.less";
@import "drop-down-icon.less";
@import "drop-down-menu.less";
@import "enhanced-button.less";
Expand Down
42 changes: 0 additions & 42 deletions src/less/components/dialog-window.less

This file was deleted.

10 changes: 0 additions & 10 deletions src/less/components/dialog.less

This file was deleted.