This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add API to Dropdown Item for Dividers and Icons (#166)
* simpler dropdown item * fixed prop typing for dropdown item * icon rendering * with an icon * icon prop * divider tests * divider
- Loading branch information
Showing
3 changed files
with
66 additions
and
13 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
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 |
---|---|---|
@@ -1,21 +1,41 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { Button } from "../.."; | ||
import { Button, IconButton, IconButtonProps } from "../.."; | ||
import { IconProps } from "../../icon"; | ||
|
||
export type DropdownItemProps = PropsWithChildren<{ | ||
active?: boolean; | ||
onClick?: () => void; | ||
}>; | ||
export type DropdownItemProps = Omit<IconButtonProps, "icon"> & | ||
PropsWithChildren<{ | ||
active?: boolean; | ||
icon?: IconProps; | ||
divider?: boolean; | ||
}>; | ||
|
||
const className = "dropdown-item"; | ||
|
||
const DropdownDivider = () => <hr className="dropdown-divider" />; | ||
|
||
export const DropdownItem = ({ | ||
children, | ||
active, | ||
onClick, | ||
divider, | ||
...buttonProps | ||
}: DropdownItemProps): JSX.Element => { | ||
const color = active ? "link" : "white"; | ||
|
||
const props: DropdownItemProps = { | ||
...buttonProps, | ||
className, | ||
color, | ||
}; | ||
|
||
const dropdownItemButton = props.icon ? ( | ||
<IconButton icon={props.icon} {...props} /> | ||
) : ( | ||
<Button {...props} /> | ||
); | ||
|
||
return ( | ||
<Button color={color} className="dropdown-item" onClick={onClick}> | ||
{children} | ||
</Button> | ||
<> | ||
{divider && <DropdownDivider />} | ||
{dropdownItemButton} | ||
</> | ||
); | ||
}; |
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