Files
web/apps/scandic-web/components/LanguageSwitcher/LanguageSwitcherContent/index.tsx
Matilda Landström 5de2a993a7 Merged in feat/SW-1711-switch-icons (pull request #1558)
Switches out all the old icons to new ones, and moves them to the design system. The new icons are of three different types: Materialise Symbol, Nucleo, and Customized. Also adds further mapping between facilities/amenities and icons.

Approved-by: Michael Zetterberg
Approved-by: Erik Tiekstra
2025-03-27 09:42:52 +00:00

65 lines
1.8 KiB
TypeScript

"use client"
import { usePathname } from "next/navigation"
import { useIntl } from "react-intl"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons"
import { type Lang, languages } from "@/constants/languages"
import Link from "@/components/TempDesignSystem/Link"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import useLang from "@/hooks/useLang"
import { replaceUrlPart } from "./utils"
import styles from "./languageSwitcherContent.module.css"
import type { LanguageSwitcherContentProps } from "@/types/components/languageSwitcher/languageSwitcher"
export default function LanguageSwitcherContent({
urls,
onLanguageSwitch,
}: LanguageSwitcherContentProps) {
const intl = useIntl()
const currentLanguage = useLang()
const urlKeys = Object.keys(urls) as Lang[]
const pathname = usePathname()
return (
<div className={styles.languageWrapper}>
<Subtitle className={styles.subtitle} type="two">
{intl.formatMessage({ id: "Select your language" })}
</Subtitle>
<ul className={styles.list}>
{urlKeys.map((key) => {
const url = urls[key]?.url
const isActive = currentLanguage === key
if (url) {
return (
<li key={key}>
<Link
className={`${styles.link} ${isActive ? styles.active : ""}`}
href={replaceUrlPart(pathname, url)}
onClick={onLanguageSwitch}
keepSearchParams
>
{languages[key]}
{isActive ? (
<MaterialIcon
icon="check"
color="Icon/Interactive/Default"
/>
) : null}
</Link>
</li>
)
}
})}
</ul>
</div>
)
}