style: update mobile ToC styling

This commit is contained in:
Youwen Wu 2024-04-07 00:04:58 -07:00
parent f6a6af79f5
commit 9f2c27d429
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
4 changed files with 65 additions and 59 deletions

View file

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { ChevronRight } from 'svelte-radix'; import { ChevronRight } from 'svelte-radix';
import PostMetadata from './PostMetadata.svelte'; import PostMetadata from './PostMetadata.svelte';
import Separator from '../ui/separator/separator.svelte';
export let doc: BlogDocument; export let doc: BlogDocument;
</script> </script>
@ -12,7 +11,8 @@
<ChevronRight class="h-4 w-4" /> <ChevronRight class="h-4 w-4" />
<div class="font-medium text-foreground">{doc.title}</div> <div class="font-medium text-foreground">{doc.title}</div>
</div> </div>
<header class="space-y-2"> <header class="space-y-6">
<div class="space-y-2">
<h1 class="scroll-m-20 text-5xl font-bold font-serif tracking-tight"> <h1 class="scroll-m-20 text-5xl font-bold font-serif tracking-tight">
{doc.title} {doc.title}
</h1> </h1>
@ -28,7 +28,8 @@
length={doc.content.length} length={doc.content.length}
reverseDateAndRest reverseDateAndRest
/> />
<slot name="toc" /> </div>
<slot name="mobile-toc" />
</header> </header>
<div class="markdown-body mt-8 font-serif"> <div class="markdown-body mt-8 font-serif">

View file

@ -0,0 +1,40 @@
<script lang="ts">
import { toclink, type TocStore } from '@svelte-put/toc';
import * as Accordion from '$lib/components/ui/accordion';
import * as Card from '$lib/components/ui/card';
export let tocStore: TocStore;
const calcTextClasses = (el: HTMLElement) => {
if (el.tagName === 'H1') return 'text-xl font-medium';
if (el.tagName === 'H2') return 'text-lg';
return 'text-sm text-muted-foreground';
};
</script>
<Card.Root class="lg:hidden">
<Card.Content>
<Accordion.Root>
<Accordion.Item value="toc">
<Accordion.Trigger>
<p class="text-lg">On this page</p>
</Accordion.Trigger>
<Accordion.Content>
{#if $tocStore.items.size}
<ol class="border-l-4 border-l-muted px-4">
{#each $tocStore.items.values() as tocItem}
<li class="py-0.5">
<!-- svelte-ignore a11y-missing-attribute a11y-missing-content -->
<a
use:toclink={{ store: tocStore, tocItem, observe: true }}
class={`${calcTextClasses(tocItem.element)}`}
/>
</li>
{/each}
</ol>
{/if}
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
</Card.Content>
</Card.Root>

View file

@ -14,7 +14,7 @@
<Card.Root> <Card.Root>
<Card.Header> <Card.Header>
<Card.Title><h2 class="text-lg xl:text-xl">On this page</h2></Card.Title> <Card.Title><h2 class="text-lg xl:text-xl font-serif">On this page</h2></Card.Title>
</Card.Header> </Card.Header>
<Card.Content> <Card.Content>
{#if $tocStore.items.size} {#if $tocStore.items.size}

View file

@ -1,14 +1,9 @@
<script lang="ts"> <script lang="ts">
import ChevronRight from 'svelte-radix/ChevronRight.svelte'; import MobileToc from '$lib/components/Toc/MobileToc.svelte';
import Code from 'svelte-radix/Code.svelte';
import type { PageData } from './$types'; import type { PageData } from './$types';
// import { config } from '$lib/stores/index.js';
import Article from '$lib/components/Blog/Article.svelte'; import Article from '$lib/components/Blog/Article.svelte';
import { toc, createTocStore, toclink } from '@svelte-put/toc'; import { toc, createTocStore } from '@svelte-put/toc';
import StickyToc from '$lib/components/Toc/StickyToc.svelte'; import StickyToc from '$lib/components/Toc/StickyToc.svelte';
import { onMount } from 'svelte';
import * as Accordion from '$lib/components/ui/accordion';
import * as Card from '$lib/components/ui/card';
const tocStore = createTocStore(); const tocStore = createTocStore();
@ -24,13 +19,6 @@
description: description:
'An insightful and longer description of the post. This should be a bit more detailed than the blurb. It should give the reader a good idea of what the post is about.' 'An insightful and longer description of the post. This should be a bit more detailed than the blurb. It should give the reader a good idea of what the post is about.'
}; };
const calcTextClasses = (el: HTMLElement) => {
if (el.tagName === 'H1') return 'text-xl font-medium';
if (el.tagName === 'H2') return 'text-lg';
return 'text-sm text-muted-foreground';
};
// $: doc = data.metadata; // $: doc = data.metadata;
// $: componentSource = data.metadata.source?.replace('default', $config.style ?? 'default'); // $: componentSource = data.metadata.source?.replace('default', $config.style ?? 'default');
</script> </script>
@ -55,32 +43,9 @@
}} }}
> >
<Article {doc}> <Article {doc}>
<Card.Root slot="toc" class="lg:hidden"> <svelte:fragment slot="mobile-toc">
<Card.Content> <MobileToc {tocStore} />
<Accordion.Root> </svelte:fragment>
<Accordion.Item value="toc">
<Accordion.Trigger>
<p>On this page</p>
</Accordion.Trigger>
<Accordion.Content>
{#if $tocStore.items.size}
<ol class="border-l-2 border-l-blue-500 px-4">
{#each $tocStore.items.values() as tocItem}
<li class="py-0.5">
<!-- svelte-ignore a11y-missing-attribute a11y-missing-content -->
<a
use:toclink={{ store: tocStore, tocItem, observe: true }}
class={`${calcTextClasses(tocItem.element)}`}
/>
</li>
{/each}
</ol>
{/if}
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
</Card.Content>
</Card.Root>
</Article> </Article>
</main> </main>