refactor: TabContainer
This commit is contained in:
@@ -196,9 +196,7 @@ function AboutPage({ data }: Readonly<{ data: AboutDataModel; }>) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TabContainer
|
<TabContainer>
|
||||||
|
|
||||||
className='h-[72px] !pt-3 !pb-2 overflow-y-hidden'>
|
|
||||||
<TabHeader
|
<TabHeader
|
||||||
viewRenderer={firstTab()}
|
viewRenderer={firstTab()}
|
||||||
title='درباره ما' icon={<InfoCircle size={24} />}>
|
title='درباره ما' icon={<InfoCircle size={24} />}>
|
||||||
|
|||||||
@@ -157,9 +157,7 @@ function OrdersIndex() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TabContainer
|
<TabContainer>
|
||||||
|
|
||||||
className='h-[72px] !pt-3 !pb-2 overflow-y-hidden'>
|
|
||||||
<TabHeader
|
<TabHeader
|
||||||
viewRenderer={<PerformantTabRenderer rowHeight={310}>{firstTab()}</PerformantTabRenderer>}
|
viewRenderer={<PerformantTabRenderer rowHeight={310}>{firstTab()}</PerformantTabRenderer>}
|
||||||
title={categories[0].title} imageSrc={categories[0].image}>
|
title={categories[0].title} imageSrc={categories[0].image}>
|
||||||
|
|||||||
@@ -10,9 +10,38 @@ import Image from 'next/image';
|
|||||||
type Props = {
|
type Props = {
|
||||||
itemRenderer?: (child: ReactNode, index: number) => ReactElement;
|
itemRenderer?: (child: ReactNode, index: number) => ReactElement;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
} & React.OlHTMLAttributes<HTMLUListElement>;
|
className?: TabContainerClassName;
|
||||||
|
} & Omit<React.OlHTMLAttributes<HTMLUListElement>, 'className'>;
|
||||||
|
|
||||||
function TabContainer({ itemRenderer, children, ...restProps }: Props) {
|
export type TabContainerClassName = {
|
||||||
|
wrapper?: string;
|
||||||
|
scrollView?: string;
|
||||||
|
header?: string;
|
||||||
|
headerDeactive?: string;
|
||||||
|
headerActive?: string;
|
||||||
|
icon?: string;
|
||||||
|
iconDeactive?: string;
|
||||||
|
iconActive?: string;
|
||||||
|
title?: string;
|
||||||
|
titleDeactive?: string;
|
||||||
|
titleActive?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TabContainerClassNames: TabContainerClassName = {
|
||||||
|
wrapper: 'h-full',
|
||||||
|
scrollView: 'h-[72px] !pt-3 !pb-2 w-full overflow-y-hidden bg-[#FFFFFF70] justify-center border border-2 border-solid border-white rounded-[32px] inline-flex items-center gap-10',
|
||||||
|
header: '',
|
||||||
|
headerDeactive: '',
|
||||||
|
headerActive: '',
|
||||||
|
icon: 'text-xs transition-all duration-150',
|
||||||
|
iconDeactive: 'stroke-disabled-text',
|
||||||
|
iconActive: 'stroke-black',
|
||||||
|
title: 'text-xs transition-all duration-150',
|
||||||
|
titleDeactive: 'text-disabled-text',
|
||||||
|
titleActive: 'text-black'
|
||||||
|
}
|
||||||
|
|
||||||
|
function TabContainer({ className = TabContainerClassNames, itemRenderer, children, ...restProps }: Props) {
|
||||||
|
|
||||||
const [selectedTab, setSelectedTab] = useState(0);
|
const [selectedTab, setSelectedTab] = useState(0);
|
||||||
|
|
||||||
@@ -26,18 +55,9 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='h-full'>
|
<div className={className.wrapper}>
|
||||||
<HorizontalScrollView
|
<HorizontalScrollView
|
||||||
style={{
|
className={className.scrollView}
|
||||||
width: '100%',
|
|
||||||
backgroundColor: '#FFFFFF70',
|
|
||||||
justifyContent: 'center',
|
|
||||||
border: '2px solid white',
|
|
||||||
borderRadius: '32px',
|
|
||||||
display: 'inline-flex',
|
|
||||||
justifyItems: 'center',
|
|
||||||
gap: '40px'
|
|
||||||
}}
|
|
||||||
itemRenderer={itemRenderer}
|
itemRenderer={itemRenderer}
|
||||||
{...restProps}>
|
{...restProps}>
|
||||||
{items.map((item, index) => {
|
{items.map((item, index) => {
|
||||||
@@ -45,7 +65,10 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
|
|||||||
return (
|
return (
|
||||||
<TabHeaderRenderer
|
<TabHeaderRenderer
|
||||||
key={index}
|
key={index}
|
||||||
className={''}
|
className={clsx(
|
||||||
|
className.header,
|
||||||
|
index === selectedTab ? className.headerActive : className.headerDeactive
|
||||||
|
)}
|
||||||
onClick={() => updateTab(index)}
|
onClick={() => updateTab(index)}
|
||||||
>
|
>
|
||||||
{imageSrc &&
|
{imageSrc &&
|
||||||
@@ -59,18 +82,18 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
|
|||||||
}
|
}
|
||||||
{icon &&
|
{icon &&
|
||||||
<span className={clsx(
|
<span className={clsx(
|
||||||
'text-xs transition-all duration-150',
|
className.icon,
|
||||||
index === selectedTab ? 'stroke-black' : 'stroke-disabled-text'
|
index === selectedTab ? className.iconActive : className.iconDeactive
|
||||||
)}>
|
)}>
|
||||||
{icon}
|
{icon}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
<span className={clsx(
|
<h6 className={clsx(
|
||||||
'text-xs transition-all duration-150',
|
className.title,
|
||||||
index === selectedTab ? 'text-black' : 'text-disabled-text'
|
index === selectedTab ? className.titleActive : className.titleDeactive
|
||||||
)}>
|
)}>
|
||||||
{title}
|
{title}
|
||||||
</span>
|
</h6>
|
||||||
</TabHeaderRenderer>
|
</TabHeaderRenderer>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user