-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path61. Tabbed interface(improved).tsx
More file actions
53 lines (48 loc) · 1.43 KB
/
Copy path61. Tabbed interface(improved).tsx
File metadata and controls
53 lines (48 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useState } from "react";
const App: React.FC = () => {
// Define the tabs array with label and content
const tabs = [
{ label: "Home", content: "Welcome to the homepage!" },
{ label: "Profile", content: "This is your profile." },
{ label: "Settings", content: "Adjust your preferences here." },
];
// Track the active tab index
const [activeTab, setActiveTab] = useState<number>(0);
return (
<div
style={{ width: "400px", margin: "50px auto", fontFamily: "sans-serif" }}
>
{/* Tab buttons */}
<div style={{ display: "flex", marginBottom: "12px" }}>
{tabs.map((tab, index) => (
<button
key={index}
onClick={() => setActiveTab(index)}
style={{
flex: 1,
padding: "10px",
cursor: "pointer",
border: "1px solid #ccc",
backgroundColor: activeTab === index ? "#007bff" : "#f0f0f0",
color: activeTab === index ? "white" : "black",
fontWeight: activeTab === index ? "bold" : "normal",
}}
>
{tab.label}
</button>
))}
</div>
{/* Active tab content */}
<div
style={{
padding: "16px",
border: "1px solid #ccc",
backgroundColor: "#fafafa",
}}
>
{tabs[activeTab].content}
</div>
</div>
);
};
export default App;