-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Showing
5 changed files
with
180 additions
and
51 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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import React from "react" | ||
import { Link } from "gatsby" | ||
import { SiteNav } from "./layout/TopNav" | ||
|
||
|
||
declare const __PATH_PREFIX__: string | ||
|
||
export class Layout extends React.Component<any> { | ||
render() { | ||
const { children } = this.props | ||
return ( | ||
<div> | ||
<SiteNav /> | ||
<> | ||
<SiteNav /> | ||
<main>{children}</main> | ||
</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
31 changes: 31 additions & 0 deletions
31
packages/typescriptlang-org/src/components/layout/stickyNavigation.ts
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,31 @@ | ||
export function setupStickyNavigation() { | ||
const nav = document.getElementById("top-menu") | ||
let previousY = 0 | ||
|
||
// Non-blocking nav change | ||
document.addEventListener( | ||
"scroll", | ||
event => { | ||
// iOS scrolls to make sure the viewport fits, don't hide the input then | ||
const hasKeyboardFocus = document.activeElement.nodeName == "INPUT" | ||
if (hasKeyboardFocus) { | ||
return | ||
} | ||
|
||
const goingUp = window.pageYOffset > 1 && window.pageYOffset > previousY | ||
previousY = window.pageYOffset | ||
console.log(document.activeElement, event) | ||
if (goingUp) { | ||
nav.classList.add("down") | ||
nav.classList.remove("up") | ||
} else { | ||
nav.classList.add("up") | ||
nav.classList.remove("down") | ||
} | ||
}, | ||
{ | ||
capture: true, | ||
passive: true, | ||
} | ||
) | ||
} |
Oops, something went wrong.