Skip to content

Commit d734979

Browse files
committed
Add comment editor skeleton component
1 parent 0cccf62 commit d734979

3 files changed

Lines changed: 56 additions & 28 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { css, html, LitElement } from 'lit';
2+
import { repeat } from 'lit/directives/repeat.js';
3+
import './emoji-button';
4+
5+
export class CommentEditorSkeleton extends LitElement {
6+
protected override render() {
7+
return html`<div
8+
class="border rounded-md border-solid border-gray-200"
9+
>
10+
<div class="animate-pulse p-4">
11+
<div class="h-4 my-1 w-20 bg-gray-200 rounded"></div>
12+
</div>
13+
<div class="py-2.5 px-3 flex gap-1 m-0 items-center">
14+
${repeat(
15+
Array(7),
16+
() => html`
17+
<div
18+
role="button"
19+
class="size-7 flex items-center justify-center cursor-pointer"
20+
>
21+
<div class="size-5 animate-pulse bg-gray-200 rounded-md"></div>
22+
</div>
23+
`
24+
)}
25+
</div>
26+
</div>`;
27+
}
28+
29+
static override styles = [
30+
css`
31+
@unocss-placeholder;
32+
33+
:host {
34+
display: block;
35+
width: 100%;
36+
}
37+
`,
38+
];
39+
}
40+
41+
customElements.get('comment-editor-skeleton') ||
42+
customElements.define('comment-editor-skeleton', CommentEditorSkeleton);
43+
44+
declare global {
45+
interface HTMLElementTagNameMap {
46+
'comment-editor-skeleton': CommentEditorSkeleton;
47+
}
48+
}

packages/comment-widget/src/comment-editor.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { css, html, LitElement, type PropertyValues, unsafeCSS } from 'lit';
44
import { state } from 'lit/decorators.js';
55
import { repeat } from 'lit/directives/repeat.js';
66
import './emoji-button';
7-
import { CharacterCount } from '@tiptap/extensions';
8-
import CodeBlockShiki from 'tiptap-extension-code-block-shiki';
97
import contentStyles from './styles/content.css?inline';
8+
import './comment-editor-skeleton';
109

1110
interface ActionItem {
1211
name?: string;
@@ -87,6 +86,10 @@ export class CommentEditor extends LitElement {
8786
const { Editor } = await import('@tiptap/core');
8887
const { Placeholder } = await import('@tiptap/extensions');
8988
const { StarterKit } = await import('@tiptap/starter-kit');
89+
const { CodeBlockShiki } = await import(
90+
'tiptap-extension-code-block-shiki'
91+
);
92+
const { CharacterCount } = await import('@tiptap/extensions');
9093

9194
this.loading = false;
9295

@@ -139,7 +142,7 @@ export class CommentEditor extends LitElement {
139142
}
140143

141144
protected override render() {
142-
return html` ${this.renderSkeleton()}
145+
return html` ${this.loading ? html`<comment-editor-skeleton></comment-editor-skeleton>` : ''}
143146
<div
144147
class="border rounded-md border-solid border-[var(--component-form-input-border-color)] focus-within:border-[var(--component-form-input-border-color-focus)] transition-all"
145148
?hidden=${this.loading}
@@ -160,30 +163,6 @@ export class CommentEditor extends LitElement {
160163
</div>`;
161164
}
162165

163-
private renderSkeleton() {
164-
return html`<div
165-
class="border rounded-md border-solid border-gray-200"
166-
?hidden=${!this.loading}
167-
>
168-
<div class="animate-pulse p-4">
169-
<div class="h-4 my-1 w-20 bg-gray-200 rounded"></div>
170-
</div>
171-
<div class="py-2.5 px-3 flex gap-1 m-0 items-center">
172-
${repeat(
173-
Array(7),
174-
() => html`
175-
<div
176-
role="button"
177-
class="size-7 flex items-center justify-center cursor-pointer"
178-
>
179-
<div class="size-5 animate-pulse bg-gray-200 rounded-md"></div>
180-
</div>
181-
`
182-
)}
183-
</div>
184-
</div>`;
185-
}
186-
187166
private renderActionItem(item: ActionItem, editor?: Editor) {
188167
if (item.type === 'separator') {
189168
return html`<li class="flex items-center" aria-hidden="true">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import varStyles from './styles/var';
3030
import type { ConfigMapData } from './types';
3131
import './comment-list';
3232
import { ofetch } from 'ofetch';
33+
import './comment-editor-skeleton';
3334

3435
export class CommentWidget extends LitElement {
3536
@provide({ context: baseUrlContext })
@@ -75,7 +76,7 @@ export class CommentWidget extends LitElement {
7576
return html` <div class="comment-widget">
7677
${
7778
!this.isInitialized
78-
? html`<loading-block></loading-block>`
79+
? html`<comment-editor-skeleton></comment-editor-skeleton>`
7980
: html`
8081
<comment-form></comment-form>
8182
<comment-list></comment-list>

0 commit comments

Comments
 (0)