React + jQuery Tab Scroller
A simple Tab Scroller built with React and jQuery
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-with-addons.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="root"></div>
CSS
* {
margin: 0;
padding: 0;
}
#root {
background: #20262e;
color: white;
}
.tabScroller {
display: flex;
flex-wrap: wrap;
}
.NavList {
display: flex;
overflow: hidden;
}
.tabNav {
display: flex;
justify-content: center;
align-items: center;
}
.tabNav i {
display: flex;
justify-content: center;
align-items: center;
width: 35px;
height: 35px;
cursor: pointer;
}
.tabNav i:hover {
background: #353f4c;
}
ul {
display: flex;
align-items: stretch;
width: 100%;
list-style-type: none;
border-left: 1.5px solid #2D333B;
border-right: 1.5px solid #2D333B;
overflow: hidden;
}
li {
display: flex;
align-items: center;
padding: 0 10px;
cursor: pointer;
transition: all .3s ease-in-out;
}
ul li:last-child {
margin: 0;
border-right: none;
}
ul li:hover {
background: #1566b4;
transition: all .3s ease-in-out;
}
.active {
background: #104C86;
}
.tabContent {
display: flex;
width: 100%;
height: 300px;
padding: 10px;
border-top: 1.5px solid #2D333B;
}
Babel + JSX
/**
* Name: React + jQuery Tab Scroller
* Description: A simple Tab Scroller
* @package Chimera Apps
* @version 1.0.7
* @author Chimera.Zen
* @copyright Copyright (c) 2018, Chimera.Zen
* @link https://github.com/ChimeraZen
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/*
To be added:
- a means of getting the width of the tab list
- enclose the list in a container and get displayed width
- disable TabNav arrow if at start/end of tab list scrollable area
*/
const tabs = [
{
id: 0,
label: "Archery",
content: "Lorem Ipsum 1"
},
{
id: 1,
label: "Baseball",
content: "Lorem Ipsum 2"
},
{
id: 2,
label: "Basketball",
content: "Lorem Ipsum 3"
},
{
id: 3,
label: "Boxing",
content: "Lorem Ipsum 4"
},
{
id: 4,
label: "Football",
content: "Lorem Ipsum 5"
},
{
id: 5,
label: "Golf",
content: "Lorem Ipsum 6"
},
{
id: 6,
label: "Soccer",
content: "Lorem Ipsum 7"
},
{
id: 7,
label: "Surfing",
content: "Lorem Ipsum 8"
}
];
function TabContent(props) {
return (
<div className="tabContent">
{props.content}
</div>
);
}
class Tab extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
onClick(event) {
this.props.handleClick(event)
}
render() {
const active = (this.props.id === this.props.activeTab) ? "active" : ""
return (
<li id={this.props.id} onClick={this.onClick} className={active}>
{this.props.children}
</li>
);
}
}
class TabList extends React.Component {
constructor(props) {
super(props);
this.state = {
scrollPosition: 0
}
}
...