1- import { Key , useCallback } from 'react' ;
1+ import { Key , ReactElement , useCallback } from 'react' ;
2+ import ActionGroup from '../ActionGroup' ;
23import { ItemContent } from '../ItemContent' ;
4+ import { ListActionGroupProps } from '../ListActionGroup' ;
35import { Item } from '../shared' ;
46import {
57 getItemKey ,
@@ -10,11 +12,14 @@ import {
1012} from './itemUtils' ;
1113import { wrapIcon , wrapPrimitiveWithText } from './itemWrapperUtils' ;
1214
15+ export type ListActions < T > = ReactElement < ListActionGroupProps < T > > ;
16+
1317export interface UseRenderNormalizedItemOptions {
1418 itemIconSlot : ItemIconSlot ;
1519 showItemDescriptions : boolean ;
1620 showItemIcons : boolean ;
1721 tooltipOptions : TooltipOptions | null ;
22+ actions ?: ListActions < unknown > ;
1823}
1924
2025/**
@@ -24,19 +29,21 @@ export interface UseRenderNormalizedItemOptions {
2429 * @param showItemDescriptions Whether to show item descriptions
2530 * @param showItemIcons Whether to show item icons
2631 * @param tooltipOptions Tooltip options to use when rendering the item
32+ * @param actions Optional actions to render with the item
2733 * @returns Render function for normalized items
2834 */
2935export function useRenderNormalizedItem ( {
3036 itemIconSlot,
3137 showItemDescriptions,
3238 showItemIcons,
3339 tooltipOptions,
40+ actions,
3441} : UseRenderNormalizedItemOptions ) : (
3542 normalizedItem : NormalizedItem
3643) => JSX . Element {
3744 return useCallback (
3845 ( normalizedItem : NormalizedItem ) => {
39- const key = getItemKey ( normalizedItem ) ;
46+ const itemKey = getItemKey ( normalizedItem ) ;
4047 const content = wrapPrimitiveWithText ( normalizedItem . item ?. content ) ;
4148 const textValue = normalizedItem . item ?. textValue ?? '' ;
4249
@@ -57,7 +64,7 @@ export function useRenderNormalizedItem({
5764 // key. We can't really get around setting in order to support Windowed
5865 // data, so we'll need to do some manual conversion of keys to strings
5966 // in other components that use this hook.
60- key = { key as Key }
67+ key = { itemKey as Key }
6168 // The `textValue` prop gets used to provide the content of `<option>`
6269 // elements that back the Spectrum Picker. These are not visible in the UI,
6370 // but are used for accessibility purposes, so we set to an arbitrary
@@ -70,11 +77,19 @@ export function useRenderNormalizedItem({
7077 { icon }
7178 { content }
7279 { description }
80+ { actions ?. props == null ? null : (
81+ < ActionGroup
82+ // eslint-disable-next-line react/jsx-props-no-spreading
83+ { ...actions . props }
84+ onAction = { key => actions . props . onAction ( key , itemKey ) }
85+ onChange = { keys => actions . props . onChange ?.( keys , itemKey ) }
86+ />
87+ ) }
7388 </ ItemContent >
7489 </ Item >
7590 ) ;
7691 } ,
77- [ itemIconSlot , showItemDescriptions , showItemIcons , tooltipOptions ]
92+ [ actions , itemIconSlot , showItemDescriptions , showItemIcons , tooltipOptions ]
7893 ) ;
7994}
8095
0 commit comments