refactor: TabContainer

This commit is contained in:
Mahyar Khanbolooki
2025-07-21 15:56:22 +03:30
parent d2572d5c99
commit a0b52e7945
3 changed files with 45 additions and 26 deletions
+1 -3
View File
@@ -196,9 +196,7 @@ function AboutPage({ data }: Readonly<{ data: AboutDataModel; }>) {
return (
<div>
<TabContainer
className='h-[72px] !pt-3 !pb-2 overflow-y-hidden'>
<TabContainer>
<TabHeader
viewRenderer={firstTab()}
title='درباره ما' icon={<InfoCircle size={24} />}>
+1 -3
View File
@@ -157,9 +157,7 @@ function OrdersIndex() {
return (
<div>
<TabContainer
className='h-[72px] !pt-3 !pb-2 overflow-y-hidden'>
<TabContainer>
<TabHeader
viewRenderer={<PerformantTabRenderer rowHeight={310}>{firstTab()}</PerformantTabRenderer>}
title={categories[0].title} imageSrc={categories[0].image}>
+43 -20
View File
@@ -10,9 +10,38 @@ import Image from 'next/image';
type Props = {
itemRenderer?: (child: ReactNode, index: number) => ReactElement;
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);
@@ -26,18 +55,9 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
);
return (
<div className='h-full'>
<div className={className.wrapper}>
<HorizontalScrollView
style={{
width: '100%',
backgroundColor: '#FFFFFF70',
justifyContent: 'center',
border: '2px solid white',
borderRadius: '32px',
display: 'inline-flex',
justifyItems: 'center',
gap: '40px'
}}
className={className.scrollView}
itemRenderer={itemRenderer}
{...restProps}>
{items.map((item, index) => {
@@ -45,7 +65,10 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
return (
<TabHeaderRenderer
key={index}
className={''}
className={clsx(
className.header,
index === selectedTab ? className.headerActive : className.headerDeactive
)}
onClick={() => updateTab(index)}
>
{imageSrc &&
@@ -59,18 +82,18 @@ function TabContainer({ itemRenderer, children, ...restProps }: Props) {
}
{icon &&
<span className={clsx(
'text-xs transition-all duration-150',
index === selectedTab ? 'stroke-black' : 'stroke-disabled-text'
className.icon,
index === selectedTab ? className.iconActive : className.iconDeactive
)}>
{icon}
</span>
}
<span className={clsx(
'text-xs transition-all duration-150',
index === selectedTab ? 'text-black' : 'text-disabled-text'
<h6 className={clsx(
className.title,
index === selectedTab ? className.titleActive : className.titleDeactive
)}>
{title}
</span>
</h6>
</TabHeaderRenderer>
)
})}