From d3b43eaaa989a57e81a3206f0cd6d959b3513007 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Fri, 15 Mar 2024 12:41:58 +0100 Subject: [PATCH] feat: Allow overriding chip list empty state (#577) --- src/components/ChipList.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/ChipList.tsx b/src/components/ChipList.tsx index 6297bcf1..cfe9aa89 100644 --- a/src/components/ChipList.tsx +++ b/src/components/ChipList.tsx @@ -1,4 +1,5 @@ import { Flex, Span } from 'honorable' +import isEmpty from 'lodash-es/isEmpty' import { type ComponentProps, type ReactElement, useState } from 'react' import { HamburgerMenuCollapseIcon } from '../icons' @@ -13,12 +14,14 @@ export type ChipListProps = { values: TValue[] transformValue?: TransformFn limit: number + emptyState?: JSX.Element } & ChipProps function ChipList({ values = [], transformValue, limit = 4, + emptyState, ...props }: ChipListProps): ReactElement { const [collapsed, setCollapsed] = useState(true) @@ -28,9 +31,12 @@ function ChipList({ gap="xsmall" wrap > - {values.length === 0 && ( - There is nothing to display here. - )} + {isEmpty(values) && + (emptyState !== undefined ? ( + emptyState + ) : ( + There is nothing to display here. + ))} {values.slice(0, collapsed ? limit : undefined).map((v, i) => (