diff --git a/src/core/client/ui/components/Popover/Popover.mdx b/src/core/client/ui/components/Popover/Popover.mdx new file mode 100644 index 000000000..936cc615e --- /dev/null +++ b/src/core/client/ui/components/Popover/Popover.mdx @@ -0,0 +1,29 @@ +--- +name: Popover +menu: UI Kit +--- + +import { Playground, PropsTable } from 'docz' +import Popover from './Popover' +import Button from '../Button' + +# Popover + +`Popover` uses `react-popper` + +## Basic usage + + ( + This is the body + )} + > + {({ toggleVisibility, forwardRef }) => ( + + Click me! + + )} + + diff --git a/src/core/client/ui/components/Popover/Popover.tsx b/src/core/client/ui/components/Popover/Popover.tsx index 0873f42c1..3564aa7ee 100644 --- a/src/core/client/ui/components/Popover/Popover.tsx +++ b/src/core/client/ui/components/Popover/Popover.tsx @@ -4,10 +4,22 @@ import { Manager, Popper, Reference, RefHandler } from "react-popper"; import AriaInfo from "../AriaInfo"; import * as styles from "./Popover.css"; -interface RenderProps { - toggleVisibility?: () => void; - forwardRef?: RefHandler; -} +type Placement = + | "auto-start" + | "auto" + | "auto-end" + | "top-start" + | "top" + | "top-end" + | "right-start" + | "right" + | "right-end" + | "bottom-end" + | "bottom" + | "bottom-start" + | "left-end" + | "left" + | "left-start"; interface InnerProps { body: (props: RenderProps) => any; @@ -17,6 +29,7 @@ interface InnerProps { id?: string; onClose?: () => void; className?: string; + placement?: Placement; } interface State { @@ -28,6 +41,11 @@ interface Props { style: CSSProperties; } +interface RenderProps { + toggleVisibility?: () => void; + forwardRef?: RefHandler; +} + class Popover extends React.Component { public state: State = { visible: false, @@ -40,43 +58,58 @@ class Popover extends React.Component { }; public render() { - const { id, body, children, description, className } = this.props; + const { + id, + body, + children, + description, + className, + placement, + } = this.props; const { visible } = this.state; return ( - {(props: Props) => children({ forwardRef: props.ref })} + {(props: Props) => + children({ + forwardRef: props.ref, + toggleVisibility: this.toggleVisibility, + }) + } - {(props: Props) => ( - - {description} - - {/* */} + {(props: Props) => + visible && ( - {body({ - toggleVisibility: this.toggleVisibility, - forwardRef: props.ref, - })} + {description} + + {/* */} + + {body({ + toggleVisibility: this.toggleVisibility, + forwardRef: props.ref, + })} + + {/* */} - {/* */} - - )} + ) + } );