|
| 1 | +<script lang="ts"> |
| 2 | + import { page } from "$app/stores"; |
| 3 | + import { Button } from "$lib/components/ui/button"; |
| 4 | + import { |
| 5 | + connect, |
| 6 | + hasInitiatedConnection, |
| 7 | + isConnected, |
| 8 | + } from "$lib/connection.svelte"; |
| 9 | + import Github from "@lucide/svelte/icons/github"; |
| 10 | + import Menu from "@lucide/svelte/icons/menu"; |
| 11 | + import Radio from "@lucide/svelte/icons/radio"; |
| 12 | + import Vibrate from "@lucide/svelte/icons/vibrate"; |
| 13 | + import WifiOff from "@lucide/svelte/icons/wifi-off"; |
| 14 | + import X from "@lucide/svelte/icons/x"; |
| 15 | +
|
| 16 | + let mobileMenuOpen = $state(false); |
| 17 | +
|
| 18 | + const connected = $derived(isConnected()); |
| 19 | + const hasInitiated = $derived(hasInitiatedConnection()); |
| 20 | +
|
| 21 | + const navLinks = [ |
| 22 | + { href: "/", label: "Home" }, |
| 23 | + { href: "/install", label: "Install" }, |
| 24 | + { href: "/integrate", label: "Integrate" }, |
| 25 | + { href: "/api", label: "API" }, |
| 26 | + { href: "/playground", label: "Playground" }, |
| 27 | + ]; |
| 28 | +
|
| 29 | + function handleConnect() { |
| 30 | + connect(); |
| 31 | + } |
| 32 | +
|
| 33 | + const connectionStatus = $derived.by(() => { |
| 34 | + if (connected) { |
| 35 | + return { icon: Radio, class: "text-green-400", label: "Connected" }; |
| 36 | + } |
| 37 | + if (hasInitiated) { |
| 38 | + return { icon: WifiOff, class: "text-red-400", label: "Disconnected" }; |
| 39 | + } |
| 40 | + return null; |
| 41 | + }); |
| 42 | +</script> |
| 43 | + |
| 44 | +<nav |
| 45 | + class="sticky top-0 z-50 border-b border-border bg-background/95 backdrop-blur supports-backdrop-filter:bg-background/60"> |
| 46 | + <div class="max-w-6xl mx-auto px-4"> |
| 47 | + <div class="flex h-16 items-center justify-between"> |
| 48 | + <!-- Logo --> |
| 49 | + <a href="/" class="flex items-center gap-2 font-semibold"> |
| 50 | + <div class="p-1.5 rounded-lg bg-primary/20 border border-primary/30"> |
| 51 | + <Vibrate class="w-4 h-4 text-primary" /> |
| 52 | + </div> |
| 53 | + <span class="hidden sm:inline">HapticWeb</span> |
| 54 | + </a> |
| 55 | + |
| 56 | + <!-- Desktop nav --> |
| 57 | + <div class="hidden md:flex items-center gap-1"> |
| 58 | + {#each navLinks as link} |
| 59 | + <a |
| 60 | + href={link.href} |
| 61 | + class="px-3 py-2 text-sm rounded-md transition-colors {$page.url |
| 62 | + .pathname === link.href |
| 63 | + ? 'text-primary font-medium' |
| 64 | + : 'text-muted-foreground hover:text-foreground hover:bg-accent'}"> |
| 65 | + {link.label} |
| 66 | + </a> |
| 67 | + {/each} |
| 68 | + </div> |
| 69 | + |
| 70 | + <!-- Right side --> |
| 71 | + <div class="flex items-center gap-3"> |
| 72 | + <!-- Connection status/button --> |
| 73 | + {#if connectionStatus} |
| 74 | + <div |
| 75 | + class="hidden sm:flex items-center gap-1.5 text-sm {connectionStatus.class}"> |
| 76 | + <connectionStatus.icon class="w-4 h-4" /> |
| 77 | + <span>{connectionStatus.label}</span> |
| 78 | + </div> |
| 79 | + {:else} |
| 80 | + <Button |
| 81 | + size="sm" |
| 82 | + variant="outline" |
| 83 | + onclick={handleConnect} |
| 84 | + class="hidden sm:flex"> |
| 85 | + Connect Mouse |
| 86 | + </Button> |
| 87 | + {/if} |
| 88 | + |
| 89 | + <!-- GitHub --> |
| 90 | + <a |
| 91 | + href="https://github.com/fallstop/HapticWebPlugin" |
| 92 | + target="_blank" |
| 93 | + rel="noopener noreferrer" |
| 94 | + class="p-2 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"> |
| 95 | + <Github class="w-5 h-5" /> |
| 96 | + </a> |
| 97 | + |
| 98 | + <!-- Mobile menu button --> |
| 99 | + <button |
| 100 | + onclick={() => (mobileMenuOpen = !mobileMenuOpen)} |
| 101 | + class="md:hidden p-2 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent"> |
| 102 | + {#if mobileMenuOpen} |
| 103 | + <X class="w-5 h-5" /> |
| 104 | + {:else} |
| 105 | + <Menu class="w-5 h-5" /> |
| 106 | + {/if} |
| 107 | + </button> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + |
| 111 | + <!-- Mobile menu --> |
| 112 | + {#if mobileMenuOpen} |
| 113 | + <div class="md:hidden pb-4 space-y-1"> |
| 114 | + {#each navLinks as link} |
| 115 | + <a |
| 116 | + href={link.href} |
| 117 | + onclick={() => (mobileMenuOpen = false)} |
| 118 | + class="block px-3 py-2 text-sm rounded-md transition-colors {$page |
| 119 | + .url.pathname === link.href |
| 120 | + ? 'text-primary font-medium bg-primary/10' |
| 121 | + : 'text-muted-foreground hover:text-foreground hover:bg-accent'}"> |
| 122 | + {link.label} |
| 123 | + </a> |
| 124 | + {/each} |
| 125 | + |
| 126 | + {#if !connectionStatus} |
| 127 | + <Button |
| 128 | + size="sm" |
| 129 | + variant="outline" |
| 130 | + onclick={handleConnect} |
| 131 | + class="w-full mt-2"> |
| 132 | + Connect Mouse |
| 133 | + </Button> |
| 134 | + {:else} |
| 135 | + <div |
| 136 | + class="flex items-center gap-1.5 px-3 py-2 text-sm {connectionStatus.class}"> |
| 137 | + <connectionStatus.icon class="w-4 h-4" /> |
| 138 | + <span>{connectionStatus.label}</span> |
| 139 | + </div> |
| 140 | + {/if} |
| 141 | + </div> |
| 142 | + {/if} |
| 143 | + </div> |
| 144 | +</nav> |
0 commit comments