|
| 1 | +/* |
| 2 | +Copyright 2015 OpenMarket Ltd |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +/* |
| 20 | + * Usage: |
| 21 | + * Modal.createDialog(ErrorDialog, { |
| 22 | + * title: "some text", (default: "Error") |
| 23 | + * description: "some more text", |
| 24 | + * button: "Button Text", |
| 25 | + * onClose: someFunction, |
| 26 | + * focus: true|false (default: true) |
| 27 | + * }); |
| 28 | + */ |
| 29 | + |
| 30 | +var React = require('react'); |
| 31 | + |
| 32 | +module.exports = React.createClass({ |
| 33 | + displayName: 'ErrorDialog', |
| 34 | + |
| 35 | + // can't use getDefaultProps, see Modal.js |
| 36 | + componentWillMount: function() { |
| 37 | + if (!this.props.title) { |
| 38 | + this.props.title = "Error"; |
| 39 | + } |
| 40 | + if (!this.props.description) { |
| 41 | + this.props.description = "An error has occurred."; |
| 42 | + } |
| 43 | + if (!this.props.button) { |
| 44 | + this.props.button = "OK"; |
| 45 | + } |
| 46 | + if (this.props.focus === undefined) { |
| 47 | + this.props.focus = true; |
| 48 | + } |
| 49 | + if (!this.props.onClose) { |
| 50 | + var self = this; |
| 51 | + this.props.onClose = function() { |
| 52 | + self.props.onFinished(); |
| 53 | + }; |
| 54 | + } |
| 55 | + }, |
| 56 | + |
| 57 | + render: function() { |
| 58 | + return ( |
| 59 | + <div className="mx_ErrorDialog"> |
| 60 | + <div className="mx_ErrorDialogTitle"> |
| 61 | + {this.props.title} |
| 62 | + </div> |
| 63 | + {this.props.description}<br /> |
| 64 | + <button onClick={this.props.onClose} autoFocus={this.props.focus}> |
| 65 | + {this.props.button} |
| 66 | + </button> |
| 67 | + </div> |
| 68 | + ); |
| 69 | + } |
| 70 | +}); |
| 71 | + |
0 commit comments