File size: 1,701 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 |
// @flow
import * as React from "react";
import cn from "classnames";
import { Popper } from "react-popper";
import type { Placement, PopperChildrenProps } from "react-popper";
import type { Style } from "typed-styles";
type StyleOffsets = { top: number, left: number };
type StylePosition = { position: "absolute" | "fixed" };
export type Props = {|
+children?: React.Node,
+className?: string,
+position?: Placement,
/**
* Display an arrow pointing towards the trigger
*/
+arrow?: boolean,
/**
* The position of the arrow pointing towards the trigger
*/
+arrowPosition?: "left" | "right",
+style?: Style & StyleOffsets & StylePosition,
+rootRef?: (?HTMLElement) => void,
/**
* Show the DropdownMenu
*/
show?: boolean,
|};
/**
* The wrapper element for a Dropdowns Items
*/
function DropdownMenu({
className,
children,
position = "bottom",
arrow,
arrowPosition = "left",
style,
rootRef,
show = false,
}: Props): React.Node {
const classes = cn(
{
"dropdown-menu": true,
[`dropdown-menu-${arrowPosition}`]: arrowPosition,
[`dropdown-menu-arrow`]: arrow,
show: show,
},
className
);
return (
show && (
<Popper placement={position} eventsEnabled={true} positionFixed={false}>
{({ ref, style, placement }: PopperChildrenProps) => {
return (
<div
className={classes}
data-placement={placement}
style={style}
ref={ref}
>
{children}
</div>
);
}}
</Popper>
)
);
}
DropdownMenu.displayName = "Dropdown.Menu";
export default DropdownMenu;
|