-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDualScrollSyncNavItem.tsx
More file actions
52 lines (45 loc) · 1.23 KB
/
DualScrollSyncNavItem.tsx
File metadata and controls
52 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import clsx from 'clsx';
import type { FC } from 'react';
import { useDualScrollSyncContext } from '@/hooks';
import styles from './DualScrollSyncNavItem.module.scss';
import type { DualScrollSyncNavItemProps } from './DualScrollSyncNavItem.types';
export const DualScrollSyncNavItem: FC<DualScrollSyncNavItemProps> = ({
children,
className,
sectionKey,
style = {}
}) => {
const { navId, onMenuItemSelect, onItemClick, activeKey, navItemRefs } =
useDualScrollSyncContext();
const navItemId = `${navId}-item-${sectionKey}`;
const handleMenuItemClick = () => {
onMenuItemSelect(sectionKey);
if (onItemClick) onItemClick(sectionKey);
};
return (
<button
className={clsx(
styles.scrollSyncNavItem,
activeKey === sectionKey && styles.scrollSyncNavItemActive,
className
)}
style={style}
data-testid={navItemId}
id={navItemId}
onClick={handleMenuItemClick}
ref={(navItemRef) => {
if (!navItemRef) return;
navItemRefs.current[sectionKey] = navItemRef;
}}
>
{typeof children === 'string' ? (
<span className={styles.scrollSyncNavItemLabel} title={children}>
{children}
</span>
) : (
children
)}
</button>
);
};
DualScrollSyncNavItem.displayName = 'DualScrollSync.NavItem';