Skip to content

Commit 5d4e594

Browse files
authored
feature(ui5-messagestrip): allow any content for the icon (#1216)
1 parent 894d457 commit 5d4e594

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

packages/main/src/MessageStrip.hbs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
aria-labelledby="{{_id}}">
66

77
{{#unless noIcon}}
8-
<ui5-icon class="ui5-messagestrip-icon" name="{{messageStripIcon}}"></ui5-icon>
8+
<div class="ui5-messagestrip-icon">
9+
{{#if iconProvided}}
10+
<slot name="icon"></slot>
11+
{{else}}
12+
<ui5-icon name="{{standardIconName}}"></ui5-icon>
13+
{{/if}}
14+
</div>
915
{{/unless}}
1016

1117
<span class="ui5-hidden-text">{{hiddenText}}</span>

packages/main/src/MessageStrip.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,8 @@ const metadata = {
3838
},
3939

4040
/**
41-
* Defines the icon src URI to be displayed as graphical element within the <code>ui5-messagestrip</code>.
42-
* <br><br>
43-
* <b>Note:</b> If no icon is given, the default icon for the <code>ui5-messagestrip</code> type will be added.
44-
* The SAP-icons font provides numerous options.
45-
* <br><br>
46-
* Example:
47-
* <br>
48-
* <pre>ui5-messagestrip icon="palette"</pre>
49-
*
50-
* See all the available icons in the <ui5-link target="_blank" href="https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/iconExplorer/webapp/index.html" class="api-table-content-cell-link">Icon Explorer</ui5-link>.
51-
*
52-
* @type {string}
53-
* @defaultvalue ""
54-
* @public
55-
*/
56-
icon: {
57-
type: String,
58-
},
59-
60-
/**
61-
* Defines whether the MessageStrip renders icon in the beginning.
41+
* Defines whether the MessageStrip will show an icon in the beginning.
42+
* You can directly provide an icon with the <code>icon</code> slot. Otherwise, the default icon for the type will be used.
6243
*
6344
* @type {boolean}
6445
* @defaultvalue false
@@ -91,6 +72,23 @@ const metadata = {
9172
"default": {
9273
type: Node,
9374
},
75+
76+
/**
77+
* Defines the content to be displayed as graphical element within the <code>ui5-messagestrip</code>.
78+
* <br><br>
79+
* <b>Note:</b> If no icon is given, the default icon for the <code>ui5-messagestrip</code> type will be used.
80+
* The SAP-icons font provides numerous options.
81+
* <br><br>
82+
*
83+
* See all the available icons in the <ui5-link target="_blank" href="https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/iconExplorer/webapp/index.html" class="api-table-content-cell-link">Icon Explorer</ui5-link>.
84+
*
85+
* @type {string}
86+
* @defaultvalue ""
87+
* @public
88+
*/
89+
"icon": {
90+
type: HTMLElement,
91+
},
9492
},
9593
events: /** @lends sap.ui.webcomponents.main.MessageStrip.prototype */ {
9694

@@ -222,8 +220,12 @@ class MessageStrip extends UI5Element {
222220
};
223221
}
224222

225-
get messageStripIcon() {
226-
return this.icon || MessageStrip.iconMappings()[this.type];
223+
get iconProvided() {
224+
return this.icon.length > 0;
225+
}
226+
227+
get standardIconName() {
228+
return MessageStrip.iconMappings()[this.type];
227229
}
228230

229231
get typeClasses() {

packages/main/test/pages/MessageStrip.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<ui5-messagestrip no-icon no-close-button class="top" type="Information">Ea mollit nulla laborum et fugiat nulla excepteur ea. Duis et dolor enim Lorem laboris adipisicing cillum quis proident dolor veniam voluptate. Nostrud dolore ipsum anim voluptate enim dolore eiusmod aliqua et. Est eu ex dolor ea ipsum. Adipisicing duis aliquip ullamco culpa dolore exercitation ullamco cillum irure.</ui5-messagestrip>
4444
<ui5-messagestrip no-close-button class="top" type="Information">Ea mollit nulla laborum et fugiat nulla excepteur ea. Duis et dolor enim Lorem laboris adipisicing cillum quis proident dolor veniam voluptate. Nostrud dolore ipsum anim voluptate enim dolore eiusmod aliqua et. Est eu ex dolor ea ipsum. Adipisicing duis aliquip ullamco culpa dolore exercitation ullamco cillum irure.</ui5-messagestrip>
4545

46+
<ui5-messagestrip type="Warning" class="top"><ui5-icon name="palette" slot="icon"></ui5-icon>Custom icon</ui5-messagestrip>
47+
48+
<ui5-messagestrip type="Positive" class="top"><img src="./img/loading.gif" width="16" height="16" slot="icon">Custom icon</ui5-messagestrip>
4649

4750
<script>
4851
var counter = 0;
4.08 KB
Loading

packages/main/test/samples/MessageStrip.sample.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ <h3>Custom MessageStrip</h3>
7878
<ui5-messagestrip class="samples-margin-bottom samples-vertical-align" style="width: 200px;" type="Positive" no-close-button>Successfull login!</ui5-messagestrip>
7979
<ui5-messagestrip class="samples-margin-bottom samples-vertical-align" style="width: 200px;" type="Negative" no-icon>Access denied!</ui5-messagestrip>
8080
<ui5-messagestrip class="samples-margin-bottom samples-vertical-align" style="width: 200px;" type="Warning">Update is required.</ui5-messagestrip>
81+
<ui5-messagestrip class="samples-margin-bottom samples-vertical-align" style="width: 200px;" type="Warning"><ui5-icon name="palette" slot="icon"></ui5-icon>Custom icon</ui5-messagestrip>
82+
<ui5-messagestrip class="samples-margin-bottom samples-vertical-align" style="width: 200px;" type="Positive"><img src="../../../assets/images/loading.gif" width="16" height="16" slot="icon">Custom animated gif</ui5-messagestrip>
8183
</div>
8284
<pre class="prettyprint lang-html"><xmp>
8385
<ui5-messagestrip type="Information" style="width: 200px;" no-icon no-close-button>You have new message.</ui5-messagestrip>
8486
<ui5-messagestrip type="Positive" style="width: 200px;" no-close-button>Successfull login!</ui5-messagestrip>
8587
<ui5-messagestrip type="Negative" style="width: 200px;" no-icon>Access denied!</ui5-messagestrip>
8688
<ui5-messagestrip type="Warning" style="width: 200px;">Update is required.</ui5-messagestrip>
89+
<ui5-messagestrip type="Warning" style="width: 200px;"><ui5-icon name="palette" slot="icon"></ui5-icon>Custom icon</ui5-messagestrip>
90+
<ui5-messagestrip type="Positive" style="width: 200px;"><img src="../../../assets/images/loading.gif" width="16" height="16" slot="icon">Custom animated gif</ui5-messagestrip>
8791
<script>
8892
document.querySelectorAll("ui5-messagestrip").forEach(function(messageStrip) {
8993
messageStrip.addEventListener("close", function() {
4.08 KB
Loading

0 commit comments

Comments
 (0)