-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
354 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ComponentProps, FC, PropsWithChildren, ReactNode, useMemo } from 'react'; | ||
import { HiOutlineChevronDown, HiOutlineChevronLeft, HiOutlineChevronRight, HiOutlineChevronUp } from 'react-icons/hi'; | ||
import classNames from 'classnames'; | ||
|
||
import { Button, ButtonProps } from '../Button'; | ||
import { Tooltip, TooltipProps } from '../Tooltip'; | ||
import { DropdownItem } from './DropdownItem'; | ||
import { DropdownDivider } from './DropdownDivider'; | ||
import { DropdownHeader } from './DropdownHeader'; | ||
|
||
export type DropdownProps = ButtonProps & | ||
Omit<TooltipProps, 'content' | 'style' | 'animation'> & { | ||
className?: string; | ||
label: ReactNode; | ||
inline?: boolean; | ||
}; | ||
|
||
const icons: Record<string, FC<ComponentProps<'svg'>>> = { | ||
top: HiOutlineChevronUp, | ||
right: HiOutlineChevronRight, | ||
bottom: HiOutlineChevronDown, | ||
left: HiOutlineChevronLeft, | ||
}; | ||
|
||
const DropdownComponent: FC<DropdownProps> = (props) => { | ||
const { children, className, label, inline, ...restProps } = props; | ||
const { | ||
placement = inline ? 'bottom-start' : 'bottom', | ||
arrow = false, | ||
trigger = 'click', | ||
...buttonProps | ||
} = restProps; | ||
|
||
const Icon = useMemo(() => { | ||
const [p] = placement.split('-'); | ||
|
||
return icons[p] ?? HiOutlineChevronDown; | ||
}, [placement]); | ||
const content = useMemo(() => <ul className="py-1">{children}</ul>, [children]); | ||
|
||
const TriggerWrapper = ({ children }: PropsWithChildren<any>) => | ||
inline ? <button className="flex items-center">{children}</button> : <Button {...buttonProps}>{children}</Button>; | ||
|
||
return ( | ||
<Tooltip | ||
className={classNames('w-44 !rounded !p-0', className)} | ||
content={content} | ||
style="auto" | ||
animation="duration-100" | ||
placement={placement} | ||
arrow={arrow} | ||
trigger={trigger} | ||
> | ||
<TriggerWrapper> | ||
{label} | ||
<Icon className="ml-2 h-4 w-4" /> | ||
</TriggerWrapper> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
DropdownComponent.displayName = 'Dropdown'; | ||
DropdownItem.displayName = 'Dropdown.Item'; | ||
DropdownHeader.displayName = 'Dropdown.Header'; | ||
DropdownDivider.displayName = 'Dropdown.Divider'; | ||
|
||
export const Dropdown = Object.assign(DropdownComponent, { | ||
Item: DropdownItem, | ||
Header: DropdownHeader, | ||
Divider: DropdownDivider, | ||
}); |
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,3 @@ | ||
import { FC } from 'react'; | ||
|
||
export const DropdownDivider: FC = () => <div className="my-1 h-px bg-gray-100 dark:bg-gray-600" />; |
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,9 @@ | ||
import { FC } from 'react'; | ||
import { DropdownDivider } from './DropdownDivider'; | ||
|
||
export const DropdownHeader: FC = ({ children }) => ( | ||
<> | ||
<div className="block py-2 px-4 text-sm text-gray-700 dark:text-gray-200">{children}</div> | ||
<DropdownDivider /> | ||
</> | ||
); |
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,14 @@ | ||
import { FC } from 'react'; | ||
|
||
export type DropdownItemProps = { | ||
onClick?: () => void; | ||
}; | ||
|
||
export const DropdownItem: FC<DropdownItemProps> = ({ children, onClick }) => ( | ||
<li | ||
className="block cursor-pointer py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-600 dark:hover:text-white" | ||
onClick={onClick} | ||
> | ||
{children} | ||
</li> | ||
); |
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
Oops, something went wrong.
169b46e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: