2017-02-05 00:58:25 +00:00
|
|
|
import ColumnHeader from './column_header';
|
2016-09-10 16:36:48 +00:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2017-02-05 00:58:25 +00:00
|
|
|
import { DragSource } from 'react-dnd';
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2016-09-18 16:18:46 +00:00
|
|
|
const easingOutQuint = (x, t, b, c, d) => c*((t=t/d-1)*t*t*t*t + 1) + b;
|
|
|
|
|
|
|
|
const scrollTop = (node) => {
|
|
|
|
const startTime = Date.now();
|
|
|
|
const offset = node.scrollTop;
|
|
|
|
const targetY = -offset;
|
|
|
|
const duration = 1000;
|
|
|
|
let interrupt = false;
|
|
|
|
|
|
|
|
const step = () => {
|
|
|
|
const elapsed = Date.now() - startTime;
|
|
|
|
const percentage = elapsed / duration;
|
|
|
|
|
|
|
|
if (percentage > 1 || interrupt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-06 14:18:32 +00:00
|
|
|
node.scrollTop = easingOutQuint(0, elapsed, offset, targetY, duration);
|
2016-09-18 16:18:46 +00:00
|
|
|
requestAnimationFrame(step);
|
|
|
|
};
|
|
|
|
|
|
|
|
step();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
interrupt = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-10-12 11:17:17 +00:00
|
|
|
const style = {
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
background: '#282c37',
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column'
|
|
|
|
};
|
|
|
|
|
2017-02-05 00:58:25 +00:00
|
|
|
const columnSource = {
|
|
|
|
beginDrag (props) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const collect = (connect, monitor) => ({
|
|
|
|
connectDragSource: connect.dragSource(),
|
|
|
|
isDragging: monitor.isDragging()
|
|
|
|
});
|
|
|
|
|
2016-08-24 15:56:44 +00:00
|
|
|
const Column = React.createClass({
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2016-08-24 15:56:44 +00:00
|
|
|
propTypes: {
|
2017-02-05 00:58:25 +00:00
|
|
|
connectDragSource: React.PropTypes.func.isRequired,
|
|
|
|
isDragging: React.PropTypes.bool.isRequired,
|
2016-09-10 16:36:48 +00:00
|
|
|
heading: React.PropTypes.string,
|
2017-01-02 13:09:57 +00:00
|
|
|
icon: React.PropTypes.string,
|
|
|
|
children: React.PropTypes.node
|
2016-08-24 15:56:44 +00:00
|
|
|
},
|
|
|
|
|
2016-08-31 14:15:12 +00:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-09-05 22:44:28 +00:00
|
|
|
handleHeaderClick () {
|
|
|
|
let node = ReactDOM.findDOMNode(this);
|
2016-09-18 16:18:46 +00:00
|
|
|
this._interruptScrollAnimation = scrollTop(node.querySelector('.scrollable'));
|
|
|
|
},
|
|
|
|
|
|
|
|
handleWheel () {
|
|
|
|
if (typeof this._interruptScrollAnimation !== 'undefined') {
|
|
|
|
this._interruptScrollAnimation();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-31 14:15:12 +00:00
|
|
|
render () {
|
2017-02-05 00:58:25 +00:00
|
|
|
const { heading, icon, children, connectDragSource, isDragging } = this.props;
|
|
|
|
|
2016-09-10 16:36:48 +00:00
|
|
|
let header = '';
|
|
|
|
|
2017-02-05 00:58:25 +00:00
|
|
|
if (heading) {
|
|
|
|
header = <ColumnHeader icon={icon} type={heading} onClick={this.handleHeaderClick} />;
|
2016-09-10 16:36:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 00:58:25 +00:00
|
|
|
return connectDragSource(
|
|
|
|
<div className='column' style={{...style, opacity: isDragging ? '0.5' : '1' }} onWheel={this.handleWheel}>
|
2016-09-10 16:36:48 +00:00
|
|
|
{header}
|
2017-02-05 00:58:25 +00:00
|
|
|
{children}
|
2016-08-24 15:56:44 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2016-08-24 15:56:44 +00:00
|
|
|
});
|
|
|
|
|
2017-02-05 00:58:25 +00:00
|
|
|
export default DragSource('column', columnSource, collect)(Column);
|