This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/components/Scrollable/Scrollable.js
2018-05-06 12:46:52 -07:00

40 lines
894 B
JavaScript

// @flow
import * as React from 'react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import styled from 'styled-components';
type Props = {
shadow?: boolean,
};
@observer
class Scrollable extends React.Component<Props> {
@observable shadow: boolean = false;
handleScroll = (ev: SyntheticMouseEvent<*>) => {
this.shadow = !!(this.props.shadow && ev.currentTarget.scrollTop > 0);
};
render() {
const { shadow, ...rest } = this.props;
return (
<Wrapper onScroll={this.handleScroll} shadow={this.shadow} {...rest} />
);
}
}
const Wrapper = styled.div`
height: 100%;
overflow-y: auto;
overflow-x: hidden;
overscroll-behavior: none;
-webkit-overflow-scrolling: touch;
box-shadow: ${props =>
props.shadow ? '0 1px inset rgba(0,0,0,.1)' : 'none'};
transition: all 250ms ease-in-out;
`;
export default Scrollable;