Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
feat: Pass ref's measurements to PopOver renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
diondiondion committed Aug 22, 2019
1 parent 9fb637e commit 7f0fbe6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/PopOver/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useState} from 'react';
import {Manager, Reference, Popper, placements} from 'react-popper';
import PropTypes from 'prop-types';

Expand All @@ -23,6 +23,19 @@ function PopOver(props) {

const autoDistance = +arrowSize / 2 + +distance;

const [refMeasurements, setRefMeasurements] = useState({});

const getRefModifier = {
enabled: true,
order: 950,
fn: data => {
if (data.offsets && data.offsets.reference) {
setRefMeasurements(data.offsets.reference);
}
return data;
},
};

return (
<Manager>
<Reference innerRef={innerRef}>{children}</Reference>
Expand All @@ -33,6 +46,7 @@ function PopOver(props) {
offset: {offset: `${offset}, ${autoDistance}`},
computeStyle: {gpuAcceleration: false},
flip: {flipVariations: true, flipVariationsByContent: true},
getRefModifier,
}}
>
{({ref, style, placement, arrowProps, scheduleUpdate}) => {
Expand All @@ -56,6 +70,7 @@ function PopOver(props) {
isOpen={isOpen}
content={content}
arrow={arrow}
refMeasurements={refMeasurements}
resizeWatcher={resizeWatcher}
/>
);
Expand Down Expand Up @@ -127,7 +142,8 @@ PopOver.propTypes = {
/**
* Customise popover rendering (e.g. for custom styling, transitions, etc).
* Should be a React component that takes the props
* `popOverRef`, `isOpen`, `style`, `content`, `arrow`, `resizeWatcher`
* `popOverRef`, `isOpen`, `style`, `content`, `arrow`, `resizeWatcher`,
* and `refMeasurements`
*/
renderer: PropTypes.elementType,
};
Expand Down

0 comments on commit 7f0fbe6

Please sign in to comment.