Popover
evergreen-popover
is a package exporting a Popover
React component.
Popovers display floating content in relation to a target.
Popovers appear either at the top or bottom of their target.
The preferred and default side is the bottom.
Popovers use smart positioning if there is not enough space on the bottom.
Key points
- Uses
Positioner
fromevergreen-positioner
- Tooltips use
onMouseLeave
andonMouseEnter
to show and hide the tooltip
When creating a popover, you must specify both:
- its content, by setting the content prop, and
- its target, as a single child element or a function
When you pass a function to the content prop you will be able to close the popover inside of the content.
Popovers close on:
- outside click
- escape key
- window resize
- something in content that calls the close function
Design Example
The Card that is rendered is a <Card elevation={3} />
.
Prop types and default props
static propTypes = ...PositionerpropTypes onOpen: PropTypesfuncisRequired // Use isOpen to manually control the Popover isOpen: PropTypesbool onClose: PropTypesfuncisRequired content: PropTypesisRequired children: PropTypes isRequired display: PropTypesstring minWidth: PropTypes minHeight: PropTypes statelessProps: PropTypes static defaultProps = side: 'bottom' {} {} minWidth: 200 minHeight: 40
Complete story
import storiesOf from '@storybook/react'import React from 'react'import PropTypes from 'prop-types'import Box from 'ui-box'import Popover from '../src/'import Pane from 'evergreen-layers'import Text from 'evergreen-typography'import Button from 'evergreen-buttons' const PopoverContent = <Pane ="240px" ="240px" ="flex" ="center" ="center" ="column" > <Text>PopoverContent</Text> </Pane> const ClosablePopoverContent = close <Pane ="240px" ="240px" ="flex" ="center" ="center" ="column" > <Text>ClosablePopoverContent</Text> <Button =>Close</Button> </Pane> ClosablePopoverContentpropTypes = close: PropTypesfunc // Using it with a function for complete controlconst controlUsage = <Popover = ="inline-block" > isOpen toggle getRef key <Button // `` // , // = // / = // // () = // // , = = > isOpen ? 'is open' : 'open' </Button> </Popover>