Skip to content

feat(ui5-shellbar): branding slot introduced #11320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
28 changes: 27 additions & 1 deletion packages/fiori/cypress/specs/ShellBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ToggleButton from "@ui5/webcomponents/dist/ToggleButton.js";
import ListItemStandard from "@ui5/webcomponents/dist/ListItemStandard.js";
import Avatar from "@ui5/webcomponents/dist/Avatar.js";
import Switch from "@ui5/webcomponents/dist/Switch.js";
import ShellBarBranding from "../../src/ShellBarBranding.js"
import Search from "../../src/Search.js";

const RESIZE_THROTTLE_RATE = 300; // ms
Expand Down Expand Up @@ -392,6 +393,31 @@ describe("Slots", () => {
});
});

describe("Branding slot", () => {
it("Test branding slot priority over logo", () => {
cy.mount(
<ShellBar id="shellbar" primaryTitle="Primary Title">
<img id="mainLogo" slot="logo" src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg" />

<ShellBarBranding href="https://www.w3schools.com" target="_blank" slot="branding">
<img id="brandingLogo" src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg" slot="logo"/>
Branding Comp
</ShellBarBranding>
</ShellBar>
);

cy.get("#shellbar")
.find("#mainLogo")
.should('exist')
.should('not.be.visible');

cy.get("#shellbar")
.find("#brandingLogo")
.should('exist')
.should('be.visible');
});
});

describe("Search field slot", () => {
it("Test search button is not visible when the search field slot is empty", () => {
cy.mount(
Expand Down Expand Up @@ -516,7 +542,7 @@ describe("Events", () => {
.shadow()
.find(".ui5-shellbar-search-button")
.as("searchButton");

cy.get("@searchButton")
.click();

Expand Down
15 changes: 15 additions & 0 deletions packages/fiori/src/ShellBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,17 @@ class ShellBar extends UI5Element {
@slot()
assistant!: Array<IButton>;

/**
* Defines the branding slot.
* The `ui5-shellbar-branding` component is intended to be placed inside this slot.
* Content placed here takes precedence over the `primaryTitle` property and the `logo` content slot.
*
* @since 2.11.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since 2.10.0

* @public
*/
@slot()
branding!: Array<UI5Element>;

/**
* Defines the `ui5-shellbar` additional items.
*
Expand Down Expand Up @@ -1378,6 +1389,10 @@ class ShellBar extends UI5Element {
return !!this.assistant.length;
}

get hasBranding() {
return !!this.branding.length;
}

get hasSearchField() {
return !!this.searchField.length;
}
Expand Down
139 changes: 139 additions & 0 deletions packages/fiori/src/ShellBarBranding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";

import type {
AriaRole,
} from "@ui5/webcomponents-base";

// Template
import ShellBarBrandingTemplate from "./ShellBarBrandingTemplate.js";

// Styles
import shellBarStyles from "./generated/themes/ShellBar.css.js";
import shellBarBrandingCss from "./generated/themes/ShellBarBranding.css.js";

type ShellBarLogoAccessibilityAttributes = {
role?: Extract<AriaRole, "link" | "button">
}

type ShellBarBrandingAccessibilityAttributes = {
logo?: ShellBarLogoAccessibilityAttributes
};

/**
* @class
*
* ### Overview
* The `ui5-shellbar-branding` component is intended to be placed inside the branding slot of the
* `ui5-shellbar` component. Its content has higher priority than the `primaryTitle` property
* and the `logo` slot of `ui5-shellbar`.
*
* @constructor
* @extends UI5Element
* @since 2.11.0
* @public
*/
@customElement({
tag: "ui5-shellbar-branding",
languageAware: true,
renderer: jsxRenderer,
template: ShellBarBrandingTemplate,
styles: [shellBarStyles, shellBarBrandingCss],
})

class ShellBarBranding extends UI5Element {
/**
* Defines the component href.
*
* **Note:** Standard hyperlink behavior is supported.
* @default undefined
* @public
*/
@property()
href?: string;

/**
* Defines the component target.
*
* **Notes:**
*
* - `_self`
* - `_top`
* - `_blank`
* - `_parent`
* - `_search`
*
* **This property must only be used when the `href` property is set.**
* @default undefined
* @public
*/
@property()
target?: string;

/**
* Defines the title for the ui5-shellbar-branding component.
*
* @default undefined
* @public
*/
@slot({ type: HTMLElement, "default": true })
brandingTitle!: Array<HTMLElement>;

/**
* Defines additional accessibility attributes to the component.
*
* The accessibilityAttributes object has the following fields,
* where each field is an object supporting one or more accessibility attributes:
*
* - **logo** - `logo.role`
*
* The accessibility attributes support the following values:
*
* - **role**: Defines the accessible ARIA role of the logo area.
* Accepts the following string values: `link` or `button`.
*
*
* @default {}
* @public
*/
@property({ type: Object })
accessibilityAttributes: ShellBarBrandingAccessibilityAttributes = {};

/**
* Defines the logo of the `ui5-shellbar`.
* For example, you can use `ui5-avatar` or `img` elements as logo.
* @public
*/
@slot({ type: HTMLElement })
logo!: Array<HTMLElement>;

get parsedRef() {
return (this.href && this.href.length > 0) ? this.href : undefined;
}

get _logoAreaText() {
const defaultSlot = this.shadowRoot!.querySelector("slot:not([name])") as HTMLSlotElement;
if (defaultSlot) {
const assignedNodes = defaultSlot.assignedNodes({ flatten: true });
const texts = assignedNodes
.filter(n => n.nodeType === Node.TEXT_NODE)
.map(n => n.textContent?.trim())
.filter(Boolean);
return texts[0];
}
}

get accLogoRole() {
return this.accessibilityAttributes.logo?.role || "link";
}
}

ShellBarBranding.define();

export default ShellBarBranding;
export type {
ShellBarBrandingAccessibilityAttributes,
};
23 changes: 23 additions & 0 deletions packages/fiori/src/ShellBarBrandingTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type ShellBarBranding from "./ShellBarBranding.js";

export default function ShellBarBrandingTemplate(this: ShellBarBranding) {
return (
<a
part="root"
class="ui5-shellbar-branding-root"
href={this.parsedRef}
target={this.target}
role={this.accLogoRole}
tabIndex={0}
aria-label={this._logoAreaText}
>
<slot name="logo"></slot>

<h1 class="ui5-shellbar-title">
<bdi>
<slot></slot>
</bdi>
</h1>
</a>
);
}
31 changes: 22 additions & 9 deletions packages/fiori/src/ShellBarTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export default function ShellBarTemplate(this: ShellBar) {
<div class="ui5-shellbar-overflow-container ui5-shellbar-overflow-container-left">
{this.startButton.length > 0 && <slot name="startButton"></slot>}

{this.hasMenuItems && (
{this.hasBranding && (
<span class="ui5-shellbar-branding">
<slot name="branding"></slot>
</span>
)}

{this.hasMenuItems && !this.hasBranding && (
<>
{!this.showLogoInMenuButton && this.hasLogo && singleLogo.call(this)}
{this.showTitleInMenuButton && <h1 class="ui5-hidden-text">{this.primaryTitle}</h1>}
Expand All @@ -42,23 +48,30 @@ export default function ShellBarTemplate(this: ShellBar) {
)}
<Icon class="ui5-shellbar-menu-button-arrow" name={slimArrowDown} />
</button>
{this.secondaryTitle && !this.isSBreakPoint && (
<div style={{ display: "block" }} class="ui5-shellbar-secondary-title" data-ui5-stable="secondary-title">
{this.secondaryTitle}
</div>
)}
</>
)}
</>
)}

{this.hasMenuItems && (
// The secondary title remains visible when both menu items and the branding slot are present,
// as the branding slot has higher priority and takes precedence in visibility.
<>
{this.secondaryTitle && !this.isSBreakPoint && (
<div style={{ display: "block" }} class="ui5-shellbar-secondary-title" data-ui5-stable="secondary-title">
{this.secondaryTitle}
</div>
)}
</>
)}

{!this.hasMenuItems && (
<>
{this.isSBreakPoint && this.hasLogo && singleLogo.call(this)}
{this.isSBreakPoint && this.hasLogo && !this.hasBranding && singleLogo.call(this)}
{!this.isSBreakPoint && (
<>
{combinedLogo.call(this)}
{this.secondaryTitle && this.primaryTitle && (
{!this.hasBranding && combinedLogo.call(this)}
{this.secondaryTitle && (this.primaryTitle || this.hasBranding) && (
<h2 class="ui5-shellbar-secondary-title" data-ui5-stable="secondary-title">
{this.secondaryTitle}
</h2>
Expand Down
1 change: 1 addition & 0 deletions packages/fiori/src/bundle.esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Search from "./Search.js";
import SearchMessageArea from "./SearchMessageArea.js";
import SearchItem from "./SearchItem.js";
import SearchItemGroup from "./SearchItemGroup.js";
import ShellBarBranding from "./ShellBarBranding.js";
import ShellBarSpacer from "./ShellBarSpacer.js";
import ShellBarItem from "./ShellBarItem.js";
import SideNavigationItem from "./SideNavigationItem.js";
Expand Down
37 changes: 37 additions & 0 deletions packages/fiori/src/themes/ShellBarBranding.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
:host(:not([hidden])) .ui5-shellbar-branding-root {
text-decoration: none;
}

:host(:not([hidden])) {
display: inline;
}

.ui5-shellbar-branding-root {
overflow: hidden;
display: flex;
align-items: center;
padding: .25rem .5rem .25rem .25rem;
box-sizing: border-box;
cursor: pointer;
background: var(--sapButton_Lite_Background);
border: 1px solid var(--sapButton_Lite_BorderColor);
color: var(--sapShell_TextColor);
/* fix cutting of the focus outline */
margin-inline-start: 0.125rem;
}

.ui5-shellbar-branding-root:focus {
outline: var(--_ui5_shellbar_logo_outline);
border-radius: var(--_ui5_shellbar_logo_border_radius);
}

.ui5-shellbar-branding-root:hover {
box-shadow: var(--_ui5_shellbar_button_box_shadow);
border-radius: var(--_ui5_shellbar_logo_border_radius);
}

.ui5-shellbar-branding-root:active:focus {
background: var(--sapShell_Active_Background);
border: 1px solid var(--sapButton_Lite_Active_BorderColor);
color: var(--sapShell_Active_TextColor);
}
34 changes: 32 additions & 2 deletions packages/fiori/test/pages/ShellBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@
<ui5-input slot="searchField" value-state="Negative"></ui5-input>
</ui5-shellbar>

<ui5-shellbar
id="shellBarWithBrandingSlot"
class="shellbar-example"
data-ui5-static-stable="shellbarWithLogoClickStatic"
secondary-title="Brading Component"
show-notifications
show-product-switch
>
<ui5-avatar slot="profile" icon="customer"></ui5-avatar>

<ui5-shellbar-branding id="sbBrandingComp" href="https://sap.github.io/ui5-webcomponents/" target="_blank" slot="branding">
<img src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg" slot="logo"/>
Branding Title
</ui5-shellbar-branding>

<ui5-shellbar-item icon="activities" text="Tasks"></ui5-shellbar-item>
<ui5-shellbar-item icon="thing-type" text="Messages"></ui5-shellbar-item>
<ui5-shellbar-item icon="action-settings" text="Settings"></ui5-shellbar-item>
<ui5-shellbar-item icon="sys-help" text="Help"></ui5-shellbar-item>
<ui5-input slot="searchField" value-state="Negative"></ui5-input>
</ui5-shellbar>

<script>
sbBrandingComp.accessibilityAttributes = {
logo: {
role: "button"
},
};
</script>

<ui5-checkbox id="checkKeepPopoverOpen" text="keep popover open on menu-item click"></ui5-checkbox>
<ui5-shellbar
class="shellbar-example"
Expand Down Expand Up @@ -146,11 +176,11 @@

<img slot="logo" src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg"/>

<ui5-button icon="nav-back" slot="startButton"></ui5-button>
<ui5-button icon="nav-back" slot="startButton"></ui5-button>

<ui5-shellbar-item icon="disconnected" text="Disconnect"></ui5-shellbar-item>
<ui5-shellbar-item icon="incoming-call" text="Incoming Calls"></ui5-shellbar-item>

<ui5-li slot="menuItems" data-key="key1">Application 1</ui5-li>
<ui5-li slot="menuItems" data-key="key2">Application 2</ui5-li>
<ui5-li slot="menuItems" data-key="key3">Application 3</ui5-li>
Expand Down
Loading
Loading