You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Creating a web component abstract item to be used inside Toolbar
2
+
3
+
*This section explains how to build abstract items in order to be compatible with UI5 Toolbar.*
4
+
*It will guide you through the process of how we created `ui5-toolbar-button`, to be
5
+
compatible with `ui5-toolbar`. Currently developed items can be used without those efforts. They are:*
6
+
1. ui5-toolbar-button
7
+
2. ui5-toolbar-select
8
+
3. ui5-toolbar-separator
9
+
4. ui5-toolbar-spacer
10
+
11
+
## Abstract items
12
+
13
+
### Why are abstract items needed?
14
+
15
+
When the toolbar renders its slotted items within a popover in the static area, simply relocating the actual DOM nodes within its slots can lead to reference issues, causing the slotted nodes to lose their parent reference (e.g., the toolbar). This is the reason why the toolbar must operate with abstract items. Abstract items are not rendered directly within the DOM; instead, they function as data used by the toolbar to produce corresponding physical web components. On the other hand, useful modifications detected by the toolbar on the physical items are synchronised with the abstract ones. (see step [Events](#events))
16
+
17
+
The `ui5-toolbar` is a composite web component, that slots different UI5 components, designing them as abstract items. They can contain
18
+
properties, slots and events, and they can match the API of already existing component.
19
+
In order to be suitable for usage inside `ui5-toolbar`, each component should adhere to following guidelines:
20
+
21
+
22
+
1. The component needs to implement a class with component name of the following type:
23
+
24
+
```javascript
25
+
ToolbarButton.ts
26
+
```
27
+
28
+
2. The new component needs to implement two template files with name of the following type:
29
+
30
+
```javascript
31
+
ToolbarButton.hbs and ToolbarPopoverButton.hbs
32
+
```
33
+
34
+
3. It needs to implement **customElement** decorator, which is good to contain custom tag name:
35
+
36
+
```javascript
37
+
@customElement({
38
+
tag:"ui5-toolbar-button"
39
+
})
40
+
```
41
+
42
+
4. The class should extend **ToolbarItem** base class, which should also be added as a dependency.
43
+
44
+
```javascript
45
+
classToolbarButtonextendsToolbarItem
46
+
```
47
+
48
+
5. Inside the module there should be two template getters: for toolbar and popover representation.
49
+
50
+
```javascript
51
+
staticgettoolbarTemplate() {
52
+
return ToolbarButtonTemplate;
53
+
}
54
+
55
+
staticgettoolbarPopoverTemplate() {
56
+
return ToolbarPopoverButtonTemplate;
57
+
}
58
+
```
59
+
60
+
6. After the class declaration there should be a registry call for the item inside the toolbar. **registerToolbarItem** helper should be added as a dependency.
Abstract items can provide a map of events through the `subscribedEvents` getter. The toolbar will actively monitor these events on the physical items, and when triggered, it will also fire the information to the corresponding abstract item. This mechanism proves useful when the abstract item requires synchronization of changes or interactions with the physical items. Importantly, events described as public offer benefits to consumers of the abstract items informing them about interactions with the physical elements. Additionally, the map contains information about the popover, such as `preventClosing: true`, which ensures that the popover remains open when this event is triggered by the physical item.
113
+
114
+
A good example is the Map of the `ui5-toolbar-select`:
115
+
116
+
```javascript
117
+
getsubscribedEvents() {
118
+
constmap=newMap();
119
+
120
+
map.set("click", { preventClosing:true });
121
+
map.set("change", { preventClosing:false });
122
+
map.set("open", { preventClosing:true });
123
+
map.set("close", { preventClosing:true });
124
+
125
+
return map;
126
+
}
127
+
```
128
+
129
+
The `ui5-toolbar-select` then waits for the toolbar to fire the `change` event, in order to notify (synchronize) its `options` slots:
0 commit comments