-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2160 from WordPress/update/popover-portal
Popover: Refactor to render using React portals
- Loading branch information
Showing
14 changed files
with
565 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Popover | ||
======= | ||
|
||
Popover is a React component to render a floating content modal. It is similar in purpose to a tooltip, but renders content of any sort, not only simple text. It anchors itself to its parent node, optionally by a specified direction. If the popover exceeds the bounds of the page in the direction it opens, its position will be flipped automatically. | ||
|
||
## Usage | ||
|
||
Render a Popover within the parent to which it should anchor: | ||
|
||
```jsx | ||
import { Popover } from '@wordpress/components'; | ||
|
||
function ToggleButton( { isVisible, toggleVisible } ) { | ||
return ( | ||
<button onClick={ toggleVisible }> | ||
Toggle Popover! | ||
<Popover | ||
isOpen={ isVisible } | ||
onClose={ toggleVisible } | ||
onClick={ ( event ) => event.stopPropagation() } | ||
> | ||
Popover is toggled! | ||
</Popover> | ||
</button> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
The component accepts the following props: | ||
|
||
### position | ||
|
||
The direction in which the popover should open relative to its parent node. Specify y- and x-axis as a space-separated string. Supports `"top"`, `"bottom"` y axis, and `"left"`, `"center"`, `"right"` x axis. | ||
|
||
- Type: `String` | ||
- Required: No | ||
- Default: `"top center"` | ||
|
||
### children | ||
|
||
The content to be displayed within the popover. | ||
|
||
- Type: `Element` | ||
- Required: Yes | ||
|
||
### className | ||
|
||
An optional additional class name to apply to the rendered popover. | ||
|
||
- Type: `String` | ||
- Required: No |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import clickOutside from 'react-click-outside'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
|
||
class PopoverDetectOutside extends Component { | ||
handleClickOutside( event ) { | ||
const { onClickOutside } = this.props; | ||
if ( onClickOutside ) { | ||
onClickOutside( event ); | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default clickOutside( PopoverDetectOutside ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.