impr: use label based opening for disclosures

This commit is contained in:
Xylight committed 2025-09-23 17:42:18 -07:00
1 parent 24101665d0
commit 17d259de9c
12 files changed
+86 -47

No files matched your search

+10 -6
View File
@@ -40,15 +40,19 @@
<svelte:element
this={htmlElement}
{style}
class="{!expanded
? `overflow-hidden
bg-linear-to-b text-transparent from-slate-600 via-slate-600
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36`
: 'text-slate-600 dark:text-zinc-400 max-h-full'} text-base {clazz}"
class={[
expanded
? 'text-slate-600 dark:text-zinc-400 max-h-full'
: [
'overflow-hidden bg-linear-to-b text-transparent from-slate-600 via-slate-600',
'dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36',
],
clazz,
]}
class:pointer-events-none={!clickThrough}
bind:this={element}
>
<Markdown inline source={expanded ? body : body.slice(0, 1000)} />
<Markdown source={expanded ? body : body.slice(0, 1000)} />
{#if overflows}
<Button
onclick={() => (expanded = !expanded)}
+4 -3
View File
@@ -138,15 +138,16 @@
},
}: Props = $props()
setContext('options', rendererOptions)
setContext('options', { ...rendererOptions, inline: inline })
let tokens = $derived(marked.lexer(source))
</script>
<article
<svelte:element
this={inline ? 'div' : 'article'}
dir="auto"
class={[!noStyle && 'break-words space-y-4 leading-normal', clazz]}
{style}
>
<MdTree {tokens} renderers={inline ? inlineRenderers : renderers} />
</article>
</svelte:element>
@@ -30,6 +30,7 @@
<Material
padding="none"
rounding="2xl"
class="flex flex-col rounded-xl
divide-y divide-slate-200 dark:divide-zinc-800 overflow-hidden"
>
@@ -1,8 +1,12 @@
<script>
import { getContext } from 'svelte'
let { children } = $props()
const options = getContext('options')
</script>
<p class="leading-[1.7] break-words max-w">
<p class={[!options.inline && 'leading-[1.7] break-words max-w']}>
{@render children?.()}
</p>
@@ -5,11 +5,11 @@ export const spoilerPlugin = {
name: 'spoiler',
level: 'block',
start(src) {
return src.match(/^:::/)?.index
return src.match(/:::/)?.index
},
// eslint-disable-next-line
tokenizer(src, tokens) {
const rule = /^::: spoiler (.+)\n([\s\S]*?)\n:::/
const rule = /::: ?spoiler(?: ?(.*))\n([\s\S]*?)\n:::/
const match = rule.exec(src)
if (match) {
return {
@@ -24,11 +24,11 @@ export default function (tokensExtractor) {
name: 'container',
level: 'block',
start(src) {
return src.match(/^:::[^:\n]/)?.index
return src.match(/:::[^:\n]/)?.index
},
tokenizer(src) {
const rule =
/^:::[\s]?(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n|$)/i
/:::[\s]?(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n)*/i
const match = rule.exec(findRawContainer(src))
if (!match || !match.groups) return null
+5 -3
View File
@@ -37,7 +37,7 @@
{#if icon}
<div
class={[
'ml-auto ',
'ml-auto',
!open && 'rotate-90',
'transition-transform duration-300 ease-out',
]}
@@ -51,8 +51,10 @@
></div>
</div>
{/snippet}
{#if content}{@render content()}{:else}
<div class="pt-2 text-slate-900 dark:text-zinc-100">
{#if content}
{@render content()}
{:else}
<div class="text-slate-900 dark:text-zinc-100 *:mt-2">
{@render children?.()}
</div>
{/if}
+1 -1
View File
@@ -316,7 +316,7 @@
.btn-disabled {
pointer-events: none;
filter: brightness(70%);
filter: brightness(90%);
cursor: normal;
}
}
+26 -9
View File
@@ -1,8 +1,6 @@
<script lang="ts">
import type { Snippet } from 'svelte'
import { expoOut } from 'svelte/easing'
import type { ClassValue } from 'svelte/elements'
import { slide } from 'svelte/transition'
interface Props {
open?: boolean
@@ -20,16 +18,35 @@
children,
...rest
}: Props = $props()
const id = $props.id()
</script>
<div {...rest} class={['w-full', clazz]}>
<button onclick={() => (open = !open)} class="w-full">
<label for={id} class="w-full">
{@render summary?.({ open })}
</button>
</label>
{@render extended?.()}
{#if open}
<div transition:slide={{ axis: 'y', easing: expoOut, duration: 300 }}>
{@render children?.({ open })}
</div>
{/if}
<input {id} class="hidden input" type="checkbox" bind:checked={open} />
<div class="expand">
{@render children?.({ open })}
</div>
</div>
<style>
.expand {
display: grid;
grid-template-rows: 0fr;
grid-template-columns: 100%;
overflow: hidden;
transition: grid-template-rows 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}
.input:checked + .expand {
grid-template-rows: 1fr;
}
.expand > :global(*) {
min-height: 0;
}
</style>
+1 -1
View File
@@ -24,7 +24,7 @@
}
const roundedClass = {
none: 'rounded-none',
none: '',
sm: 'rounded-xs',
md: 'rounded-md',
lg: 'rounded-lg',