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