Skip to content

Commit

Permalink
[Dialog] Re-enable legacy API with deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgenEvens committed Nov 4, 2015
1 parent 8050f49 commit 801e05a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/webpack-production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ var config = {
warnings: false
}
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new HtmlWebpackPlugin({
inject: false,
template: path.join(__dirname, '/src/www/index.html')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"homepage": "http://material-ui.com/",
"dependencies": {
"lodash.throttle": "~3.0.4",
"lodash.debounce": "~3.1.1"
"lodash.debounce": "~3.1.1",
"warning": "^2.1.0"
},
"peerDependencies": {
"inline-style-prefixer": "^0.3.3",
Expand Down
53 changes: 51 additions & 2 deletions src/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Overlay = require('./overlay');
const Paper = require('./paper');
const DefaultRawTheme = require('./styles/raw-themes/light-raw-theme');
const ThemeManager = require('./styles/theme-manager');
const warning = (process.env.NODE_ENV !== 'production') ? require('warning') : function(){};

const ReactTransitionGroup = require('react-addons-transition-group');

Expand Down Expand Up @@ -134,6 +135,8 @@ let Dialog = React.createClass({
},

getInitialState() {
if (process.env.NODE_ENV !== 'production') this._testDeprecations();

let open = this.props.isOpen;

if (open === null)
Expand All @@ -151,6 +154,8 @@ let Dialog = React.createClass({
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});

if (process.env.NODE_ENV !== 'production') this._testDeprecations();

if (nextProps.isOpen !== this.props.isOpen) {
if (nextProps.isOpen && !this.state.open)
this._show();
Expand Down Expand Up @@ -276,6 +281,22 @@ let Dialog = React.createClass({
return this.state.open;
},

_testDeprecations() {
if (process.env.NODE_ENV !== 'production') {
warning(!this.props.hasOwnProperty('openImmediately'),
'openImmediately has been deprecated in favor of defaultIsOpen');

warning(!this.props.hasOwnProperty('onShow'),
'onShow will be removed in favor of explicitly setting isOpen');

warning(!this.props.hasOwnProperty('onDismiss'),
'onDismiss will be removed in favor of explicitly setting isOpen and can be replaced by onRequestClose');

warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');
}
},

_getAction(actionJSON, key) {
let styles = {marginRight: 8};
let props = {
Expand Down Expand Up @@ -376,20 +397,48 @@ let Dialog = React.createClass({
}
},

show() {
if (process.env.NODE_ENV !== 'production')
warning(false, 'show has been deprecated in favor of explicitly setting the isOpen property.');

this._show();
},

_onShow() {
if (this.props.onShow) this.props.onShow();
},

_show() {
this.refs.dialogOverlay.preventScrolling();
this.setState({ open: true });
this.setState({ open: true }, this._onShow);
},

dismiss() {
if (process.env.NODE_ENV !== 'production')
warning(false, 'dismiss has been deprecated in favor of explicitly setting the isOpen property.');

this._dismiss();
},

_onDismiss() {
if (this.props.onDismiss) this.props.onDismiss();
},

_dismiss() {
CssEvent.onTransitionEnd(ReactDOM.findDOMNode(this), () => {
this.refs.dialogOverlay.allowScrolling();
});

this.setState({ open: false });
this.setState({ open: false }, this._onDismiss);
},

_requestClose(buttonClicked) {
if (process.env.NODE_ENV !== 'production')
warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');

if (!buttonClicked && this.props.modal) return;

// Close the dialog if the isOpen state is not explicitly set.
if (this.props.isOpen === null) this._dismiss();
if (this.props.onRequestClose) this.props.onRequestClose(!!buttonClicked);
Expand Down

0 comments on commit 801e05a

Please sign in to comment.