Skip to content
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

fix(ui5-avatar): new interaction behavior #7374

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/main/src/Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class Avatar extends UI5Element implements ITabbable {
@property({ type: Boolean })
focused!: boolean;

/**
* Indicates if the elements is pressed
* @private
*/
@property({ type: Boolean })
pressed!: boolean;

/**
* Defines the name of the UI5 Icon, that will be displayed.
* <br>
Expand Down Expand Up @@ -423,7 +430,7 @@ class Avatar extends UI5Element implements ITabbable {
_onClickHandler(e: MouseEvent) {
// prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired
e.stopPropagation();
this.fireEvent("click");
this._fireClick();
}

_onkeydown(e: KeyboardEvent) {
Expand All @@ -432,7 +439,7 @@ class Avatar extends UI5Element implements ITabbable {
}

if (isEnter(e)) {
this.fireEvent("click");
this._fireClick();
}

if (isSpace(e)) {
Expand All @@ -442,10 +449,15 @@ class Avatar extends UI5Element implements ITabbable {

_onkeyup(e: KeyboardEvent) {
if (this._interactive && !e.shiftKey && isSpace(e)) {
this.fireEvent("click");
this._fireClick();
}
}

_fireClick() {
this.fireEvent("click");
this.pressed = !this.pressed;
}

_onfocusout() {
this.focused = false;
}
Expand Down
19 changes: 18 additions & 1 deletion packages/main/src/themes/Avatar.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
opacity: .7;
}

:host([focused]) {
:host(:not([hidden]):not([pressed]):hover) {
box-shadow: var(--ui5-avatar-hover-box-shadow-offset);
}

:host(:not([hidden])[focused]:not([pressed])) {
outline: var(--_ui5_avatar_outline);
outline-offset: var(--_ui5_avatar_focus_offset);
}
Expand All @@ -22,6 +26,18 @@
opacity: var(--sapContent_DisabledOpacity);
}

:host(:not([hidden])[pressed]) {
background: var(--sapButton_Active_Background);
border-color: var(--sapButton_Active_BorderColor);
color: var(--sapButton_Active_TextColor);
}

:host(:not([hidden])[pressed]:hover) {
background: var(--sapButton_Selected_Hover_Background);
border-color: var(--sapButton_Selected_Hover_BorderColor);
color: var(--sapButton_Selected_TextColor);
}

:host {
height: 3rem;
width: 3rem;
Expand Down Expand Up @@ -212,6 +228,7 @@
}

:host([_has-image]) {
color: var(--ui5-avatar-accent10-color);
background-color: transparent;
vertical-align: middle;
}
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/themes/base/Avatar-parameters.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:root {
--ui5-avatar-hover-box-shadow-offset: 0px 0px 0px 0.0625rem;
--ui5-avatar-initials-color: var(--sapContent_ImagePlaceholderForegroundColor);
--ui5-avatar-border-radius: .25rem;
--ui5-avatar-border-radius-img-deduction: 0.0625rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-color: #fff;
--ui5-avatar-initials-border: .0625rem solid #fff;
--ui5-avatar-accent1: #000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-color: #000;
--ui5-avatar-initials-border: .0625rem solid #000;
--ui5-avatar-accent1: #fff;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-color: var(--sapTextColor);
--ui5-avatar-initials-border: .0625rem solid var(--sapField_BorderColor);
--ui5-avatar-accent1: var(--sapBackgroundColor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-color: var(--sapTextColor);
--ui5-avatar-initials-border: .0625rem solid var(--sapField_BorderColor);
--ui5-avatar-accent1: var(--sapBackgroundColor);
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/themes/sap_horizon/Avatar-parameters.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--_ui5_avatar_focus_offset: 0.125rem;
--ui5-avatar-initials-border: 0.0625rem solid var(--sapAvatar_1_BorderColor);
--ui5-avatar-border-radius: var(--sapElement_BorderCornerRadius);
--_ui5_avatar_fontsize_XS: 1rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--_ui5_avatar_focus_offset: 0.125rem;
--ui5-avatar-initials-border: 0.0625rem solid var(--sapAvatar_1_BorderColor);
--ui5-avatar-border-radius: var(--sapElement_BorderCornerRadius);
--_ui5_avatar_fontsize_XS: 1rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-border: 0.0625rem solid var(--sapAvatar_1_BorderColor);
--ui5-avatar-border-radius: var(--sapElement_BorderCornerRadius);
--_ui5_avatar_fontsize_XS: 1rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../base/Avatar-parameters.css";

:root {
--ui5-avatar-hover-box-shadow-offset: 0px;
--ui5-avatar-initials-border: 0.0625rem solid var(--sapAvatar_1_BorderColor);
--ui5-avatar-border-radius: var(--sapElement_BorderCornerRadius);
--_ui5_avatar_fontsize_XS: 1rem;
Expand Down