React - tabs component with active style

0 votes
38 views
added Jan 19 in React by lcjr First Warrant Officer (11,850 points)
import React, { useState } from 'react';

const Tabs = () => {
  const [activeTab, setActiveTab] = useState(1);

  const handleTabClick = (tabNumber) => {
    setActiveTab(tabNumber);
  };

  return (
    <div>
      <div style={{ display: 'flex' }}>
        <div
          style={{
            padding: '10px',
            cursor: 'pointer',
            borderBottom: activeTab === 1 ? '2px solid blue' : 'none',
          }}
          onClick={() => handleTabClick(1)}
        >
          Tab 1
        </div>
        <div
          style={{
            padding: '10px',
            cursor: 'pointer',
            borderBottom: activeTab === 2 ? '2px solid blue' : 'none',
          }}
          onClick={() => handleTabClick(2)}
        >
          Tab 2
        </div>
      </div>
      <div className="tab-content">
        {activeTab === 1 && <div>Content for Tab 1</div>}
        {activeTab === 2 && <div>Content for Tab 2</div>}
      </div>
    </div>
  );
};

export default Tabs;

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...