feat: dont show expand button if post body length is below maximum height
This commit is contained in:
1 parent
fbf3b95bfe
commit
2a73e22b06
2 files changed
+28
-16
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user