Skip to content

Commit c682012

Browse files
authored
Merge branch 'master' into treeview
2 parents ce55f60 + 226f7c9 commit c682012

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/contained-list/contained-list-item.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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
*/

src/contained-list/contained-list.stories.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,54 @@ const withActionsTemplate = () => ({
193193
});
194194
export 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+
196244
const withIconsTemplate = () => ({
197245
template: `
198246
<ng-template #apple let-icon>

0 commit comments

Comments
 (0)