UNPKG

@nodeject/ui-components

Version:

UI library for non-trivial components

78 lines (77 loc) 2.88 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as React from 'react'; export var TITLE_PLACEHOLDER = 'Edit title'; import { Popover } from 'antd'; var NodeMenu = /** @class */ (function (_super) { __extends(NodeMenu, _super); function NodeMenu() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { visible: false }; _this.hide = function () { _this.setState({ visible: false }); }; _this.handleVisibleChange = function (visible) { _this.setState({ visible: visible }); }; return _this; } NodeMenu.prototype.render = function () { var _this = this; var menuContent = this.props.content && React.cloneElement(this.props.content, { closeCallBack: function () { return _this.hide(); } }); return (React.createElement(Popover, { content: menuContent, title: this.props.title, trigger: "click", placement: "bottom", visible: this.state.visible, onVisibleChange: this.handleVisibleChange }, this.props.button)); }; return NodeMenu; }(React.Component)); export { NodeMenu }; // export interface NodeMenuProps extends PropsNodeButton { // title?: string // content?: JSX.Element // button?: JSX.Element // } // export const NodeMenu: React.SFC<NodeMenuProps> = props => { // const [isVisible, setIsVisible] = React.useState(false) // const hide = () => { // setIsVisible(false) // } // const handleVisibleChange = (visible: boolean) => { // setIsVisible(visible) // This does not set isVisible to `true`. // } // const menuContent: any = React.cloneElement(props.content, { // closeCallBack: () => hide() // }) // return ( // <div className={props.className}> // <div className={styles.requestNodeMenuIcon}> // <Popover // content={menuContent} // title={props.title} // trigger="click" // placement="bottom" // visible={isVisible} // onVisibleChange={handleVisibleChange} // > // {props.button} // </Popover> // </div> // </div> // ) // }