127 lines
3.4 KiB
Vue
127 lines
3.4 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
|
import { Moon, Sun, Globe } from "lucide-vue-next";
|
|
|
|
const { locale, setLocale } = useI18n();
|
|
const colorMode = useColorMode();
|
|
|
|
const scrolled = ref(false);
|
|
const changingLocale = useState("locale-loading", () => false);
|
|
|
|
const handleScroll = () => {
|
|
scrolled.value = window.scrollY > 20;
|
|
};
|
|
|
|
const toggleTheme = () => {
|
|
colorMode.preference =
|
|
colorMode.value === "dark" ? "light" : "dark";
|
|
};
|
|
|
|
const changeLocale = async () => {
|
|
if (changingLocale.value) return;
|
|
|
|
const nextLocale = locale.value === "id" ? "en" : "id";
|
|
|
|
changingLocale.value = true;
|
|
|
|
try {
|
|
await setLocale(nextLocale);
|
|
} 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 -->
|
|
<span
|
|
class="text-lg font-bold tracking-tight"
|
|
:style="{ color: 'var(--text)' }"
|
|
>
|
|
DifarFT
|
|
</span>
|
|
|
|
<!-- Actions -->
|
|
<div class="flex items-center gap-1.5">
|
|
<!-- Language -->
|
|
<button
|
|
type="button"
|
|
@click="changeLocale"
|
|
:disabled="changingLocale"
|
|
class="flex h-9 items-center gap-1.5 rounded-xl border px-2.5 transition-transform duration-200 hover:scale-[1.03] disabled:cursor-wait disabled:opacity-60 sm:h-10 sm:px-3"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
:aria-label="
|
|
locale === 'id'
|
|
? 'Bahasa Indonesia aktif'
|
|
: 'English language active'
|
|
"
|
|
>
|
|
<Globe class="h-4 w-4" />
|
|
|
|
<span class="text-[11px] font-semibold sm:text-sm">
|
|
{{ locale.toUpperCase() }}
|
|
</span>
|
|
</button>
|
|
|
|
<!-- Theme -->
|
|
<button
|
|
type="button"
|
|
@click="toggleTheme"
|
|
class="flex h-9 w-9 items-center justify-center rounded-xl border transition-transform duration-200 hover:scale-[1.03] sm:h-10 sm:w-10"
|
|
:style="{
|
|
backgroundColor: 'var(--surface)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text)',
|
|
}"
|
|
:aria-label="
|
|
colorMode.value === 'dark'
|
|
? 'Switch to light mode'
|
|
: 'Switch to dark mode'
|
|
"
|
|
>
|
|
<Sun
|
|
v-if="colorMode.value === 'dark'"
|
|
class="h-4 w-4"
|
|
/>
|
|
|
|
<Moon v-else class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
</template> |