fix: recalculate overflow every time post body changes
This commit is contained in:
1 parent
6c0dfdca01
commit
8129fded76
2 files changed
+32
-24
No files matched your search
@@ -6,16 +6,22 @@
|
||||
|
||||
export let body: string
|
||||
export let view: View = 'cozy'
|
||||
let overflows = false
|
||||
let expanded = false
|
||||
let element: Element
|
||||
|
||||
function isOverflown(element: Element) {
|
||||
overflows =
|
||||
function isOverflown(element: Element, body: string = '') {
|
||||
if (!element) return
|
||||
let overflows =
|
||||
element.scrollHeight > element.clientHeight ||
|
||||
element.scrollWidth > element.clientWidth
|
||||
|
||||
if (!overflows) expanded = true
|
||||
else expanded = false
|
||||
|
||||
return overflows
|
||||
}
|
||||
|
||||
$: overflows = isOverflown(element, body)
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -26,7 +32,7 @@ bg-gradient-to-b text-transparent from-slate-600 via-slate-600
|
||||
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0
|
||||
${view == 'list' ? `max-h-24` : 'max-h-48'}`
|
||||
: 'text-slate-600 dark:text-zinc-400 max-h-full'} {$$props.class ?? ''}"
|
||||
use:isOverflown
|
||||
bind:this={element}
|
||||
>
|
||||
<Markdown inline={!expanded} source={body} />
|
||||
{#if overflows}
|
||||
|
||||
@@ -77,26 +77,28 @@
|
||||
{/key}
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="border-l h-6 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
||||
></div>
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex items-center gap-0.5 !pr-2.5 {buttonColor.secondary} transition-colors border-0
|
||||
{#if $site?.site_view.local_site.enable_downvotes ?? true}
|
||||
<div
|
||||
class="border-l h-6 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
||||
></div>
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex items-center gap-0.5 !pr-2.5 {buttonColor.secondary} transition-colors border-0
|
||||
{vote == -1 ? shouldShowVoteColor(vote, 'downvotes') : ''}"
|
||||
>
|
||||
<Icon src={ChevronDown} size="18" mini />
|
||||
<span class="grid text-sm">
|
||||
{#key downvotes}
|
||||
<span
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
in:fly={{ duration: 200, y: -6 }}
|
||||
out:fly={{ duration: 200, y: 6 }}
|
||||
>
|
||||
<FormattedNumber number={downvotes} />
|
||||
</span>
|
||||
{/key}
|
||||
</span>
|
||||
</button>
|
||||
>
|
||||
<Icon src={ChevronDown} size="18" mini />
|
||||
<span class="grid text-sm">
|
||||
{#key downvotes}
|
||||
<span
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
in:fly={{ duration: 200, y: -6 }}
|
||||
out:fly={{ duration: 200, y: 6 }}
|
||||
>
|
||||
<FormattedNumber number={downvotes} />
|
||||
</span>
|
||||
{/key}
|
||||
</span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</slot>
|
||||
Reference in new issue
Block a user