Skip to content

Commit 50d9d2a

Browse files
committed
feat: chrome style tabs
1 parent 3f5fccc commit 50d9d2a

3 files changed

Lines changed: 81 additions & 12 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { useState } from 'react'
2+
3+
const FixTabs = () => {
4+
// 定义tab数据
5+
const tabs = [
6+
{ id: 1, label: '首页' },
7+
{ id: 2, label: '产品' },
8+
{ id: 3, label: '服务' },
9+
{ id: 4, label: '关于我们' },
10+
{ id: 5, label: '联系我们' },
11+
]
12+
13+
// 设置默认激活的tab
14+
const [activeTab, setActiveTab] = useState(1)
15+
16+
// 切换tab的函数
17+
const handleTabClick = (tabId) => {
18+
setActiveTab(tabId)
19+
}
20+
21+
return (
22+
<div className="mx-auto mt-8 w-full max-w-3xl">
23+
<div className="flex flex-wrap border-b border-gray-200">
24+
{tabs.map((tab) => (
25+
<button
26+
key={tab.id}
27+
className={`relative cursor-pointer px-2 ${
28+
activeTab === tab.id ? 'rounded-tab text-blue-600' : 'text-gray-500 hover:text-gray-700'
29+
}`}
30+
onClick={() => handleTabClick(tab.id)}
31+
>
32+
<div className="flex items-center px-4 py-1">{tab.label}</div>
33+
</button>
34+
))}
35+
</div>
36+
37+
{/* Tab内容区域 */}
38+
<div className="py-6">
39+
{tabs.map((tab) => (
40+
<div key={tab.id} className={activeTab === tab.id ? 'block' : 'hidden'}>
41+
<h2 className="mb-4 text-xl font-bold">{tab.label}</h2>
42+
<p>这是{tab.label}的内容区域。您可以在这里添加任何相关内容。</p>
43+
</div>
44+
))}
45+
</div>
46+
</div>
47+
)
48+
}
49+
50+
export default FixTabs

src/pages/demo/index.jsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import FloatingIcon, { SocialIcon } from '@stateless/FloatingIcon'
77
import GradientTracing from '@stateless/GradientTracing'
88
import Footer from '@stateless/Footer'
99
import StarBack from '@stateless/StarBackground'
10-
import OrbitingCirclesDemo from '@stateless/OrbitingCircles'
10+
// import OrbitingCirclesDemo from '@stateless/OrbitingCircles'
11+
import FixTabs from '@stateless/FixTabs'
1112

1213
import StickyCard from '@stateless/StickyCard'
1314
import SpringPng from '@assets/images/spring.png'
@@ -16,9 +17,9 @@ import SongPng from '@assets/images/song.png'
1617
import XuePng from '@assets/images/xue.png'
1718

1819
import { Command, Cannabis, Beer, Mail } from 'lucide-react'
19-
import ScriptView from '@stateless/ScriptView'
20-
import AnimatedList from '@stateless/AnimatedList'
21-
import { DraggableList, DraggableItem } from '@stateless/DraggableList'
20+
// import ScriptView from '@stateless/ScriptView'
21+
// import AnimatedList from '@stateless/AnimatedList'
22+
// import { DraggableList, DraggableItem } from '@stateless/DraggableList'
2223
import FixCarousel from '@stateless/FixCarouse'
2324
import styles from './index.module.less'
2425

@@ -107,17 +108,18 @@ const dateDifference = (date1, date2) => {
107108
}
108109

109110
const ProDemo = () => {
110-
const [items, setItems] = useState([
111-
{ id: '1', content: <DraggableItem>First Item</DraggableItem> },
112-
{ id: '2', content: <DraggableItem>Second Item</DraggableItem> },
113-
{ id: '3', content: <DraggableItem>Third Item</DraggableItem> },
114-
])
115-
const handleReorder = (newItems) => {
116-
setItems(newItems)
117-
}
111+
// const [items, setItems] = useState([
112+
// { id: '1', content: <DraggableItem>First Item</DraggableItem> },
113+
// { id: '2', content: <DraggableItem>Second Item</DraggableItem> },
114+
// { id: '3', content: <DraggableItem>Third Item</DraggableItem> },
115+
// ])
116+
// const handleReorder = (newItems) => {
117+
// setItems(newItems)
118+
// }
118119

119120
return (
120121
<FixTabPanel>
122+
<FixTabs />
121123
<FixCarousel />
122124
{/* <OrbitingCirclesDemo /> */}
123125
{/* <ScriptView showMultiplePackageOptions={true} codeLanguage="shell" commandMap={customCommandMap} /> */}

src/styles/reset.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,20 @@ select:-webkit-autofill:active {
330330
transform: rotate(360deg);
331331
}
332332
}
333+
334+
.rounded-tab {
335+
--r: 12px;
336+
337+
padding-inline: 0.8em;
338+
border-inline: var(--r) solid #0000;
339+
border-radius: calc(2 * var(--r)) calc(2 * var(--r)) 0 0 / var(--r);
340+
mask:
341+
radial-gradient(var(--r) at var(--r) 0, #0000 98%, #000 101%) calc(-1 * var(--r)) 100%/100% var(--r) repeat-x,
342+
conic-gradient(#000 0 0) padding-box;
343+
background: #e1e1e1 border-box;
344+
width: fit-content;
345+
}
346+
347+
div[className*='cursor-pointer'] {
348+
transition: all 0.2s ease-in-out;
349+
}

0 commit comments

Comments
 (0)