From 07e088e268abcd9fa6922a86d4fea5c5694bf4c7 Mon Sep 17 00:00:00 2001 From: sonnguyenkieio Date: Mon, 6 Sep 2021 14:02:33 +0700 Subject: [PATCH] :sparkles: feat: Tab Common --- .../common/TabCommon/TabCommon.module.scss | 27 ++++++---- src/components/common/TabCommon/TabCommon.tsx | 50 +++++++++++++++---- .../TabCommon/TabItem/TabItem.module.scss | 1 - .../common/TabCommon/TabItem/TabItem.tsx | 9 ++-- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/components/common/TabCommon/TabCommon.module.scss b/src/components/common/TabCommon/TabCommon.module.scss index 9e5fbc1df..f794a841a 100644 --- a/src/components/common/TabCommon/TabCommon.module.scss +++ b/src/components/common/TabCommon/TabCommon.module.scss @@ -1,15 +1,22 @@ @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 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.module.scss b/src/components/common/TabCommon/TabItem/TabItem.module.scss index efb10f1f4..3d3b44604 100644 --- a/src/components/common/TabCommon/TabItem/TabItem.module.scss +++ b/src/components/common/TabCommon/TabItem/TabItem.module.scss @@ -7,7 +7,6 @@ &.active { @apply font-bold; - border-bottom: 2px solid var(--primary); } &:hover { 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}