-
Notifications
You must be signed in to change notification settings - Fork 719
Implement sticky header for PR overview with tests #8528
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
+185
−1
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ab4891
Implement sticky header for PR overview and add related tests
ce3e1dd
Refactor sticky header functionality into separate component and hook
852feac
Update webviews/editorWebview/index.css
mrleemurray 35a0145
Apply suggestion from @Copilot
mrleemurray a717b3a
Add hidden props to StickyHeader for improved accessibility
3dcb8fd
Add spacing after sticky header status for improved layout
b9b10be
Remove box-shadow from sticky header in high contrast mode
084aff7
Update webviews/components/stickyHeader.tsx
mrleemurray bb7670c
Refactor StickyHeader to manage inert attribute and aria-hidden for i…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as React from 'react'; | ||
| import { getStatus } from './header'; | ||
| import { copyIcon } from './icon'; | ||
| import { PullRequest } from '../../src/github/views'; | ||
| import PullRequestContext from '../common/context'; | ||
|
|
||
| export function useStickyHeader(titleRef: React.RefObject<HTMLDivElement | null>): boolean { | ||
| const [isStuck, setIsStuck] = React.useState(false); | ||
|
|
||
| React.useEffect(() => { | ||
| const el = titleRef.current; | ||
| if (!el) { | ||
| return; | ||
| } | ||
|
|
||
| const observer = new IntersectionObserver( | ||
| ([entry]) => setIsStuck(!entry.isIntersecting), | ||
| { threshold: 0 }, | ||
| ); | ||
| observer.observe(el); | ||
|
|
||
| return () => observer.disconnect(); | ||
| }, [titleRef]); | ||
|
|
||
| return isStuck; | ||
| } | ||
|
|
||
| export function StickyHeader({ pr, visible }: { pr: PullRequest; visible: boolean }): JSX.Element { | ||
| const { text, color, icon } = getStatus(pr.state, !!pr.isDraft, pr.isIssue, pr.stateReason); | ||
| const { copyPrLink } = React.useContext(PullRequestContext); | ||
|
|
||
| const stickyRef = React.useCallback((node: HTMLDivElement | null) => { | ||
| if (node) { | ||
| if (visible) { | ||
| node.removeAttribute('inert'); | ||
| } else { | ||
| node.setAttribute('inert', ''); | ||
| } | ||
| } | ||
| }, [visible]); | ||
|
|
||
| return ( | ||
| <div ref={stickyRef} className={`sticky-header${visible ? ' visible' : ''}`}> | ||
| <div className="sticky-header-left"> | ||
| <div id="sticky-status" className={`status-badge-${color}`}> | ||
| <span className="icon">{icon}</span> | ||
| <span>{text}</span> | ||
| </div> | ||
| <span className="sticky-header-title" dangerouslySetInnerHTML={{ __html: pr.titleHTML }} /> | ||
| <a | ||
| className="sticky-header-number" | ||
| href={pr.url} | ||
| title={pr.url} | ||
| data-vscode-context={JSON.stringify({ | ||
| url: pr.url, | ||
mrleemurray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| preventDefaultContextMenuItems: true, | ||
| owner: pr.owner, | ||
| repo: pr.repo, | ||
| number: pr.number, | ||
| 'github:copyMenu': true, | ||
| })} | ||
| > | ||
| #{pr.number} | ||
| </a> | ||
| <button title="Copy Link" onClick={copyPrLink} className="icon-button sticky-header-copy" aria-label="Copy Pull Request Link"> | ||
| {copyIcon} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.