Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions components/Common/LanguageDropDown/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.iconWrapper {
@apply h-9
w-9
rounded-md
bg-neutral-100
p-2
text-neutral-700
dark:bg-neutral-900
dark:text-neutral-300;
}

.dropDownContent {
@apply max-h-80
w-48
overflow-y-scroll
rounded
border
border-neutral-200
py-[1px]
shadow-lg
dark:border-neutral-900;
}

.dropDownItem {
@apply cursor-default
px-2.5
py-1.5
text-sm
font-medium
text-neutral-800
outline-none
data-[highlighted]:bg-green-600
data-[highlighted]:text-white
dark:text-white;
}

.currentDropDown {
@apply bg-green-600 text-white;
}
10 changes: 10 additions & 0 deletions components/Common/LanguageDropDown/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import LanguageDropDown from './index';

type Story = StoryObj<typeof LanguageDropDown>;
type Meta = MetaObj<typeof LanguageDropDown>;

export const Default: Story = {};

export default { component: LanguageDropDown } as Meta;
56 changes: 56 additions & 0 deletions components/Common/LanguageDropDown/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 { useIntl } from 'react-intl';

import { useLocale } from '@/hooks/useLocale';

import styles from './index.module.css';

export type LanguageDropDownProps = {
onClick?: () => void;
};

const LanguageDropdown: FC<LanguageDropDownProps> = ({
onClick = () => {},
}) => {
const { availableLocales, currentLocale } = useLocale();
const intl = useIntl();

const ariaLabel = intl.formatMessage({
id: 'components.common.languageDropdown.label',
});

return (
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<button className={styles.iconWrapper} aria-label={ariaLabel}>
<LanguageIcon height="20" />
</button>
</DropdownMenu.Trigger>

<DropdownMenu.Portal>
<DropdownMenu.Content
align="start"
className={styles.dropDownContent}
sideOffset={5}
>
{availableLocales.map(({ name, code }) => (
<DropdownMenu.Item
key={code}
onClick={onClick}
className={classNames(styles.dropDownItem, {
[styles.currentDropDown]: code === currentLocale.code,
})}
>
{name}
</DropdownMenu.Item>
))}
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
);
};

export default LanguageDropdown;
39 changes: 0 additions & 39 deletions hooks/__tests__/useClickOutside.test.mjs

This file was deleted.

21 changes: 0 additions & 21 deletions hooks/useClickOutside.ts

This file was deleted.

3 changes: 2 additions & 1 deletion i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
"components.common.pagination.next": "Next",
"components.common.pagination.nextAriaLabel": "Next page",
"components.common.pagination.defaultLabel": "Pagination",
"components.common.pagination.pageLabel": "Go to page {pageNumber}"
"components.common.pagination.pageLabel": "Go to page {pageNumber}",
"components.common.languageDropdown.label": "Choose Language"
}
70 changes: 70 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@mdx-js/react": "^2.3.0",
"@nodevu/core": "~0.1.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tabs": "^1.0.4",
Expand Down