react-toolbox/spec/components/dialog.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-03-05 22:29:42 +03:00
import React, { PropTypes } from 'react';
2015-09-21 11:01:52 +03:00
import Button from '../../components/button';
import Dialog from '../../components/dialog';
2015-10-22 02:31:17 +03:00
class DialogTest extends React.Component {
state = {
2015-11-05 13:28:42 +03:00
active: false
};
2015-09-21 11:01:52 +03:00
2015-11-05 13:28:42 +03:00
handleToggle = () => {
this.setState({
active: !this.state.active
});
2016-01-08 18:50:07 +03:00
};
2015-09-21 11:01:52 +03:00
2015-11-05 13:28:42 +03:00
actions = [
{ label: 'Disagree', primary: true, onClick: this.handleToggle },
{ label: 'Agree', primary: true, onClick: this.handleToggle }
2015-11-05 13:28:42 +03:00
];
2015-09-21 11:01:52 +03:00
render () {
return (
<section>
2015-10-06 22:34:43 +03:00
<h5>Dialog</h5>
2015-09-21 11:01:52 +03:00
<p>lorem ipsum...</p>
<Button label='Show Dialog' raised primary onClick={this.handleToggle} />
2016-03-05 22:29:42 +03:00
<ContextComponent>
<Dialog
actions={this.actions}
active={this.state.active}
title="Use Google's location service?"
onOverlayClick={this.handleToggle}
onEscKeyDown={this.handleToggle}
2016-03-05 22:29:42 +03:00
>
<p>Let Google help apps <strong>determine location</strong>. This means sending anonymous location data to Google, even when no apps are running.</p>
<DialogChild />
</Dialog>
</ContextComponent>
2015-09-21 11:01:52 +03:00
</section>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2016-03-05 22:29:42 +03:00
class ContextComponent extends React.Component {
static propTypes = {
children: PropTypes.any
};
static childContextTypes = {
message: PropTypes.string
}
getChildContext () {
return {
message: 'Hi, I\'m the top container'
};
}
render () {
return this.props.children;
}
}
class DialogChild extends React.Component {
static contextTypes = {
message: PropTypes.string
}
render () {
2016-03-05 22:32:45 +03:00
return <p>This message comes from a parent: <strong>{this.context.message}</strong></p>;
2016-03-05 22:29:42 +03:00
}
}
2015-10-22 02:31:17 +03:00
export default DialogTest;