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 body: string
|
||||||
export let view: View = 'cozy'
|
export let view: View = 'cozy'
|
||||||
|
let overflows = false
|
||||||
let expanded = false
|
let expanded = false
|
||||||
|
|
||||||
|
function isOverflown(element: Element) {
|
||||||
|
overflows =
|
||||||
|
element.scrollHeight > element.clientHeight ||
|
||||||
|
element.scrollWidth > element.clientWidth
|
||||||
|
|
||||||
|
if (!overflows) expanded = true
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<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
|
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0
|
||||||
${view == 'list' ? `max-h-24` : 'max-h-48'}`
|
${view == 'list' ? `max-h-24` : 'max-h-48'}`
|
||||||
: 'text-slate-600 dark:text-zinc-400 max-h-full'}
|
: 'text-slate-600 dark:text-zinc-400 max-h-full'}
|
||||||
|
use:isOverflown
|
||||||
>
|
>
|
||||||
<Markdown inline={!expanded} source={body} />
|
<Markdown inline={!expanded} source={body} />
|
||||||
<Button
|
{#if overflows}
|
||||||
on:click={() => (expanded = !expanded)}
|
<Button
|
||||||
size="square-sm"
|
on:click={() => (expanded = !expanded)}
|
||||||
color="tertiary"
|
size="square-sm"
|
||||||
class="text-black dark:text-white absolute z-10 isolate drop-shadow-xl {expanded
|
color="tertiary"
|
||||||
? 'bottom-6'
|
class="text-black dark:text-white absolute z-10 isolate drop-shadow-xl {expanded
|
||||||
: 'bottom-16'} left-1/2 -translate-x-1/2"
|
? 'bottom-6'
|
||||||
>
|
: 'bottom-16'} left-1/2 -translate-x-1/2"
|
||||||
<Icon
|
>
|
||||||
src={ChevronDown}
|
<Icon
|
||||||
size="20"
|
src={ChevronDown}
|
||||||
mini
|
size="20"
|
||||||
class="{expanded ? 'rotate-180' : ''} transition-transform"
|
mini
|
||||||
/>
|
class="{expanded ? 'rotate-180' : ''} transition-transform"
|
||||||
</Button>
|
/>
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
<nav
|
<nav
|
||||||
class="flex flex-row gap-2 items-center
|
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}
|
{$$props.class}
|
||||||
"
|
"
|
||||||
style={$$props.style}
|
style={$$props.style}
|
||||||
|
|||||||
Reference in new issue
Block a user