Skip to content

Commit

Permalink
display hidden chips in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Nov 29, 2024
1 parent 04af5d4 commit 90fa8db
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/components/CatalogCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function CatalogCardRef(
{(category || tags?.length > 0) && (
<Flex
alignItems="start"
gap="large"
gap="small"
justifyContent={category ? 'space-between' : 'end'}
marginTop={theme.spacing.medium}
>
Expand All @@ -118,6 +118,7 @@ function CatalogCardRef(
size="small"
border="none"
fillLevel={3}
truncateWidth={70}
>
{category}
</Chip>
Expand All @@ -128,7 +129,7 @@ function CatalogCardRef(
fillLevel={3}
values={tags ?? []}
limit={1}
truncateWidth={100}
truncateWidth={70}
emptyState={null}
/>
</Flex>
Expand Down
66 changes: 29 additions & 37 deletions src/components/ChipList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TValue> = (
Expand All @@ -33,7 +31,23 @@ function ChipList<TValue = string>({
onClick,
...props
}: ChipListProps<TValue>): ReactElement {
const [collapsed, setCollapsed] = useState(true)
const chip = useCallback(
(v: TValue, i: number) => {
const clickable = onClickCondition?.(v) ?? false

return (
<Chip
key={(v as any).key || i}
clickable={clickable}
onClick={() => clickable && onClick(v)}
{...props}
>
{transformValue ? transformValue(v) : `${v}`}
</Chip>
)
},
[onClick, onClickCondition, props, transformValue]
)

return (
<Flex
Expand All @@ -46,41 +60,19 @@ function ChipList<TValue = string>({
) : (
<Span body2>There is nothing to display here.</Span>
))}
{values.slice(0, collapsed ? limit : undefined).map((v, i) => {
const clickable = onClickCondition?.(v) ?? false

return (
<Chip
key={(v as any).key || i}
clickable={clickable}
onClick={() => clickable && onClick(v)}
{...props}
>
{transformValue ? transformValue(v) : `${v}`}
</Chip>
)
})}
{values.slice(0, limit).map(chip)}
{values.length > limit && (
<>
{collapsed && (
<Chip
onClick={() => setCollapsed(false)}
{...props}
clickable
>
{`+${values.length - limit}`}
</Chip>
)}
{!collapsed && (
<Chip
onClick={() => setCollapsed(true)}
{...props}
clickable
<Chip
{...props}
tooltip={
<Flex
gap="xsmall"
wrap="wrap"
>
<HamburgerMenuCollapseIcon />
</Chip>
)}
</>
{values.slice(limit, values.length).map(chip)}
</Flex>
}
>{`+${values.length - limit}`}</Chip>
)}
</Flex>
)
Expand Down

0 comments on commit 90fa8db

Please sign in to comment.