-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Component/language drop down (#5982)
* feat: Added LanguageDropDown Component * chore: Removed Leftover Files * Resolve Issues - Proper Component Name - Use Predefined Tailwind Class - Pass Handler as Prop * Resolve Issues - Replace Tabs with Spaces - Use Tailwind Default Class for Dropdown Content
- Loading branch information
1 parent
71ec88b
commit c197726
Showing
8 changed files
with
178 additions
and
61 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
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; | ||
} |
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,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; |
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,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; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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