11import { Flex , Span } from 'honorable'
22import isEmpty from 'lodash-es/isEmpty'
3- import { type ComponentProps , type ReactElement , useState } from 'react'
3+ import {
4+ type ComponentProps ,
5+ type Dispatch ,
6+ type ReactElement ,
7+ useState ,
8+ } from 'react'
49
510import { HamburgerMenuCollapseIcon } from '../icons'
611
@@ -15,13 +20,17 @@ export type ChipListProps<TValue> = {
1520 transformValue ?: TransformFn < TValue >
1621 limit : number
1722 emptyState ?: JSX . Element | null
23+ onClickCondition ?: ( value : TValue ) => boolean
24+ onClick ?: Dispatch < TValue >
1825} & ChipProps
1926
2027function ChipList < TValue = string > ( {
2128 values = [ ] ,
2229 transformValue,
2330 limit = 4 ,
2431 emptyState,
32+ onClickCondition,
33+ onClick,
2534 ...props
2635} : ChipListProps < TValue > ) : ReactElement {
2736 const [ collapsed , setCollapsed ] = useState ( true )
@@ -37,14 +46,20 @@ function ChipList<TValue = string>({
3746 ) : (
3847 < Span body2 > There is nothing to display here.</ Span >
3948 ) ) }
40- { values . slice ( 0 , collapsed ? limit : undefined ) . map ( ( v , i ) => (
41- < Chip
42- key = { ( v as any ) . key || i }
43- { ...props }
44- >
45- { transformValue ? transformValue ( v ) : `${ v } ` }
46- </ Chip >
47- ) ) }
49+ { values . slice ( 0 , collapsed ? limit : undefined ) . map ( ( v , i ) => {
50+ const clickable = onClickCondition ?.( v ) ?? false
51+
52+ return (
53+ < Chip
54+ key = { ( v as any ) . key || i }
55+ clickable = { clickable }
56+ onClick = { ( ) => clickable && onClick ( v ) }
57+ { ...props }
58+ >
59+ { transformValue ? transformValue ( v ) : `${ v } ` }
60+ </ Chip >
61+ )
62+ } ) }
4863 { values . length > limit && (
4964 < >
5065 { collapsed && (
0 commit comments