-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
639b5dc
commit abdd7d1
Showing
6 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.scroll-shadow { | ||
transition: 0.35s; | ||
} | ||
|
||
.scroll-shadow.scroll-shadow-top { | ||
box-shadow: inset 0 18px 15px -20px #217dbb; | ||
} | ||
|
||
.scroll-shadow.scroll-shadow-bottom { | ||
box-shadow: inset 0 -18px 15px -20px #217dbb; | ||
} | ||
|
||
.scroll-shadow.scroll-shadow-top.scroll-shadow-bottom { | ||
box-shadow: | ||
inset 0 18px 15px -20px #217dbb, | ||
inset 0 -18px 15px -20px #217dbb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { PureComponent } from 'react' | ||
import classnames from 'classnames' | ||
import { observer, observe } from 'redux-observers' | ||
import { get } from 'lodash' | ||
import { store } from 'views/create-store' | ||
|
||
import './assets/scroll-shadow.css' | ||
|
||
export class ScrollShadow extends PureComponent { | ||
state = { | ||
top: true, | ||
bottom: true, | ||
} | ||
|
||
onScroll = e => { | ||
const { scrollTop, clientHeight, scrollHeight } = this.r | ||
const scrollBottom = scrollHeight - clientHeight - scrollTop | ||
let { state } = this | ||
const top = scrollTop < 5 | ||
const bottom = scrollBottom < 5 | ||
if (top !== state.top) { | ||
state = { | ||
...state, | ||
top, | ||
} | ||
} | ||
if (bottom !== state.bottom) { | ||
state = { | ||
...state, | ||
bottom, | ||
} | ||
} | ||
this.setState(state) | ||
} | ||
|
||
componentDidMount = e => { | ||
this.onScroll() | ||
const sizeObserver = new observer( | ||
state => get(state, this.props.observerPath), | ||
this.onScroll, | ||
) | ||
this.unobserve = observe(store, [ sizeObserver ]) | ||
} | ||
|
||
componentWillUnmount = e => { | ||
this.unobserve() | ||
} | ||
|
||
render () { | ||
const { children, className } = this.props | ||
const scrollClassName = classnames(className, 'scroll-shadow', { | ||
'scroll-shadow-top': !this.state.top, | ||
'scroll-shadow-bottom': !this.state.bottom, | ||
}) | ||
return ( | ||
<div ref={r => this.r = r} className={scrollClassName} onScroll={this.onScroll}> | ||
{ children } | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters