Skip to content

Commit

Permalink
refactor(ui5-ai-button): change api names
Browse files Browse the repository at this point in the history
  • Loading branch information
tsanislavgatev committed Jan 15, 2025
1 parent 5493f68 commit ea859e0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions packages/ai/src/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ import ButtonCss from "./generated/themes/Button.css.js";
* [Alt] + [Arrow Up]/ [Arrow Down], or [F4] keyboard keys.
* @public
*/
@event("arrow-click", {
@event("arrow-button-click", {
bubbles: true,
})

class Button extends UI5Element {
eventDetails!: {
"click": void;
"arrow-click": void;
"arrow-button-click": void;
}
/**
* Defines the component design.
Expand Down Expand Up @@ -117,7 +117,7 @@ class Button extends UI5Element {
* @since 2.6.0
*/
@property({ type: Boolean, noAttribute: true })
activeArrowButton = false;
arrowButtonPressed = false;

/**
* Keeps the current state object of the component.
Expand Down Expand Up @@ -151,7 +151,7 @@ class Button extends UI5Element {
_hiddenSplitButton?: SplitButton;

get _hideArrowButton() {
return !this._effectiveStateObject?.splitMode;
return !this._effectiveStateObject?.showArrowButton;
}

get _effectiveState() {
Expand All @@ -175,7 +175,7 @@ class Button extends UI5Element {
}

get _stateEndIcon() {
const endIcon = this._effectiveStateObject?.splitMode ? "" : this._effectiveStateObject?.endIcon;
const endIcon = this._effectiveStateObject?.showArrowButton ? "" : this._effectiveStateObject?.endIcon;
return endIcon;
}

Expand All @@ -187,7 +187,7 @@ class Button extends UI5Element {
const splitButton = this._splitButton;

if (splitButton) {
splitButton.activeArrowButton = this.activeArrowButton;
splitButton.activeArrowButton = this.arrowButtonPressed;
}

if (!this._currentStateObject?.name) {
Expand Down Expand Up @@ -225,10 +225,10 @@ class Button extends UI5Element {
const buttonWidth = button.offsetWidth;
const currentState: Partial<ButtonState> = this._currentStateObject || {};

if ((!currentState.splitMode && newStateObject.splitMode) || (!currentState.endIcon && !!newStateObject.endIcon)) {
if ((!currentState.showArrowButton && newStateObject.showArrowButton) || (!currentState.endIcon && !!newStateObject.endIcon)) {
this.classList.add("ui5-ai-button-button-to-menu");
}
if ((currentState.splitMode && !newStateObject.splitMode) || (!!currentState.endIcon && !newStateObject.endIcon)) {
if ((currentState.showArrowButton && !newStateObject.showArrowButton) || (!!currentState.endIcon && !newStateObject.endIcon)) {
this.classList.add("ui5-ai-button-menu-to-button");
}

Expand Down Expand Up @@ -298,12 +298,12 @@ class Button extends UI5Element {
}

/**
* Handles the arrow-click event when `ui5-ai-button` is in split mode.
* Handles the arrow-button-click event when `ui5-ai-button` is in split mode.
* @private
*/
_onArrowClick(e: CustomEvent): void {
e.stopImmediatePropagation();
this.fireDecoratorEvent("arrow-click");
this.fireDecoratorEvent("arrow-button-click");
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ai/src/ButtonState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ButtonState extends UI5Element {
* @public
*/
@property({ type: Boolean })
splitMode = false;
showArrowButton = false;
}

ButtonState.define();
Expand Down
8 changes: 4 additions & 4 deletions packages/ai/test/pages/Button.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ui5-ai-button id="myAiButtonSplit" state="generate">
<ui5-ai-button-state name="generate" text="Regenerate" icon="ai"></ui5-ai-button-state>
<ui5-ai-button-state name="generating" text="Stop Generating" icon="stop"></ui5-ai-button-state>
<ui5-ai-button-state name="revise" text="Regenerate" icon="ai" split-mode></ui5-ai-button-state>
<ui5-ai-button-state name="revise" text="Regenerate" icon="ai" show-arrow-button></ui5-ai-button-state>
</ui5-ai-button>
<br/>
<br/>
Expand Down Expand Up @@ -227,18 +227,18 @@
menuReg.addEventListener("open", function(evt) {
var button = menuReg.opener;

button.activeArrowButton = true;
button.arrowButtonPressed = true;
});

menuReg.addEventListener("close", function(evt) {
var button = menuReg.opener;

button.activeArrowButton = false;
button.arrowButtonPressed = false;
});

myAiButton.addEventListener("click", aiButtonClickHandler);
myAiButtonSplit.addEventListener("click", aiButtonSplitClickHandler);
myAiButtonSplit.addEventListener("arrow-click", aiButtonSplitArrowClickHandler);
myAiButtonSplit.addEventListener("arrow-button-click", aiButtonSplitArrowClickHandler);
myAiButtonIconOnly.addEventListener("click", aiButtonClickHandler);

function aiQuickPromptButtonClickHandler(e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ function menuItemClickHandler(evt) {
function menuOpenHandler() {
var button = menu.opener;

button.activeArrowButton = true;
button.arrowButtonPressed = true;
}

function menuCloseHandler() {
var button = menu.opener;

button.activeArrowButton = false;
button.arrowButtonPressed = false;
}

myAiButton.addEventListener("click", aiButtonClickHandler);
myAiButton.addEventListener("arrow-click", aiButtonArrowClickHandler);
myAiButton.addEventListener("arrow-button-click", aiButtonArrowClickHandler);
menu.addEventListener("item-click", menuItemClickHandler);
menu.addEventListener("open", menuOpenHandler);
menu.addEventListener("close", menuCloseHandler);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ui5-ai-button id="myAiButton" state="generate">
<ui5-ai-button-state name="generate" text="Generate" icon="ai"></ui5-ai-button-state>
<ui5-ai-button-state name="generating" text="Stop Generating" icon="stop"></ui5-ai-button-state>
<ui5-ai-button-state name="revise" text="Revise" icon="ai" split-mode></ui5-ai-button-state>
<ui5-ai-button-state name="revise" text="Revise" icon="ai" show-arrow-button></ui5-ai-button-state>
</ui5-ai-button>

<ui5-menu id="menu">
Expand Down

0 comments on commit ea859e0

Please sign in to comment.