forked from halo-dev/plugin-comment-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase-comment-item.ts
More file actions
143 lines (120 loc) · 3.27 KB
/
base-comment-item.ts
File metadata and controls
143 lines (120 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import './user-avatar';
import { msg } from '@lit/localize';
import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import baseStyles from './styles/base';
import varStyles from './styles/var';
import { formatDate, timeAgo } from './utils/date';
export class BaseCommentItem extends LitElement {
@property({ type: String })
userAvatar: string | undefined;
@property({ type: String })
userDisplayName: string | undefined;
@property({ type: String })
userWebsite: string | undefined;
@property({ type: String })
creationTime: string | undefined;
@property({ type: Boolean })
approved: boolean | undefined;
@property({ type: Boolean })
breath: boolean | undefined;
@property({ type: String })
content = '';
override render() {
return html`<div class="item ${this.breath ? 'item--animate-breath' : ''}">
<div class="item__avatar">
<user-avatar
src="${this.userAvatar || ''}"
alt="${this.userDisplayName || ''}"
></user-avatar>
</div>
<div class="item__main">
<div class="item__meta">
${
this.userWebsite
? html`<a class="item__author" target="_blank" href=${this.userWebsite}>
${this.userDisplayName}
</a>`
: html`<div class="item__author">${this.userDisplayName}</div>`
}
<div class="item__meta-info" title=${formatDate(this.creationTime)}>
${timeAgo(this.creationTime)}
</div>
${!this.approved ? html`<div class="item__meta-info">${msg('Reviewing')}</div>` : ''}
</div>
<div class="item__content">
<pre><slot name="pre-content"></slot>${this.content}</pre>
</div>
<div class="item__actions">
<slot name="action"></slot>
</div>
<slot name="footer"></slot>
</div>
</div>`;
}
static override styles = [
varStyles,
baseStyles,
css`
.item {
display: flex;
gap: 0.75em;
padding: 1em 0;
}
.item__main {
flex: 1;
}
.item__meta {
display: flex;
align-items: center;
gap: 0.75em;
}
.item__author {
color: var(--base-color);
font-weight: 500;
font-size: 0.875em;
}
.item__meta-info {
color: var(--base-info-color);
font-size: 0.75em;
line-height: 1em;
}
.item__content {
margin-top: 0.5em;
}
.item__content pre {
color: var(--base-color);
white-space: pre-wrap;
overflow-wrap: break-word;
word-break: break-all;
}
.item__actions {
margin-top: 0.5em;
display: flex;
align-items: center;
gap: 0.7em;
}
.item--animate-breath {
animation: breath 1s ease-in-out infinite;
}
@keyframes breath {
0% {
transform: scale(1);
}
50% {
transform: scale(1.02);
}
100% {
transform: scale(1);
}
}
`,
];
}
customElements.get('base-comment-item') ||
customElements.define('base-comment-item', BaseCommentItem);
declare global {
interface HTMLElementTagNameMap {
'base-comment-item': BaseCommentItem;
}
}