React Tabs

Size
3,390 Kb
Views
10,120

How do I make an react tabs?

What is a react tabs? How do you make a react tabs? This script and codes were developed by Tushar Mehrotra on 06 January 2023, Friday.

React Tabs Previews

React Tabs - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>React Tabs</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="root"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

React Tabs - Script Codes CSS Codes

.flex-container { display: flex; height: 100vh; justify-content: center; align-items: center;
}
.tab { text-decoration: none; padding: 15px; background: #f6f6f6; border: 1px solid #dfe5ed; color: #000;
}
.tab-selected { background: #1d9fdb; color: #fff;
}
.content { display: none;
}
.content-selected { display: block;
}

React Tabs - Script Codes JS Codes

'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var App = function (_React$Component) { _inherits(App, _React$Component); function App(props) { _classCallCheck(this, App); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = { data: [{ title: 'first tab', content: 'first tab content' }, { title: 'Second tab', content: 'Second tab content' }], active: 0 }; return _this; } App.prototype.handleClick = function handleClick(index) { this.setState({ active: index }); }; App.prototype.render = function render() { return React.createElement( 'div', { className: 'flex-container' }, React.createElement(Tabs, { tabs: this.state.data, active: this.state.active, onTabClick: this.handleClick.bind(this) }), React.createElement(Content, { tabs: this.state.data, active: this.state.active }) ); }; return App;
}(React.Component);
var Tabs = function (_React$Component2) { _inherits(Tabs, _React$Component2); function Tabs() { _classCallCheck(this, Tabs); return _possibleConstructorReturn(this, _React$Component2.apply(this, arguments)); } Tabs.prototype.supplyIndex = function supplyIndex(index) { this.props.onTabClick(index); }; Tabs.prototype.render = function render() { var _this3 = this; var active = this.props.active; var tabs = this.props.tabs.map(function (tab, index) { return React.createElement( 'a', { href: '#', key: index, className: 'tab ' + (active === index ? 'tab-selected' : ''), onClick: _this3.supplyIndex.bind(_this3, index) }, tab.title ); }); return React.createElement( 'div', null, tabs ); }; return Tabs;
}(React.Component);
var Content = function (_React$Component3) { _inherits(Content, _React$Component3); function Content() { _classCallCheck(this, Content); return _possibleConstructorReturn(this, _React$Component3.apply(this, arguments)); } Content.prototype.render = function render() { var active = this.props.active; var content = this.props.tabs.map(function (content, index) { return React.createElement( 'div', { key: index, className: 'content ' + (active === index ? 'content-selected' : '') }, content.content ); }); return React.createElement( 'div', null, content ); }; return Content;
}(React.Component);
ReactDOM.render(React.createElement(App, null), document.querySelector("#root"));
React Tabs - Script Codes
React Tabs - Script Codes
Home Page Home
Developer Tushar Mehrotra
Username MTushar
Uploaded January 06, 2023
Rating 3
Size 3,390 Kb
Views 10,120
Do you need developer help for React Tabs?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tushar Mehrotra (MTushar) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!