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 {
3030 </div>
3131 </ng-container>
3232 <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>
3434 </div>
3535 ` ,
3636 changeDetection : ChangeDetectionStrategy . OnPush
@@ -41,6 +41,11 @@ export class ContainedListItem {
4141 */
4242 @Input ( ) action : TemplateRef < any > ;
4343
44+ /**
45+ * Optional interactive element data.
46+ */
47+ @Input ( ) actionData : any ;
48+
4449 /**
4550 * Whether this item is disabled.
4651 */
Original file line number Diff line number Diff line change @@ -193,6 +193,54 @@ const withActionsTemplate = () => ({
193193} ) ;
194194export const withActions = withActionsTemplate . bind ( { } ) ;
195195
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+
196244const withIconsTemplate = ( ) => ( {
197245 template : `
198246 <ng-template #apple let-icon>
You can’t perform that action at this time.
0 commit comments