1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/components/ascribe_panel/action_panel.js

74 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2015-08-06 13:56:37 +02:00
'use strict';
import React from 'react';
2016-05-09 11:12:46 +02:00
import ReactDOM from 'react-dom';
import classnames from 'classnames';
2015-08-06 13:56:37 +02:00
2016-05-09 11:12:46 +02:00
2015-08-06 13:56:37 +02:00
let ActionPanel = React.createClass({
propTypes: {
title: React.PropTypes.string,
2015-08-10 11:57:38 +02:00
content: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element
]),
2015-08-06 13:56:37 +02:00
buttons: React.PropTypes.element,
onClick: React.PropTypes.func,
2015-09-08 10:15:26 +02:00
ignoreFocus: React.PropTypes.bool,
leftColumnWidth: React.PropTypes.string,
rightColumnWidth: React.PropTypes.string
2015-08-06 13:56:37 +02:00
},
2015-09-08 10:15:26 +02:00
2015-08-06 13:56:37 +02:00
getInitialState() {
return {
isFocused: false
};
},
handleFocus() {
// if ignoreFocus (bool) is defined, then just ignore focusing on
// the property and input
if(this.props.ignoreFocus) {
return;
}
// if onClick is defined from the outside,
// just call it
if(this.props.onClick) {
this.props.onClick();
}
2016-05-09 11:12:46 +02:00
ReactDOM.findDOMNode(this.refs.input).focus();
2015-08-06 13:56:37 +02:00
this.setState({
isFocused: true
});
},
render() {
2015-09-08 10:15:26 +02:00
let { leftColumnWidth, rightColumnWidth } = this.props;
2015-08-06 13:56:37 +02:00
return (
<div className={classnames('ascribe-panel-wrapper', {'is-focused': this.state.isFocused})}>
2015-09-08 10:15:26 +02:00
<div
className="ascribe-panel-table"
style={{width: leftColumnWidth}}>
<div className="ascribe-panel-content">
{this.props.content}
</div>
</div>
2015-09-08 10:15:26 +02:00
<div
className="ascribe-panel-table"
style={{width: rightColumnWidth}}>
<div className="ascribe-panel-content">
{this.props.buttons}
</div>
2015-08-06 13:56:37 +02:00
</div>
</div>
);
}
});
2016-05-09 11:12:46 +02:00
export default ActionPanel;