feat: dont show expand button if post body length is below maximum height

This commit is contained in:
Xylight committed 2024-02-10 12:07:24 -08:00
1 parent fbf3b95bfe
commit 2a73e22b06
2 files changed
+28 -16

No files matched your search

+27 -15
View File
@@ -6,7 +6,16 @@
export let body: string
export let view: View = 'cozy'
let overflows = false
let expanded = false
function isOverflown(element: Element) {
overflows =
element.scrollHeight > element.clientHeight ||
element.scrollWidth > element.clientWidth
if (!overflows) expanded = true
}
</script>
<div
@@ -17,21 +26,24 @@ 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'}
use:isOverflown
>
<Markdown inline={!expanded} source={body} />
<Button
on:click={() => (expanded = !expanded)}
size="square-sm"
color="tertiary"
class="text-black dark:text-white absolute z-10 isolate drop-shadow-xl {expanded
? 'bottom-6'
: 'bottom-16'} left-1/2 -translate-x-1/2"
>
<Icon
src={ChevronDown}
size="20"
mini
class="{expanded ? 'rotate-180' : ''} transition-transform"
/>
</Button>
{#if overflows}
<Button
on:click={() => (expanded = !expanded)}
size="square-sm"
color="tertiary"
class="text-black dark:text-white absolute z-10 isolate drop-shadow-xl {expanded
? 'bottom-6'
: 'bottom-16'} left-1/2 -translate-x-1/2"
>
<Icon
src={ChevronDown}
size="20"
mini
class="{expanded ? 'rotate-180' : ''} transition-transform"
/>
</Button>
{/if}
</div>
+1 -1
View File
@@ -53,7 +53,7 @@
<nav
class="flex flex-row gap-2 items-center
backdrop-blur-sm w-full mx-auto px-4 py-2 z-50 box-border h-16
backdrop-blur-lg w-full mx-auto px-4 py-2 z-50 box-border h-16
{$$props.class}
"
style={$$props.style}