-
Notifications
You must be signed in to change notification settings - Fork 355
/
TabBar.tsx
90 lines (81 loc) · 1.88 KB
/
TabBar.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
import cn from "classnames";
import React, { FunctionComponent } from "react";
import { withStyles } from "coral-ui/hocs";
import styles from "./TabBar.css";
export interface TabBarProps {
/**
* Convenient prop to override the root styling.
*/
className?: string;
/**
* Override or extend the styles applied to the component.
*/
classes: typeof styles;
/**
* Style variant
*/
variant?:
| "primary"
| "secondary"
| "default"
| "streamSecondary"
| "streamPrimary";
/**
* Active tab id/name
*/
activeTab?: string;
/**
* Default active tab id/name
*/
defaultActiveTab?: string;
/**
* Action taken on tab click
*/
onTabClick?: (tabID: string) => void;
}
const TabBar: FunctionComponent<TabBarProps> = (props) => {
const {
className,
classes,
children,
onTabClick,
activeTab,
variant,
defaultActiveTab,
} = props;
const rootClassName = cn(
classes.root,
[
{
[classes.primary]: variant === "primary",
[classes.secondary]: variant === "secondary",
[classes.streamSecondary]: variant === "streamSecondary",
[classes.streamPrimary]: variant === "streamPrimary",
[classes.default]: variant === "default",
},
],
className
);
const tabs = React.Children.toArray(children).map(
(child: React.ReactElement<any>, index: number) =>
React.cloneElement(child, {
tabID: child.props.tabID ? child.props.tabID : index,
active:
defaultActiveTab && !activeTab
? child.props.tabID === defaultActiveTab
: child.props.tabID === activeTab,
variant,
onTabClick,
})
);
return (
<ul className={rootClassName} role="tablist">
{tabs}
</ul>
);
};
TabBar.defaultProps = {
variant: "default",
};
const enhanced = withStyles(styles)(TabBar);
export default enhanced;