-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Patient Search and Register UI (#9400)
- Loading branch information
1 parent
2203a25
commit 35e0725
Showing
49 changed files
with
2,386 additions
and
2,192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
|
||
export default function SectionNavigator(props: { | ||
sections: { label: string; id: string }[]; | ||
className?: string; | ||
}) { | ||
const { sections, className } = props; | ||
|
||
const [activeSection, setActiveSection] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const updateActiveSection = () => { | ||
sections.forEach((section) => { | ||
const element = document.getElementById(section.id); | ||
if (element) { | ||
const rect = element.getBoundingClientRect(); | ||
if (rect.top >= 0 && rect.bottom <= window.innerHeight) { | ||
setActiveSection(section.id); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
setActiveSection(entry.target.id); | ||
} | ||
}); | ||
}, | ||
{ rootMargin: "0px 0px -80% 0px", threshold: 0.1 }, | ||
); | ||
|
||
sections.forEach((section) => { | ||
const element = document.getElementById(section.id); | ||
if (element) { | ||
observer.observe(element); | ||
} | ||
}); | ||
|
||
updateActiveSection(); // Update on page load | ||
|
||
return () => { | ||
sections.forEach((section) => { | ||
const element = document.getElementById(section.id); | ||
if (element) { | ||
observer.unobserve(element); | ||
} | ||
}); | ||
}; | ||
}, [sections]); | ||
|
||
return ( | ||
<div className={cn("sticky top-4 left-0 flex flex-col w-52", className)}> | ||
{sections.map((section) => ( | ||
<Button | ||
key={section.id} | ||
className={cn( | ||
"justify-start bg-transparent shadow-none text-gray-700 hover:bg-black/5", | ||
activeSection === section.id && "text-primary-500 font-semibold", | ||
)} | ||
onClick={() => { | ||
const element = document.getElementById(section.id); | ||
if (element) { | ||
element.scrollIntoView({ behavior: "smooth" }); | ||
} | ||
}} | ||
> | ||
{section.label} | ||
</Button> | ||
))} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.