diff --git a/src/components/common/TabCommon/TabCommon.module.scss b/src/components/common/TabCommon/TabCommon.module.scss index 9e5fbc1df..3d3473d82 100644 --- a/src/components/common/TabCommon/TabCommon.module.scss +++ b/src/components/common/TabCommon/TabCommon.module.scss @@ -1,15 +1,21 @@ @import '../../../styles/utilities'; -.tabCommonOutSide { - @apply spacing-horizontal; - - .tabCommon { - @apply flex; - position: relative; - border-bottom: 2px solid #FBFBFB; - padding-top: 1.6rem; - padding-bottom: 1.6rem; - width: 100%; +.tabCommon { + @apply flex; + position: relative; + border-bottom: 2px solid #FBFBFB; + padding-top: 1.6rem; + padding-bottom: 1.6rem; + width: 100%; + + .slider { + @apply inline-block; + height: .2rem; + border-radius: 3px; + background-color: var(--primary); + position: absolute; + z-index: 1200; + bottom: 0; + transition: all .4s linear; } } - diff --git a/src/components/common/TabCommon/TabCommon.tsx b/src/components/common/TabCommon/TabCommon.tsx index 67fe107a6..b837004d6 100644 --- a/src/components/common/TabCommon/TabCommon.tsx +++ b/src/components/common/TabCommon/TabCommon.tsx @@ -1,75 +1,36 @@ -import React, { useState, RefObject, useEffect, useRef } from "react" +import React, { RefObject, useEffect } from "react" import s from './TabCommon.module.scss' import TabItem from './TabItem/TabItem' interface TabCommonProps { - changeTab: (target:string) => void; + tabs: {ref:RefObject, tabName: string, active: boolean, onClick: (tabIndex: number, tabPane?: string) => void}[]; + defaultActiveTab: number; + sliderRef : RefObject; + slideToTab: (ref: any) => void; } -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) - } +const TabCommon = ({ tabs, defaultActiveTab, sliderRef, slideToTab } : TabCommonProps) => { useEffect(() => { - slide(item1); + slideToTab(tabs[defaultActiveTab].ref); }, []) return (
    -
  • - Wait for Comfirmation -
  • -
  • - Delivering -
  • -
  • - Delivered -
  • -
    + { + tabs.map((tab) => { + return ( +
  • + {tab.tabName} +
  • + ) + }) + } + +
) } -export default TabCommon; \ No newline at end of file +export default TabCommon; diff --git a/src/components/common/TabCommon/TabItem/TabItem.module.scss b/src/components/common/TabCommon/TabItem/TabItem.module.scss index efb10f1f4..bdbb0b66a 100644 --- a/src/components/common/TabCommon/TabItem/TabItem.module.scss +++ b/src/components/common/TabCommon/TabItem/TabItem.module.scss @@ -5,10 +5,16 @@ padding-top: 1.6rem; padding-bottom: 1.6rem; - &.active { - @apply font-bold; - border-bottom: 2px solid var(--primary); + &:hover { + @apply cursor-pointer; } +} + +.tabItemActive { + @apply font-bold; + margin-right: 4.8rem; + padding-top: 1.6rem; + padding-bottom: 1.6rem; &:hover { @apply cursor-pointer; diff --git a/src/components/common/TabCommon/TabItem/TabItem.tsx b/src/components/common/TabCommon/TabItem/TabItem.tsx index 62de3c595..6881c2aca 100644 --- a/src/components/common/TabCommon/TabItem/TabItem.tsx +++ b/src/components/common/TabCommon/TabItem/TabItem.tsx @@ -1,22 +1,19 @@ -import classNames from "classnames"; import React from "react" import s from './TabItem.module.scss' interface TabItemProps { - active: string; + active: boolean; children: string; - onClick: () => void; + onClick: (tabIndex: number, tabPane: string) => void; } -const TabItem = ({ active = "", children, onClick } : TabItemProps) => { +const TabItem = ({ active = false, children, onClick } : TabItemProps) => { return ( - + {children} ) } -export default TabItem; \ No newline at end of file +export default TabItem;