Skip to content

Commit

Permalink
feat(hn): toggle comments by details > summary (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton authored Aug 22, 2023
1 parent f86a6fe commit 11e985f
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions sites/hn.svelte.dev/src/routes/item/[id]/Comment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,32 @@
* }}
*/
export let comment;
let hidden = false;
</script>

{#if !comment.deleted}
<article class="comment" class:hidden>
<div
class="meta-bar"
role="button"
tabindex="0"
on:click={() => (hidden = !hidden)}
on:keyup={(e) => e.key === ' ' && (hidden = !hidden)}
>
<span class="meta">
<a href="/user/{comment.user}">{comment.user}</a>
{comment.time_ago}
</span>
</div>

<div class="body">
{@html comment.content}
</div>

{#if comment.comments.length > 0}
<ul class="children">
{#each comment.comments as child}
<li><svelte:self comment={child} /></li>
{/each}
</ul>
{/if}
<article class="comment">
<details open>
<summary>
<div class="meta-bar" role="button" tabindex="0">
<span class="meta">
<a href="/user/{comment.user}">{comment.user}</a>
{comment.time_ago}
</span>
</div>
</summary>

<div class="body">
{@html comment.content}
</div>

{#if comment.comments.length > 0}
<ul class="children">
{#each comment.comments as child}
<li><svelte:self comment={child} /></li>
{/each}
</ul>
{/if}
</details>
</article>
{/if}

Expand All @@ -54,24 +50,28 @@
.meta-bar {
padding: 1em 0;
cursor: pointer;
background: 100% 50% no-repeat url(./fold.svg);
background: 100% 50% no-repeat url(./unfold.svg);
background-size: 1em 1em;
}
.hidden .meta-bar {
background-image: url(./unfold.svg);
.comment details[open] .meta-bar {
background-image: url(./fold.svg);
}
.comment .children {
padding: 0 0 0 1em;
margin: 0;
.comment details > summary {
list-style-type: none;
}
.hidden .body,
.hidden .children {
.comment details > summary::marker,
.comment details > summary::-webkit-details-marker {
display: none;
}
.comment .children {
padding: 0 0 0 1em;
margin: 0;
}
@media (min-width: 720px) {
.comment .children {
padding: 0 0 0 2em;
Expand Down

2 comments on commit 11e985f

@vercel
Copy link

@vercel vercel bot commented on 11e985f Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hn – ./sites/hn.svelte.dev

hn-svelte.vercel.app
hn.svelte.dev
sites-zeta.vercel.app
hn-git-master-svelte.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 11e985f Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

repl – ./packages/repl

repl-git-master-svelte.vercel.app
svelte-rappel.vercel.app
repl-svelte.vercel.app
repl-zeta.vercel.app

Please sign in to comment.