Skip to content

Commit d848a69

Browse files
committed
Adds avatar hover
1 parent c61b89b commit d848a69

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

src/webviews/apps/shared/components/commit/commit-identity.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { css, html, LitElement } from 'lit';
1+
import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { when } from 'lit/directives/when.js';
44
import { dateConverter } from '../converters/date-converter';
55
import '../code-icon';
66
import '../formatted-date';
7+
import '../overlays/tooltip';
78

89
@customElement('commit-identity')
910
export class CommitIdentity extends LitElement {
1011
static override styles = css`
11-
:host {
12+
:host,
13+
.author {
1214
display: flex;
1315
flex-direction: row;
1416
align-items: center;
@@ -20,6 +22,19 @@ export class CommitIdentity extends LitElement {
2022
text-decoration: none;
2123
}
2224
25+
.author-hover {
26+
display: flex;
27+
flex-direction: column;
28+
align-items: center;
29+
justify-content: center;
30+
gap: 0.6rem;
31+
margin: 0.6rem 0.2rem 0.2rem 0.2rem;
32+
}
33+
34+
.author-hover img {
35+
max-width: 64px;
36+
}
37+
2338
.avatar {
2439
width: 1.8rem;
2540
}
@@ -74,23 +89,35 @@ export class CommitIdentity extends LitElement {
7489
actionLabel?: string;
7590

7691
private renderAvatar() {
77-
if (this.showAvatar && this.avatarUrl != null && this.avatarUrl.length > 0) {
92+
if (this.showAvatar && this.avatarUrl?.length) {
7893
return html`<img class="thumb" src="${this.avatarUrl}" alt="${this.name}" />`;
7994
}
8095
return html`<code-icon icon="person" size="18"></code-icon>`;
8196
}
8297

8398
override render() {
8499
return html`
85-
${when(
86-
this.url != null,
87-
() =>
88-
html`<a class="avatar" href="${this.url}">${this.renderAvatar()}</a
89-
><a class="name" href="${this.url}">${this.name}</a>`,
90-
() =>
91-
html`<span class="avatar">${this.renderAvatar()}</span
92-
><span class="name" href="${this.url}">${this.name}</span>`,
93-
)}
100+
<gl-tooltip>
101+
${when(
102+
this.url != null,
103+
() =>
104+
html`<a class="author" href="${this.url}"
105+
><span class="avatar">${this.renderAvatar()}</span
106+
><span class="name" href="${this.url}">${this.name}</span></a
107+
>`,
108+
() =>
109+
html`<span class="author"
110+
><span class="avatar">${this.renderAvatar()}</span
111+
><span class="name" href="${this.url}">${this.name}</span></span
112+
>`,
113+
)}
114+
<div class="author-hover" slot="content">
115+
${this.avatarUrl?.length
116+
? html`<img class="thumb" src="${this.avatarUrl}" alt="${this.name}" />`
117+
: nothing}
118+
<span>${this.name}</span>
119+
</div>
120+
</gl-tooltip>
94121
<span class="date">
95122
${this.actionLabel}
96123
<formatted-date

src/webviews/apps/shared/components/formatted-date.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { html, LitElement } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { formatDate, fromNow } from '../../../../system/date';
44
import { dateConverter } from './converters/date-converter';
5+
import './overlays/tooltip';
56

67
@customElement('formatted-date')
78
export class FormattedDate extends LitElement {
@@ -16,8 +17,10 @@ export class FormattedDate extends LitElement {
1617

1718
override render() {
1819
const formattedDate = formatDate(this.date, this.format ?? 'MMMM Do, YYYY h:mma');
19-
return html`<time datetime="${this.date.toISOString()}" title="${formattedDate}"
20-
>${this.dateStyle === 'relative' ? fromNow(this.date) : formattedDate}</time
20+
return html`<gl-tooltip content="${formattedDate}"
21+
><time datetime="${this.date.toISOString()}"
22+
>${this.dateStyle === 'relative' ? fromNow(this.date) : formattedDate}</time
23+
></gl-tooltip
2124
>`;
2225
}
2326
}

0 commit comments

Comments
 (0)