design: use commonlist in sidebars

This commit is contained in:
James Xylight committed 2025-08-20 20:48:50 -07:00
1 parent bf0d4cf238
commit 9e9fc326b8
9 files changed
+216 -69

No files matched your search

@@ -44,8 +44,8 @@
onedit,
onhide,
}: Props = $props()
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
let buttonHeight = $derived(view == 'compact' ? 'h-7.5' : 'h-8')
let buttonSquare = $derived(view == 'compact' ? 'w-7.5 h-7.5' : 'w-8 h-8')
</script>
{#if editing}
@@ -39,23 +39,6 @@
let { post, onhide, editing = $bindable() }: Props = $props()
</script>
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
<MenuButton link href={userLink(post.creator)}>
{#snippet prefix()}
<Icon src={UserCircle} size="16" micro class="shrink-0" />
{/snippet}
<TextProps wrap="no-wrap">
{post.creator.name}
</TextProps>
</MenuButton>
<MenuButton link href={communityLink(post.community)}>
{#snippet prefix()}
<Icon src={Newspaper} size="16" micro class="shrink-0" />
{/snippet}
<TextProps wrap="no-wrap">
{post.community.title}
</TextProps>
</MenuButton>
<MenuDivider>
{$t('post.actions.more.actions')}
</MenuDivider>
+5 -5
View File
@@ -34,15 +34,15 @@
{@render title?.(open)}
</div>
{#if icon}
<Icon
src={open ? Minus : Plus}
size="16"
micro
<div
class={[
'ml-auto ',
!open && 'rotate-90',
'transition-transform duration-300 ease-out',
]}
/>
>
<Icon src={open ? Minus : Plus} size="16" micro class={[]} />
</div>
{/if}
<div
class="inset-0 -z-10 opacity-0 absolute bg-slate-200 dark:bg-zinc-900 rounded-full
+46 -10
View File
@@ -1,10 +1,12 @@
<script lang="ts" generics="T">
import type { Snippet } from 'svelte'
import type { ClassValue } from 'svelte/elements'
const sizeDelay: Record<'lg' | 'md' | 'sm', number> = {
const sizeDelay: Record<'lg' | 'md' | 'sm' | 'xs', number> = {
lg: 120,
md: 80,
sm: 40,
xs: 0,
}
interface Props {
@@ -12,7 +14,9 @@
item?: Snippet<[T, number]>
children?: Snippet
animate?: boolean
size?: 'lg' | 'md' | 'sm'
size?: 'lg' | 'md' | 'sm' | 'xs'
class?: ClassValue
selected?: (item: T) => boolean
}
let {
@@ -21,6 +25,8 @@
children,
animate = true,
size = 'sm',
class: clazz,
selected,
}: Props = $props()
</script>
@@ -28,7 +34,13 @@
{#if items}
{#each items as item, index (item)}
<li
class={['group/li', animate && 'animate']}
class={[
'group/li',
animate && 'animate',
size == 'xs' && 'xs',
selected?.(item) && 'selected',
clazz,
]}
style="--i: {index < 10 ? index * sizeDelay[size] : 0}ms;"
>
{@render itemSnippet?.(item, index)}
@@ -40,8 +52,6 @@
<style>
ul > :global(li) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
transition: background-color 0.1s;
background-color: var(--color-white);
container-type: inline-size;
@@ -60,13 +70,39 @@
&:hover {
background-color: var(--color-slate-25);
}
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
}
@media screen and (min-width: 40rem) {
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
}
.xs {
padding-block: calc(var(--spacing) * 0.5);
padding-block: calc(var(--spacing) * 1);
}
}
@media screen and (min-width: 40rem) {
ul > :global(li) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
ul > :global(li).selected {
background-color: color-mix(
in oklab,
var(--color-white),
var(--color-slate-100)
);
}
:global(.dark) ul > :global(li).selected {
background-color: color-mix(
in oklab,
var(--color-zinc-925),
var(--color-zinc-800)
);
}
:global(.dark) ul > :global(li) {
@@ -54,7 +54,7 @@
{#snippet prefix()}
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
{#if icon}
<Icon src={icon} size="20" />
<Icon src={icon} size="20" mini />
{:else}
{@render customIcon?.({ size: 16, isSelected })}
{/if}
+46 -31
View File
@@ -18,6 +18,9 @@
} from 'svelte-hero-icons'
import EndPlaceholder from '../EndPlaceholder.svelte'
import type { ClassValue } from 'svelte/elements'
import CommonList from '../layout/CommonList.svelte'
import { communityLink } from '$lib/lemmy/generic'
import Avatar from '../Avatar.svelte'
interface Props {
style?: string
@@ -104,40 +107,24 @@
</EndPlaceholder>
</span>
{/snippet}
<div class="w-full flex gap-px flex-col">
{#each [...profile.meta.profiles] as prof, index}
<div class="w-full">
<ProfileButton {index} {prof} />
</div>
{/each}
</div>
<CommonList
size="xs"
animate={false}
items={profile.meta.profiles}
class="px-1 py-0.5"
selected={prof => prof.id == profile.meta.profile}
>
{#snippet item(prof, index)}
<ProfileButton {index} {prof} />
{/snippet}
</CommonList>
<div class="my-2"></div>
<SidebarButton href="/accounts" icon={UserGroup}>
{$t('account.accounts')}
</SidebarButton>
</Expandable>
{/if}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{#if profile.current?.favorites && profile.current?.favorites.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.favorites}
>
{#snippet title()}
<span class="px-2 py-1 w-full">
<EndPlaceholder>
{$t('routes.profile.favorites')}
{#snippet action()}
<span class="dark:text-white text-black">
{profile.current.favorites?.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList isFavorites items={profile.current.favorites} />
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{/if}
{#if profile.current?.user}
{#if profile.current?.user.moderates.length > 0}
<Expandable
@@ -179,9 +166,37 @@
</EndPlaceholder>
</span>
{/snippet}
<CommunityList
items={profile.current.user.follows.map(i => i.community)}
/>
<CommonList
animate={false}
size="xs"
items={profile.current.user.follows}
class="px-1 py-0.5"
>
{#snippet item(follow)}
<SidebarButton
class="font-normal w-full h-max"
color="none"
alignment="left"
href={communityLink(follow.community)}
>
{#snippet customIcon()}
<Avatar
url={follow.community.icon}
alt={follow.community.name}
title={follow.community.title}
width={28}
/>{/snippet}
{#snippet label()}
<div class="flex flex-col max-w-full break-words">
<span>{follow.community.title}</span>
<span class="text-xs text-slate-600 dark:text-zinc-400">
{new URL(follow.community.actor_id).hostname}
</span>
</div>
{/snippet}
</SidebarButton>
{/snippet}
</CommonList>
</Expandable>
{/if}
</nav>
@@ -46,7 +46,7 @@
{#if customIcon}
{@render customIcon({ selected })}
{:else if icon}
<Icon src={icon} solid={selected} size="20" />
<Icon src={icon} solid size="20" />
{/if}
{/snippet}
{@render children?.()}
+2 -2
View File
@@ -125,12 +125,12 @@
{...rest}
tabindex={disabled ? -1 : undefined}
class={[
loading ? buttonColor.secondary : buttonColor[color],
buttonSize[size],
buttonRounding[rounding],
buttonShadow[shadow],
buttonColor[color],
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
disabled && 'pointer-events-none opacity-50 shadow-none',
(disabled || loading) && 'pointer-events-none opacity-50 shadow-none',
alignment == 'center'
? 'origin-center'
: alignment == 'left'