Skip to content

Commit

Permalink
Styling of Language Switcher #33
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmoli committed Apr 1, 2020
1 parent be79b62 commit 7821735
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/components/LanguageSwitcher/LanguageSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { IntlContextConsumer, changeLocale } from 'gatsby-plugin-intl';
import { Button } from '@chakra-ui/core';
import { Select, Box } from '@chakra-ui/core';

const languageName = {
en: '🇬🇧 English',
Expand All @@ -14,26 +14,29 @@ const languageName = {

const LanguageSwitcher: React.FC = () => {
return (
<IntlContextConsumer>
{({
languages,
language: currentLocale
}: {
languages: string[];
currentLocale: string;
}) =>
languages.map((code: string) => (
<Button
isDisabled={code === currentLocale}
<Box width="4em">
<IntlContextConsumer>
{({
languages,
language: currentLocale
}: {
languages: string[];
currentLocale: string;
}) => (
<Select
onChange={({ currentTarget }) => changeLocale(currentTarget.value)}
size="sm"
key={code}
onClick={() => changeLocale(code)}
placeholder={languageName[currentLocale]}
>
{languageName[code]}
</Button>
))
}
</IntlContextConsumer>
{languages.map((code: string) => (
<option key={code} value={code}>
{languageName[code]}
</option>
))}
</Select>
)}
</IntlContextConsumer>
</Box>
);
};

Expand Down

0 comments on commit 7821735

Please sign in to comment.