-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
54 lines (47 loc) · 1.24 KB
/
index.tsx
File metadata and controls
54 lines (47 loc) · 1.24 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
54
import * as TabsPrimitive from '@radix-ui/react-tabs';
import classNames from 'classnames';
import type { FC, PropsWithChildren, ReactNode } from 'react';
import styles from './index.module.css';
type Tab = {
key: string;
label: string;
secondaryLabel?: string;
value?: string;
};
type TabsProps = TabsPrimitive.TabsProps & {
tabs: Array<Tab>;
addons?: ReactNode;
triggerClassName?: string;
};
const Tabs: FC<PropsWithChildren<TabsProps>> = ({
tabs,
addons,
triggerClassName,
children,
...props
}) => (
<TabsPrimitive.Root
{...props}
className={classNames(styles.tabsRoot, props.className)}
>
<TabsPrimitive.List className={styles.tabsList}>
{tabs.map(tab => (
<TabsPrimitive.Trigger
key={tab.key}
value={tab.value ?? tab.key}
className={classNames(styles.tabsTrigger, triggerClassName)}
>
{tab.label}
{tab.secondaryLabel ? (
<span className={styles.tabSecondaryLabel}>
{tab.secondaryLabel}
</span>
) : null}
</TabsPrimitive.Trigger>
))}
{addons && <div className={styles.addons}>{addons}</div>}
</TabsPrimitive.List>
{children}
</TabsPrimitive.Root>
);
export default Tabs;