mirror of
https://github.com/vercel/commerce.git
synced 2025-07-21 11:51:20 +00:00
Merge branch 'm4-sonnguyen' of github.com:KieIO/grocery-vercel-commerce into m5-datnguyen
This commit is contained in:
commit
aec9872bba
@ -1,15 +1,21 @@
|
|||||||
@import '../../../styles/utilities';
|
@import '../../../styles/utilities';
|
||||||
|
|
||||||
.tabCommonOutSide {
|
.tabCommon {
|
||||||
@apply spacing-horizontal;
|
@apply flex;
|
||||||
|
position: relative;
|
||||||
.tabCommon {
|
border-bottom: 2px solid #FBFBFB;
|
||||||
@apply flex;
|
padding-top: 1.6rem;
|
||||||
position: relative;
|
padding-bottom: 1.6rem;
|
||||||
border-bottom: 2px solid #FBFBFB;
|
width: 100%;
|
||||||
padding-top: 1.6rem;
|
|
||||||
padding-bottom: 1.6rem;
|
.slider {
|
||||||
width: 100%;
|
@apply inline-block;
|
||||||
|
height: .2rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: var(--primary);
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1200;
|
||||||
|
bottom: 0;
|
||||||
|
transition: all .4s linear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 s from './TabCommon.module.scss'
|
||||||
|
|
||||||
import TabItem from './TabItem/TabItem'
|
import TabItem from './TabItem/TabItem'
|
||||||
|
|
||||||
interface TabCommonProps {
|
interface TabCommonProps {
|
||||||
changeTab: (target:string) => void;
|
tabs: {ref:RefObject<HTMLLIElement>, tabName: string, active: boolean, onClick: (tabIndex: number, tabPane?: string) => void}[];
|
||||||
|
defaultActiveTab: number;
|
||||||
|
sliderRef : RefObject<HTMLDivElement>;
|
||||||
|
slideToTab: (ref: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TabCommon = ({ changeTab } : TabCommonProps) => {
|
const TabCommon = ({ tabs, defaultActiveTab, sliderRef, slideToTab } : TabCommonProps) => {
|
||||||
const active = "active", unActive = "";
|
|
||||||
const [item1Active, setItem1Active] = useState(active);
|
|
||||||
const [item2Active, setItem2Active] = useState(unActive);
|
|
||||||
const [item3Active, setItem3Active] = useState(unActive);
|
|
||||||
|
|
||||||
const item1 = useRef<HTMLLIElement>(null);
|
|
||||||
const item2 = useRef<HTMLLIElement>(null);
|
|
||||||
const item3 = useRef<HTMLLIElement>(null);
|
|
||||||
const slider = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
function slide(ref: RefObject<HTMLLIElement>) {
|
|
||||||
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(() => {
|
useEffect(() => {
|
||||||
slide(item1);
|
slideToTab(tabs[defaultActiveTab].ref);
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className={s.tabCommon}>
|
<ul className={s.tabCommon}>
|
||||||
<li ref={item1}>
|
{
|
||||||
<TabItem onClick={toggleItem1} active={item1Active}>Wait for Comfirmation</TabItem>
|
tabs.map((tab) => {
|
||||||
</li>
|
return (
|
||||||
<li ref={item2}>
|
<li key={tab.tabName} ref={tab.ref}>
|
||||||
<TabItem onClick={toggleItem2} active={item2Active}>Delivering</TabItem>
|
<TabItem onClick={tab.onClick} active={tab.active}>{tab.tabName}</TabItem>
|
||||||
</li>
|
</li>
|
||||||
<li ref={item3}>
|
)
|
||||||
<TabItem onClick={toggleItem3} active={item3Active}>Delivered</TabItem>
|
})
|
||||||
</li>
|
}
|
||||||
<div ref={slider} className={s.slider}></div>
|
|
||||||
|
<div ref={sliderRef} className={s.slider}></div>
|
||||||
</ul>
|
</ul>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TabCommon;
|
export default TabCommon;
|
||||||
|
@ -5,10 +5,16 @@
|
|||||||
padding-top: 1.6rem;
|
padding-top: 1.6rem;
|
||||||
padding-bottom: 1.6rem;
|
padding-bottom: 1.6rem;
|
||||||
|
|
||||||
&.active {
|
&:hover {
|
||||||
@apply font-bold;
|
@apply cursor-pointer;
|
||||||
border-bottom: 2px solid var(--primary);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabItemActive {
|
||||||
|
@apply font-bold;
|
||||||
|
margin-right: 4.8rem;
|
||||||
|
padding-top: 1.6rem;
|
||||||
|
padding-bottom: 1.6rem;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
@apply cursor-pointer;
|
@apply cursor-pointer;
|
||||||
|
@ -1,22 +1,19 @@
|
|||||||
import classNames from "classnames";
|
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import s from './TabItem.module.scss'
|
import s from './TabItem.module.scss'
|
||||||
|
|
||||||
interface TabItemProps {
|
interface TabItemProps {
|
||||||
active: string;
|
active: boolean;
|
||||||
children: string;
|
children: string;
|
||||||
onClick: () => void;
|
onClick: (tabIndex: number, tabPane: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TabItem = ({ active = "", children, onClick } : TabItemProps) => {
|
const TabItem = ({ active = false, children, onClick } : TabItemProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span onClick={onClick} className={classNames(s.tabItem, {
|
<span onClick={onClick} className={active ? s.tabItemActive : s.tabItem} >
|
||||||
[s[active]]: active
|
|
||||||
})}>
|
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TabItem;
|
export default TabItem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user