-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
56 lines (50 loc) · 1.58 KB
/
index.tsx
File metadata and controls
56 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { LanguageIcon } from '@heroicons/react/24/outline';
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import classNames from 'classnames';
import type { FC } from 'react';
import type { SimpleLocaleConfig } from '#ui/types';
import styles from './index.module.css';
type LanguageDropDownProps = {
onChange?: (newLocale: SimpleLocaleConfig) => void;
currentLanguage: string;
availableLanguages: Array<SimpleLocaleConfig>;
ariaLabel: string;
};
const LanguageDropdown: FC<LanguageDropDownProps> = ({
onChange = () => {},
currentLanguage,
availableLanguages,
ariaLabel,
}) => {
return (
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<button className={styles.languageDropdown} aria-label={ariaLabel}>
<LanguageIcon height="20" />
</button>
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content
align="start"
className={styles.dropDownContent}
sideOffset={5}
>
<div>
{availableLanguages.map(({ name, code, localName }) => (
<DropdownMenu.Item
key={code}
onClick={() => onChange({ name, code, localName })}
className={classNames(styles.dropDownItem, {
[styles.currentDropDown]: code === currentLanguage,
})}
>
{localName}
</DropdownMenu.Item>
))}
</div>
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
);
};
export default LanguageDropdown;