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 Oct 29, 2015
1 parent 8070abf commit a86fd3a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"sinon": "^1.15.4",
"sinon-chai": "^2.8.0",
"transfer-webpack-plugin": "^0.1.4",
"warning": "^2.1.0",
"webpack": "^1.11.0"
}
}
45 changes: 43 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 = require('warning');

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

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

getInitialState() {
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});

this._testDeprecations();

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

_testDeprecations() {
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 +395,42 @@ let Dialog = React.createClass({
}
},

show() {
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() {
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) {
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 a86fd3a

Please sign in to comment.