diff --git a/src/components/common/TabCommon/TabCommon.tsx b/src/components/common/TabCommon/TabCommon.tsx index d07cf06e8..67fe107a6 100644 --- a/src/components/common/TabCommon/TabCommon.tsx +++ b/src/components/common/TabCommon/TabCommon.tsx @@ -1,46 +1,74 @@ -import React, { useState } from "react" +import React, { useState, RefObject, useEffect, useRef } from "react" import s from './TabCommon.module.scss' import TabItem from './TabItem/TabItem' interface TabCommonProps { - + changeTab: (target:string) => void; } -const TabCommon = ({ } : TabCommonProps) => { +const TabCommon = ({ changeTab } : TabCommonProps) => { const active = "active", unActive = ""; - const [item1Active, setItem1Active] = useState(active); const [item2Active, setItem2Active] = useState(unActive); const [item3Active, setItem3Active] = useState(unActive); + const item1 = useRef(null); + const item2 = useRef(null); + const item3 = useRef(null); + const slider = useRef(null); + + function slide(ref: RefObject) { + const width = ref.current.offsetWidth; + const left = ref.current.offsetLeft; + + slider.current.style.width = (width-48).toString()+"px"; + slider.current.style.left = left.toString()+"px"; + } + function toggleItem1():void { setItem1Active(active) + changeTab("waiting") setItem2Active(unActive) setItem3Active(unActive) + slide(item1) } + function toggleItem2():void { setItem2Active(active) + changeTab("delivering") setItem1Active(unActive) setItem3Active(unActive) + slide(item2) } function toggleItem3():void { setItem3Active(active) + changeTab("delivered") setItem1Active(unActive) setItem2Active(unActive) + slide(item3) } + useEffect(() => { + slide(item1); + }, []) + return ( -
-
- Wait for Comfirmation - Delivering - Delivered -
-
+
    +
  • + Wait for Comfirmation +
  • +
  • + Delivering +
  • +
  • + Delivered +
  • +
    +
) } diff --git a/src/components/common/TabCommon/TabItem/TabItem.tsx b/src/components/common/TabCommon/TabItem/TabItem.tsx index a889ee68b..62de3c595 100644 --- a/src/components/common/TabCommon/TabItem/TabItem.tsx +++ b/src/components/common/TabCommon/TabItem/TabItem.tsx @@ -4,13 +4,14 @@ import s from './TabItem.module.scss' interface TabItemProps { active: string; - target?: string; - children?: string; + children: string; + onClick: () => void; } -const TabItem = ({ active = "", children } : TabItemProps) => { +const TabItem = ({ active = "", children, onClick } : TabItemProps) => { + return ( - {children}