UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

27 lines (26 loc) 869 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true, }); Object.defineProperty(exports, 'cloneElementWithRef', { enumerable: true, get: function () { return cloneElementWithRef; }, }); const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard'); const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react')); const _useMergedRefs = require('../hooks/useMergedRefs.js'); const cloneElementWithRef = (children, getProps) => { if (!children) return null; if (!_react.isValidElement(children)) return children; let childrenRef = children.props?.ref || children?.ref; let props = getProps(children); let ref = (0, _useMergedRefs.mergeRefs)( ...[childrenRef, 'ref' in props ? props.ref : null].filter(Boolean), ); return _react.cloneElement(children, { ...props, ref, }); };