UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

29 lines (26 loc) • 906 B
"use client"; import { isValidElement, cloneElement } from 'react'; import { usePopper } from './PopperContext.mjs'; const PopperClose = ({ children })=>{ const { handleClose } = usePopper(); if (!/*#__PURE__*/ isValidElement(children)) { return children; } const element = children; return /*#__PURE__*/ cloneElement(element, { 'aria-label': element.props['aria-label'] || 'Close', onClick: ()=>{ const { onClick } = element.props; if (onClick) { const result = onClick(); // Check if the result is a Promise if (result && result instanceof Promise && typeof result.then === 'function') { result.then(()=>handleClose()).catch(()=>{}); return; } } handleClose(); } }); }; export { PopperClose };