From f781ddbc608cfb6c17db4f128d8ba3035993239b Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 22 Mar 2025 23:51:10 -0500 Subject: [PATCH] Collapse long sidebar sections --- src/components/HeaderList.tsx | 39 +++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/components/HeaderList.tsx b/src/components/HeaderList.tsx index b652538a..3b058f5a 100644 --- a/src/components/HeaderList.tsx +++ b/src/components/HeaderList.tsx @@ -1,6 +1,12 @@ +'use client'; + import { clsx } from 'clsx/lite'; import AnimateItems from './AnimateItems'; -import { ReactNode } from 'react'; +import { ReactNode, useState } from 'react'; +import LoaderButton from './primitives/LoaderButton'; +import { IoChevronDownOutline, IoChevronUpOutline } from 'react-icons/io5'; + +const SIDEBAR_MAX_COLLAPSE_ITEMS = 5; export default function HeaderList({ title, @@ -13,6 +19,10 @@ export default function HeaderList({ icon?: ReactNode, items: ReactNode[] }) { + const [isExpanded, setIsExpanded] = useState(false); + + const hasMoreItems = items.length > SIDEBAR_MAX_COLLAPSE_ITEMS; + return ( ] :[] as ReactNode[] - ).concat(items)} + ) + .concat(items.slice(0, isExpanded + ? items.length + : SIDEBAR_MAX_COLLAPSE_ITEMS)) + .concat(hasMoreItems + ? [ + setIsExpanded(!isExpanded)} + className={clsx( + 'mt-1', + 'text-xs tracking-wide', + 'border-medium rounded-md', + 'px-1.5 h-6!', + 'hover:bg-dim active:bg-main', + )} + > + { + {isExpanded ? 'HIDE' : 'MORE'} + {isExpanded + ? + : } + } + , + ] + : null)} classNameItem="text-dim uppercase" /> );