2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2015-10-21 13:25:07 +03:00
|
|
|
import autobind from 'autobind-decorator';
|
2015-10-07 02:31:55 +03:00
|
|
|
import Button from '../button';
|
2015-10-10 21:06:16 +03:00
|
|
|
import style from './style';
|
2015-09-19 17:45:27 +03:00
|
|
|
|
2015-10-21 09:13:24 +03:00
|
|
|
@autobind
|
2015-10-20 08:40:51 +03:00
|
|
|
export default class Dialog extends React.Component {
|
|
|
|
static propTypes = {
|
2015-09-19 17:45:27 +03:00
|
|
|
actions: React.PropTypes.array,
|
|
|
|
active: React.PropTypes.bool,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
type: React.PropTypes.string
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-19 17:45:27 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
|
|
|
actions: [],
|
|
|
|
type: 'normal'
|
|
|
|
};
|
2015-09-19 17:45:27 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
state = {
|
|
|
|
active: this.props.active
|
|
|
|
};
|
2015-09-19 17:45:27 +03:00
|
|
|
|
2015-10-07 02:31:55 +03:00
|
|
|
renderActions () {
|
|
|
|
return this.props.actions.map((action, idx) => {
|
|
|
|
let className = style.button;
|
|
|
|
if (action.className) className += ` ${action.className}`;
|
|
|
|
return <Button key={idx} {...action} className={className} />;
|
|
|
|
});
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-10-07 02:31:55 +03:00
|
|
|
|
2015-09-19 17:45:27 +03:00
|
|
|
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}>
|
2015-10-10 21:06:16 +03:00
|
|
|
<div role='overlay' className={style.overlay} />
|
|
|
|
<div role='content' className={style.content}>
|
|
|
|
<section role='body' className={style.body}>
|
2015-10-07 02:31:55 +03:00
|
|
|
{ this.props.title ? <h6 className={style.title}>{this.props.title}</h6> : null }
|
2015-10-06 08:21:24 +03:00
|
|
|
{ this.props.children }
|
|
|
|
</section>
|
2015-10-10 21:06:16 +03:00
|
|
|
<nav role='navigation' className={style.navigation}>
|
2015-10-07 02:31:55 +03:00
|
|
|
{ this.renderActions() }
|
|
|
|
</nav>
|
2015-09-19 17:45:27 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-19 17:45:27 +03:00
|
|
|
|
|
|
|
show () {
|
|
|
|
this.setState({active: true});
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-19 17:45:27 +03:00
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.setState({active: false});
|
|
|
|
}
|
2015-10-21 13:25:07 +03:00
|
|
|
}
|