design: change profile page to use tabs

This commit is contained in:
Xylight committed 2024-07-18 16:57:34 -07:00
1 parent 1aed9b3e48
commit 1a30bcee1d
3 files changed
+120 -63

No files matched your search

+59 -45
View File
@@ -1,37 +1,10 @@
<script lang="ts">
import { userSettings } from '$lib/settings.js'
import { colors, colorsToVars } from '$lib/ui/colors'
import { routes } from '$lib/util.js'
export let route: { id: string | null } | undefined = undefined
$: title = route ? routes[(route.id as keyof typeof routes) ?? ''] : ''
const calculatePadding = (
panel: boolean,
top: boolean,
content: boolean
): string => {
if (panel) {
if (top) {
if (content) return '!pt-20'
else return 'top-16 !max-h-[calc(100vh-4rem)]'
} else return '!pb-20'
} else {
if (!content) return ''
if (top) return '!pt-24'
else return '!pb-24'
}
return 'hi this is easter egg, my code broke'
}
let screenWidth = 1000
<script lang="ts" context="module">
const calculateDockProperties = (
settings: typeof $userSettings.dock,
screenWidth: number
settings: {
top: boolean | null
noGap: boolean | null
},
screenWidth: number,
): {
noGap: boolean
top: boolean
@@ -59,14 +32,55 @@
}
}
$: dockProps = calculateDockProperties($userSettings.dock, screenWidth)
export const calculatePadding = (
panel: boolean,
top: boolean,
content: boolean,
): {
top: number
class: string
} => {
if (panel) {
if (top) {
if (content) return { top: 80, class: '!pt-20' }
else return { top: 64, class: 'top-16 !max-h-[calc(100vh-4rem)]' }
} else return { top: 0, class: '!pb-20' }
} else {
if (!content) return { top: 0, class: '' }
$: contentPadding = calculatePadding(dockProps.noGap, dockProps.top, true)
$: sidePadding = calculatePadding(dockProps.noGap, dockProps.top, false)
$: topPanel = dockProps.noGap && dockProps.top
if (top) return { top: 96, class: '!pt-24' }
else return { top: 0, class: '!pb-24' }
}
return { top: 0, class: ' failed-to-calculate' }
}
export let screenWidth = writable(1000)
export let dockProps: Readable<ReturnType<typeof calculateDockProperties>> =
derived([userSettings, screenWidth], ([$settings, $screenWidth], set) => {
set(calculateDockProperties($settings.dock, $screenWidth))
})
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
derived(dockProps, ($dockProps, set) =>
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
)
</script>
<svelte:window bind:innerWidth={screenWidth} />
<script lang="ts">
import { userSettings } from '$lib/settings.js'
import { colors, colorsToVars } from '$lib/ui/colors'
import { routes } from '$lib/util.js'
import { derived, writable, type Readable, type Writable } from 'svelte/store'
export let route: { id: string | null } | undefined = undefined
$: title = route ? routes[(route.id as keyof typeof routes) ?? ''] : ''
$: sidePadding = calculatePadding($dockProps.noGap, $dockProps.top, false)
$: topPanel = $dockProps.noGap && $dockProps.top
</script>
<svelte:window bind:innerWidth={$screenWidth} />
<div
{...$$restProps}
@@ -76,8 +90,8 @@
<slot />
<div
class="
{dockProps.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'}
{dockProps.top ? 'top-0' : 'bottom-0'}
{$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'}
w-full z-50 pointer-events-none"
style="grid-area: navbar;
@@ -88,8 +102,8 @@
<slot
name="navbar"
class="
{dockProps.noGap
? dockProps.top
{$dockProps.noGap
? $dockProps.top
? 'border-b shadow-none rounded-none'
: 'border-t rounded-none'
: 'border rounded-full'}
@@ -112,18 +126,18 @@
name="sidebar"
class="hidden md:flex sticky top-0 left-0 max-w-full h-max bg-slate-50 dark:bg-zinc-950
z-40
{sidePadding}"
{sidePadding.class}"
style="grid-area: sidebar; width: 100% !important;"
/>
<slot
name="main"
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
{contentPadding}"
{$contentPadding.class}"
style="grid-area: main"
/>
<slot
name="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="max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 {sidePadding.class}"
style="grid-area: suffix;"
/>
</div>
@@ -0,0 +1,31 @@
<script lang="ts">
import { page } from '$app/stores'
import { fly } from 'svelte/transition'
export let routes: {
href: string
name: string
}[]
</script>
<nav
class="flex flex-row items-center gap-1 p-1 rounded-full bg-[#fff]/60 dark:bg-neutral-800/60
backdrop-blur-lg border border-gray-200/60 dark:border-neutral-800 shadow-lg overflow-auto
"
>
{#each routes as route}
<a
href={route.href}
class="font-medium rounded-full px-4 py-1 hover:bg-gray-200/40 hover:dark:bg-neutral-700/40
transition-colors duration-100 relative z-0"
>
{route.name}
{#if $page.url.pathname == route.href}
<div
class="rounded-full bg-gray-100/60 dark:bg-neutral-700/60
absolute inset-0 w-full h-full -z-10"
></div>
{/if}
</a>
{/each}
</nav>
+30 -18
View File
@@ -3,6 +3,8 @@
import { page } from '$app/stores'
import MultiSelect from '$lib/components/input/Switch.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
import { t } from '$lib/translations'
</script>
@@ -11,23 +13,33 @@
</svelte:head>
<div class="flex flex-col gap-4 h-full z-0">
<MultiSelect
options={[
'/profile/user',
'/profile/settings',
'/profile/blocks',
'/profile/password',
]}
optionNames={[
$t('routes.profile.user'),
$t('routes.profile.settings'),
$t('routes.profile.blocks'),
$t('routes.profile.credentials'),
]}
selected={$page.url.pathname}
on:select={(e) => {
goto(e.detail)
}}
/>
<div
class="sticky mx-auto z-50 max-w-full"
style="top: max(1.5rem, {$contentPadding.top}px);"
>
<Tabs
routes={[
{
href: '/profile/user',
name: $t('routes.profile.user'),
},
{
href: '/profile/settings',
name: $t('routes.profile.settings'),
},
{
href: '/profile/blocks',
name: $t('routes.profile.blocks'),
},
{
href: '/profile/password',
name: $t('routes.profile.credentials'),
},
]}
/>
</div>
<slot />
</div>