MCPcopy
hub / github.com/devias-io/material-kit-react / isNavItemActive

Function isNavItemActive

src/lib/is-nav-item-active.ts:3–27  ·  view source on GitHub ↗
({
  disabled,
  external,
  href,
  matcher,
  pathname,
}: Pick<NavItemConfig, 'disabled' | 'external' | 'href' | 'matcher'> & { pathname: string })

Source from the content-addressed store, hash-verified

1import type { NavItemConfig } from '@/types/nav';
2
3export function isNavItemActive({
4 disabled,
5 external,
6 href,
7 matcher,
8 pathname,
9}: Pick<NavItemConfig, 'disabled' | 'external' | 'href' | 'matcher'> & { pathname: string }): boolean {
10 if (disabled || !href || external) {
11 return false;
12 }
13
14 if (matcher) {
15 if (matcher.type === 'startsWith') {
16 return pathname.startsWith(matcher.href);
17 }
18
19 if (matcher.type === 'equals') {
20 return pathname === matcher.href;
21 }
22
23 return false;
24 }
25
26 return pathname === href;
27}

Callers 2

NavItemFunction · 0.90
NavItemFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected