feat(SW-184): added language switcher
This commit is contained in:
@@ -1,30 +1,65 @@
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import { useState } from "react"
|
||||
|
||||
import { ChevronDownIcon, GlobeIcon } from "@/components/Icons"
|
||||
import { Lang, languages } from "@/constants/languages"
|
||||
|
||||
import { CheckIcon, ChevronDownIcon, GlobeIcon } from "@/components/Icons"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
import Button from "../Button"
|
||||
|
||||
import styles from "./languageSwitcher.module.css"
|
||||
|
||||
export default function LanguageSwitcher() {
|
||||
import { LanguageSwitcherProps } from "@/types/components/current/languageSwitcher"
|
||||
|
||||
export default function LanguageSwitcher({ urls }: LanguageSwitcherProps) {
|
||||
const currentLanguage = useLang()
|
||||
const [isExpanded, setIsExpanded] = useState(false)
|
||||
|
||||
function handleButtonClick() {
|
||||
function toggleExpand() {
|
||||
setIsExpanded((prev) => !prev)
|
||||
}
|
||||
|
||||
const urlKeys = Object.keys(urls) as Lang[]
|
||||
|
||||
return (
|
||||
<Button onClick={handleButtonClick}>
|
||||
<GlobeIcon width={20} height={20} color="burgundy" />
|
||||
<span>English</span>
|
||||
<ChevronDownIcon
|
||||
className={`${styles.chevron} ${isExpanded ? styles.isExpanded : ""}`}
|
||||
width={20}
|
||||
height={20}
|
||||
color="burgundy"
|
||||
/>
|
||||
</Button>
|
||||
<div className={styles.languageSwitcher}>
|
||||
<Button onClick={toggleExpand}>
|
||||
<GlobeIcon width={20} height={20} color="burgundy" />
|
||||
<span>{languages[currentLanguage]}</span>
|
||||
<ChevronDownIcon
|
||||
className={`${styles.chevron} ${isExpanded ? styles.isExpanded : ""}`}
|
||||
width={20}
|
||||
height={20}
|
||||
color="burgundy"
|
||||
/>
|
||||
</Button>
|
||||
<div
|
||||
className={`${styles.dropdown} ${isExpanded ? styles.isExpanded : ""}`}
|
||||
>
|
||||
<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 : ""}`}
|
||||
color="burgundy"
|
||||
href={url}
|
||||
>
|
||||
{languages[key]}
|
||||
{isActive ? <CheckIcon color="burgundy" /> : null}
|
||||
</Link>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
.languageSwitcher {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.button {
|
||||
background-color: transparent;
|
||||
color: var(--Base-Text-High-contrast);
|
||||
@@ -15,3 +19,62 @@
|
||||
.chevron.isExpanded {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: absolute;
|
||||
top: 2.25rem;
|
||||
right: 0;
|
||||
background-color: var(--Base-Surface-Primary-light-Normal);
|
||||
padding: var(--Spacing-x2) var(--Spacing-x3);
|
||||
border-radius: var(--Corner-radius-Large);
|
||||
box-shadow: 0px 0px 14px 6px #0000001a;
|
||||
display: none;
|
||||
min-width: 12.5rem;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Triangle above dropdown */
|
||||
.dropdown::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: -1.25rem;
|
||||
right: 2.4rem;
|
||||
transform: rotate(180deg);
|
||||
border-width: 0.75rem;
|
||||
border-style: solid;
|
||||
border-color: var(--Base-Surface-Primary-light-Normal) transparent transparent
|
||||
transparent;
|
||||
}
|
||||
|
||||
.dropdown.isExpanded {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: var(--Scandic-Brand-Burgundy);
|
||||
font-family: var(--typography-Body-Regular-fontFamily);
|
||||
font-size: var(--typography-Body-Regular-fontSize);
|
||||
line-height: var(--typography-Body-Regular-lineHeight);
|
||||
letter-spacing: var(--typography-Body-Regular-letterSpacing);
|
||||
padding: var(--Spacing-x1);
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
display: flex;
|
||||
gap: var(--Spacing-x1);
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
background-color: var(--Base-Surface-Primary-light-Hover-alt);
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
}
|
||||
|
||||
.link.active,
|
||||
.link:hover {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { LanguageSwitcherData } from "@/types/requests/languageSwitcher"
|
||||
|
||||
export interface LanguageSwitcherProps {
|
||||
urls: LanguageSwitcherData
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { GiftIcon } from "@/components/Icons"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
|
||||
@@ -7,6 +9,12 @@ import Search from "./Search"
|
||||
import styles from "./topMenu.module.css"
|
||||
|
||||
export default async function TopMenu() {
|
||||
const languages = await serverClient().contentstack.languageSwitcher.get()
|
||||
|
||||
if (!languages) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.topMenu}>
|
||||
<div className={styles.content}>
|
||||
@@ -15,7 +23,7 @@ export default async function TopMenu() {
|
||||
Join Scandic Friends
|
||||
</Link>
|
||||
<div className={styles.right}>
|
||||
<LanguageSwitcher />
|
||||
<LanguageSwitcher urls={languages.urls} />
|
||||
<Search />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
}
|
||||
|
||||
.content {
|
||||
position: relative;
|
||||
max-width: 89.5rem;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user