generated from theodorusclarence/ts-nextjs-tailwind-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create LanguageSwitcher component
- Loading branch information
Showing
10 changed files
with
96 additions
and
6 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
73 changes: 73 additions & 0 deletions
73
src/components/atoms/LanguageSwitcher/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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { InputLabel, MenuItem, Select, SelectChangeEvent } from '@mui/material'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import { useState } from 'react'; | ||
|
||
// export interface LanguageSwitcherProps { | ||
// language: string; | ||
// } | ||
|
||
interface Language { | ||
label: string; | ||
value: string; | ||
enabled: boolean; | ||
} | ||
|
||
const languages: Language[] = [ | ||
{ | ||
label: '🇬🇧 EN', | ||
value: 'en', | ||
enabled: true, | ||
}, | ||
{ | ||
label: '🇮🇹 IT', | ||
value: 'it', | ||
enabled: true, | ||
}, | ||
{ | ||
label: '🇩🇪 DE', | ||
value: 'de', | ||
enabled: true, | ||
}, | ||
]; | ||
|
||
const LanguageSwitcher = () => { | ||
const [chosenLanguage, setChosenLanguage] = useState(''); | ||
|
||
const handleChange = (event: SelectChangeEvent) => { | ||
setChosenLanguage(event.target.value); | ||
}; | ||
|
||
const label = <>🌐</>; | ||
|
||
return ( | ||
<div> | ||
<FormControl sx={{ m: 1, minWidth: 80 }} size='small'> | ||
<InputLabel id='demo-select-small-label'>{label}</InputLabel> | ||
<Select | ||
id='demo-select-small' | ||
labelId='demo-select-small-label' | ||
value={chosenLanguage} | ||
label={label} | ||
onChange={handleChange} | ||
style={{ fontSize: '14px' }} | ||
> | ||
{languages.map( | ||
(lang: Language) => | ||
lang.enabled && ( | ||
<MenuItem | ||
className='font-light' | ||
style={{ fontSize: '14px', fontWeight: 300 }} | ||
key={lang.value} | ||
value={lang.value} | ||
> | ||
{lang.label} | ||
</MenuItem> | ||
) | ||
)} | ||
</Select> | ||
</FormControl> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LanguageSwitcher; |
17 changes: 17 additions & 0 deletions
17
src/components/atoms/LanguageSwitcher/__stories__/LanguageSwitcher.stories.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Meta } from '@storybook/react'; | ||
|
||
import LanguageSwitcher, { | ||
LanguageSwitcherProps, | ||
} from '@/components/atoms/LanguageSwitcher/LanguageSwitcher'; | ||
|
||
const meta: Meta<typeof LanguageSwitcher> = { | ||
title: 'LanguageSwitcher', | ||
component: LanguageSwitcher, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const SampleStory = (args: LanguageSwitcherProps) => { | ||
return <LanguageSwitcher {...args} />; | ||
}; |
File renamed without changes.
File renamed without changes.
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