Skip to content

Commit

Permalink
feat(ui5-shellbar): adds logoPress and coPilotPress events (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
MapTo0 committed Apr 8, 2019
1 parent 5902704 commit f221123
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/main/src/ShellBar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{/if}}

{{#unless interactiveLogo}}
<img class="{{classes.logo}}" src="{{ctr.logo}}" />
<img class="{{classes.logo}}" src="{{ctr.logo}}" @click="{{ctr._logoPress}}" />
{{/unless}}

{{#if showArrowDown}}
Expand Down Expand Up @@ -96,8 +96,8 @@
</div>

{{#*inline "coPilot"}}
<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"
style="background-color: transparent;">
<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"
style="background-color: transparent; cursor: pointer;" class="ui5-shellbar-coPilot">
<defs>
<linearGradient id="grad1" x1="0%" x2="100%" y1="100%" y2="0%">
<stop offset="0%" style="stop-color:#C0D9F2;stop-opacity:0.87"></stop>
Expand Down
47 changes: 47 additions & 0 deletions packages/main/src/ShellBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Bootstrap from "@ui5/webcomponents-base/src/Bootstrap";
import { getRTL } from "@ui5/webcomponents-base/src/Configuration";
import URI from "@ui5/webcomponents-base/src/types/URI";
import WebComponent from "@ui5/webcomponents-base/src/WebComponent";
import Function from "@ui5/webcomponents-base/src/types/Function";
import { addCustomCSS } from "@ui5/webcomponents-base/src/theming/CustomStyle";
import ResizeHandler from "@ui5/webcomponents-base/src/delegate/ResizeHandler";
import ItemNavigation from "@ui5/webcomponents-base/src/delegate/ItemNavigation";
Expand Down Expand Up @@ -136,6 +137,14 @@ const metadata = {
_header: {
type: Object,
},

_logoPress: {
type: Function,
},

_coPilotPress: {
type: Function,
},
},

slots: /** @lends sap.ui.webcomponents.main.ShellBar.prototype */ {
Expand Down Expand Up @@ -231,6 +240,32 @@ const metadata = {
targetRef: { type: HTMLElement },
},
},

/**
* Fired, when the logo is pressed.
*
* @event
* @param {HTMLElement} targetRef dom ref of the clicked element
* @public
*/
logoPress: {
detail: {
targetRef: { type: HTMLElement },
},
},

/**
* Fired, when the co pilot is pressed.
*
* @event
* @param {HTMLElement} targetRef dom ref of the clicked element
* @public
*/
coPilotPress: {
detail: {
targetRef: { type: HTMLElement },
},
},
},
};

Expand Down Expand Up @@ -374,6 +409,18 @@ class ShellBar extends WebComponent {
this.shadowRoot.querySelector("ui5-popover").close();
this._overflowActions();
};

this._logoPress = event => {
this.fireEvent("logoPress", {
targetRef: this.shadowRoot.querySelector(".sapWCShellBarLogo"),
});
};

this._coPilotPress = event => {
this.fireEvent("coPilotPress", {
targetRef: this.shadowRoot.querySelector(".ui5-shellbar-coPilot"),
});
};
}

onBeforeRendering() {
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/themes-next/ShellBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ ui5-shellbar {
}

.sapWCShellBarLogo {
cursor: pointer;
height: 1.675rem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
window["press-input"].value = "Product Switch"
});

shellbar.addEventListener("logoPress", function(event) {
window["press-input"].value = "Logo"
});

shellbar.addEventListener("coPilotPress", function(event) {
window["press-input"].value = "CoPilot"
});

["disc", "call"].forEach(function(id) {
window[id].addEventListener("press", function(event) {
window["press-input"].value = event.target.id;
Expand Down
16 changes: 16 additions & 0 deletions packages/main/test/specs/ShellBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ describe("Component Behaviour", () => {
assert.strictEqual(input.getValue(), "Product Switch", "Input value is set by click event of Product Switch icon");
});

it("tests logoPress event", () => {
const logo = browser.findElementDeep("#shellbar >>> .sapWCShellBarLogo");
const input = browser.findElementDeep("#press-input");

logo.click();
assert.strictEqual(input.getValue(), "Logo", "Input value is set by click event of Logo");
});

it("tests coPilotPress event", () => {
const coPilot = browser.findElementDeep("#shellbar >>> .ui5-shellbar-coPilot");
const input = browser.findElementDeep("#press-input");

coPilot.click();
assert.strictEqual(input.getValue(), "CoPilot", "Input value is set by click event of CoPilot");
});

it("tests if searchfield appears when clicking on search icon", () => {
const searchIcon = browser.findElementDeep("#shellbar >>> .sapWCShellBarSearchIcon");
const searchField = browser.findElementDeep("#shellbar ui5-input");
Expand Down

0 comments on commit f221123

Please sign in to comment.