-
Notifications
You must be signed in to change notification settings - Fork 278
chore(ui5-toolbar): toolbar item wrapper introduced #12243
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
base: main
Are you sure you want to change the base?
Changes from all commits
4b9e525
eb44c13
0439ce7
7c49aa4
682adfa
a177545
6169477
6d61c76
84607fb
8b60ec7
433a23b
72da995
a82c920
fed79a5
2324db6
22648ff
669a44a
9a12522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import property from "@ui5/webcomponents-base/dist/decorators/property.js"; | ||
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js"; | ||
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js"; | ||
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js"; | ||
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js"; | ||
import ToolbarItemTemplate from "./ToolbarItemTemplate.js"; | ||
|
||
import type ToolbarItemOverflowBehavior from "./types/ToolbarItemOverflowBehavior.js"; | ||
|
||
|
@@ -16,13 +20,19 @@ type ToolbarItemEventDetail = { | |
bubbles: true, | ||
}) | ||
|
||
@customElement({ | ||
tag: "ui5-toolbar-item", | ||
languageAware: true, | ||
renderer: jsxRenderer, | ||
template: ToolbarItemTemplate, | ||
}) | ||
|
||
/** | ||
* @class | ||
* | ||
* Represents an abstract class for items, used in the `ui5-toolbar`. | ||
* @constructor | ||
* @extends UI5Element | ||
* @abstract | ||
* @public | ||
* @since 1.17.0 | ||
*/ | ||
|
@@ -65,6 +75,17 @@ class ToolbarItem extends UI5Element { | |
onAfterRendering(): void { | ||
this._isRendering = false; | ||
} | ||
/** | ||
* Wrapped component slot. | ||
* @public | ||
* @since 2.15.0 | ||
*/ | ||
|
||
@slot({ | ||
"default": true, type: HTMLElement, invalidateOnChildChange: true, | ||
}) | ||
item!: HTMLElement | undefined; | ||
|
||
/** | ||
* Defines if the width of the item should be ignored in calculating the whole width of the toolbar | ||
* @protected | ||
|
@@ -112,10 +133,26 @@ class ToolbarItem extends UI5Element { | |
}, | ||
}; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the constructor doesn't handle any arguments, this override can be omitted |
||
} | ||
|
||
/** | ||
* Handles the click event on the toolbar item. | ||
* If `preventOverflowClosing` is false, it will fire a "close-overflow" event. | ||
*/ | ||
onClick(e?: Event): void { | ||
if (e && !this.preventOverflowClosing) { | ||
this.fireDecoratorEvent("close-overflow"); | ||
} | ||
} | ||
} | ||
|
||
export type { | ||
IEventOptions, | ||
ToolbarItemEventDetail, | ||
}; | ||
ToolbarItem.define(); | ||
|
||
export default ToolbarItem; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type ToolbarItem from "./ToolbarItem.js"; | ||
|
||
export default function ToolbarItemTemplate(this: ToolbarItem) { | ||
return ( | ||
<div onClick={this.onClick}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we have a sample with different types of components we should test if this click only event handling is enough to manage the closing of the popover. If not we should extend it or think of another mehanism. |
||
<slot></slot> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add other components : Title, Text, Input, CheckBox, ToggleButton, DIV |
||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<title>Toolbar</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
<meta charset="utf-8"> | ||
|
||
<script src="%VITE_BUNDLE_PATH%" type="module"></script> | ||
<link rel="stylesheet" type="text/css" href="./styles/Toolbar.css"> | ||
</head> | ||
|
||
<body> | ||
<div id="toolbars-container"> | ||
<ui5-title level="H3">Standard Toolbar with ToolbarSelect and ToolbarButton</ui5-title> | ||
<br /> | ||
<section> | ||
<ui5-toolbar id="otb_standard"> | ||
<ui5-toolbar-button icon="add" stable-dom-ref="otb_button_1" text="Left 1 (long)"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="decline" text="Left 2"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="employee" text="Left 3"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="decline" text="Left 4"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="add" text="Mid 1"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="decline" text="Mid 2"></ui5-toolbar-button> | ||
<ui5-toolbar-button icon="add" text="Right 1"></ui5-toolbar-button> | ||
<ui5-toolbar-button overflow-priority="NeverOverflow" icon="employee" text="Right 4"></ui5-toolbar-button> | ||
<ui5-toolbar-select id="toolbar-select"> | ||
<ui5-toolbar-select-option>1</ui5-toolbar-select-option> | ||
<ui5-toolbar-select-option selected>2</ui5-toolbar-select-option> | ||
<ui5-toolbar-select-option>3</ui5-toolbar-select-option> | ||
</ui5-toolbar-select> | ||
<ui5-toolbar-separator></ui5-toolbar-separator> | ||
<ui5-toolbar-separator></ui5-toolbar-separator> | ||
<ui5-toolbar-button overflow-priority="AlwaysOverflow" icon="employee" prevent-overflow-closing text="Call me later" ></ui5-toolbar-button> | ||
</ui5-toolbar> | ||
</section> | ||
<ui5-title level="H3">Toolbar with ui5-select and ui5-button wrapped in ui5-toolbar-item</ui5-title> | ||
<br /> | ||
<section> | ||
<ui5-toolbar id="otb_standard"> | ||
<ui5-toolbar-item><ui5-button icon="add" stable-dom-ref="otb_button_1">Left 1 (long)</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="decline">Left 2</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="employee">Left 3</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="decline">Left 4</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="add">Mid 1</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="decline">Mid 2</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item><ui5-button icon="add">Right 1</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item overflow-priority="NeverOverflow"><ui5-button icon="employee">Right 4</ui5-button></ui5-toolbar-item> | ||
<ui5-toolbar-item> | ||
<ui5-select id="toolbar-select"> | ||
<ui5-option>1</ui5-option> | ||
<ui5-option selected>2</ui5-option> | ||
<ui5-option>3</ui5-option> | ||
</ui5-select> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-separator></ui5-toolbar-separator> | ||
<ui5-toolbar-separator></ui5-toolbar-separator> | ||
<ui5-toolbar-item overflow-priority="AlwaysOverflow" prevent-overflow-closing > | ||
<ui5-button icon="employee">Call me later</ui5-button> | ||
</ui5-toolbar-item> | ||
</ui5-toolbar> | ||
</section> | ||
<ui5-title level="H3">Toolbar with various components</ui5-title> | ||
<br /> | ||
<section> | ||
<ui5-toolbar id="otb_standard"> | ||
<ui5-toolbar-item> | ||
<ui5-input id="myInput" class="input2auto" show-suggestions placeholder="Search for a country ..."> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-item> | ||
<ui5-text style="max-width:50px; text-overflow: ellipsis;white-space: nowrap;display: inline-block;">Simple text</ui5-text> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-item> | ||
<ui5-combobox id="combo" class="combobox2auto" value="ComboBox" accessible-name-ref="countryLabel"> | ||
<ui5-cb-item text="Algeria"></ui5-cb-item> | ||
<ui5-cb-item text="Argentina"></ui5-cb-item> | ||
<ui5-cb-item text="Australia"></ui5-cb-item> | ||
<ui5-cb-item text="Austria"></ui5-cb-item> | ||
<ui5-cb-item text="Bahrain"></ui5-cb-item> | ||
<ui5-cb-item text="Belgium"></ui5-cb-item> | ||
<ui5-cb-item text="Very long text that makes popover wider than the ComboBox"></ui5-cb-item> | ||
<ui5-cb-item text="Brazil"></ui5-cb-item> | ||
<ui5-cb-item text="Bulgaria"></ui5-cb-item> | ||
<ui5-cb-item text="Canada"></ui5-cb-item> | ||
<ui5-cb-item text="Chile"></ui5-cb-item> | ||
</ui5-combobox> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-item prevent-overflow-closing> | ||
<ui5-title>Simple title</ui5-title> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-item> | ||
<ui5-toggle-button icon="sap-icon://employee"></ui5-toggle-button> | ||
</ui5-toolbar-item> | ||
<ui5-toolbar-item prevent-overflow-closing> | ||
<div>div with <a onclick="alert(100)" href="#">Link</a> and text</div> | ||
</ui5-toolbar-item> | ||
|
||
</ui5-toolbar> | ||
</section> | ||
</div> | ||
</body> | ||
|
||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated comment