-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
53 lines (45 loc) · 1.16 KB
/
index.tsx
File metadata and controls
53 lines (45 loc) · 1.16 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
53
import type { FC, PropsWithChildren } from 'react';
import Select from '#ui/Common/Select';
import type { LinkLike } from '#ui/types';
import styles from './index.module.css';
type LinkTab = { key: string; label: string; link: string };
export type LinkTabsProps = PropsWithChildren<{
label?: string;
tabs: Array<LinkTab>;
activeTab: string;
as?: LinkLike;
onSelect: (value: string) => void;
}>;
const BaseLinkTabs: FC<LinkTabsProps> = ({
tabs,
label,
activeTab,
children,
as: Component = 'a',
onSelect,
}) => (
<>
<div className={styles.tabsList}>
{tabs.map(tab => (
<Component
key={tab.key}
href={tab.link}
className={styles.tabsTrigger}
data-state={tab.key === activeTab ? 'active' : 'inactive'}
>
{tab.label}
</Component>
))}
</div>
<div className={styles.tabsSelect}>
<Select
label={label}
defaultValue={tabs.find(tab => tab.key === activeTab)?.link}
values={tabs.map(tab => ({ label: tab.label, value: tab.link }))}
onChange={onSelect}
/>
</div>
{children}
</>
);
export default BaseLinkTabs;