Renamed /src to /frontend
This commit is contained in:
62
frontend/scenes/DocumentEdit/components/EditorPane.js
Normal file
62
frontend/scenes/DocumentEdit/components/EditorPane.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import React from 'react';
|
||||
|
||||
import styles from '../DocumentEdit.scss';
|
||||
import classNames from 'classnames/bind';
|
||||
const cx = classNames.bind(styles);
|
||||
|
||||
class EditorPane extends React.Component {
|
||||
static propTypes = {
|
||||
children: React.PropTypes.node.isRequired,
|
||||
onScroll: React.PropTypes.func.isRequired,
|
||||
scrollTop: React.PropTypes.number,
|
||||
fullWidth: React.PropTypes.bool,
|
||||
}
|
||||
|
||||
componentWillReceiveProps = (nextProps) => {
|
||||
|
||||
if (nextProps.scrollTop) {
|
||||
this.scrollToPosition(nextProps.scrollTop)
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
this.refs.pane.addEventListener('scroll', this.handleScroll);
|
||||
}
|
||||
|
||||
componentWillUnmount = () => {
|
||||
this.refs.pane.removeEventListener('scroll', this.handleScroll);
|
||||
}
|
||||
|
||||
handleScroll = (e) => {
|
||||
setTimeout(() => {
|
||||
const element = this.refs.pane;
|
||||
const contentEl = this.refs.content;
|
||||
this.props.onScroll(element.scrollTop / contentEl.offsetHeight);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
scrollToPosition = (percentage) => {
|
||||
const contentEl = this.refs.content;
|
||||
|
||||
// Push to edges
|
||||
if (percentage < 0.02) percentage = 0;
|
||||
if (percentage > 0.99) percentage = 100;
|
||||
|
||||
this.refs.pane.scrollTop = percentage * contentEl.offsetHeight;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={ cx(styles.editorPane, { fullWidth: this.props.fullWidth }) }
|
||||
ref="pane"
|
||||
>
|
||||
<div ref="content" className={ styles.paneContent }>
|
||||
{ this.props.children }
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default EditorPane;
|
||||
Reference in New Issue
Block a user