From ee67a41c8a2ee167fa8fa67e3f873e4d8640a66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F?= <1450374480@qq.com> Date: Sun, 17 Mar 2024 16:09:32 +0800 Subject: [PATCH] feat: Tab --- src/components/customized/tab.jsx | 73 ++++++++++++++++++++++++++++++ src/components/customized/tab.scss | 3 ++ src/views/setting/index.jsx | 24 +++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/components/customized/tab.jsx create mode 100644 src/components/customized/tab.scss diff --git a/src/components/customized/tab.jsx b/src/components/customized/tab.jsx new file mode 100644 index 0000000..fb66c8a --- /dev/null +++ b/src/components/customized/tab.jsx @@ -0,0 +1,73 @@ +import { useEffect, useRef, useState } from "react"; +import './tab.scss' + +const Tab = (props) => { + const { tabs } = props; + const tabTitles = tabs.map((item, index) => ({ + index, title: item.title + })) + const tabLength = tabs.length || 0; + const tabContent = tabs.map(item => (item.content)) + const [curLeft, setCurLeft] = useState(0) + + const [domWidth, setDomWidth] = useState(0) + const containerRef = useRef(null) + useEffect(() => { + setDomWidth(containerRef.current.offsetWidth) + }, []) + + return
+
+ { + tabTitles.map((item, index) => { + return ( +
{ + containerRef.current.scrollLeft = domWidth * index + }} + > + { item.title } +
+ ) + }) + } +
+
{ + setCurLeft(e.target.scrollLeft / 360) + console.log('scroll', e.target.scrollLeft / 360); + }} + className="tab-content relative overflow-x-auto overflow-y-hidden inline-block w-full" + > +
+ { + tabContent.map((item, index) => { + return ( +
+ {item} +
+ ) + }) + } +
+
+
+} + +export { + Tab +} \ No newline at end of file diff --git a/src/components/customized/tab.scss b/src/components/customized/tab.scss new file mode 100644 index 0000000..d3d463e --- /dev/null +++ b/src/components/customized/tab.scss @@ -0,0 +1,3 @@ +.tab-content::-webkit-scrollbar { + height: 0px; +} \ No newline at end of file diff --git a/src/views/setting/index.jsx b/src/views/setting/index.jsx index deab53d..d3d9588 100644 --- a/src/views/setting/index.jsx +++ b/src/views/setting/index.jsx @@ -1,7 +1,27 @@ +import { Tab } from "@/components/customized/tab" + export default function Setting() { + const tabs = [ + { + title: 'title1', + content:
Content1
+ }, + { + title: 'title2', + content:
Content2
+ }, + { + title: 'title3', + content:
Content3
+ }, + { + title: 'title4', + content:
Content4
+ }, + ] return ( -
- Setting +
+
) } \ No newline at end of file