From 819bb6e26cb3b7dd574a6ed66c5ee6eed1a1db03 Mon Sep 17 00:00:00 2001 From: wongcmichelle Date: Thu, 7 Mar 2019 15:22:11 -0500 Subject: [PATCH 1/2] Allow optional sticky subheader --- src/index.js | 13 +++++++++---- www/pages/index.md | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 1effac62..e4b45364 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ export default class Headroom extends Component { pinStart: PropTypes.number, style: PropTypes.object, calcHeightOnResize: PropTypes.bool, + stickySubheaderStart: PropTypes.number }; static defaultProps = { @@ -36,6 +37,7 @@ export default class Headroom extends Component { wrapperStyle: {}, pinStart: 0, calcHeightOnResize: true, + stickySubheaderStart: 0 }; constructor (props) { @@ -186,10 +188,11 @@ export default class Headroom extends Component { } unpin = () => { - this.props.onUnpin() + const {onUnpin, stickySubheaderStart} = this.props + onUnpin() this.setState({ - translateY: '-100%', + translateY: stickySubheaderStart ? `-${stickySubheaderStart}px` : '-100%', className: 'headroom headroom--unpinned', animation: true, state: 'unpinned', @@ -197,10 +200,11 @@ export default class Headroom extends Component { } unpinSnap = () => { - this.props.onUnpin() + const {onUnpin, stickySubheaderStart} = this.props + onUnpin() this.setState({ - translateY: '-100%', + translateY: stickySubheaderStart ? `-${stickySubheaderStart}px` : '-100%', className: 'headroom headroom--unpinned headroom-disable-animation', animation: false, state: 'unpinned', @@ -268,6 +272,7 @@ export default class Headroom extends Component { delete divProps.downTolerance delete divProps.pinStart delete divProps.calcHeightOnResize + delete divProps.stickySubheaderStart const { style, wrapperStyle, ...rest } = divProps diff --git a/www/pages/index.md b/www/pages/index.md index edc4808d..5df7730b 100644 --- a/www/pages/index.md +++ b/www/pages/index.md @@ -76,3 +76,4 @@ Another option is to use CSS. The component has a `headroom` class as well as a * `wrapperStyle` — pass styles for the wrapper div (this maintains the components vertical space at the top of the page). * `parent` — provide a custom 'parent' element for scroll events. `parent` should be a function which resolves to the desired element. * `pinStart` — height in px where the header should start and stop pinning. Useful when you have another element above Headroom component. +* `stickySubheaderStart` - height in px of the main header that should not be sticky (only provide this value if you want a sticky subheader) From a7c5a2de6711dcf129bc36aa2dbaa734f26e2658 Mon Sep 17 00:00:00 2001 From: wongcmichelle Date: Thu, 7 Mar 2019 15:40:26 -0500 Subject: [PATCH 2/2] Add missing trailing commas and spaces --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index e4b45364..237e9bd5 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,7 @@ export default class Headroom extends Component { pinStart: PropTypes.number, style: PropTypes.object, calcHeightOnResize: PropTypes.bool, - stickySubheaderStart: PropTypes.number + stickySubheaderStart: PropTypes.number, }; static defaultProps = { @@ -37,7 +37,7 @@ export default class Headroom extends Component { wrapperStyle: {}, pinStart: 0, calcHeightOnResize: true, - stickySubheaderStart: 0 + stickySubheaderStart: 0, }; constructor (props) { @@ -188,7 +188,7 @@ export default class Headroom extends Component { } unpin = () => { - const {onUnpin, stickySubheaderStart} = this.props + const { onUnpin, stickySubheaderStart } = this.props onUnpin() this.setState({ @@ -200,7 +200,7 @@ export default class Headroom extends Component { } unpinSnap = () => { - const {onUnpin, stickySubheaderStart} = this.props + const { onUnpin, stickySubheaderStart } = this.props onUnpin() this.setState({