282 lines
8.3 KiB
Vue
282 lines
8.3 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
|
import {
|
|
Menu,
|
|
X,
|
|
Moon,
|
|
Sun,
|
|
Globe,
|
|
House,
|
|
UserRound,
|
|
BriefcaseBusiness,
|
|
FolderKanban,
|
|
Mail,
|
|
ArrowUpRight,
|
|
} from "lucide-vue-next";
|
|
|
|
const { locale, setLocale } = useI18n();
|
|
const colorMode = useColorMode();
|
|
|
|
const mobileOpen = ref(false);
|
|
const scrolled = ref(false);
|
|
const changingLocale = useState("locale-loading", () => false);
|
|
|
|
const navItems = [
|
|
{ id: "home", label: "Home", icon: House },
|
|
{ id: "about", label: "About", icon: UserRound },
|
|
{ id: "services", label: "Services", icon: BriefcaseBusiness },
|
|
{ id: "projects", label: "Projects", icon: FolderKanban },
|
|
{ id: "contact", label: "Contact", icon: Mail },
|
|
];
|
|
|
|
const handleScroll = () => {
|
|
scrolled.value = window.scrollY > 20;
|
|
};
|
|
|
|
const scrollToSection = (id: string) => {
|
|
document.getElementById(id)?.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "start",
|
|
});
|
|
|
|
mobileOpen.value = false;
|
|
};
|
|
|
|
const toggleTheme = () => {
|
|
colorMode.preference =
|
|
colorMode.value === "dark" ? "light" : "dark";
|
|
};
|
|
|
|
const changeLocale = async () => {
|
|
if (changingLocale.value) return;
|
|
|
|
changingLocale.value = true;
|
|
mobileOpen.value = false;
|
|
|
|
try {
|
|
await setLocale(locale.value === "id" ? "en" : "id");
|
|
} catch (error) {
|
|
console.error("Gagal mengganti bahasa:", error);
|
|
} finally {
|
|
changingLocale.value = false;
|
|
}
|
|
};
|
|
|
|
onMounted(() => {
|
|
handleScroll();
|
|
|
|
window.addEventListener("scroll", handleScroll, {
|
|
passive: true,
|
|
});
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener("scroll", handleScroll);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<header
|
|
class="fixed left-1/2 top-4 z-50 w-[calc(100%-2rem)] max-w-6xl -translate-x-1/2"
|
|
>
|
|
<nav
|
|
class="rounded-2xl border backdrop-blur-xl transition-shadow duration-300"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
boxShadow: scrolled
|
|
? '0 10px 35px rgba(0,0,0,0.12)'
|
|
: '0 4px 20px rgba(0,0,0,0.06)',
|
|
}"
|
|
>
|
|
<div class="flex h-14 items-center justify-between px-3 sm:h-16 sm:px-5">
|
|
<!-- Logo -->
|
|
<button
|
|
type="button"
|
|
class="flex items-center gap-2"
|
|
aria-label="Go to home"
|
|
@click="scrollToSection('home')"
|
|
>
|
|
<span
|
|
class="text-lg font-bold tracking-tight"
|
|
:style="{ color: 'var(--text)' }"
|
|
>
|
|
DifarFT
|
|
</span>
|
|
</button>
|
|
|
|
<!-- Desktop Navigation -->
|
|
<div class="hidden items-center gap-1 md:flex">
|
|
<button
|
|
v-for="item in navItems"
|
|
:key="item.id"
|
|
type="button"
|
|
class="rounded-lg px-3 py-2 text-sm font-medium transition-transform duration-200 hover:scale-[1.02]"
|
|
:style="{ color: 'var(--text)' }"
|
|
@click="scrollToSection(item.id)"
|
|
>
|
|
{{ item.label }}
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Desktop Actions -->
|
|
<div class="hidden items-center gap-2 md:flex">
|
|
<button
|
|
type="button"
|
|
aria-label="Change language"
|
|
:disabled="changingLocale"
|
|
class="flex h-10 items-center gap-1.5 rounded-xl border px-2.5 transition-transform duration-300 hover:scale-[1.03] disabled:cursor-wait disabled:opacity-60 sm:px-3"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
@click="changeLocale"
|
|
>
|
|
<Globe class="h-4 w-4" />
|
|
|
|
<span class="text-xs font-medium sm:text-sm">
|
|
{{ locale.toUpperCase() }}
|
|
</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
aria-label="Toggle theme"
|
|
class="flex h-10 w-10 items-center justify-center rounded-xl border transition-transform duration-300 hover:scale-[1.03]"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
@click="toggleTheme"
|
|
>
|
|
<Sun
|
|
v-if="colorMode.value === 'dark'"
|
|
class="h-4 w-4"
|
|
/>
|
|
<Moon v-else class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Mobile Actions -->
|
|
<div class="flex items-center gap-1.5 md:hidden">
|
|
<button
|
|
type="button"
|
|
aria-label="Change language"
|
|
:disabled="changingLocale"
|
|
class="flex h-9 items-center gap-1.5 rounded-xl border px-2.5 transition-opacity duration-200 disabled:cursor-wait disabled:opacity-60"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
@click="changeLocale"
|
|
>
|
|
<Globe class="h-4 w-4" />
|
|
|
|
<span class="text-[11px] font-semibold">
|
|
{{ locale.toUpperCase() }}
|
|
</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
aria-label="Toggle theme"
|
|
class="flex h-9 w-9 items-center justify-center rounded-xl border"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
@click="toggleTheme"
|
|
>
|
|
<Sun
|
|
v-if="colorMode.value === 'dark'"
|
|
class="h-4 w-4"
|
|
/>
|
|
<Moon v-else class="h-4 w-4" />
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
:aria-label="
|
|
mobileOpen ? 'Close navigation' : 'Open navigation'
|
|
"
|
|
:aria-expanded="mobileOpen"
|
|
class="flex h-9 w-9 items-center justify-center rounded-xl border"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
@click="mobileOpen = !mobileOpen"
|
|
>
|
|
<X v-if="mobileOpen" class="h-4 w-4" />
|
|
<Menu v-else class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Mobile Menu -->
|
|
<Transition
|
|
enter-active-class="transition-all duration-200 ease-out"
|
|
enter-from-class="opacity-0 -translate-y-2 scale-[0.98]"
|
|
enter-to-class="opacity-100 translate-y-0 scale-100"
|
|
leave-active-class="transition-all duration-150 ease-in"
|
|
leave-from-class="opacity-100 translate-y-0 scale-100"
|
|
leave-to-class="opacity-0 -translate-y-2 scale-[0.98]"
|
|
>
|
|
<div
|
|
v-if="mobileOpen"
|
|
class="border-t px-3 pb-3 pt-2 md:hidden"
|
|
:style="{ borderColor: 'var(--border)' }"
|
|
>
|
|
<div class="space-y-1">
|
|
<button
|
|
v-for="item in navItems"
|
|
:key="item.id"
|
|
type="button"
|
|
class="flex min-h-11 w-full items-center gap-3 rounded-xl px-2 text-left transition-transform duration-200 hover:translate-x-0.5"
|
|
:style="{ color: 'var(--text)' }"
|
|
@click="scrollToSection(item.id)"
|
|
>
|
|
<div
|
|
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border"
|
|
:style="{
|
|
backgroundColor: 'var(--bg)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-muted)',
|
|
}"
|
|
>
|
|
<component :is="item.icon" class="h-4 w-4" />
|
|
</div>
|
|
|
|
<span class="flex-1 text-sm font-medium">
|
|
{{ item.label }}
|
|
</span>
|
|
|
|
<ArrowUpRight
|
|
class="h-4 w-4"
|
|
:style="{ color: 'var(--text-muted)' }"
|
|
/>
|
|
</button>
|
|
</div>
|
|
|
|
<div
|
|
class="mt-2 border-t px-3 pt-2.5"
|
|
:style="{ borderColor: 'var(--border)' }"
|
|
>
|
|
<div
|
|
class="flex items-center justify-between text-[10px] uppercase tracking-[0.18em]"
|
|
:style="{ color: 'var(--text-muted)' }"
|
|
>
|
|
<span>Navigation</span>
|
|
<span>DifarFT</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Transition>
|
|
</nav>
|
|
</header>
|
|
</template> |