Skip to content

Commit

Permalink
🎨 udpate localization switch (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle authored Sep 11, 2024
1 parent f25c9bb commit 105f369
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions sanityv3/schemas/textSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ const snippets: textSnippet = {
defaultValue: 'Close',
group: groups.others,
},
switch_to: {
title: 'Switch to',
defaultValue: 'Switch to',
group: groups.others,
},
}

type textSnippetGroup = { title: string; hidden?: boolean }
Expand Down
21 changes: 15 additions & 6 deletions web/pageComponents/shared/LocalizationSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIntl } from 'react-intl'
import { languages } from '../../languages'
import { ButtonLink } from '@core/Link'

Expand All @@ -9,34 +10,42 @@ export type LocalizationSwitchProps = {
}

export const LocalizationSwitch = ({ allSlugs: slugs, activeLocale, ...rest }: LocalizationSwitchProps) => {
const intl = useIntl()

if (slugs.length < 1) return null

return (
<div className="flex items-center md:divide-x md:divide-dashed md:divide-gray-400 " {...rest}>
<ul className="flex items-center md:divide-x md:divide-dashed md:divide-gray-400 " {...rest}>
{slugs.map((obj) => {
const language = languages.find((lang) => lang.name === obj.lang)
return (
<div
<li
className={`flex items-center ${activeLocale === String(language?.locale) ? 'hidden md:block' : ''} `}
key={obj.lang}
>
<ButtonLink
variant="ghost"
href={obj.slug}
locale={`${language?.locale}`}
className={`flex flex-col gap-0 items-stretch px-2 text-xs`}
className={`
${activeLocale === String(language?.locale) ? 'hidden md:block' : ''}
flex flex-col gap-0 items-stretch px-2 text-xs
`}
>
<span className="sr-only">{`Switch to ${language?.title}`}</span>
<span className="sr-only">{`${intl.formatMessage({
id: 'switch_to',
defaultMessage: 'Switch to',
})} ${language?.title}`}</span>
<span
aria-hidden
className={`uppercase ${activeLocale === String(language?.locale) ? 'font-bold' : 'font-normal'}`}
>
{language?.locale}
</span>
</ButtonLink>
</div>
</li>
)
})}
</div>
</ul>
)
}

0 comments on commit 105f369

Please sign in to comment.