Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce485bd

Browse files
committedSep 14, 2023
feat(ui5-li, ui5-tree-item): introduce new slot customIcon
1 parent e97e35f commit ce485bd

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed
 

‎packages/main/src/ListItem.ts

+17
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ abstract class ListItem extends ListItemBase {
257257
@slot()
258258
deleteButton!: Array<HTMLElement>;
259259

260+
/**
261+
* Defines the icon, displayed in the beginning or end of the list item.
262+
* If a custom icon is set, it will be rendered in place of the standard icon defined in the <code>icon</code> property.
263+
* <br><br>
264+
* @type {sap.ui.webc.main.IIcon}
265+
* @name sap.ui.webc.main.ListItem.prototype.customIcon
266+
* @since 1.18.0
267+
* @slot
268+
* @public
269+
*/
270+
@slot()
271+
customIcon!: Array<HTMLElement>;
272+
260273
deactivateByKey: (e: KeyboardEvent) => void;
261274
deactivate: () => void;
262275
_ontouchstart: PassiveEventListenerObject;
@@ -498,6 +511,10 @@ abstract class ListItem extends ListItemBase {
498511
return !!this.deleteButton.length;
499512
}
500513

514+
get hasCustomIconSlot() {
515+
return !!this.customIcon.length;
516+
}
517+
501518
get _accessibleNameRef(): string {
502519
if ((this as IAccessibleListItem).accessibleName) {
503520
// accessibleName is set - return labels excluding content

‎packages/main/src/StandardListItem.hbs

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,20 @@
3939

4040
{{#*inline "iconBegin"}}
4141
{{#if displayIconBegin}}
42-
<ui5-icon part="icon" name="{{icon}}" class="ui5-li-icon" accessible-role="presentation" aria-hidden="true"></ui5-icon>
42+
{{#if hasCustomIconSlot}}
43+
<slot name="customIcon"></slot>
44+
{{else}}
45+
<ui5-icon part="icon" name="{{icon}}" class="ui5-li-icon" accessible-role="presentation" aria-hidden="true"></ui5-icon>
46+
{{/if}}
4347
{{/if}}
4448
{{/inline}}
4549

4650
{{#*inline "iconEnd"}}
4751
{{#if displayIconEnd}}
48-
<ui5-icon part="icon" name="{{icon}}" class="ui5-li-icon" accessible-role="presentation" aria-hidden="true"></ui5-icon>
52+
{{#if hasCustomIconSlot}}
53+
<slot name="customIcon"></slot>
54+
{{else}}
55+
<ui5-icon part="icon" name="{{icon}}" class="ui5-li-icon" accessible-role="presentation" aria-hidden="true"></ui5-icon>
56+
{{/if}}
4957
{{/if}}
5058
{{/inline}}

‎packages/main/src/TreeItemBase.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
{{#*inline "imageBegin"}}{{/inline}}
2929

3030
{{#*inline "iconBegin"}}
31-
{{#if icon}}
31+
{{#if hasCustomIconSlot}}
32+
<slot name="customIcon"></slot>
33+
{{else if icon}}
3234
<ui5-icon part="icon" name="{{icon}}" class="ui5-li-icon"></ui5-icon>
3335
{{/if}}
3436
{{/inline}}

‎packages/main/src/themes/ListItem.css

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
object-fit: contain;
172172
}
173173

174+
::slotted([ui5-icon][slot="customIcon"]),
174175
.ui5-li-icon {
175176
min-width: var(--_ui5_list_item_icon_size);
176177
min-height: var(--_ui5_list_item_icon_size);

‎packages/main/src/themes/TreeItem.css

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
min-width: 0;
1010
}
1111

12+
:host([_minimal]) ::slotted([ui5-icon][slot="customIcon"]),
1213
:host([_minimal]) .ui5-li-icon {
1314
padding: 0;
1415
}

‎packages/playground/_stories/main/Tree/Tree.stories.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export const DynamicContent: StoryFn = () => html`
9696
</script>
9797
`;
9898

99-
export const TreeWithCustomItems = Template.bind({});
100-
TreeWithCustomItems.args = {
99+
export const WithCustomItems = Template.bind({});
100+
WithCustomItems.args = {
101101
header: `
102102
<div slot="header">
103103
<ui5-title>Tree with custom items</ui5-title>
@@ -132,3 +132,15 @@ TreeWithCustomItems.args = {
132132
</ui5-tree-item-custom>
133133
</ui5-tree-item-custom>`,
134134
};
135+
136+
137+
export const WithCustomIcon = Template.bind({});
138+
WithCustomIcon.args = {
139+
default: `
140+
<ui5-tree-item text="Tree 1" expanded>
141+
<ui5-icon slot="customIcon" name="paste" accessible-name="Paste" show-tooltip></ui5-icon>
142+
<ui5-tree-item text="Tree 1.2">
143+
<ui5-icon slot="customIcon" name="paste" accessible-name="Paste" show-tooltip></ui5-icon>
144+
</ui5-tree-item>
145+
</ui5-tree-item>`
146+
};

0 commit comments

Comments
 (0)
Please sign in to comment.