design: add unified notifications button
This commit is contained in:
8 files changed
+112
-76
No files matched your search
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { Button, buttonColor } from 'mono-svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
label: string
|
||||
@@ -35,31 +35,30 @@
|
||||
color="none"
|
||||
{...rest}
|
||||
class={[
|
||||
'shrink-0 rounded-full w-10 h-10 lg:w-max lg:h-8 lg:px-3 lg:rounded-xl',
|
||||
isSelected &&
|
||||
'bg-slate-200 dark:bg-zinc-900 text-primary-900 dark:text-primary-100!',
|
||||
!rest.color && buttonColor.tertiary,
|
||||
'shrink-0 rounded-full w-10 h-10 lg:w-max lg:h-8 lg:rounded-xl',
|
||||
!rest.color &&
|
||||
'lg:bg-white lg:dark:bg-zinc-900 border lg:border-slate-200 lg:border-b-slate-300 lg:dark:border-zinc-800 lg:dark:border-t-zinc-700/50 lg:hover:bg-slate-100 lg:dark:hover:bg-zinc-800 lg:active:bg-slate-200 lg:dark:active:bg-zinc-950',
|
||||
'hover:text-slate-900 dark:hover:text-zinc-50 transition-colors',
|
||||
isSelected
|
||||
? 'text-primary-900 dark:text-primary-100 max-lg:bg-slate-100 max-lg:dark:bg-zinc-800'
|
||||
: 'text-slate-600 dark:text-zinc-400',
|
||||
clazz,
|
||||
]}
|
||||
shadow="none"
|
||||
size="custom"
|
||||
rounding="none"
|
||||
{href}
|
||||
title={label}
|
||||
style="transition-property: background-color, filter;"
|
||||
aria-selected={isSelected}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
{#if icon}
|
||||
<div class="lg:hidden">
|
||||
<Icon src={icon} size="18" />
|
||||
</div>
|
||||
<div class="max-lg:hidden">
|
||||
<Icon src={icon} micro solid={isSelected} size="16" />
|
||||
</div>
|
||||
{:else}
|
||||
{@render customIcon?.({ size: 16, isSelected })}
|
||||
{/if}
|
||||
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
|
||||
{#if icon}
|
||||
<Icon src={icon} size="20" />
|
||||
{:else}
|
||||
{@render customIcon?.({ size: 16, isSelected })}
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
<span class="hidden {adaptive ? 'lg:block' : ''}">{label}</span>
|
||||
{@render children?.()}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { notifications, profile } from '$lib/auth.svelte.js'
|
||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
@@ -9,15 +8,18 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import { site } from '$lib/lemmy.svelte.js'
|
||||
import { Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
||||
import { Badge, Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
Bell,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
Inbox,
|
||||
MagnifyingGlass,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
ServerStack,
|
||||
ShieldCheck,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import Logo from '../Logo.svelte'
|
||||
@@ -34,6 +36,15 @@
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#snippet notifBadge(number: number)}
|
||||
<Badge
|
||||
color={number > 0 ? 'red-subtle' : 'gray-subtle'}
|
||||
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
||||
>
|
||||
{number > 99 ? '∞' : number}
|
||||
</Badge>
|
||||
{/snippet}
|
||||
|
||||
<CommandsWrapper bind:open={promptOpen} />
|
||||
<nav
|
||||
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border p-0.5
|
||||
@@ -71,7 +82,7 @@
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
<div
|
||||
class="flex flex-row gap-2 py-2 px-2 items-center w-full overflow-auto"
|
||||
class="flex flex-row gap-2 lg:gap-5 py-2 px-2 items-center w-full overflow-auto"
|
||||
style="border-radius: inherit;"
|
||||
>
|
||||
<div class="ml-auto"></div>
|
||||
@@ -82,29 +93,15 @@
|
||||
icon={ServerStack}
|
||||
class="relative"
|
||||
isSelectedFilter={path => path.startsWith('/admin')}
|
||||
>
|
||||
{#if ($notifications.applications ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
></div>
|
||||
{/if}
|
||||
</NavButton>
|
||||
/>
|
||||
{/if}
|
||||
{#if amModOfAny(profile.data?.user)}
|
||||
<NavButton
|
||||
href="/moderation"
|
||||
label={$t('nav.moderation')}
|
||||
class="relative"
|
||||
>
|
||||
{#if ($notifications.reports ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
></div>
|
||||
{/if}
|
||||
{#snippet customIcon({ size, isSelected })}
|
||||
<ShieldIcon filled={isSelected} width={size} />
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
icon={ShieldCheck}
|
||||
/>
|
||||
{/if}
|
||||
<NavButton
|
||||
href="/communities"
|
||||
@@ -112,13 +109,58 @@
|
||||
icon={GlobeAlt}
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
{#if profile.data.jwt}
|
||||
{@const linkOnly =
|
||||
!profile.data.user ||
|
||||
!(isAdmin(profile.data.user) || amModOfAny(profile.data.user))}
|
||||
<Menu manual={linkOnly} placement="top">
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
label={$t('nav.notifications')}
|
||||
icon={Bell}
|
||||
class="relative"
|
||||
adaptive={false}
|
||||
href={linkOnly ? '/inbox' : undefined}
|
||||
>
|
||||
{#if Math.max(...Object.values($notifications)) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-1 left-3 z-10"
|
||||
></div>
|
||||
{/if}
|
||||
</NavButton>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.notifications')}</MenuDivider>
|
||||
<MenuButton href="/inbox" icon={Inbox}>
|
||||
{$t('profile.inbox')}
|
||||
{#snippet suffix()}
|
||||
{@render notifBadge($notifications.inbox)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{#if amModOfAny(profile.data.user)}
|
||||
<MenuButton href="/moderation" icon={ShieldCheck}>
|
||||
{$t('routes.moderation.reports')}
|
||||
{#snippet suffix()}
|
||||
{@render notifBadge($notifications.reports)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.user && isAdmin(profile.data.user)}
|
||||
<MenuButton href="/admin/applications" icon={ServerStack}>
|
||||
{$t('routes.admin.applications.title')}
|
||||
{#snippet suffix()}
|
||||
{@render notifBadge($notifications.applications)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
{/if}
|
||||
<Menu placement="top">
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
class="relative"
|
||||
color="primary"
|
||||
label={$t('nav.create.label')}
|
||||
icon={Plus}
|
||||
adaptive={false}
|
||||
/>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||
|
||||
@@ -80,11 +80,6 @@
|
||||
alt={profile.data.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{#if $notifications.inbox > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
||||
></div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
|
||||
Reference in new issue
Block a user