-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate language selector from ranking selector (#233)
* feat: add Lang select * fix: select correct lang on ranking load * fix: handle undefined object
- Loading branch information
1 parent
1874222
commit e12f065
Showing
4 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Removable } from "@/components/custom-ui/Removable"; | ||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
|
||
export type Lang = "ITA" | "ENG"; | ||
const langs = [ | ||
{ | ||
label: <span>🇮🇹</span>, | ||
value: "ITA", | ||
}, | ||
{ | ||
label: <span>🇬🇧</span>, | ||
value: "ENG", | ||
}, | ||
] as const; | ||
|
||
export type LangSelectProps = { | ||
canChoose: boolean; | ||
selectedLang: Lang; | ||
onChange: (newLang: Lang) => void; | ||
}; | ||
|
||
export default function LangSelect({ | ||
canChoose, | ||
selectedLang, | ||
onChange, | ||
}: LangSelectProps) { | ||
const selectedLangOption = langs.find((l) => l.value === selectedLang); | ||
if (!selectedLangOption) return <></>; | ||
|
||
return ( | ||
<div className="flex items-center space-x-4"> | ||
<p className="text-muted-foreground text-sm">Lingua</p> | ||
{canChoose ? ( | ||
<Tabs | ||
value={selectedLang} | ||
onValueChange={(v) => onChange(v as Lang)} | ||
className="flex flex-1" | ||
> | ||
<TabsList className="flex overflow-x-hidden"> | ||
{langs.map((lang) => ( | ||
<TabsTrigger | ||
className="block" | ||
value={lang.value} | ||
key={lang.value} | ||
> | ||
{lang.label} | ||
</TabsTrigger> | ||
))} | ||
</TabsList> | ||
</Tabs> | ||
) : ( | ||
<Removable showRemove={false}>{selectedLangOption.label}</Removable> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters