-
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.
Merge remote-tracking branch 'origin/release' into SLB-382-Footer-men…
…u-styling
- Loading branch information
Showing
17 changed files
with
338 additions
and
265 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
98 changes: 79 additions & 19 deletions
98
packages/ui/src/components/Molecules/LanguageSwitcher.tsx
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 |
---|---|---|
@@ -1,30 +1,90 @@ | ||
import { Link, Locale, useLocation } from '@custom/schema'; | ||
import { Menu, Transition } from '@headlessui/react'; | ||
import { ChevronDownIcon } from '@heroicons/react/20/solid'; | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import React, { Fragment } from 'react'; | ||
|
||
import { useTranslations } from '../../utils/translations'; | ||
|
||
function getLanguageName(locale: string) { | ||
const languageNames = new Intl.DisplayNames([locale], { | ||
type: 'language', | ||
}); | ||
return languageNames.of(locale); | ||
} | ||
|
||
export function LanguageSwitcher() { | ||
const translations = useTranslations(); | ||
const [location] = useLocation(); | ||
|
||
return ( | ||
<ul className="flex gap-2 uppercase"> | ||
{Object.values(Locale).map((locale) => ( | ||
<li key={locale}> | ||
{translations[locale] ? ( | ||
<Link | ||
href={translations[locale]!} | ||
className={clsx('text-gray-500', { | ||
underline: location.pathname !== translations[locale], | ||
})} | ||
> | ||
{locale} | ||
</Link> | ||
) : ( | ||
<span className="text-gray-400">{locale}</span> | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
<div className="relative inline-block text-left"> | ||
<Menu as="div" className="relative inline-block text-left"> | ||
<div> | ||
{Object.values(Locale).map((locale) => ( | ||
<React.Fragment key={locale}> | ||
{translations[locale] && | ||
location.pathname !== translations[locale] ? null : ( | ||
<Menu.Button className="inline-flex justify-center w-full rounded-md bg-white text-sm hover:text-blue-600"> | ||
{getLanguageName(locale)} | ||
<ChevronDownIcon | ||
className="ml-1 h-5 w-5" | ||
aria-hidden="true" | ||
/> | ||
</Menu.Button> | ||
)} | ||
</React.Fragment> | ||
))} | ||
</div> | ||
|
||
<Transition | ||
as={Fragment} | ||
enter="transition ease-out duration-200" | ||
enterFrom="opacity-0 translate-y-1" | ||
enterTo="opacity-100 translate-y-0" | ||
leave="transition ease-in duration-150" | ||
leaveFrom="opacity-100 translate-y-0" | ||
leaveTo="opacity-0 translate-y-1" | ||
> | ||
<Menu.Items className="origin-top-right absolute z-50 right-0 mt-3 w-48 rounded bg-white shadow-md ring-1 ring-gray-100"> | ||
<div className="py-1"> | ||
{Object.values(Locale).map((locale) => ( | ||
<React.Fragment key={locale}> | ||
{translations[locale] && | ||
location.pathname !== translations[locale] ? ( | ||
<Menu.Item> | ||
{({ focus }) => | ||
translations[locale] ? ( | ||
<Link | ||
href={translations[locale]!} | ||
className={clsx( | ||
focus ? 'text-blue-600' : 'text-gray-500', | ||
'block px-4 py-2 text-sm', | ||
)} | ||
> | ||
{getLanguageName(locale as string)} | ||
</Link> | ||
) : ( | ||
<span | ||
className={clsx( | ||
focus | ||
? 'bg-gray-100 text-gray-900' | ||
: 'text-gray-500', | ||
'block px-3.5 py-2 text-sm', | ||
)} | ||
> | ||
{getLanguageName(locale as string)} | ||
</span> | ||
) | ||
} | ||
</Menu.Item> | ||
) : null} | ||
</React.Fragment> | ||
))} | ||
</div> | ||
</Menu.Items> | ||
</Transition> | ||
</Menu> | ||
</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
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
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
Oops, something went wrong.