-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dropdown_keep_in_viewport
- Loading branch information
Showing
48 changed files
with
359 additions
and
271 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export * from './constants' | ||
export exampleContext from './exampleContext' | ||
export examplePathToHash from './examplePathToHash' | ||
export getComponentGroup from './getComponentGroup' | ||
export getFormattedHash from './getFormattedHash' | ||
export getSeeItems from './getSeeItems' | ||
export scrollToAnchor from './scrollToAnchor' | ||
export examplePathToHash from './examplePathToHash' | ||
export parentComponents from './parentComponents' | ||
export scrollToAnchor from './scrollToAnchor' |
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 |
---|---|---|
@@ -1,27 +1,30 @@ | ||
const mathSign = Math.sign || function (x) { | ||
const val = +x | ||
const mathSign = | ||
Math.sign || | ||
function mathSign(x) { | ||
const val = +x | ||
|
||
if (val === 0 || isNaN(val)) return val | ||
return val > 0 ? 1 : -1 | ||
} | ||
if (val === 0 || isNaN(val)) return val | ||
return val > 0 ? 1 : -1 | ||
} | ||
|
||
const scrollToAnchor = (lastOffsetY) => { | ||
const scrollToAnchor = (lastOffsetY, lastAcceleration = 0.1) => { | ||
const anchor = location.hash && document.querySelector(location.hash) | ||
const offsetY = window.scrollY || window.pageYOffset | ||
|
||
// no scroll to target, stop | ||
if (!anchor) return | ||
|
||
const elementTop = Math.round(anchor.getBoundingClientRect().top) | ||
const scrollStep = Math.ceil((Math.abs(elementTop / 8))) * mathSign(elementTop) | ||
const scrollStep = Math.ceil(Math.abs(elementTop / 8)) * mathSign(elementTop) | ||
const acceleration = Math.min(1, (lastAcceleration * 100) ** 1.1 / 100) | ||
|
||
// if our last step was not applied, stop | ||
// we've either hit the top, bottom, or arrived at the element | ||
if (lastOffsetY === offsetY) return | ||
|
||
// more scrolling to do! | ||
scrollBy(0, scrollStep) | ||
requestAnimationFrame(() => scrollToAnchor(offsetY)) | ||
scrollBy(0, scrollStep * acceleration) | ||
requestAnimationFrame(() => scrollToAnchor(offsetY, acceleration)) | ||
} | ||
|
||
export default scrollToAnchor |
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,5 @@ | ||
{ | ||
"rules": { | ||
"react/prop-types": 0 | ||
} | ||
} |
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
Oops, something went wrong.