|
|
|
|
|
|
|
|
import * as React from "react"; |
|
|
import cn from "classnames"; |
|
|
import { Button, Icon } from "../"; |
|
|
|
|
|
import { Reference } from "react-popper"; |
|
|
import type { ReferenceChildrenProps } from "react-popper"; |
|
|
|
|
|
type Props = {| |
|
|
+children?: React.Node, |
|
|
+className?: string, |
|
|
|
|
|
|
|
|
|
|
|
+toggle?: boolean, |
|
|
|
|
|
|
|
|
|
|
|
+value?: string, |
|
|
|
|
|
|
|
|
|
|
|
+type?: "link" | "button", |
|
|
|
|
|
|
|
|
|
|
|
+color?: string, |
|
|
|
|
|
|
|
|
|
|
|
+icon?: string, |
|
|
|
|
|
|
|
|
|
|
|
+isNavLink?: boolean, |
|
|
|
|
|
|
|
|
|
|
|
+isOption?: boolean, |
|
|
|
|
|
|
|
|
|
|
|
+onClick?: ( |
|
|
e: SyntheticMouseEvent<HTMLInputElement> | SyntheticMouseEvent<HTMLElement> |
|
|
) => void, |
|
|
+rootRef?: (?HTMLElement) => void, |
|
|
|}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function DropdownTrigger({ |
|
|
className, |
|
|
toggle = true, |
|
|
value, |
|
|
children, |
|
|
type = "link", |
|
|
icon, |
|
|
color, |
|
|
isNavLink, |
|
|
isOption, |
|
|
onClick, |
|
|
rootRef, |
|
|
}: Props): React.Node { |
|
|
const classes = cn( |
|
|
{ "dropdown-toggle": toggle, "nav-link": isNavLink }, |
|
|
className |
|
|
); |
|
|
|
|
|
const childrenFragment = ( |
|
|
<React.Fragment> |
|
|
{icon && ( |
|
|
<React.Fragment> |
|
|
<Icon name={icon} />{" "} |
|
|
</React.Fragment> |
|
|
)} |
|
|
{value} |
|
|
{children} |
|
|
</React.Fragment> |
|
|
); |
|
|
|
|
|
return type === "link" ? ( |
|
|
<Reference> |
|
|
{({ ref }: ReferenceChildrenProps) => ( |
|
|
<a className={classes} onClick={onClick} ref={ref}> |
|
|
{childrenFragment} |
|
|
</a> |
|
|
)} |
|
|
</Reference> |
|
|
) : ( |
|
|
<Reference> |
|
|
{({ ref }: ReferenceChildrenProps) => ( |
|
|
<Button |
|
|
className={classes} |
|
|
color={color} |
|
|
isDropdownToggle |
|
|
isOption={isOption} |
|
|
onClick={onClick} |
|
|
rootRef={ref} |
|
|
> |
|
|
{childrenFragment} |
|
|
</Button> |
|
|
)} |
|
|
</Reference> |
|
|
); |
|
|
} |
|
|
|
|
|
DropdownTrigger.displayName = "Dropdown.Trigger"; |
|
|
|
|
|
|
|
|
export default DropdownTrigger; |
|
|
|