-
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 branch 'dev' of https://github.com/AmazeeLabs/silverback-template…
… into feat/SLB-306--info-grid
- Loading branch information
Showing
23 changed files
with
254 additions
and
105 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
PROJECT_NAME="example" | ||
DRUPAL_URL="https://nginx.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io" |
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
97 changes: 78 additions & 19 deletions
97
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,89 @@ | ||
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(); | ||
const currentLocale = Object.values(Locale).find((locale) => { | ||
const translationPath = translations[locale]; | ||
return location.pathname.includes(translationPath || ''); | ||
}); | ||
|
||
if (!currentLocale) { | ||
console.error( | ||
'No matching locale found in current path:', | ||
location.pathname, | ||
); | ||
return null; | ||
} | ||
|
||
const otherLocales = Object.values(Locale).filter( | ||
(locale) => locale !== currentLocale, | ||
); | ||
|
||
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> | ||
<Menu.Button className="inline-flex justify-center w-full rounded-md bg-white text-sm hover:text-blue-600"> | ||
{getLanguageName(currentLocale as string)} | ||
<ChevronDownIcon className="ml-1 h-5 w-5" aria-hidden="true" /> | ||
</Menu.Button> | ||
</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"> | ||
{otherLocales.map((locale) => ( | ||
<Menu.Item key={locale}> | ||
{({ 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> | ||
))} | ||
</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
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.