Skip to content

Commit f221123

Browse files
authored
feat(ui5-shellbar): adds logoPress and coPilotPress events (#301)
1 parent 5902704 commit f221123

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

packages/main/src/ShellBar.hbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{/if}}
88

99
{{#unless interactiveLogo}}
10-
<img class="{{classes.logo}}" src="{{ctr.logo}}" />
10+
<img class="{{classes.logo}}" src="{{ctr.logo}}" @click="{{ctr._logoPress}}" />
1111
{{/unless}}
1212

1313
{{#if showArrowDown}}
@@ -96,8 +96,8 @@
9696
</div>
9797

9898
{{#*inline "coPilot"}}
99-
<svg version="1.1" width="44" height="44" viewBox="-150 -150 300 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
100-
style="background-color: transparent;">
99+
<svg @click="{{ctr._coPilotPress}}" version="1.1" width="44" height="44" viewBox="-150 -150 300 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
100+
style="background-color: transparent; cursor: pointer;" class="ui5-shellbar-coPilot">
101101
<defs>
102102
<linearGradient id="grad1" x1="0%" x2="100%" y1="100%" y2="0%">
103103
<stop offset="0%" style="stop-color:#C0D9F2;stop-opacity:0.87"></stop>

packages/main/src/ShellBar.js

+47
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Bootstrap from "@ui5/webcomponents-base/src/Bootstrap";
22
import { getRTL } from "@ui5/webcomponents-base/src/Configuration";
33
import URI from "@ui5/webcomponents-base/src/types/URI";
44
import WebComponent from "@ui5/webcomponents-base/src/WebComponent";
5+
import Function from "@ui5/webcomponents-base/src/types/Function";
56
import { addCustomCSS } from "@ui5/webcomponents-base/src/theming/CustomStyle";
67
import ResizeHandler from "@ui5/webcomponents-base/src/delegate/ResizeHandler";
78
import ItemNavigation from "@ui5/webcomponents-base/src/delegate/ItemNavigation";
@@ -136,6 +137,14 @@ const metadata = {
136137
_header: {
137138
type: Object,
138139
},
140+
141+
_logoPress: {
142+
type: Function,
143+
},
144+
145+
_coPilotPress: {
146+
type: Function,
147+
},
139148
},
140149

141150
slots: /** @lends sap.ui.webcomponents.main.ShellBar.prototype */ {
@@ -231,6 +240,32 @@ const metadata = {
231240
targetRef: { type: HTMLElement },
232241
},
233242
},
243+
244+
/**
245+
* Fired, when the logo is pressed.
246+
*
247+
* @event
248+
* @param {HTMLElement} targetRef dom ref of the clicked element
249+
* @public
250+
*/
251+
logoPress: {
252+
detail: {
253+
targetRef: { type: HTMLElement },
254+
},
255+
},
256+
257+
/**
258+
* Fired, when the co pilot is pressed.
259+
*
260+
* @event
261+
* @param {HTMLElement} targetRef dom ref of the clicked element
262+
* @public
263+
*/
264+
coPilotPress: {
265+
detail: {
266+
targetRef: { type: HTMLElement },
267+
},
268+
},
234269
},
235270
};
236271

@@ -374,6 +409,18 @@ class ShellBar extends WebComponent {
374409
this.shadowRoot.querySelector("ui5-popover").close();
375410
this._overflowActions();
376411
};
412+
413+
this._logoPress = event => {
414+
this.fireEvent("logoPress", {
415+
targetRef: this.shadowRoot.querySelector(".sapWCShellBarLogo"),
416+
});
417+
};
418+
419+
this._coPilotPress = event => {
420+
this.fireEvent("coPilotPress", {
421+
targetRef: this.shadowRoot.querySelector(".ui5-shellbar-coPilot"),
422+
});
423+
};
377424
}
378425

379426
onBeforeRendering() {

packages/main/src/themes-next/ShellBar.css

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ ui5-shellbar {
193193
}
194194

195195
.sapWCShellBarLogo {
196+
cursor: pointer;
196197
height: 1.675rem;
197198
}
198199

packages/main/test/sap/ui/webcomponents/main/pages/ShellBar.html

+8
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@
175175
window["press-input"].value = "Product Switch"
176176
});
177177

178+
shellbar.addEventListener("logoPress", function(event) {
179+
window["press-input"].value = "Logo"
180+
});
181+
182+
shellbar.addEventListener("coPilotPress", function(event) {
183+
window["press-input"].value = "CoPilot"
184+
});
185+
178186
["disc", "call"].forEach(function(id) {
179187
window[id].addEventListener("press", function(event) {
180188
window["press-input"].value = event.target.id;

packages/main/test/specs/ShellBar.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ describe("Component Behaviour", () => {
228228
assert.strictEqual(input.getValue(), "Product Switch", "Input value is set by click event of Product Switch icon");
229229
});
230230

231+
it("tests logoPress event", () => {
232+
const logo = browser.findElementDeep("#shellbar >>> .sapWCShellBarLogo");
233+
const input = browser.findElementDeep("#press-input");
234+
235+
logo.click();
236+
assert.strictEqual(input.getValue(), "Logo", "Input value is set by click event of Logo");
237+
});
238+
239+
it("tests coPilotPress event", () => {
240+
const coPilot = browser.findElementDeep("#shellbar >>> .ui5-shellbar-coPilot");
241+
const input = browser.findElementDeep("#press-input");
242+
243+
coPilot.click();
244+
assert.strictEqual(input.getValue(), "CoPilot", "Input value is set by click event of CoPilot");
245+
});
246+
231247
it("tests if searchfield appears when clicking on search icon", () => {
232248
const searchIcon = browser.findElementDeep("#shellbar >>> .sapWCShellBarSearchIcon");
233249
const searchField = browser.findElementDeep("#shellbar ui5-input");

0 commit comments

Comments
 (0)