-
-
Notifications
You must be signed in to change notification settings - Fork 102
adding feature of anchor links #960
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
arkid15r
merged 47 commits into
OWASP:main
from
shining-bluemoon-11:feature/add-anchor-links
Apr 21, 2025
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
629f0e4
adding feature of anchor links
shining-bluemoon-11 c8f5865
fix update
shining-bluemoon-11 858bd9a
resolves conflicts
shining-bluemoon-11 39af270
Merge branch 'main' into feature/add-anchor-links
kasya 79e372f
Merge branch 'main' into feature/add-anchor-links
kasya f1de9aa
update asked changes
shining-bluemoon-11 daf3979
update fix
shining-bluemoon-11 04dd54c
fix checks
shining-bluemoon-11 4f40573
remove unwanted file
shining-bluemoon-11 0127c28
fix checks
shining-bluemoon-11 e42db29
update fix
shining-bluemoon-11 63e5c44
fix
shining-bluemoon-11 b2c8854
update fix
shining-bluemoon-11 a58ff4e
resolve conversation
shining-bluemoon-11 b493f9f
Merge branch 'main' into feature/add-anchor-links
shining-bluemoon-11 9a8e6e1
Merge branch 'main' into feature/add-anchor-links
kasya 4ae3100
resolve updates
shining-bluemoon-11 ccb5315
resolve
shining-bluemoon-11 0f22366
fix checks
shining-bluemoon-11 6c9d866
fix required updates
shining-bluemoon-11 d8a2f5c
Merge branch 'main' into feature/add-anchor-links
kasya 9142ec3
final fix
shining-bluemoon-11 57f3ace
resolve fix
shining-bluemoon-11 719b826
Merge branch 'main' into feature/add-anchor-links
shining-bluemoon-11 846bf78
fix
shining-bluemoon-11 dc40bb4
fix conversations update
shining-bluemoon-11 53ba80b
Merge branch 'main' into feature/add-anchor-links
shining-bluemoon-11 11f99cd
update fix
shining-bluemoon-11 b770ccb
update
shining-bluemoon-11 fb9d1a8
resolve conflict
shining-bluemoon-11 ccbca51
Merge branch 'main' into feature/add-anchor-links
kasya 3d8b058
fix conversations
shining-bluemoon-11 3d4e484
fix
shining-bluemoon-11 cab4472
resolve
shining-bluemoon-11 3e36d0b
resolve update
shining-bluemoon-11 627e034
Merge branch 'main' into feature/add-anchor-links
kasya 28684f3
resolve
shining-bluemoon-11 7b49504
fix
shining-bluemoon-11 75457c4
fix
shining-bluemoon-11 599c438
fix e2e test
shining-bluemoon-11 6fce824
Merge branch 'main' into feature/add-anchor-links
kasya 12291e9
Fix icon/title alignments. Resolve conflicts
kasya 89ea621
Fix tests
kasya 9c8d215
Fix tests
kasya 8529ed9
Update code
arkid15r ebc6a64
Merge branch 'main' into feature/add-anchor-links
arkid15r ea80a3a
Merge branch 'main' into feature/add-anchor-links
arkid15r 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { faLink } from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import React, { useEffect, useCallback } from 'react' | ||
|
||
interface AnchorTitleProps { | ||
href: string | ||
title: string | ||
className?: string | ||
} | ||
|
||
const AnchorTitle: React.FC<AnchorTitleProps> = ({ href, title }) => { | ||
shining-bluemoon-11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const id = href.replace('#', '') // TODO(arkid15r): refactor get href from title automatically. | ||
|
||
const scrollToElement = useCallback(() => { | ||
const element = document.getElementById(id) | ||
if (element) { | ||
const headingHeight = | ||
(element.querySelector('div#anchor-title') as HTMLElement)?.offsetHeight || 0 | ||
const yOffset = -headingHeight - 50 | ||
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset | ||
window.scrollTo({ top: y, behavior: 'smooth' }) | ||
} | ||
}, [id]) | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => { | ||
event.preventDefault() | ||
scrollToElement() | ||
window.history.pushState(null, '', href) | ||
} | ||
|
||
useEffect(() => { | ||
const hash = window.location.hash.replace('#', '') | ||
if (hash === id) { | ||
requestAnimationFrame(() => scrollToElement()) | ||
} | ||
}, [id, scrollToElement]) | ||
|
||
useEffect(() => { | ||
const handlePopState = () => { | ||
const hash = window.location.hash.replace('#', '') | ||
if (hash === id) { | ||
requestAnimationFrame(() => scrollToElement()) | ||
} | ||
} | ||
window.addEventListener('popstate', handlePopState) | ||
return () => window.removeEventListener('popstate', handlePopState) | ||
}, [id, scrollToElement]) | ||
|
||
return ( | ||
<div id={id} className="relative"> | ||
<div className="group relative flex items-center"> | ||
<div className="flex items-center text-2xl font-semibold" id="anchor-title"> | ||
{title} | ||
</div> | ||
<a | ||
href={href} | ||
className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100" | ||
onClick={handleClick} | ||
> | ||
shining-bluemoon-11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<FontAwesomeIcon icon={faLink} className="custom-icon h-7 w-5" /> | ||
</a> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AnchorTitle |
Oops, something went wrong.
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.