Skip to content

Commit 2e21afc

Browse files
author
Parth Shah
committed
adding tabs component
1 parent ba7c098 commit 2e21afc

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

components/Tabs/Tabs.jsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import cn from 'classnames'
44
require('./Tabs.scss')
55

66

7-
const Tabs = ({activeKey, children, onSelect}) => (
8-
<div>
9-
<div className="tabs">
10-
<ul>
11-
{children.map(({props: {title, eventKey}}) =>
12-
<li key={eventKey} onClick={(e) => onSelect(eventKey, e)} className={cn({active: activeKey === eventKey})}>
13-
<a >{title}</a>
14-
</li>
15-
)}
16-
</ul>
17-
</div>
18-
<div className="tab-content">
19-
{children.filter(({props: {eventKey}}) => eventKey === activeKey)[0]}
7+
const Tabs = ({activeKey, children, onSelect}) => {
8+
const renderTabPill = ({props: {title, eventKey}}) => (
9+
<li key={eventKey} className={cn({active: activeKey === eventKey})}>
10+
<a onClick={function(e) { onSelect(eventKey, e)} }>{title}</a>
11+
</li>
12+
)
13+
const activeChild = ({props: {eventKey}}) => eventKey === activeKey
14+
return (
15+
<div>
16+
<div className="tabs">
17+
<ul>
18+
{children.map(renderTabPill)}
19+
</ul>
20+
</div>
21+
<div className="tab-content">
22+
{children.filter(activeChild)[0]}
23+
</div>
2024
</div>
21-
</div>
22-
)
25+
)
26+
}
2327

2428
Tabs.propTypes = {
2529
/**

0 commit comments

Comments
 (0)