From 801e05ac6724cd711b16bad8fe14a69d7bc76dd7 Mon Sep 17 00:00:00 2001 From: Jorgen Evens Date: Thu, 29 Oct 2015 20:26:37 +0100 Subject: [PATCH] [Dialog] Re-enable legacy API with deprecation warnings. --- docs/webpack-production.config.js | 5 +++ package.json | 3 +- src/dialog.jsx | 53 +++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/docs/webpack-production.config.js b/docs/webpack-production.config.js index 27987231..e742dec2 100644 --- a/docs/webpack-production.config.js +++ b/docs/webpack-production.config.js @@ -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') diff --git a/package.json b/package.json index b248478e..a276ef2a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dialog.jsx b/src/dialog.jsx index e0823f6b..e457ac29 100644 --- a/src/dialog.jsx +++ b/src/dialog.jsx @@ -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'); @@ -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) @@ -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(); @@ -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 = { @@ -376,9 +397,31 @@ 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() { @@ -386,10 +429,16 @@ let Dialog = React.createClass({ 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);