parent
377c86d8ad
commit
364c138fac
4 changed files with 66 additions and 49 deletions
@ -1,48 +1,69 @@ |
|||||||
import { cn } from '../../lib/classname'; |
import { cn } from '../../lib/classname'; |
||||||
import { Blocks, BoxSelect, StickyNote, Text } from 'lucide-react'; |
import { |
||||||
|
Blocks, |
||||||
|
BoxSelect, |
||||||
|
type LucideIcon, |
||||||
|
StickyNote, |
||||||
|
Text, |
||||||
|
} from 'lucide-react'; |
||||||
|
|
||||||
export const allowedProjectTabs = ['details', 'solutions'] as const; |
export const allowedProjectTabs = ['details', 'solutions'] as const; |
||||||
export type AllowedProjectTab = (typeof allowedProjectTabs)[number]; |
export type AllowedProjectTab = (typeof allowedProjectTabs)[number]; |
||||||
|
|
||||||
type ProjectTabsProps = { |
type TabButtonProps = { |
||||||
activeTab: AllowedProjectTab; |
text: string; |
||||||
projectId: string; |
icon: LucideIcon; |
||||||
|
smText?: string; |
||||||
|
isActive?: boolean; |
||||||
|
href: string; |
||||||
}; |
}; |
||||||
|
|
||||||
export function ProjectTabs(props: ProjectTabsProps) { |
function TabButton(props: TabButtonProps) { |
||||||
const { activeTab, projectId } = props; |
const { text, icon: ButtonIcon, smText, isActive, href } = props; |
||||||
|
|
||||||
const tabs = [ |
|
||||||
{ name: 'Project Details', value: 'details', icon: Text }, |
|
||||||
{ name: 'Community Solutions', value: 'solutions', icon: Blocks }, |
|
||||||
]; |
|
||||||
|
|
||||||
return ( |
|
||||||
<div className="my-3 flex flex-row flex-wrap items-center gap-1.5 rounded-md border bg-white px-2.5 text-sm"> |
|
||||||
{tabs.map((tab) => { |
|
||||||
const isActive = tab.value === activeTab; |
|
||||||
|
|
||||||
return ( |
return ( |
||||||
<a |
<a |
||||||
key={tab.value} |
href={href} |
||||||
href={ |
|
||||||
tab.value === 'details' |
|
||||||
? `/projects/${projectId}` |
|
||||||
: `/projects/${projectId}/${tab.value}` |
|
||||||
} |
|
||||||
className={cn('relative flex items-center gap-1 p-2', { |
className={cn('relative flex items-center gap-1 p-2', { |
||||||
'text-black': isActive, |
'text-black': isActive, |
||||||
'opacity-40 hover:opacity-90': !isActive, |
'opacity-40 hover:opacity-90': !isActive, |
||||||
})} |
})} |
||||||
> |
> |
||||||
{tab.icon && <tab.icon className="mr-1 inline-block h-4 w-4" />} |
{ButtonIcon && <ButtonIcon className="mr-1 inline-block h-4 w-4" />} |
||||||
{tab.name} |
<span className="hidden sm:inline">{text}</span> |
||||||
|
{smText && <span className="sm:hidden">{smText}</span>} |
||||||
|
|
||||||
{isActive && ( |
{isActive && ( |
||||||
<span className="absolute bottom-0 left-0 right-0 h-0.5 translate-y-1/2 bg-black"></span> |
<span className="absolute bottom-0 left-0 right-0 h-0.5 translate-y-1/2 bg-black rounded-t-md"></span> |
||||||
)} |
)} |
||||||
</a> |
</a> |
||||||
); |
); |
||||||
})} |
} |
||||||
|
|
||||||
|
type ProjectTabsProps = { |
||||||
|
activeTab: AllowedProjectTab; |
||||||
|
projectId: string; |
||||||
|
}; |
||||||
|
|
||||||
|
export function ProjectTabs(props: ProjectTabsProps) { |
||||||
|
const { activeTab, projectId } = props; |
||||||
|
|
||||||
|
return ( |
||||||
|
<div className="my-3 flex flex-row flex-wrap items-center gap-1.5 rounded-md border bg-white px-2.5 text-sm"> |
||||||
|
<TabButton |
||||||
|
text={'Project Detail'} |
||||||
|
icon={Text} |
||||||
|
smText={'Details'} |
||||||
|
isActive={activeTab === 'details'} |
||||||
|
href={`/projects/${projectId}`} |
||||||
|
/> |
||||||
|
<TabButton |
||||||
|
text={'Community Solutions'} |
||||||
|
icon={Blocks} |
||||||
|
smText={'Solutions'} |
||||||
|
isActive={activeTab === 'solutions'} |
||||||
|
href={`/projects/${projectId}/solutions`} |
||||||
|
/> |
||||||
</div> |
</div> |
||||||
); |
); |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue