MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / CardNav

Function CardNav

src/ts-default/Components/CardNav/CardNav.tsx:32–218  ·  view source on GitHub ↗
({
  logo,
  logoAlt = 'Logo',
  items,
  className = '',
  ease = 'power3.out',
  baseColor = '#fff',
  menuColor,
  buttonBgColor,
  buttonTextColor
})

Source from the content-addressed store, hash-verified

30}
31
32const CardNav: React.FC<CardNavProps> = ({
33 logo,
34 logoAlt = 'Logo',
35 items,
36 className = '',
37 ease = 'power3.out',
38 baseColor = '#fff',
39 menuColor,
40 buttonBgColor,
41 buttonTextColor
42}) => {
43 const [isHamburgerOpen, setIsHamburgerOpen] = useState(false);
44 const [isExpanded, setIsExpanded] = useState(false);
45 const navRef = useRef<HTMLDivElement | null>(null);
46 const cardsRef = useRef<HTMLDivElement[]>([]);
47 const tlRef = useRef<gsap.core.Timeline | null>(null);
48
49 const calculateHeight = () => {
50 const navEl = navRef.current;
51 if (!navEl) return 260;
52
53 const isMobile = window.matchMedia('(max-width: 768px)').matches;
54 if (isMobile) {
55 const contentEl = navEl.querySelector('.card-nav-content') as HTMLElement;
56 if (contentEl) {
57 const wasVisible = contentEl.style.visibility;
58 const wasPointerEvents = contentEl.style.pointerEvents;
59 const wasPosition = contentEl.style.position;
60 const wasHeight = contentEl.style.height;
61
62 contentEl.style.visibility = 'visible';
63 contentEl.style.pointerEvents = 'auto';
64 contentEl.style.position = 'static';
65 contentEl.style.height = 'auto';
66
67 contentEl.offsetHeight;
68
69 const topBar = 60;
70 const padding = 16;
71 const contentHeight = contentEl.scrollHeight;
72
73 contentEl.style.visibility = wasVisible;
74 contentEl.style.pointerEvents = wasPointerEvents;
75 contentEl.style.position = wasPosition;
76 contentEl.style.height = wasHeight;
77
78 return topBar + contentHeight + padding;
79 }
80 }
81 return 260;
82 };
83
84 const createTimeline = () => {
85 const navEl = navRef.current;
86 if (!navEl) return null;
87
88 gsap.set(navEl, { height: 60, overflow: 'hidden' });
89 gsap.set(cardsRef.current, { y: 50, opacity: 0 });

Callers

nothing calls this directly

Calls 3

createTimelineFunction · 0.70
toggleMenuFunction · 0.70
setCardRefFunction · 0.70

Tested by

no test coverage detected