From 90fa8db347820df5bd0af05a82be4e4878a3afcf Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Fri, 29 Nov 2024 09:10:25 +0100 Subject: [PATCH] display hidden chips in tooltip --- src/components/CatalogCard.tsx | 5 +-- src/components/ChipList.tsx | 66 +++++++++++++++------------------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/components/CatalogCard.tsx b/src/components/CatalogCard.tsx index c304f27c..5008783e 100644 --- a/src/components/CatalogCard.tsx +++ b/src/components/CatalogCard.tsx @@ -109,7 +109,7 @@ function CatalogCardRef( {(category || tags?.length > 0) && ( @@ -118,6 +118,7 @@ function CatalogCardRef( size="small" border="none" fillLevel={3} + truncateWidth={70} > {category} @@ -128,7 +129,7 @@ function CatalogCardRef( fillLevel={3} values={tags ?? []} limit={1} - truncateWidth={100} + truncateWidth={70} emptyState={null} /> diff --git a/src/components/ChipList.tsx b/src/components/ChipList.tsx index c877eb90..fe89b8b3 100644 --- a/src/components/ChipList.tsx +++ b/src/components/ChipList.tsx @@ -4,11 +4,9 @@ import { type ComponentProps, type Dispatch, type ReactElement, - useState, + useCallback, } from 'react' -import { HamburgerMenuCollapseIcon } from '../icons' - import Chip, { type ChipProps } from './Chip' type TransformFn = ( @@ -33,7 +31,23 @@ function ChipList({ onClick, ...props }: ChipListProps): ReactElement { - const [collapsed, setCollapsed] = useState(true) + const chip = useCallback( + (v: TValue, i: number) => { + const clickable = onClickCondition?.(v) ?? false + + return ( + clickable && onClick(v)} + {...props} + > + {transformValue ? transformValue(v) : `${v}`} + + ) + }, + [onClick, onClickCondition, props, transformValue] + ) return ( ({ ) : ( There is nothing to display here. ))} - {values.slice(0, collapsed ? limit : undefined).map((v, i) => { - const clickable = onClickCondition?.(v) ?? false - - return ( - clickable && onClick(v)} - {...props} - > - {transformValue ? transformValue(v) : `${v}`} - - ) - })} + {values.slice(0, limit).map(chip)} {values.length > limit && ( - <> - {collapsed && ( - setCollapsed(false)} - {...props} - clickable - > - {`+${values.length - limit}`} - - )} - {!collapsed && ( - setCollapsed(true)} - {...props} - clickable + - - - )} - + {values.slice(limit, values.length).map(chip)} + + } + >{`+${values.length - limit}`} )} )