@@ -2,7 +2,7 @@ import { RenderResult } from '@dojo/framework/core/interfaces';
2
2
import { focus } from '@dojo/framework/core/middleware/focus' ;
3
3
import { createICacheMiddleware } from '@dojo/framework/core/middleware/icache' ;
4
4
import { create , tsx } from '@dojo/framework/core/vdom' ;
5
- import { Keys } from '../common/util' ;
5
+ import { Keys , isRenderResult } from '../common/util' ;
6
6
import theme , { ThemeProperties } from '../middleware/theme' ;
7
7
import offscreen from '../middleware/offscreen' ;
8
8
import * as listItemCss from '../theme/default/list-item.m.css' ;
@@ -104,7 +104,18 @@ export interface ListItemProperties {
104
104
collapsed ?: boolean ;
105
105
}
106
106
107
- const listItemFactory = create ( { theme } ) . properties < ListItemProperties > ( ) ;
107
+ export interface ListItemChildren {
108
+ /** Icon or avatar to place before the primary content */
109
+ leading ?: RenderResult ;
110
+ /** The main content of the item, typically text */
111
+ primary ?: RenderResult ;
112
+ /** Icon or text to place after the primary content */
113
+ trailing ?: RenderResult ;
114
+ }
115
+
116
+ const listItemFactory = create ( { theme } )
117
+ . properties < ListItemProperties > ( )
118
+ . children < ListItemChildren | RenderResult | RenderResult [ ] > ( ) ;
108
119
109
120
export const ListItem = listItemFactory ( function ListItem ( {
110
121
properties,
@@ -141,6 +152,11 @@ export const ListItem = listItemFactory(function ListItem({
141
152
! disabled && ! active && onRequestActive ( ) ;
142
153
}
143
154
155
+ const [ firstChild , ...otherChildren ] = children ( ) ;
156
+ const { leading = undefined , primary, trailing = undefined } = isRenderResult ( firstChild )
157
+ ? { primary : [ firstChild , ...otherChildren ] }
158
+ : firstChild ;
159
+
144
160
return (
145
161
< div
146
162
id = { widgetId }
@@ -176,8 +192,10 @@ export const ListItem = listItemFactory(function ListItem({
176
192
ondrop = { onDrop }
177
193
styles = { { visibility : dragged ? 'hidden' : undefined } }
178
194
>
179
- { children ( ) }
180
- { draggable && (
195
+ { leading ? < span classes = { themedCss . leading } > { leading } </ span > : undefined }
196
+ < span classes = { themedCss . primary } > { primary } </ span >
197
+ { trailing ? < span classes = { themedCss . trailing } > { trailing } </ span > : undefined }
198
+ { draggable && ! trailing && (
181
199
< Icon
182
200
type = "barsIcon"
183
201
classes = { { '@dojo/widgets/icon' : { icon : [ themedCss . dragIcon ] } } }
0 commit comments