-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
share collapsible navbar to layouts (docs, api, blog)
- Loading branch information
Showing
9 changed files
with
61 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** scrollDir is not memo-friendly. | ||
It must be used with pattern matching. | ||
Do not pass it directly to child components. */ | ||
type scrollDir = | ||
| Up({scrollY: int}) | ||
| Down({scrollY: int}) | ||
|
||
/** | ||
This will cause highly frequent events, so use it only once in a root as possible. | ||
And split the children components to prevent heavy ones from being re-rendered unnecessarily. */ | ||
let useScrollDirection = () => { | ||
let (_, startScrollEventTransition) = React.useTransition() | ||
let (scrollDir, setScrollDir) = React.useState(() => Up({scrollY: %raw(`Infinity`)})) | ||
|
||
React.useEffect(() => { | ||
let onScroll = _e => { | ||
startScrollEventTransition(() => { | ||
setScrollDir( | ||
prev => { | ||
let Up({scrollY}) | Down({scrollY}) = prev | ||
if scrollY === 0 || scrollY > Webapi.Window.scrollY { | ||
Up({scrollY: Webapi.Window.scrollY}) | ||
} else { | ||
Down({scrollY: Webapi.Window.scrollY}) | ||
} | ||
}, | ||
) | ||
}) | ||
} | ||
Webapi.Window.addEventListener("scroll", onScroll) | ||
Some(() => Webapi.Window.removeEventListener("scroll", onScroll)) | ||
}, []) | ||
|
||
scrollDir | ||
} |
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,2 +1,6 @@ | ||
@react.component | ||
let make: (~components: MarkdownComponents.t=?, ~children: React.element) => React.element | ||
let make: ( | ||
~components: MarkdownComponents.t=?, | ||
~navbarCollapsible: bool=?, | ||
~children: React.element, | ||
) => React.element |
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