UNPKG

@adaptabletools/adaptable

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

57 lines (56 loc) 1.73 kB
import { useRef } from 'react'; import useProperty from '../utils/useProperty'; import getAvailableSizeInfo from '../utils/getAvailableSizeInfo'; import { getConstrainRect } from '../OverlayTrigger'; export default (props, positionerRef) => { const positionInfoRef = useRef({ maxHeight: '50vh', maxWidth: '50vw', verticalPosition: 'bottom', horizontalPosition: 'right', }); const updatePosition = () => { const positionRect = positionerRef.current.getBoundingClientRect(); positionInfoRef.current = getAvailableSizeInfo({ constrainRect: getConstrainRect(positionerRef.current, props.constrainTo), targetRect: positionRect, maxSizeOffset: 30, }); }; const [expanded, doSetExpanded] = useProperty(props, 'expanded', false, { onChange: (expanded) => { if (expanded) { if (props.onExpand) { props.onExpand(); } } else if (props.onCollapse) { props.onCollapse(); } if (props.onToggle) { props.onToggle(expanded); } if (props.onExpandedChange) { props.onExpandedChange(expanded); } }, }); const setExpanded = (newExpanded) => { // if (!newExpanded) { // return; // } if (!expanded && newExpanded) { updatePosition(); } doSetExpanded(newExpanded); }; const toggle = () => { setExpanded(!expanded); }; return { expanded, setExpanded, toggle, positionInfo: positionInfoRef.current, }; };