MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / NavigationGroup

Function NavigationGroup

apps/baseai.dev/src/components/Navigation.tsx:138–277  ·  view source on GitHub ↗
({
	group,
	className
}: {
	group: NavigationItem;
	className?: string;
})

Source from the content-addressed store, hash-verified

136}
137
138function NavigationGroup({
139 group,
140 className
141}: {
142 group: NavigationItem;
143 className?: string;
144}) {
145 // If this is the mobile navigation then we always render the initial
146 // state, so that the state does not change during the close animation.
147 // The state will still update when we re-open (re-render) the navigation.
148 let isInsideMobileNavigation = useIsInsideMobileNavigation();
149 let [pathname, sections] = useInitialValue(
150 [usePathname(), useSectionStore(s => s.sections)],
151 isInsideMobileNavigation
152 );
153 let isActiveGroup =
154 group.links.findIndex(link => link.href === pathname) !== -1;
155
156 // Scroll to active link
157 const activeLinkRef = useRef<HTMLAnchorElement>(null);
158 useEffect(() => {
159 if (activeLinkRef.current) {
160 const rect = activeLinkRef.current.getBoundingClientRect();
161 const isInView =
162 rect.top >= 0 &&
163 rect.left >= 0 &&
164 rect.bottom <=
165 (window.innerHeight ||
166 document.documentElement.clientHeight) &&
167 rect.right <=
168 (window.innerWidth || document.documentElement.clientWidth);
169
170 // Only scroll if the active link is not in view
171 if (!isInView) {
172 activeLinkRef.current.scrollIntoView({
173 behavior: 'instant'
174 });
175 }
176 }
177 }, []);
178
179 return (
180 <li className={clsx('relative mt-6', className)}>
181 <motion.h2
182 layout="position"
183 className="text-xs font-semibold text-zinc-900 dark:text-white"
184 >
185 {group.isCommand ? (
186 <code className="rounded-lg bg-muted/60 px-2 py-1 ring-2 ring-muted">
187 {group.title}
188 </code>
189 ) : (
190 group.title
191 )}
192 </motion.h2>
193 <div className="relative mt-3 pl-2">
194 <AnimatePresence initial={!isInsideMobileNavigation}>
195 {isActiveGroup && (

Callers

nothing calls this directly

Calls 3

useSectionStoreFunction · 0.90
useInitialValueFunction · 0.85

Tested by

no test coverage detected