-
Notifications
You must be signed in to change notification settings - Fork 645
Add stickyTop prop to PageLayout.Pane #2232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
515992a
Add stickyTop prop to PageLayout.Pane
broccolinisoup 3d1f53b
update docs
broccolinisoup bc54d11
add changeset
broccolinisoup d06c1a7
Update stickyTop story
colebemis 2d429d1
Allow stickyTop to accept a string
colebemis 3919fdd
Update docs/content/PageLayout.mdx
broccolinisoup e4060b0
Update docs/content/PageLayout.mdx
broccolinisoup c433888
Merge branch 'main' into pagelayout-stickyTop-prop
broccolinisoup 800b3ec
Update prop description on the docs
broccolinisoup d949608
Merge branch 'main' into pagelayout-stickyTop-prop
colebemis 319f756
Add stickyTop example and prop docs
broccolinisoup 753a6f1
Update SplitPageLayout example
colebemis 0adf6b0
Fix code fence
colebemis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,14 +5,12 @@ import {useInView} from 'react-intersection-observer' | |
| * Calculates the height of the sticky pane such that it always | ||
| * fits into the viewport even when the header or footer are visible. | ||
| */ | ||
| // TODO: Handle sticky header | ||
| export function useStickyPaneHeight() { | ||
| const rootRef = React.useRef<HTMLDivElement>(null) | ||
|
|
||
| // Default the height to the viewport height | ||
| const [height, setHeight] = React.useState('100vh') | ||
| // stickyTop state | ||
| const [stickyTopHeight, setStickyTopHeight] = React.useState(0) | ||
| const [stickyTop, setStickyTop] = React.useState<number | string>(0) | ||
|
|
||
| // Create intersection observers to track the top and bottom of the content region | ||
| const [contentTopRef, contentTopInView, contentTopEntry] = useInView() | ||
|
|
@@ -46,11 +44,13 @@ export function useStickyPaneHeight() { | |
| // We need to account for this when calculating the offset. | ||
| const overflowScroll = Math.max(window.scrollY + window.innerHeight - document.body.scrollHeight, 0) | ||
|
|
||
| calculatedHeight = `calc(100vh - ${Math.max(topOffset, stickyTopHeight) + bottomOffset - overflowScroll}px)` | ||
| const stickyTopWithUnits = typeof stickyTop === 'number' ? `${stickyTop}px` : stickyTop | ||
|
|
||
| calculatedHeight = `calc(100vh - (max(${topOffset}px, ${stickyTopWithUnits}) + ${bottomOffset}px - ${overflowScroll}px))` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love that! 🙌🏼 |
||
| } | ||
|
|
||
| setHeight(calculatedHeight) | ||
| }, [contentTopEntry, contentBottomEntry, stickyTopHeight]) | ||
| }, [contentTopEntry, contentBottomEntry, stickyTop]) | ||
|
|
||
| // We only want to add scroll and resize listeners if the pane is sticky. | ||
| // Since hooks can't be called conditionally, we need to use state to track | ||
|
|
@@ -90,12 +90,14 @@ export function useStickyPaneHeight() { | |
| } | ||
| }, [isEnabled, contentTopInView, contentBottomInView, calculateHeight]) | ||
|
|
||
| const enableStickyPane = (stickyTop: number) => { | ||
| function enableStickyPane(top: string | number) { | ||
| setIsEnabled(true) | ||
| setStickyTopHeight(stickyTop) | ||
| setStickyTop(top) | ||
| } | ||
|
|
||
| const disableStickyPane = () => setIsEnabled(false) | ||
| function disableStickyPane() { | ||
| setIsEnabled(false) | ||
| } | ||
|
|
||
| return { | ||
| rootRef, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add into the description that if it is number, we expect px and if it is string value with units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! 800b3ec let me know if you have a better wording :)