123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- define(['react', 'react-dom', 'prop-types', 'ca-ui-toolkit'], function (React, ReactDOM, PropTypes, UI_Toolkit) {
- var Component = React.Component;
- var ContextMenu = UI_Toolkit.ContextMenu;
- var ContextMenuWrapper = function (_Component) {
- _inherits(ContextMenuWrapper, _Component);
- function ContextMenuWrapper() {
- _classCallCheck(this, ContextMenuWrapper);
- return _possibleConstructorReturn(this, _Component.apply(this, arguments));
- }
- ContextMenuWrapper.prototype.render = function render() {
- var _props = this.props,
- theme = _props.theme,
- _props$placement = _props.placement,
- placement = _props$placement === undefined ? 'bottomRight' : _props$placement,
- _props$align = _props.align,
- align = _props$align === undefined ? 'left' : _props$align,
- _props$domNodeToAttac = _props.domNodeToAttachTo,
- domNodeToAttachTo = _props$domNodeToAttac === undefined ? document.body : _props$domNodeToAttac,
- triggerNode = _props.triggerNode,
- contextMenuItems = _props.contextMenuItems,
- onClose = _props.onClose,
- onChange = _props.onChange;
- if (!contextMenuItems || !contextMenuItems.length) {
- return;
- }
- return React.createElement(
- ContextMenu,
- {
- theme: theme,
- placement: placement,
- align: align,
- triggerNode: triggerNode,
- domNodeToAttachTo: domNodeToAttachTo,
- onClose: onClose,
- onChange: onChange
- },
- this._renderMenuItems(contextMenuItems)
- );
- };
- ContextMenuWrapper.prototype._renderMenuItems = function _renderMenuItems(items) {
- var _this2 = this;
- if (items) {
- return items.map(function (section, index) {
- return _this2._renderMenuSection(section, index);
- });
- }
- };
- ContextMenuWrapper.prototype._renderMenuSection = function _renderMenuSection(section, key) {
- if (Array.isArray(section.items)) {
- var _section$name = section.name,
- name = _section$name === undefined ? 'menu' : _section$name,
- label = section.label,
- items = section.items;
- return React.createElement(ContextMenu.List, {
- key: key,
- content: items,
- name: name,
- label: label,
- clickSelection: true });
- } else {
- return React.createElement(ContextMenu.Separator, {
- key: key
- });
- }
- };
- return ContextMenuWrapper;
- }(Component);
- ContextMenuWrapper.propTypes = {
- contextMenuItems: PropTypes.array,
- placement: PropTypes.string,
- align: PropTypes.string,
- triggerNode: PropTypes.object,
- style: PropTypes.object,
- domNodeToAttachTo: PropTypes.object,
- theme: PropTypes.bool,
- onClose: PropTypes.func,
- onChange: PropTypes.func
- };
- return ContextMenuWrapper;
- });
|