diff --git a/packages/main/src/ListItem.ts b/packages/main/src/ListItem.ts index 07ab3c52b523..a00352067d88 100644 --- a/packages/main/src/ListItem.ts +++ b/packages/main/src/ListItem.ts @@ -257,6 +257,19 @@ abstract class ListItem extends ListItemBase { @slot() deleteButton!: Array; + /** + * Defines the icon, displayed in the beginning or end of the list item. + * If a custom icon is set, it will be rendered in place of the standard icon defined in the icon property. + *

+ * @type {sap.ui.webc.main.IIcon} + * @name sap.ui.webc.main.ListItem.prototype.customIcon + * @since 1.18.0 + * @slot + * @public + */ + @slot() + customIcon!: Array; + deactivateByKey: (e: KeyboardEvent) => void; deactivate: () => void; _ontouchstart: PassiveEventListenerObject; @@ -498,6 +511,10 @@ abstract class ListItem extends ListItemBase { return !!this.deleteButton.length; } + get hasCustomIconSlot() { + return !!this.customIcon.length; + } + get _accessibleNameRef(): string { if ((this as IAccessibleListItem).accessibleName) { // accessibleName is set - return labels excluding content diff --git a/packages/main/src/StandardListItem.hbs b/packages/main/src/StandardListItem.hbs index bfdc17f5b617..115bc9230f83 100644 --- a/packages/main/src/StandardListItem.hbs +++ b/packages/main/src/StandardListItem.hbs @@ -39,12 +39,20 @@ {{#*inline "iconBegin"}} {{#if displayIconBegin}} - + {{#if hasCustomIconSlot}} + + {{else}} + + {{/if}} {{/if}} {{/inline}} {{#*inline "iconEnd"}} {{#if displayIconEnd}} - + {{#if hasCustomIconSlot}} + + {{else}} + + {{/if}} {{/if}} {{/inline}} diff --git a/packages/main/src/TreeItemBase.hbs b/packages/main/src/TreeItemBase.hbs index 2cf49ca9f39f..1b6c3c2e33f5 100644 --- a/packages/main/src/TreeItemBase.hbs +++ b/packages/main/src/TreeItemBase.hbs @@ -28,7 +28,9 @@ {{#*inline "imageBegin"}}{{/inline}} {{#*inline "iconBegin"}} - {{#if icon}} + {{#if hasCustomIconSlot}} + + {{else if icon}} {{/if}} {{/inline}} diff --git a/packages/main/src/themes/ListItem.css b/packages/main/src/themes/ListItem.css index 8abb23289a39..ed4bc6740c13 100644 --- a/packages/main/src/themes/ListItem.css +++ b/packages/main/src/themes/ListItem.css @@ -171,6 +171,7 @@ object-fit: contain; } +::slotted([ui5-icon][slot="customIcon"]), .ui5-li-icon { min-width: var(--_ui5_list_item_icon_size); min-height: var(--_ui5_list_item_icon_size); diff --git a/packages/main/src/themes/TreeItem.css b/packages/main/src/themes/TreeItem.css index ce80d64033a0..3fa028386753 100644 --- a/packages/main/src/themes/TreeItem.css +++ b/packages/main/src/themes/TreeItem.css @@ -9,6 +9,7 @@ min-width: 0; } +:host([_minimal]) ::slotted([ui5-icon][slot="customIcon"]), :host([_minimal]) .ui5-li-icon { padding: 0; } diff --git a/packages/playground/_stories/main/Tree/Tree.stories.ts b/packages/playground/_stories/main/Tree/Tree.stories.ts index 995ce1a0f52f..4a9c2be693a2 100644 --- a/packages/playground/_stories/main/Tree/Tree.stories.ts +++ b/packages/playground/_stories/main/Tree/Tree.stories.ts @@ -96,8 +96,8 @@ export const DynamicContent: StoryFn = () => html` `; -export const TreeWithCustomItems = Template.bind({}); -TreeWithCustomItems.args = { +export const WithCustomItems = Template.bind({}); +WithCustomItems.args = { header: `
Tree with custom items @@ -132,3 +132,15 @@ TreeWithCustomItems.args = { `, }; + + +export const WithCustomIcon = Template.bind({}); +WithCustomIcon.args = { + default: ` + + + + + + ` +};