-
Notifications
You must be signed in to change notification settings - Fork 386
/
Copy pathSidebarLink.tsx
104 lines (98 loc) · 3.11 KB
/
SidebarLink.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import {useRef, useEffect} from 'react';
import * as React from 'react';
import cn from 'classnames';
import {IconNavArrow} from 'components/Icon/IconNavArrow';
import {IconCanary} from 'components/Icon/IconCanary';
import Link from 'next/link';
interface SidebarLinkProps {
href: string;
selected?: boolean;
title: string;
level: number;
version?: 'canary' | 'major';
icon?: React.ReactNode;
isExpanded?: boolean;
hideArrow?: boolean;
isPending: boolean;
}
export function SidebarLink({
href,
selected = false,
title,
version,
level,
isExpanded,
hideArrow,
isPending,
}: SidebarLinkProps) {
const ref = useRef<HTMLAnchorElement>(null);
useEffect(() => {
if (selected && ref && ref.current) {
// @ts-ignore
if (typeof ref.current.scrollIntoViewIfNeeded === 'function') {
// @ts-ignore
ref.current.scrollIntoViewIfNeeded();
}
}
}, [ref, selected]);
let target = '';
if (href.startsWith('https://')) {
target = '_blank';
}
return (
<Link
href={href}
ref={ref}
title={title}
target={target}
passHref
aria-current={selected ? 'page' : undefined}
className={cn(
'p-2 pe-2 w-full rounded-none lg:rounded-e-2xl text-start hover:bg-gray-5 dark:hover:bg-gray-80 relative flex items-center justify-between',
{
'text-sm ps-6': level > 0,
'ps-5': level < 2,
'text-base font-bold': level === 0,
'text-primary dark:text-primary-dark': level === 0 && !selected,
'text-base text-secondary dark:text-secondary-dark':
level > 0 && !selected,
'text-base text-link dark:text-link-dark bg-highlight dark:bg-highlight-dark border-blue-40 hover:bg-highlight hover:text-link dark:hover:bg-highlight-dark dark:hover:text-link-dark':
selected,
'dark:bg-gray-70 bg-gray-3 dark:hover:bg-gray-70 hover:bg-gray-3':
isPending,
}
)}>
{/* This here needs to be refactored ofc */}
<div>
{title}{' '}
{version === 'major' && (
<span
title="- This feature is available in React 19 beta and the React canary channel"
className={`text-xs px-1 ms-1 rounded bg-gray-10 dark:bg-gray-40 dark:bg-opacity-20 text-gray-40 dark:text-gray-40`}>
React 19
</span>
)}
{version === 'canary' && (
<IconCanary
title=" - This feature is available in the latest Canary"
className="ms-1 text-gray-30 dark:text-gray-60 inline-block w-3.5 h-3.5 align-[-3px]"
/>
)}
</div>
{isExpanded != null && !hideArrow && (
<span
className={cn('pe-1', {
'text-link dark:text-link-dark': isExpanded,
'text-tertiary dark:text-tertiary-dark': !isExpanded,
})}>
<IconNavArrow displayDirection={isExpanded ? 'down' : 'end'} />
</span>
)}
</Link>
);
}