Skip to content

Commit 79903f4

Browse files
feat(ui5-product-switch-item): added image slot (#11965)
There is a new `image` slot which can be used instead of the old `icon` property. Also a new entry is added in the `AvatarColorScheme` enum called `Transparent` in order to achieve the target design for the transparent images/SVGs in the ProductSwitchItem with image.
1 parent e6ff0e1 commit 79903f4

File tree

11 files changed

+119
-11
lines changed

11 files changed

+119
-11
lines changed

packages/fiori/cypress/specs/ProductSwitch.cy.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ProductSwitch from "../../src/ProductSwitch.js";
22
import ProductSwitchItem from "../../src/ProductSwitchItem.js";
3+
import Avatar from "../../../main/src/Avatar.js";
34
import type UI5Element from "@ui5/webcomponents-base";
45

56
describe("List - getFocusDomRef Method", () => {
@@ -48,6 +49,26 @@ describe("List - getFocusDomRef Method", () => {
4849
expect(ps.getFocusDomRef()).to.equal(psItem.getFocusDomRef());
4950
});
5051
});
52+
53+
describe("image slot", () => {
54+
it("should render custom content in the image slot and not render the icon", () => {
55+
cy.mount(
56+
<ProductSwitch>
57+
<ProductSwitchItem
58+
titleText="With Avatar"
59+
icon="file"
60+
>
61+
<Avatar slot="image" size="XS" />
62+
</ProductSwitchItem>
63+
</ProductSwitch>
64+
);
65+
66+
cy.get("ui5-product-switch-item").within(() => {
67+
cy.get("ui5-avatar").should("exist");
68+
cy.get("ui5-icon").should("not.exist");
69+
});
70+
});
71+
});
5172
});
5273

5374
describe("ProductSwitch general interaction", () => {

packages/fiori/src/ProductSwitchItem.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
55
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
66
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
77
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
8+
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
89
import ProductSwitchItemTemplate from "./ProductSwitchItemTemplate.js";
910
import type { IProductSwitchItem } from "./ProductSwitch.js";
1011

@@ -134,6 +135,17 @@ class ProductSwitchItem extends UI5Element implements IProductSwitchItem {
134135
@property({ noAttribute: true })
135136
forcedTabIndex?: string;
136137

138+
/**
139+
* Defines an image to be displayed instead of the standard icon.
140+
*
141+
* **Note:** The image slot takes precedence over the icon property.
142+
* **Note:** We recommend using non-interactive ui5-avatar with size S, Square shape and Transparent colorScheme for best alignment.
143+
* @public
144+
* @since 2.14.0
145+
*/
146+
@slot({ type: HTMLElement })
147+
image!: Array<HTMLElement>;
148+
137149
_deactivate: () => void;
138150

139151
constructor() {

packages/fiori/src/ProductSwitchItemTemplate.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ export default function ProductSwitchItemTemplate(this: ProductSwitchItem) {
4141
function item(this: ProductSwitchItem) {
4242
return (
4343
<>
44-
{this.icon &&
44+
{this.image && this.image.length > 0 ? (
45+
<span class="ui5-product-switch-item-image-placeholder">
46+
<slot name="image"></slot>
47+
</span>
48+
) : (
49+
this.icon &&
4550
<Icon
4651
class="ui5-product-switch-item-icon"
4752
name={this.icon}
4853
/>
49-
}
54+
)}
5055

5156
<span class="ui5-product-switch-item-text-content">
5257
{this.titleText &&

packages/fiori/src/themes/ProductSwitchItem.css

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@
5353
outline: none;
5454
box-sizing: border-box;
5555
padding: .5rem;
56-
padding-top: 4rem;
56+
padding-top: .5rem;
5757
cursor: pointer;
5858
border: var(--_ui5_product_switch_item_border);
5959
}
6060

61-
:host([icon]) .ui5-product-switch-item-root {
62-
padding-top: .5rem;
63-
}
64-
6561
:host([selected]) .ui5-product-switch-item-root {
6662
padding: .375rem;
6763
}
@@ -76,6 +72,12 @@
7672
pointer-events: none;
7773
}
7874

75+
.ui5-product-switch-item-root .ui5-product-switch-item-image-placeholder {
76+
width: 3rem;
77+
height: 3rem;
78+
margin-bottom: .5rem;
79+
}
80+
7981
.ui5-product-switch-item-root .ui5-product-switch-item-text-content {
8082
display: flex;
8183
align-items: center;
@@ -126,7 +128,7 @@
126128
flex-direction: row;
127129
}
128130

129-
:host([icon]) .ui5-product-switch-item-root {
131+
.ui5-product-switch-item-root {
130132
padding-top: 0;
131133
}
132134

@@ -136,12 +138,16 @@
136138
margin: 0 .75rem 0 0;
137139
}
138140

141+
.ui5-product-switch-item-root .ui5-product-switch-item-image-placeholder {
142+
margin: 0 .75rem 0 0;
143+
}
144+
139145
.ui5-product-switch-item-root .ui5-product-switch-item-text-content {
140146
align-items: flex-start;
141147
max-width: 100%;
142148
}
143149

144-
:host([icon]) .ui5-product-switch-item-root .ui5-product-switch-item-text-content {
150+
.ui5-product-switch-item-root .ui5-product-switch-item-text-content {
145151
max-width: calc(100% - 3.75rem); /* 100% width - (3rem for the icon + right margin)*/
146152
}
147153

packages/fiori/test/pages/ProductSwitch.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
<body class="productswitch2auto">
2727
<ui5-product-switch id="productSwitchThreeColumn">
28-
<ui5-product-switch-item title-text="Home" subtitle-text="Central Home" icon="home"></ui5-product-switch-item>
28+
<ui5-product-switch-item title-text="Home" subtitle-text="Central Home">
29+
<ui5-avatar slot="image" shape="Square" fallback-icon="employee" color-scheme="Transparent" size="S">
30+
<img alt="Woman" src="https://www.sap.com/dam/application/shared/logos/sap-logo-svg.svg.adapt.svg/1493030643828.svg" />
31+
</ui5-avatar>
32+
</ui5-product-switch-item>
2933
<ui5-product-switch-item title-text="Analytics Cloud" subtitle-text="Analytics Cloud" icon="business-objects-experience"></ui5-product-switch-item>
3034
<ui5-product-switch-item title-text="Catalog" subtitle-text="Ariba" icon="contacts"></ui5-product-switch-item>
3135
<ui5-product-switch-item title-text="Guided Buying" icon="credit-card"></ui5-product-switch-item>

packages/main/src/themes/Avatar.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@
275275
border-color: var(--sapAvatar_Lite_BorderColor);
276276
}
277277

278+
:host([_color-scheme="Transparent"]),
279+
:host([ui5-avatar][color-scheme="Transparent"]) {
280+
background-color: transparent;
281+
border-color: transparent;
282+
}
283+
278284
:host([_has-image]) {
279285
color: var(--ui5-avatar-accent10-color);
280286
border: var(--ui5-avatar-optional-border);

packages/main/src/types/AvatarColorScheme.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ enum AvatarColorScheme {
6363
* @public
6464
*/
6565
Placeholder = "Placeholder",
66+
67+
/**
68+
* @public
69+
*/
70+
Transparent = "Transparent",
6671
}
6772

6873
export default AvatarColorScheme;

packages/website/docs/_components_pages/fiori/ProductSwitch/ProductSwitch.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Basic from "../../../_samples/fiori/ProductSwitch/Basic/Basic.md";
22
import WithShellBar from "../../../_samples/fiori/ProductSwitch/WithShellBar/WithShellBar.md";
3+
import WithImageSlot from "../../../_samples/fiori/ProductSwitch/WithImageSlot/WithImageSlot.md";
34

45
<%COMPONENT_OVERVIEW%>
56

@@ -13,4 +14,8 @@ import WithShellBar from "../../../_samples/fiori/ProductSwitch/WithShellBar/Wit
1314
### ProductSwitch in ShellBar
1415
Press the "grid" on the right-most part of the ShellBar to show the ProductSwitch.
1516

16-
<WithShellBar />
17+
<WithShellBar />
18+
19+
### ProductSwitchItem with "image" slot
20+
21+
<WithImageSlot />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import html from '!!raw-loader!./sample.html';
2+
import js from '!!raw-loader!./main.js';
3+
4+
<Editor html={html} js={js} />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import "@ui5/webcomponents/dist/Avatar.js";
2+
import "@ui5/webcomponents-fiori/dist/ProductSwitch.js";
3+
import "@ui5/webcomponents-fiori/dist/ProductSwitchItem.js";
4+
5+
import "@ui5/webcomponents-icons/dist/home.js";
6+
import "@ui5/webcomponents-icons/dist/business-objects-experience.js";
7+
import "@ui5/webcomponents-icons/dist/contacts.js";
8+
import "@ui5/webcomponents-icons/dist/flight.js";

0 commit comments

Comments
 (0)