diff --git a/stylesheets/components/Avatar.scss b/stylesheets/components/Avatar.scss index dab26213b..ca4c0fa56 100644 --- a/stylesheets/components/Avatar.scss +++ b/stylesheets/components/Avatar.scss @@ -112,12 +112,30 @@ } &__badge { - pointer-events: none; position: absolute; z-index: 1; // Positioning should be overridden by JavaScript. These are set defensively. bottom: 0; right: 0; + + &--static { + pointer-events: none; + } + + &--button { + background-color: transparent; + background-position: center center; + background-size: contain; + border: 0; + outline: none; + + @include keyboard-mode { + &:focus { + outline: 2px solid $color-ultramarine; + border-radius: 6px; + } + } + } } } diff --git a/ts/components/Avatar.stories.tsx b/ts/components/Avatar.stories.tsx index 6a49ef625..31a3e4a8d 100644 --- a/ts/components/Avatar.stories.tsx +++ b/ts/components/Avatar.stories.tsx @@ -53,6 +53,7 @@ const createProps = (overrideProps: Partial = {}): Props => ({ name: text('name', overrideProps.name || ''), noteToSelf: boolean('noteToSelf', overrideProps.noteToSelf || false), onClick: action('onClick'), + onClickBadge: action('onClickBadge'), phoneNumber: text('phoneNumber', overrideProps.phoneNumber || ''), searchResult: boolean( 'searchResult', diff --git a/ts/components/Avatar.tsx b/ts/components/Avatar.tsx index 2e151f44e..2b7ec8cf4 100644 --- a/ts/components/Avatar.tsx +++ b/ts/components/Avatar.tsx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { + CSSProperties, FunctionComponent, MouseEvent, ReactChild, @@ -68,6 +69,7 @@ export type Props = { searchResult?: boolean; onClick?: (event: MouseEvent) => unknown; + onClickBadge?: (event: MouseEvent) => unknown; // Matches Popper's RefHandler type innerRef?: React.Ref; @@ -104,6 +106,7 @@ export const Avatar: FunctionComponent = ({ loading, noteToSelf, onClick, + onClickBadge, sharedGroupNames, size, theme, @@ -254,19 +257,35 @@ export const Avatar: FunctionComponent = ({ badgeTheme ); if (badgeImagePath) { - badgeNode = ( - {badge.name} - ); + const positionStyles: CSSProperties = { + width: badgePlacement.size, + height: badgePlacement.size, + bottom: badgePlacement.bottom, + right: badgePlacement.right, + }; + if (onClickBadge) { + badgeNode = ( +