Move logic to Scrollable component

This commit is contained in:
Tom Moor
2018-05-06 12:46:52 -07:00
parent d55a8ad02d
commit b37ed1f8d0
3 changed files with 30 additions and 3 deletions

View File

@ -1,12 +1,39 @@
// @flow // @flow
import * as React from 'react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import styled from 'styled-components'; import styled from 'styled-components';
const Scrollable = styled.div` 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%; height: 100%;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
overscroll-behavior: none; overscroll-behavior: none;
-webkit-overflow-scrolling: touch; -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; export default Scrollable;

View File

@ -52,7 +52,7 @@ class MainSidebar extends React.Component<Props> {
} }
/> />
<Flex auto column> <Flex auto column>
<Scrollable> <Scrollable shadow>
<Section> <Section>
<SidebarLink to="/dashboard" icon={<HomeIcon />}> <SidebarLink to="/dashboard" icon={<HomeIcon />}>
Home Home

View File

@ -36,7 +36,7 @@ class SettingsSidebar extends React.Component<Props> {
/> />
<Flex auto column> <Flex auto column>
<Scrollable> <Scrollable shadow>
<Section> <Section>
<Header>Account</Header> <Header>Account</Header>
<SidebarLink to="/settings" icon={<ProfileIcon />}> <SidebarLink to="/settings" icon={<ProfileIcon />}>