|
1 | 1 | "use client"; |
2 | 2 |
|
3 | | -import { cn } from "@/lib/utils"; |
4 | 3 | import { |
5 | 4 | SupportedLanguage, |
6 | 5 | supportedLanguages |
7 | 6 | } from "@/locales/.generated/types"; |
8 | | -import Link from "next/link"; |
| 7 | + |
| 8 | +const labelByLang: Record<SupportedLanguage, string> = { |
| 9 | + en: "🇬🇧 English", |
| 10 | + id: "🇮🇩 Indonesia" |
| 11 | +}; |
9 | 12 |
|
10 | 13 | export function LanguagePicker({ |
11 | 14 | lang, |
12 | | - isOpen |
| 15 | + type = "hyperjump" |
13 | 16 | }: { |
14 | 17 | lang: SupportedLanguage; |
15 | | - isOpen?: boolean; |
| 18 | + type?: "hyperjump" | "services"; |
16 | 19 | }) { |
17 | | - return ( |
18 | | - <div className="flex gap-2"> |
19 | | - {supportedLanguages.map((l) => { |
20 | | - const isActive = lang === l; |
21 | | - |
22 | | - return ( |
23 | | - <Link |
24 | | - scroll={false} |
25 | | - key={l} |
26 | | - href={`/${l}`} |
27 | | - className={cn( |
28 | | - "flex h-8 w-8 items-center justify-center rounded-md text-sm font-medium transition-colors", |
29 | | - isActive |
30 | | - ? isOpen |
31 | | - ? "bg-hyperjump-blue" |
32 | | - : "text-white group-data-[scroll='false']:bg-white group-data-[scroll='true']:bg-hyperjump-blue group-data-[scroll='false']:text-hyperjump-black group-data-[scroll='true']:text-white" |
33 | | - : isOpen |
34 | | - ? "text-hyperjump-black" |
35 | | - : "text-white group-data-[scroll='true']:text-hyperjump-black" |
36 | | - )}> |
37 | | - {l.toUpperCase()} |
38 | | - </Link> |
39 | | - ); |
40 | | - })} |
41 | | - </div> |
42 | | - ); |
43 | | -} |
| 20 | + const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => { |
| 21 | + const newLang = e.target.value as SupportedLanguage; |
| 22 | + window.location.href = |
| 23 | + type === "hyperjump" ? `/${newLang}#hero` : `/services/${newLang}#hero`; |
| 24 | + }; |
44 | 25 |
|
45 | | -export function LanguagePickerServices({ |
46 | | - lang, |
47 | | - isOpen |
48 | | -}: { |
49 | | - lang: SupportedLanguage; |
50 | | - isOpen?: boolean; |
51 | | -}) { |
52 | 26 | return ( |
53 | | - <div className="flex gap-2"> |
54 | | - {supportedLanguages.map((l) => { |
55 | | - const isActive = lang === l; |
56 | | - |
57 | | - return ( |
58 | | - <Link |
59 | | - scroll={false} |
60 | | - key={l} |
61 | | - href={`/services/${l}`} |
62 | | - className={cn( |
63 | | - "flex h-8 w-8 items-center justify-center rounded-md text-sm font-medium transition-colors", |
64 | | - isActive |
65 | | - ? "bg-hyperjump-blue text-white" |
66 | | - : isOpen |
67 | | - ? "text-hyperjump-black" |
68 | | - : "text-hyperjump-black group-data-[scroll='true']:text-hyperjump-black" |
69 | | - )}> |
70 | | - {l.toUpperCase()} |
71 | | - </Link> |
72 | | - ); |
73 | | - })} |
74 | | - </div> |
| 27 | + <select |
| 28 | + value={lang} |
| 29 | + onChange={handleChange} |
| 30 | + className="max-w-32 rounded-full border border-[#2D364A] bg-transparent px-3 py-2 text-sm font-medium text-white"> |
| 31 | + {supportedLanguages.map((l) => ( |
| 32 | + <option key={l} value={l}> |
| 33 | + {labelByLang[l]} |
| 34 | + </option> |
| 35 | + ))} |
| 36 | + </select> |
75 | 37 | ); |
76 | 38 | } |
0 commit comments