-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathToolbarButton.ts
More file actions
224 lines (203 loc) · 5.78 KB
/
ToolbarButton.ts
File metadata and controls
224 lines (203 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
import type { ButtonAccessibilityAttributes } from "./Button.js";
import type ButtonDesign from "./types/ButtonDesign.js";
import ToolbarItem from "./ToolbarItem.js";
import ToolbarButtonTemplate from "./ToolbarButtonTemplate.js";
import ToolbarButtonCss from "./generated/themes/ToolbarButton.css.js";
type ToolbarButtonAccessibilityAttributes = ButtonAccessibilityAttributes;
/**
* @class
*
* ### Overview
* The `ui5-toolbar-button` represents an abstract action,
* used in the `ui5-toolbar`.
*
* ### ES6 Module Import
* `import "@ui5/webcomponents/dist/ToolbarButton.js";`
* @constructor
* @abstract
* @extends ToolbarItem
* @public
* @since 1.17.0
*/
@customElement({
tag: "ui5-toolbar-button",
template: ToolbarButtonTemplate,
renderer: jsxRenderer,
styles: [ToolbarButtonCss],
})
/**
* Fired when the component is activated either with a
* mouse/tap or by using the Enter or Space key.
*
* **Note:** The event will not be fired if the `disabled`
* property is set to `true`.
* @public
*/
@event("click", {
bubbles: true,
cancelable: true,
})
class ToolbarButton extends ToolbarItem {
/**
* Defines if the action is disabled.
*
* **Note:** a disabled action can't be pressed or focused, and it is not in the tab chain.
* @default false
* @public
*/
@property({ type: Boolean })
disabled = false;
/**
* Defines the action design.
* @default "Default"
* @public
*/
@property()
design: `${ButtonDesign}` = "Default";
/**
* Defines the `icon` source URI.
*
* **Note:** SAP-icons font provides numerous buil-in icons. To find all the available icons, see the
* [Icon Explorer](https://sdk.openui5.org/test-resources/sap/m/demokit/iconExplorer/webapp/index.html).
* @default undefined
* @public
*/
@property()
icon?: string
/**
* Defines the icon, displayed as graphical element within the component after the button text.
*
* **Note:** It is highly recommended to use `endIcon` property only together with `icon` and/or `text` properties.
* Usage of `endIcon` only should be avoided.
*
* The SAP-icons font provides numerous options.
*
* Example:
* See all the available icons within the [Icon Explorer](https://sdk.openui5.org/test-resources/sap/m/demokit/iconExplorer/webapp/index.html).
* @default undefined
* @public
*/
@property()
endIcon?: string;
/**
* Defines the tooltip of the component.
*
* **Note:** A tooltip attribute should be provided for icon-only buttons, in order to represent their exact meaning/function.
* @default undefined
* @public
*/
@property()
tooltip?: string
/**
* Defines the accessible ARIA name of the component.
* @default undefined
* @public
*/
@property()
accessibleName?: string;
/**
* Receives id(or many ids) of the elements that label the component.
* @default undefined
* @public
*/
@property()
accessibleNameRef?: string;
/**
* Defines the additional accessibility attributes that will be applied to the component.
*
* The following fields are supported:
*
* - **expanded**: Indicates whether the button, or another grouping element it controls, is currently expanded or collapsed.
* Accepts the following string values: `true` or `false`
*
* - **hasPopup**: Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by the button.
* Accepts the following string values: `dialog`, `grid`, `listbox`, `menu` or `tree`.
*
* - **controls**: Identifies the element (or elements) whose contents or presence are controlled by the button element.
* Accepts a lowercase string value.
*
* @default {}
* @public
*/
@property({ type: Object })
accessibilityAttributes: ToolbarButtonAccessibilityAttributes = {};
/**
* Button text
* @public
* @default undefined
*/
@property()
text?: string;
/**
* Defines whether the button text should only be displayed in the overflow popover.
*
* When set to `true`, the button appears as icon-only in the main toolbar,
* but shows both icon and text when moved to the overflow popover.
*
* **Note:** This property only takes effect when the `text` property is also set.
*
* @default false
* @public
* @since 2.17.0
*/
@property({ type: Boolean })
showOverflowText = false;
/**
* Defines the width of the button.
*
* **Note:** all CSS sizes are supported - 'percentage', 'px', 'rem', 'auto', etc.
* @default undefined
* @public
*/
@property()
width?: string;
get styles() {
return {
width: this.width,
display: this.hidden ? "none" : "inline-block",
};
}
/**
* Returns the effective text to display based on overflow state and showOverflowText property.
*
* When showOverflowText is true:
* - Normal state: returns empty string (icon-only)
* - Overflow state: returns text
*
* When showOverflowText is false:
* - Returns text in both states (normal behavior)
*/
get effectiveText(): string | undefined {
if (this.showOverflowText) {
return this.isOverflowed ? this.text : "";
}
return this.text;
}
onClick(e: Event) {
e.stopImmediatePropagation();
const prevented = !this.fireDecoratorEvent("click", { targetRef: e.target as HTMLElement });
if (!prevented && !this.preventOverflowClosing) {
this.fireDecoratorEvent("close-overflow");
}
}
/**
* @override
*/
get classes() {
return {
root: {
...super.classes.root,
"ui5-tb-button": true,
},
};
}
}
ToolbarButton.define();
export default ToolbarButton;
export type {
ToolbarButtonAccessibilityAttributes,
};