UNPKG

@brizy/ui

Version:
27 lines (26 loc) 1.16 kB
import React, { useContext, useMemo } from "react"; import Popover from "antd/lib/popover"; import { FrameContentContext } from "../../Frame/FrameContent"; import { getWidthStyle } from "../utils"; import { BRZ_PREFIX } from "../../constants"; export const ToolbarPopover = (props) => { const { content, opened, onOpenedChange, children, getContainer, width } = props; const context = useContext(FrameContentContext); const handleGetContainer = () => { if (typeof getContainer === "function") { return getContainer(); } if (context.node) { return context.node; } return document.body; }; const selectedProps = {}; if (opened !== undefined) { selectedProps.visible = opened; } const _getWidthStyle = useMemo(() => { return getWidthStyle(width); }, [width]); return (React.createElement(Popover, Object.assign({ trigger: "click", content: content, overlayClassName: `${BRZ_PREFIX}-toolbar__popover`, getPopupContainer: handleGetContainer, onVisibleChange: onOpenedChange }, selectedProps, { overlayStyle: _getWidthStyle }), children)); };