File size: 2,073 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
// @flow
import * as React from "react";
import cn from "classnames";
import { Icon, Badge } from "../";
type Props = {|
+children?: React.Node,
+className?: string,
/**
* Display an Icon to the left of DropdownItem content
*/
+icon?: string,
/**
* The content of the DropdownItem if children is not used
*/
+value?: string,
/**
* Display a badge with this content to the right of DropdownItem content
*/
+badge?: string,
/**
* The type/color of Badge to be displayed
*/
+badgeType?: string,
/**
* Where the user should be taken on click.
* By default this will be passed as the 'href' prop to the <a> tag,
* but to the RootComponent it will be a 'to' prop instead
*/
+to?: string,
/**
* A component to be used instead of an <a> tag
*/
+RootComponent?: React.ElementType,
/**
* onClick handler
*/
+onClick?: (event: SyntheticMouseEvent<*>) => mixed,
/**
* Whether or not to pass "exact" property to underlying NavLink component
*/
+useExact?: boolean,
|};
/**
* An individual item that should be contained within a Dropdown.Menu
*/
function DropdownItem({
className,
icon,
value,
children,
badge,
badgeType,
to,
RootComponent,
onClick,
useExact,
}: Props): React.Node {
const classes = cn({ "dropdown-item": true }, className);
const childrenForAll = (
<React.Fragment>
{badge && (
<span className="float-right">
<Badge color={badgeType}>{badge}</Badge>
</span>
)}
{icon && (
<React.Fragment>
<Icon name={icon} className="dropdown-icon" />{" "}
</React.Fragment>
)}
{value}
{children}
</React.Fragment>
);
return RootComponent ? (
<RootComponent className={classes} to={to} onClick={onClick} exact={useExact}>
{childrenForAll}
</RootComponent>
) : (
<a className={classes} href={to} onClick={onClick}>
{childrenForAll}
</a>
);
}
DropdownItem.displayName = "Dropdown.Item";
/** @component */
export default DropdownItem;
|