refactor: Add GroupedListContent and enhance GroupedList components

This commit is contained in:
Shibo Lyu 2025-04-12 04:17:59 +08:00
parent 39de2176fa
commit a5e1a07e69
3 changed files with 38 additions and 19 deletions

View file

@ -0,0 +1,14 @@
<script lang="ts">
import { tw } from '$lib/tw';
interface Props {
class?: string;
children?: import('svelte').Snippet;
}
let { children, class: classNames }: Props = $props();
</script>
<div class={tw('px-4 py-3', classNames)}>
{@render children?.()}
</div>

View file

@ -1,8 +1,8 @@
<script lang="ts"> <script lang="ts">
interface Props { interface Props {
header?: import('svelte').Snippet; header?: import('svelte').Snippet | string;
children?: import('svelte').Snippet; children?: import('svelte').Snippet;
footer?: import('svelte').Snippet; footer?: import('svelte').Snippet | string;
} }
let { header, children, footer }: Props = $props(); let { header, children, footer }: Props = $props();
@ -10,18 +10,26 @@
<section class="my-6 cursor-default px-4"> <section class="my-6 cursor-default px-4">
{#if header} {#if header}
<h3 class="mb-1 truncate px-4 text-sm font-medium uppercase text-sf-tertiary"> <h3 class="text-sf-tertiary mb-1 truncate px-4 text-sm font-medium uppercase">
{@render header?.()} {#if typeof header === 'string'}
{header}
{:else}
{@render header?.()}
{/if}
</h3> </h3>
{/if} {/if}
<div <div
class="divide-y-[0.5px] divide-ss-secondary overflow-hidden rounded-lg border-[0.5px] border-ss-secondary bg-sb-primary shadow-xs" class="divide-ss-secondary border-ss-secondary bg-sb-primary divide-y-[0.5px] overflow-hidden rounded-lg border-[0.5px] shadow-xs"
> >
{@render children?.()} {@render children?.()}
</div> </div>
{#if footer} {#if footer}
<div class="mt-1 px-4 text-sm text-sf-tertiary"> <div class="text-sf-tertiary mt-1 px-4 text-sm">
{@render footer?.()} {#if typeof footer === 'string'}
{footer}
{:else}
{@render footer?.()}
{/if}
</div> </div>
{/if} {/if}
</section> </section>

View file

@ -15,9 +15,9 @@
import RichTextInput from '$lib/components/RichTextInput.svelte'; import RichTextInput from '$lib/components/RichTextInput.svelte';
import Link from '$lib/components/Link.svelte'; import Link from '$lib/components/Link.svelte';
import type { BlahProfile } from '@blah-im/core/identity'; import type { BlahProfile } from '@blah-im/core/identity';
import { onMount } from 'svelte';
import type { Node } from 'prosemirror-model'; import type { Node } from 'prosemirror-model';
import { messageSchema } from '$lib/components/RichTextInput/schema'; import { messageSchema } from '$lib/components/RichTextInput/schema';
import GroupedListContent from '$lib/components/GroupedList/GroupedListContent.svelte';
let name: string = $state(''); let name: string = $state('');
let bioDoc: Node | null = $state(null); let bioDoc: Node | null = $state(null);
@ -64,7 +64,7 @@
<GroupedListContainer> <GroupedListContainer>
<GroupedListSection> <GroupedListSection>
<GroupedListItem> <GroupedListContent class="flex items-center">
<ProfilePicture size={64} account={undefined} /> <ProfilePicture size={64} account={undefined} />
<input <input
type="text" type="text"
@ -73,24 +73,22 @@
disabled={isBusy} disabled={isBusy}
class="caret-accent-500 ms-3 flex-1 bg-transparent text-lg leading-loose outline-hidden placeholder:opacity-50" class="caret-accent-500 ms-3 flex-1 bg-transparent text-lg leading-loose outline-hidden placeholder:opacity-50"
/> />
</GroupedListItem> </GroupedListContent>
</GroupedListSection> </GroupedListSection>
<GroupedListSection> <GroupedListSection
{#snippet header()}Bio{/snippet} header="Bio"
footer="Introduce yourself. This will be public for everyone to see."
>
<RichTextInput <RichTextInput
schema={messageSchema} schema={messageSchema}
onDocChange={(newDoc) => (bioDoc = newDoc)} onDocChange={(newDoc) => (bioDoc = newDoc)}
class="p-4 shadow-none ring-0" class="p-4 shadow-none ring-0"
placeholder="a 25 yo. artist from Paris." placeholder="a 25 yo. artist from Paris."
/> />
{#snippet footer()}
<p>Introduce yourself. This will be public for everyone to see.</p>
{/snippet}
</GroupedListSection> </GroupedListSection>
<GroupedListSection> <GroupedListSection header="Security">
{#snippet header()}Security{/snippet}
<GroupedListInputItem> <GroupedListInputItem>
Password Password
<input type="password" bind:value={password} placeholder="Password" disabled={isBusy} /> <input type="password" bind:value={password} placeholder="Password" disabled={isBusy} />
@ -117,8 +115,7 @@
{/snippet} {/snippet}
</GroupedListSection> </GroupedListSection>
{#if customize} {#if customize}
<GroupedListSection> <GroupedListSection header="Identity Service">
{#snippet header()}Identity Service{/snippet}
<GroupedListInputItem> <GroupedListInputItem>
Initial Service Initial Service
<input type="text" bind:value={identityServer} /> <input type="text" bind:value={identityServer} />