Skip to content

Commit 47c5cc3

Browse files
committed
Add user website link to avatar and author name
Fixes #127 Fixes #11
1 parent de67bc4 commit 47c5cc3

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

packages/comment-widget/src/base-comment-item.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class BaseCommentItem extends LitElement {
7777
<user-avatar
7878
src="${this.userAvatar || ''}"
7979
alt="${this.userDisplayName || ''}"
80+
href=${this.userWebsite}
8081
></user-avatar>
8182
</div>
8283
<div class="item-main flex-[1_1_auto] min-w-0 w-full">
@@ -87,6 +88,7 @@ export class BaseCommentItem extends LitElement {
8788
class="item-author font-medium text-sm"
8889
target="_blank"
8990
href=${this.userWebsite}
91+
rel="noopener noreferrer"
9092
>
9193
${this.userDisplayName}
9294
</a>`

packages/comment-widget/src/user-avatar.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export class UserAvatar extends LitElement {
1010
@property({ type: String })
1111
alt: string | undefined;
1212

13+
@property({ type: String })
14+
href: string | undefined;
15+
1316
@state()
1417
error = false;
1518

@@ -63,29 +66,33 @@ export class UserAvatar extends LitElement {
6366
}
6467

6568
override render() {
66-
if (this.src) {
67-
if (this.loading) {
68-
return html`<div class="avatar">
69-
<icon-loading></icon-loading>
70-
</div>`;
71-
}
72-
73-
if (this.error) {
74-
return html`<div class="avatar">
75-
<i class="i-tabler:alert-circle size-5"></i>
76-
</div>`;
77-
}
78-
79-
return html`<div class="avatar">
80-
<img class="avatar-image size-full object-cover" src="${this.src}" alt="${this.alt || ''}" loading="lazy" />
81-
</div>`;
69+
if (this.href) {
70+
return html`<a class="avatar" href="${this.href}" target="_blank" rel="noopener noreferrer">
71+
${this.renderAvatarContent()}
72+
</a>`;
8273
}
8374

8475
return html`<div class="avatar">
85-
<span class="avatar-placeholder text-sm font-medium text-text-1 select-none">${this.getPlaceholderText()}</span>
76+
${this.renderAvatarContent()}
8677
</div>`;
8778
}
8879

80+
renderAvatarContent() {
81+
if (!this.src) {
82+
return html`<span class="avatar-placeholder text-sm font-medium text-text-1 select-none">${this.getPlaceholderText()}</span>`;
83+
}
84+
85+
if (this.loading) {
86+
return html`<icon-loading></icon-loading>`;
87+
}
88+
89+
if (this.error) {
90+
return html`<i class="i-tabler:alert-circle size-5"></i>`;
91+
}
92+
93+
return html`<img class="avatar-image size-full object-cover" src="${this.src}" alt="${this.alt || ''}" loading="lazy" />`;
94+
}
95+
8996
static override styles = [
9097
...baseStyles,
9198
css`

0 commit comments

Comments
 (0)