Skip to content

Commit ba7c098

Browse files
author
Parth Shah
committed
adding tabs component
1 parent 7dd1683 commit ba7c098

File tree

5 files changed

+124
-1
lines changed

5 files changed

+124
-1
lines changed

components/Tabs/Tab.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, {PropTypes} from 'react'
2+
3+
const Tab = ({children}) => <div>{children}</div>
4+
5+
Tab.propTypes = {
6+
/**
7+
* The unique key of the tab. Used by parent component.
8+
*/
9+
eventKey: PropTypes.any.isRequired,
10+
11+
/**
12+
* The tab title. Used by parent component.
13+
*/
14+
title: PropTypes.string.isRequired,
15+
16+
/**
17+
* The tab content
18+
*/
19+
children: PropTypes.any.isRequired
20+
}
21+
22+
export default Tab

components/Tabs/Tabs.jsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react'
2+
import uncontrollable from 'uncontrollable'
3+
import cn from 'classnames'
4+
require('./Tabs.scss')
5+
6+
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]}
20+
</div>
21+
</div>
22+
)
23+
24+
Tabs.propTypes = {
25+
/**
26+
* Mark the Tab with a matching `eventKey` as active.
27+
*/
28+
activeKey: React.PropTypes.any,
29+
30+
/**
31+
* Callback fired when a Tab is selected.
32+
*
33+
* ```js
34+
* function (
35+
* Any eventKey,
36+
* SyntheticEvent event?
37+
* )
38+
*
39+
*/
40+
onSelect: React.PropTypes.func
41+
}
42+
43+
44+
export default uncontrollable(Tabs, { activeKey: 'onSelect' })

components/Tabs/Tabs.scss

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* can't use 'tabs', because of conflicts */
2+
3+
@import "~tc-ui/src/styles/variables";
4+
@import "~tc-ui/src/styles/typography";
5+
6+
.tabs {
7+
width: 240px;
8+
list-style-type: none;
9+
margin: 0 auto 50px auto;
10+
ul{
11+
text-align: center;
12+
display: -webkit-flex;
13+
display: flex;
14+
width:240px;
15+
}
16+
li {
17+
// -webkit-flex: initial;
18+
flex: initial;
19+
width: 50%;
20+
padding: 10px 0;
21+
text-align: center;
22+
background-color: $tc-gray-neutral-light;
23+
@include roboto-medium;
24+
font-size: 15px;
25+
line-height:20px;
26+
background: $tc-white;
27+
border: 1px solid $tc-gray-30;
28+
a{
29+
color: $tc-gray-80;
30+
}
31+
&:hover {
32+
}
33+
&.active {
34+
background-color: $tc-dark-blue-90;
35+
border: 1px solid $tc-dark-blue-90;
36+
a{
37+
color: $tc-white;
38+
}
39+
}
40+
&:first-child{
41+
border-radius: 2px 0 0 2px;
42+
border-right:none;
43+
}
44+
&:last-child{
45+
border-radius: 0 2px 2px 0 ;
46+
border-left:none;
47+
}
48+
49+
50+
}
51+
}

exports.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ RightArrowIcon = require './components/Icons/RightArrowIcon'
3333
HamburgerIcon = require './components/Icons/HamburgerIcon'
3434
PlaceholderIcon = require './components/Icons/PlaceholderIcon'
3535
XMarkIcon = require './components/Icons/XMarkIcon'
36+
Tabs = require './components/Tabs/Tabs'
37+
Tab = require './components/Tabs/Tab'
3638

3739
# Redux Forms
3840
InputFormField = require './components/ReduxForms/Input'
@@ -81,6 +83,9 @@ module.exports =
8183
ConnectLogo : ConnectLogo.default,
8284
XMarkIcon : XMarkIcon.default,
8385
SwitchButton : SwitchButton.default
86+
Tabs : Tabs.default
87+
Tab : Tab.default
88+
8489
# Redux Forms
8590
InputFormField : InputFormField.default
8691
TextareaFormField : TextareaFormField.default

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"react-select": "^0.9.1",
4545
"react-switch-button": "^1.1.2",
4646
"redux-thunk": "^2.1.0",
47-
"tc-ui": "https://github.com/appirio-tech/tc-ui.git#feature/connectv2"
47+
"tc-ui": "https://github.com/appirio-tech/tc-ui.git#feature/connectv2",
48+
"uncontrollable": "^4.0.1"
4849
}
4950
}

0 commit comments

Comments
 (0)