File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import {
30
30
</div>
31
31
</ng-container>
32
32
<div class="cds--contained-list-item__action" *ngIf="action">
33
- <ng-template [ngTemplateOutlet]="action"></ng-template>
33
+ <ng-template [ngTemplateOutlet]="action" [ngTemplateOutletContext]="{ $implicit: actionData }" ></ng-template>
34
34
</div>
35
35
` ,
36
36
changeDetection : ChangeDetectionStrategy . OnPush
@@ -41,6 +41,11 @@ export class ContainedListItem {
41
41
*/
42
42
@Input ( ) action : TemplateRef < any > ;
43
43
44
+ /**
45
+ * Optional interactive element data.
46
+ */
47
+ @Input ( ) actionData : any ;
48
+
44
49
/**
45
50
* Whether this item is disabled.
46
51
*/
Original file line number Diff line number Diff line change @@ -193,6 +193,54 @@ const withActionsTemplate = () => ({
193
193
} ) ;
194
194
export const withActions = withActionsTemplate . bind ( { } ) ;
195
195
196
+ export const withActionsAndContextData = ( args ) => {
197
+ args = {
198
+ items : [
199
+ {
200
+ id : 1 ,
201
+ label : 'List Item'
202
+ } ,
203
+ {
204
+ id : 2 ,
205
+ label : 'List Item'
206
+ } ,
207
+ {
208
+ id : 3 ,
209
+ label : 'List Item'
210
+ } ,
211
+ {
212
+ id : 4 ,
213
+ label : 'List Item'
214
+ } ,
215
+ ] ,
216
+ onActionClick : ( item : any ) => { alert ( `${ item . label } ${ item . id } action click triggered` ) }
217
+ }
218
+
219
+ return {
220
+ props : args ,
221
+ template : `
222
+ <ng-template #actionWithClick let-actionData>
223
+ <button
224
+ ibmButton="ghost"
225
+ aria-label="Action"
226
+ iconOnly="true"
227
+ (click)="onActionClick(actionData)">
228
+ <svg ibmIcon="add" size="16" class="cds--btn__icon"></svg>
229
+ </button>
230
+ </ng-template>
231
+
232
+ <cds-contained-list label="List title">
233
+ <cds-contained-list-item
234
+ *ngFor="let item of items"
235
+ [action]="actionWithClick"
236
+ [actionData]="item">
237
+ {{ item.label }} {{ item.id }}
238
+ </cds-contained-list-item>
239
+ </cds-contained-list>
240
+ `
241
+ }
242
+ } ;
243
+
196
244
const withIconsTemplate = ( ) => ( {
197
245
template : `
198
246
<ng-template #apple let-icon>
You can’t perform that action at this time.
0 commit comments