feat: add adaptive nav positioning

This commit is contained in:
Xylight committed 2024-05-26 13:35:54 -07:00
1 parent 3bd0b066a3
commit 5e43c3a102
4 files changed
+80 -27

No files matched your search

+46 -15
View File
@@ -27,34 +27,65 @@
return 'hi this is easter egg, my code broke' return 'hi this is easter egg, my code broke'
} }
$: contentPadding = calculatePadding( let screenWidth = 1000
$userSettings.dock.noGap,
$userSettings.dock.top, const calculateDockProperties = (
true settings: typeof $userSettings.dock,
) screenWidth: number
$: sidePadding = calculatePadding( ): {
$userSettings.dock.noGap, noGap: boolean
$userSettings.dock.top, top: boolean
false } => {
) 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,
}
}
$: dockProps = calculateDockProperties($userSettings.dock, screenWidth)
$: contentPadding = calculatePadding(dockProps.noGap, dockProps.top, true)
$: sidePadding = calculatePadding(dockProps.noGap, dockProps.top, false)
$: topPanel = $userSettings.dock.noGap && $userSettings.dock.top $: topPanel = $userSettings.dock.noGap && $userSettings.dock.top
</script> </script>
<svelte:window bind:innerWidth={screenWidth} />
<div class="shell {$$props.class}" style={colorsToVars($colors)}> <div class="shell {$$props.class}" style={colorsToVars($colors)}>
<slot /> <slot />
<div <div
class=" class="
{$userSettings.dock.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'} {dockProps.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'}
{$userSettings.dock.top ? 'top-0' : 'bottom-0'} {dockProps.top ? 'top-0' : 'bottom-0'}
{topPanel ? 'fixed top-0' : 'fixed'} {topPanel ? 'fixed top-0' : 'fixed'}
w-full z-50 pointer-events-none" w-full z-50 pointer-events-none"
style="grid-area: navbar; transition: padding 250ms cubic-bezier(0.075, 0.82, 0.165, 1);" style="grid-area: navbar;
transition-property: padding, top, bottom;
transition-duration: 250ms;
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);"
> >
<slot <slot
name="navbar" name="navbar"
class=" class="
{$userSettings.dock.noGap {dockProps.noGap
? $userSettings.dock.top ? dockProps.top
? 'border-b shadow-none rounded-none' ? 'border-b shadow-none rounded-none'
: 'border-t rounded-none' : 'border-t rounded-none'
: 'border rounded-full'} : 'border rounded-full'}
+17 -1
View File
@@ -28,6 +28,7 @@
import SearchBar from '$lib/components/lemmy/util/SearchBar.svelte' import SearchBar from '$lib/components/lemmy/util/SearchBar.svelte'
import { swipeGesture } from '$lib/input/swipe' import { swipeGesture } from '$lib/input/swipe'
import Logo from '../Logo.svelte' import Logo from '../Logo.svelte'
import { LINKED_INSTANCE_URL } from '$lib/instance'
let searching = false let searching = false
</script> </script>
@@ -40,7 +41,22 @@
style={$$props.style} style={$$props.style}
> >
<NavButton href="/" label="Home" class="ml-2 logo"> <NavButton href="/" label="Home" class="ml-2 logo">
<Logo width={32} slot="icon" /> <svelte:fragment slot="icon">
{#if LINKED_INSTANCE_URL}
{#if $site}
<Avatar
alt={$site.site_view.site.name}
url={$site.site_view.site.icon}
width={32}
circle={false}
/>
{:else}
<Spinner width={32} />
{/if}
{:else}
<Logo width={32} />
{/if}
</svelte:fragment>
</NavButton> </NavButton>
{#if searching} {#if searching}
<div <div
+4 -4
View File
@@ -70,8 +70,8 @@ interface Settings {
youtube: 'youtube' | 'invidious' | 'piped' youtube: 'youtube' | 'invidious' | 'piped'
} }
dock: { dock: {
noGap: boolean noGap: boolean | null
top: boolean top: boolean | null
} }
posts: { posts: {
deduplicateEmbed: boolean deduplicateEmbed: boolean
@@ -127,8 +127,8 @@ export const defaultSettings: Settings = {
youtube: 'youtube', youtube: 'youtube',
}, },
dock: { dock: {
noGap: toBool(env.PUBLIC_DOCK_PANEL) ?? false, noGap: toBool(env.PUBLIC_DOCK_PANEL) ?? null,
top: toBool(env.PUBLIC_DOCK_TOP) ?? false top: toBool(env.PUBLIC_DOCK_TOP) ?? null
}, },
posts: { posts: {
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true, deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
+13 -7
View File
@@ -64,16 +64,22 @@
<span slot="title">Dock position</span> <span slot="title">Dock position</span>
<span slot="description">Where the dock should be put</span> <span slot="description">Where the dock should be put</span>
<MultiSelect <MultiSelect
options={[true, false]} options={[true, false, null]}
optionNames={['Top', 'Bottom']} optionNames={['Top', 'Bottom', 'Adaptive']}
bind:selected={$userSettings.dock.top} bind:selected={$userSettings.dock.top}
/> />
</Setting> </Setting>
<ToggleSetting <Setting>
bind:checked={$userSettings.dock.noGap} <span slot="title">Panel mode</span>
title="Panel mode" <span slot="description">
description="Extend the dock to screen edges, similar to a panel." Extend the dock to screen edges, similar to a panel.
/> </span>
<MultiSelect
options={[true, false, null]}
optionNames={['On', 'Off', 'Adaptive']}
bind:selected={$userSettings.dock.noGap}
/>
</Setting>
</Section> </Section>
<Section title="Photon"> <Section title="Photon">