Skip to content

Commit 11e985f

Browse files
authored
feat(hn): toggle comments by details > summary (#532)
1 parent f86a6fe commit 11e985f

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

sites/hn.svelte.dev/src/routes/item/[id]/Comment.svelte

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,32 @@
99
* }}
1010
*/
1111
export let comment;
12-
13-
let hidden = false;
1412
</script>
1513

1614
{#if !comment.deleted}
17-
<article class="comment" class:hidden>
18-
<div
19-
class="meta-bar"
20-
role="button"
21-
tabindex="0"
22-
on:click={() => (hidden = !hidden)}
23-
on:keyup={(e) => e.key === ' ' && (hidden = !hidden)}
24-
>
25-
<span class="meta">
26-
<a href="/user/{comment.user}">{comment.user}</a>
27-
{comment.time_ago}
28-
</span>
29-
</div>
30-
31-
<div class="body">
32-
{@html comment.content}
33-
</div>
34-
35-
{#if comment.comments.length > 0}
36-
<ul class="children">
37-
{#each comment.comments as child}
38-
<li><svelte:self comment={child} /></li>
39-
{/each}
40-
</ul>
41-
{/if}
15+
<article class="comment">
16+
<details open>
17+
<summary>
18+
<div class="meta-bar" role="button" tabindex="0">
19+
<span class="meta">
20+
<a href="/user/{comment.user}">{comment.user}</a>
21+
{comment.time_ago}
22+
</span>
23+
</div>
24+
</summary>
25+
26+
<div class="body">
27+
{@html comment.content}
28+
</div>
29+
30+
{#if comment.comments.length > 0}
31+
<ul class="children">
32+
{#each comment.comments as child}
33+
<li><svelte:self comment={child} /></li>
34+
{/each}
35+
</ul>
36+
{/if}
37+
</details>
4238
</article>
4339
{/if}
4440

@@ -54,24 +50,28 @@
5450
.meta-bar {
5551
padding: 1em 0;
5652
cursor: pointer;
57-
background: 100% 50% no-repeat url(./fold.svg);
53+
background: 100% 50% no-repeat url(./unfold.svg);
5854
background-size: 1em 1em;
5955
}
6056
61-
.hidden .meta-bar {
62-
background-image: url(./unfold.svg);
57+
.comment details[open] .meta-bar {
58+
background-image: url(./fold.svg);
6359
}
6460
65-
.comment .children {
66-
padding: 0 0 0 1em;
67-
margin: 0;
61+
.comment details > summary {
62+
list-style-type: none;
6863
}
6964
70-
.hidden .body,
71-
.hidden .children {
65+
.comment details > summary::marker,
66+
.comment details > summary::-webkit-details-marker {
7267
display: none;
7368
}
7469
70+
.comment .children {
71+
padding: 0 0 0 1em;
72+
margin: 0;
73+
}
74+
7575
@media (min-width: 720px) {
7676
.comment .children {
7777
padding: 0 0 0 2em;

0 commit comments

Comments
 (0)