react-toolbox/spec/components/dialog.js

97 lines
2.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
2015-09-21 11:01:52 +03:00
import Button from '../../components/button';
import Dialog from '../../components/dialog';
import Dropdown from '../../components/dropdown';
const dialogTypes = [
2017-01-26 20:05:32 +03:00
{ value: 'small', label: 'small' },
{ value: 'normal', label: 'normal' },
{ value: 'large', label: 'large' },
{ value: 'fullscreen', label: 'fullscreen' },
];
2015-09-21 11:01:52 +03:00
2015-10-22 02:31:17 +03:00
class DialogTest extends React.Component {
state = {
active: false,
2017-01-26 20:05:32 +03:00
type: 'normal',
};
2015-09-21 11:01:52 +03:00
2015-11-05 13:28:42 +03:00
handleToggle = () => {
this.setState({
2017-01-26 20:05:32 +03:00
active: !this.state.active,
2015-11-05 13:28:42 +03:00
});
2016-01-08 18:50:07 +03:00
};
2015-09-21 11:01:52 +03:00
changeDialogType = (value) => {
2017-01-26 20:05:32 +03:00
this.setState({ type: value });
};
2015-11-05 13:28:42 +03:00
actions = [
{ label: 'Disagree', primary: true, onClick: this.handleToggle },
2017-01-26 20:05:32 +03:00
{ label: 'Agree', primary: true, onClick: this.handleToggle },
2015-11-05 13:28:42 +03:00
];
2015-09-21 11:01:52 +03:00
2017-01-26 20:05:32 +03:00
render() {
2015-09-21 11:01:52 +03:00
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>
<Dropdown
2017-01-26 20:05:32 +03:00
label="Dialog Type"
auto
onChange={this.changeDialogType}
source={dialogTypes}
value={this.state.type}
/>
2017-01-26 20:05:32 +03:00
<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}
type={this.state.type}
2016-03-05 22:29:42 +03:00
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 = {
2017-01-26 20:05:32 +03:00
children: PropTypes.any,
2016-03-05 22:29:42 +03:00
};
static childContextTypes = {
2017-01-26 20:05:32 +03:00
message: PropTypes.string,
2016-03-05 22:29:42 +03:00
}
2017-01-26 20:05:32 +03:00
getChildContext() {
2016-03-05 22:29:42 +03:00
return {
2017-01-26 20:05:32 +03:00
message: 'Hi, I\'m the top container',
2016-03-05 22:29:42 +03:00
};
}
2017-01-26 20:05:32 +03:00
render() {
2016-03-05 22:29:42 +03:00
return this.props.children;
}
}
class DialogChild extends React.Component {
static contextTypes = {
2017-01-26 20:05:32 +03:00
message: PropTypes.string,
2016-03-05 22:29:42 +03:00
}
2017-01-26 20:05:32 +03:00
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;