|
| 1 | +<script lang="ts"> |
| 2 | + import type { HTMLAttributes } from 'svelte/elements'; |
| 3 | + import { Home, CommentsTwo, Search, Camera, Settings } from '$lib/icons'; |
| 4 | + import { goto } from '$app/navigation'; |
| 5 | + import { page } from '$app/state'; |
| 6 | + import Button from '$lib/ui/Button/Button.svelte'; |
| 7 | + import { cn } from '$lib/utils'; |
| 8 | +
|
| 9 | + interface ISideBarProps extends HTMLAttributes<HTMLElement> { |
| 10 | + activeTab?: string; |
| 11 | + profileSrc: string; |
| 12 | + handlePost?: () => Promise<void>; |
| 13 | + } |
| 14 | + let { |
| 15 | + activeTab = $bindable('home'), |
| 16 | + profileSrc = 'https://picsum.photos/200', |
| 17 | + handlePost, |
| 18 | + ...restProps |
| 19 | + }: ISideBarProps = $props(); |
| 20 | +
|
| 21 | + let _activeTab = $derived(page.url.pathname); |
| 22 | +
|
| 23 | + const handleNavClick = (newTab: string) => { |
| 24 | + activeTab = newTab; |
| 25 | + goto(`/${newTab}`); |
| 26 | + }; |
| 27 | +
|
| 28 | + $effect(() => { |
| 29 | + activeTab = _activeTab.split('/').pop() ?? ''; |
| 30 | + }); |
| 31 | +
|
| 32 | + const cBase = |
| 33 | + 'hidden h-screen border border-y-0 border-e-gray-200 py-14 md:flex md:justify-center'; |
| 34 | +</script> |
| 35 | + |
| 36 | +<!-- svelte-ignore a11y_no_noninteractive_element_to_interactive_role --> |
| 37 | +<nav |
| 38 | + {...restProps} |
| 39 | + aria-label="Main navigation" |
| 40 | + class={cn([cBase, restProps.class].join(' '))} |
| 41 | + role="tablist" |
| 42 | +> |
| 43 | + <div class="flex flex-col items-start justify-start gap-12"> |
| 44 | + <h1 class="bg-[image:var(--color-brand-gradient)] bg-clip-text text-transparent"> |
| 45 | + Pictique |
| 46 | + </h1> |
| 47 | + <button |
| 48 | + type="button" |
| 49 | + class="flex items-center gap-2" |
| 50 | + aria-current={activeTab === 'home' ? 'page' : undefined} |
| 51 | + onclick={() => handleNavClick('home')} |
| 52 | + > |
| 53 | + <Home |
| 54 | + size="24px" |
| 55 | + color={activeTab === 'home' |
| 56 | + ? 'var(--color-brand-burnt-orange)' |
| 57 | + : 'var(--color-black-400)'} |
| 58 | + fill={activeTab === 'home' ? 'var(--color-brand-burnt-orange)' : 'white'} |
| 59 | + /> |
| 60 | + <h3 |
| 61 | + class={`${activeTab === 'home' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 62 | + > |
| 63 | + Feed |
| 64 | + </h3> |
| 65 | + </button> |
| 66 | + |
| 67 | + <button |
| 68 | + type="button" |
| 69 | + class="flex items-center gap-2" |
| 70 | + aria-current={activeTab === 'discover' ? 'page' : undefined} |
| 71 | + onclick={() => handleNavClick('discover')} |
| 72 | + > |
| 73 | + <Search |
| 74 | + size="24px" |
| 75 | + color={activeTab === 'discover' |
| 76 | + ? 'var(--color-brand-burnt-orange)' |
| 77 | + : 'var(--color-black-400)'} |
| 78 | + fill={activeTab === 'discover' ? 'var(--color-brand-burnt-orange)' : 'white'} |
| 79 | + /> |
| 80 | + <h3 |
| 81 | + class={`${activeTab === 'discover' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 82 | + > |
| 83 | + Search |
| 84 | + </h3> |
| 85 | + </button> |
| 86 | + |
| 87 | + <button |
| 88 | + type="button" |
| 89 | + class="flex items-center gap-2" |
| 90 | + aria-current={activeTab === 'post' ? 'page' : undefined} |
| 91 | + onclick={() => handleNavClick('post')} |
| 92 | + > |
| 93 | + <Camera |
| 94 | + size="24px" |
| 95 | + color={activeTab === 'post' |
| 96 | + ? 'var(--color-brand-burnt-orange)' |
| 97 | + : 'var(--color-black-400)'} |
| 98 | + fill={activeTab === 'post' ? 'var(--color-brand-burnt-orange)' : 'white'} |
| 99 | + /> |
| 100 | + <h3 |
| 101 | + class={`${activeTab === 'post' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 102 | + > |
| 103 | + Upload a photo |
| 104 | + </h3> |
| 105 | + </button> |
| 106 | + |
| 107 | + <button |
| 108 | + type="button" |
| 109 | + class="flex items-center gap-2" |
| 110 | + aria-current={activeTab === 'messages' ? 'page' : undefined} |
| 111 | + onclick={() => handleNavClick('messages')} |
| 112 | + > |
| 113 | + <CommentsTwo |
| 114 | + size="24px" |
| 115 | + color={activeTab === 'messages' |
| 116 | + ? 'var(--color-brand-burnt-orange)' |
| 117 | + : 'var(--color-black-400)'} |
| 118 | + fill={activeTab === 'messages' ? 'var(--color-brand-burnt-orange)' : 'white'} |
| 119 | + /> |
| 120 | + <h3 |
| 121 | + class={`${activeTab === 'messages' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 122 | + > |
| 123 | + Messages |
| 124 | + </h3> |
| 125 | + </button> |
| 126 | + |
| 127 | + <button |
| 128 | + type="button" |
| 129 | + class="flex items-center gap-2" |
| 130 | + aria-current={activeTab === 'settings' ? 'page' : undefined} |
| 131 | + onclick={() => handleNavClick('settings')} |
| 132 | + > |
| 133 | + <Settings |
| 134 | + size="24px" |
| 135 | + color={activeTab === 'settings' |
| 136 | + ? 'var(--color-brand-burnt-orange)' |
| 137 | + : 'var(--color-black-400)'} |
| 138 | + fill={activeTab === 'settings' ? 'var(--color-brand-burnt-orange)' : 'white'} |
| 139 | + /> |
| 140 | + <h3 |
| 141 | + class={`${activeTab === 'settings' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 142 | + > |
| 143 | + Settings |
| 144 | + </h3> |
| 145 | + </button> |
| 146 | + |
| 147 | + <button |
| 148 | + type="button" |
| 149 | + class="flex items-center gap-2" |
| 150 | + aria-current={activeTab === 'profile' ? 'page' : undefined} |
| 151 | + onclick={() => handleNavClick('profile')} |
| 152 | + > |
| 153 | + <span |
| 154 | + class={`inline-block w-full rounded-full border p-1 ${activeTab === 'profile' ? 'border-brand-burnt-orange' : 'border-transparent'}`} |
| 155 | + > |
| 156 | + <img |
| 157 | + width="24px" |
| 158 | + height="24px" |
| 159 | + class="aspect-square rounded-full" |
| 160 | + src={profileSrc} |
| 161 | + alt="profile" |
| 162 | + /> |
| 163 | + </span> |
| 164 | + <h3 |
| 165 | + class={`${activeTab === 'profile' ? 'text-brand-burnt-orange' : 'text-black-800'} mt-[4px]`} |
| 166 | + > |
| 167 | + Profile |
| 168 | + </h3> |
| 169 | + </button> |
| 170 | + {#if handlePost} |
| 171 | + <Button size="sm" variant="secondary" callback={handlePost}>Post a photo</Button> |
| 172 | + {/if} |
| 173 | + </div> |
| 174 | +</nav> |
0 commit comments