cleanup: switch to a css-based navbar (#491)
* cleanup: remove dock options and make adaptive by default * cleanup: switch to css-based navbar * feat: add auto hide option
This commit is contained in:
1 parent
b5ce17308a
commit
10f0ed208f
17 files changed
+110
-261
No files matched your search
@@ -1,100 +1,8 @@
|
||||
<script lang="ts" module>
|
||||
import { innerWidth } from 'svelte/reactivity/window'
|
||||
|
||||
const calculateDockProperties = (
|
||||
settings: {
|
||||
top: boolean | null
|
||||
noGap: boolean | null
|
||||
},
|
||||
screenWidth: number,
|
||||
): {
|
||||
noGap: boolean
|
||||
top: boolean
|
||||
} => {
|
||||
let panel = false
|
||||
let top = false
|
||||
|
||||
if (screenWidth >= 1000) {
|
||||
panel = true
|
||||
top = true
|
||||
} else if (screenWidth > 800) {
|
||||
panel = true
|
||||
top = false
|
||||
} else if (screenWidth > 600) {
|
||||
panel = false
|
||||
top = false
|
||||
}
|
||||
|
||||
panel = settings.noGap ?? panel
|
||||
top = settings.top ?? top
|
||||
|
||||
return {
|
||||
noGap: panel,
|
||||
top: top,
|
||||
}
|
||||
}
|
||||
|
||||
export const calculatePadding = (
|
||||
panel: boolean,
|
||||
top: boolean,
|
||||
content: boolean,
|
||||
): {
|
||||
top: number
|
||||
bottom: number
|
||||
class: string
|
||||
} => {
|
||||
if (panel) {
|
||||
if (top) {
|
||||
if (content) return { top: 80, class: '!pt-20', bottom: 0 }
|
||||
else
|
||||
return {
|
||||
top: 64,
|
||||
class: 'top-16 !max-h-[calc(100vh-4rem)]',
|
||||
bottom: 0,
|
||||
}
|
||||
} else return { top: 0, class: '!pb-20', bottom: 80 }
|
||||
} else {
|
||||
if (!content) return { top: 0, class: '', bottom: 0 }
|
||||
|
||||
if (top) return { top: 96, class: '!pt-24', bottom: 0 }
|
||||
else return { top: 0, class: '!pb-24', bottom: 96 }
|
||||
}
|
||||
|
||||
return { top: 0, class: ' failed-to-calculate', bottom: 0 }
|
||||
}
|
||||
|
||||
export let screenWidth = writable(1000)
|
||||
|
||||
let dockProps = $derived(
|
||||
calculateDockProperties(settings.dock, innerWidth.current ?? 1000),
|
||||
)
|
||||
let contentPadding = $derived(
|
||||
calculatePadding(dockProps.noGap, dockProps.top, true),
|
||||
)
|
||||
|
||||
let contentPaddingStore = writable<{
|
||||
top: number
|
||||
bottom: number
|
||||
class: string
|
||||
}>(contentPadding)
|
||||
let dockPropsStore = writable<{
|
||||
noGap: boolean
|
||||
top: boolean
|
||||
}>(dockProps)
|
||||
|
||||
let sidePadding = $derived(
|
||||
calculatePadding(dockProps.noGap, dockProps.top, false),
|
||||
)
|
||||
let topPanel = $derived(dockProps.noGap && dockProps.top)
|
||||
|
||||
export { contentPaddingStore as contentPadding, dockPropsStore as dockProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { writable, type Readable, type Writable } from 'svelte/store'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import type { ClassValue, UIEventHandler } from 'svelte/elements'
|
||||
import { scrollY } from 'svelte/reactivity/window'
|
||||
|
||||
interface Props {
|
||||
route?: { id: string | null } | undefined
|
||||
@@ -118,12 +26,23 @@
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
contentPaddingStore.set(contentPadding)
|
||||
dockPropsStore.set(dockProps)
|
||||
})
|
||||
let previousTop = 0
|
||||
const onscroll: UIEventHandler<Window> = (e) => {
|
||||
if (!settings.dock.autoHide) {
|
||||
dockVisible = true
|
||||
return
|
||||
}
|
||||
|
||||
dockVisible = (scrollY?.current ?? 0) <= previousTop
|
||||
|
||||
previousTop = scrollY?.current ?? 0
|
||||
}
|
||||
|
||||
let dockVisible = $state(true)
|
||||
</script>
|
||||
|
||||
<svelte:window {onscroll} />
|
||||
|
||||
<div
|
||||
{...rest}
|
||||
class="shell bg-slate-50 dark:bg-zinc-950 {clazz}"
|
||||
@@ -131,34 +50,18 @@
|
||||
>
|
||||
{@render children?.()}
|
||||
<div
|
||||
class="
|
||||
{dockProps.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'}
|
||||
{dockProps.top ? 'top-0' : 'bottom-0'}
|
||||
{topPanel ? 'fixed top-0' : 'fixed'}
|
||||
class="fixed lg:sticky bottom-0 {dockVisible
|
||||
? ''
|
||||
: 'max-lg:-bottom-24'} lg:top-0
|
||||
max-w-3xl p-4 left-1/2 -translate-x-1/2 lg:max-w-full lg:p-0 lg:left-0 lg:translate-x-0
|
||||
w-full z-50 pointer-events-none"
|
||||
style="grid-area: navbar;
|
||||
transition-property: padding, top, bottom;
|
||||
transition-duration: 250ms;
|
||||
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);"
|
||||
transition: bottom .4s cubic-bezier(0.075, 0.82, 0.165, 1);"
|
||||
>
|
||||
{@render navbar?.({
|
||||
class: `
|
||||
${
|
||||
dockProps.noGap
|
||||
? dockProps.top
|
||||
? 'border-b shadow-none rounded-none'
|
||||
: 'border-t rounded-none'
|
||||
: 'border rounded-full'
|
||||
}
|
||||
|
||||
dark:bg-transparent transition-colors duration-500
|
||||
pointer-events-auto backdrop-blur-xl ${
|
||||
topPanel
|
||||
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||
bg-white/50 dark:bg-zinc-950/70`
|
||||
}`,
|
||||
style: 'transition: border-radius 250ms;',
|
||||
class: `bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900
|
||||
pointer-events-auto backdrop-blur-xl border lg:border-t-0 lg:border-x-0
|
||||
rounded-full lg:rounded-none`,
|
||||
})}
|
||||
</div>
|
||||
<div
|
||||
@@ -168,17 +71,16 @@
|
||||
>
|
||||
{@render sidebar?.({
|
||||
class: `hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||
z-40
|
||||
${sidePadding.class}`,
|
||||
z-40 lg:top-16`,
|
||||
style: 'grid-area: sidebar; width: 100% !important;',
|
||||
})}
|
||||
{@render main?.({
|
||||
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||
${contentPadding.class} main`,
|
||||
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0 main !pb-22 lg:!pb-0`,
|
||||
style: 'grid-area: main',
|
||||
})}
|
||||
{@render suffix?.({
|
||||
class: `max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 ${sidePadding.class}`,
|
||||
class: `max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950
|
||||
z-40 lg:top-16`,
|
||||
style: 'grid-area: suffix;',
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { contentPadding } from '../Shell.svelte'
|
||||
|
||||
interface Props {
|
||||
pageHeader?: boolean
|
||||
@@ -24,14 +23,11 @@
|
||||
{pageHeader
|
||||
? `w-[calc(100%+2rem)] sm:w-[calc(100%+3rem)]
|
||||
bg-slate-50 dark:bg-zinc-950 -m-4 sm:-m-6 mb-0 sm:mb-0 sm:p-6 p-4
|
||||
border-b border-slate-200 dark:border-zinc-800`
|
||||
border-b border-slate-200 dark:border-zinc-800 margin`
|
||||
: ''}
|
||||
|
||||
"
|
||||
style="{pageHeader
|
||||
? `margin-top: min(-12rem, calc(-1 * calc(${$contentPadding.top}px))); padding-top: max(12rem, calc(${$contentPadding.top}px));`
|
||||
: ''} {style};
|
||||
"
|
||||
{style}
|
||||
>
|
||||
<h1
|
||||
class="text-3xl font-medium flex gap-2 w-full
|
||||
@@ -45,3 +41,17 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.margin {
|
||||
margin-top: -12rem;
|
||||
padding-top: 12rem;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1024px) {
|
||||
.margin {
|
||||
margin-top: -4rem;
|
||||
padding-top: 4rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Button, buttonColor } from 'mono-svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import { dockProps } from '../layout/Shell.svelte'
|
||||
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
@@ -19,8 +18,8 @@
|
||||
|
||||
let {
|
||||
label,
|
||||
icon = undefined,
|
||||
href = undefined,
|
||||
icon,
|
||||
href,
|
||||
adaptive = true,
|
||||
isSelectedFilter = (path) => href != undefined && path == href,
|
||||
class: clazz = '',
|
||||
@@ -30,35 +29,38 @@
|
||||
}: Props = $props()
|
||||
|
||||
let isSelected = $derived(isSelectedFilter(page.url.pathname))
|
||||
let isPanel = $derived(adaptive ? $dockProps?.noGap : false)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
color={isPanel ? 'secondary' : 'tertiary'}
|
||||
color="none"
|
||||
{...rest}
|
||||
class="rounded-full w-10 h-10 flex-shrink-0 {adaptive
|
||||
? '@3xl:h-8 @3xl:px-3 @3xl:rounded-[10px] @3xl:w-auto'
|
||||
: ''} {isSelected
|
||||
? 'bg-slate-200 dark:bg-zinc-900 text-primary-900 dark:!text-primary-100'
|
||||
: ''} {clazz}"
|
||||
class={[
|
||||
'flex-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,
|
||||
!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:hover:dark:bg-zinc-800 lg:active:bg-slate-200 lg:active:dark:bg-zinc-950',
|
||||
clazz,
|
||||
]}
|
||||
size="custom"
|
||||
rounding="none"
|
||||
{href}
|
||||
rounding="pill"
|
||||
title={label}
|
||||
style="transition-property: background-color, filter;"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={icon}
|
||||
micro={isPanel}
|
||||
solid={!isPanel && isSelected}
|
||||
size={isPanel ? '16' : '18'}
|
||||
/>
|
||||
<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: isPanel ? 16 : 18, isSelected })}
|
||||
{@render customIcon?.({ size: 16, isSelected })}
|
||||
{/if}
|
||||
{/snippet}
|
||||
<span class="hidden {adaptive ? '@3xl:block' : ''}">{label}</span>
|
||||
<span class="hidden {adaptive ? 'lg:block' : ''}">{label}</span>
|
||||
{@render children?.()}
|
||||
</Button>
|
||||
@@ -50,7 +50,7 @@
|
||||
}}
|
||||
href="/"
|
||||
label={$t('nav.home')}
|
||||
class="ml-2 logo"
|
||||
class="ml-2 lg:ml-2 logo border-0 lg:rounded-full lg:w-10 lg:h-10 lg:!p-0"
|
||||
adaptive={false}
|
||||
>
|
||||
{#snippet customIcon()}
|
||||
|
||||
@@ -698,6 +698,10 @@
|
||||
"pins": {
|
||||
"title": "Pins",
|
||||
"description": "Click a pin to send it to the top of the sidebar. Right click a pinned item to remove it."
|
||||
},
|
||||
"autoHide": {
|
||||
"title": "Auto hide dock",
|
||||
"description": "Hides the dock on mobile when you scroll down, re-appears when you scroll up."
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
animations?: any
|
||||
loaderWidth?: number | undefined
|
||||
href?: string | undefined
|
||||
class?: string
|
||||
class?: ClassValue
|
||||
prefix?: Snippet
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
@@ -133,7 +133,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
import type { ClassValue, HTMLButtonAttributes } from 'svelte/elements'
|
||||
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
@@ -167,19 +167,19 @@
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...rest}
|
||||
class="
|
||||
{loading ? buttonColor.secondary : buttonColor[color]}
|
||||
{buttonSize[size]}
|
||||
{buttonRounding[rounding][roundingSide]}
|
||||
{buttonShadow[shadow]}
|
||||
text-sm transition-all font-medium cursor-pointer duration-75
|
||||
disabled:opacity-50 disabled:pointer-events-none
|
||||
{alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
? 'origin-left'
|
||||
: 'origin-right'}
|
||||
{clazz}"
|
||||
class={[
|
||||
loading ? buttonColor.secondary : buttonColor[color],
|
||||
buttonSize[size],
|
||||
buttonRounding[rounding][roundingSide],
|
||||
buttonShadow[shadow],
|
||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none',
|
||||
alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
? 'origin-left'
|
||||
: 'origin-right',
|
||||
clazz,
|
||||
]}
|
||||
type={submit ? 'submit' : 'button'}
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -84,9 +84,8 @@ interface Settings {
|
||||
piped: string | undefined
|
||||
}
|
||||
dock: {
|
||||
noGap: boolean | null
|
||||
top: boolean | null
|
||||
paletteHotkey: string
|
||||
autoHide: boolean
|
||||
}
|
||||
posts: {
|
||||
deduplicateEmbed: boolean
|
||||
@@ -164,9 +163,8 @@ export const defaultSettings: Settings = {
|
||||
piped: undefined,
|
||||
},
|
||||
dock: {
|
||||
noGap: toBool(env.PUBLIC_DOCK_PANEL) ?? null,
|
||||
top: toBool(env.PUBLIC_DOCK_TOP) ?? null,
|
||||
paletteHotkey: '/',
|
||||
autoHide: true,
|
||||
},
|
||||
posts: {
|
||||
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
|
||||
|
||||
Reference in new issue
Block a user