Add collapse expand of groups

pull/8189/head
Kamran Ahmed 3 months ago
parent 1d3a785027
commit 71c4a7d072
  1. 19
      src/components/HeroSection/HeroItemsGroup.tsx
  2. 5
      src/components/HeroSection/HeroTitle.tsx

@ -1,4 +1,4 @@
import type { ReactNode } from 'react'; import { useEffect, useState, type ReactNode } from 'react';
import { cn } from '../../lib/classname'; import { cn } from '../../lib/classname';
import { HeroTitle } from './HeroTitle'; import { HeroTitle } from './HeroTitle';
@ -23,15 +23,19 @@ export function HeroItemsGroup(props: HeroItemsGroupProps) {
className, className,
} = props; } = props;
const isCollapsed = isAllCollapsed || isLoading; const [isCollapsed, setIsCollapsed] = useState(isLoading || isAllCollapsed);
useEffect(() => {
setIsCollapsed(isAllCollapsed || isLoading);
}, [isAllCollapsed, isLoading]);
return ( return (
<div <div
className={cn( className={cn(
'', 'transition-all',
{ {
'border-b border-b-slate-800/70 pb-5 pt-5': !isCollapsed, 'pb-2 pt-5': !isCollapsed,
'py-2': isCollapsed, 'py-1': isCollapsed,
}, },
className, className,
)} )}
@ -41,8 +45,11 @@ export function HeroItemsGroup(props: HeroItemsGroupProps) {
icon={icon} icon={icon}
isLoading={isLoading} isLoading={isLoading}
title={title} title={title}
rightContent={!isCollapsed && rightContent} rightContent={rightContent}
isCollapsed={isCollapsed} isCollapsed={isCollapsed}
onToggleCollapse={() => {
setIsCollapsed(!isCollapsed);
}}
/> />
{!isCollapsed && ( {!isCollapsed && (
<div className="mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2 md:grid-cols-3"> <div className="mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2 md:grid-cols-3">

@ -9,6 +9,7 @@ type HeroTitleProps = {
title: string | ReactNode; title: string | ReactNode;
rightContent?: ReactNode; rightContent?: ReactNode;
isCollapsed?: boolean; isCollapsed?: boolean;
onToggleCollapse?: () => void;
}; };
export function HeroTitle(props: HeroTitleProps) { export function HeroTitle(props: HeroTitleProps) {
@ -18,6 +19,7 @@ export function HeroTitle(props: HeroTitleProps) {
icon, icon,
rightContent, rightContent,
isCollapsed = false, isCollapsed = false,
onToggleCollapse,
} = props; } = props;
return ( return (
@ -32,6 +34,7 @@ export function HeroTitle(props: HeroTitleProps) {
{title} {title}
{!isLoading && ( {!isLoading && (
<button <button
onClick={onToggleCollapse}
className={cn( className={cn(
'ml-2 inline-flex items-center gap-1 rounded-md bg-slate-800 py-0.5 pl-1 pr-1.5 text-xs uppercase tracking-wider text-slate-400 hover:bg-slate-700', 'ml-2 inline-flex items-center gap-1 rounded-md bg-slate-800 py-0.5 pl-1 pr-1.5 text-xs uppercase tracking-wider text-slate-400 hover:bg-slate-700',
{ {
@ -53,7 +56,7 @@ export function HeroTitle(props: HeroTitleProps) {
</button> </button>
)} )}
</p> </p>
<div>{rightContent}</div> <div>{isCollapsed && rightContent}</div>
</div> </div>
); );
} }

Loading…
Cancel
Save