react-toolbox/components/dialog/index.jsx

58 lines
1.3 KiB
React
Raw Normal View History

2015-09-19 17:45:27 +03:00
/* global React */
2015-10-06 08:21:24 +03:00
import { addons } from 'react/addons';
2015-09-19 17:45:27 +03:00
import Navigation from '../navigation';
2015-10-06 08:21:24 +03:00
import style from './style.scss';
2015-09-19 17:45:27 +03:00
export default React.createClass({
2015-10-06 08:21:24 +03:00
mixins: [addons.PureRenderMixin],
2015-09-19 17:45:27 +03:00
displayName: 'Dialog',
propTypes: {
actions: React.PropTypes.array,
active: React.PropTypes.bool,
className: React.PropTypes.string,
title: React.PropTypes.string,
type: React.PropTypes.string
},
getDefaultProps () {
return {
actions: [],
2015-10-06 08:21:24 +03:00
type: 'normal'
2015-09-19 17:45:27 +03:00
};
},
getInitialState () {
return { active: this.props.active };
},
render () {
2015-10-06 08:21:24 +03:00
let className = `${style.root} ${style[this.props.type]}`;
if (this.state.active) className += ` ${style.active}`;
if (this.props.className) className += ` ${this.props.className}`;
2015-09-19 17:45:27 +03:00
return (
2015-10-06 08:21:24 +03:00
<div data-react-toolbox='dialog' className={className}>
<div className={style.overlay} />
<div className={style.content}>
{ this.props.title ? <h6>{this.props.title}</h6> : null }
<section>
{ this.props.children }
</section>
2015-09-19 17:45:27 +03:00
{ this.props.actions.length > 0 ? <Navigation actions={this.props.actions}/> : null }
</div>
</div>
);
},
show () {
this.setState({active: true});
},
hide () {
this.setState({active: false});
}
});