ContextMenuWrapper.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['react', 'react-dom', 'prop-types', 'ca-ui-toolkit'], function (React, ReactDOM, PropTypes, UI_Toolkit) {
  11. var Component = React.Component;
  12. var ContextMenu = UI_Toolkit.ContextMenu;
  13. var ContextMenuWrapper = function (_Component) {
  14. _inherits(ContextMenuWrapper, _Component);
  15. function ContextMenuWrapper() {
  16. _classCallCheck(this, ContextMenuWrapper);
  17. return _possibleConstructorReturn(this, _Component.apply(this, arguments));
  18. }
  19. ContextMenuWrapper.prototype.render = function render() {
  20. var _props = this.props,
  21. theme = _props.theme,
  22. _props$placement = _props.placement,
  23. placement = _props$placement === undefined ? 'bottomRight' : _props$placement,
  24. _props$align = _props.align,
  25. align = _props$align === undefined ? 'left' : _props$align,
  26. _props$domNodeToAttac = _props.domNodeToAttachTo,
  27. domNodeToAttachTo = _props$domNodeToAttac === undefined ? document.body : _props$domNodeToAttac,
  28. triggerNode = _props.triggerNode,
  29. contextMenuItems = _props.contextMenuItems,
  30. onClose = _props.onClose,
  31. onChange = _props.onChange;
  32. if (!contextMenuItems || !contextMenuItems.length) {
  33. return;
  34. }
  35. return React.createElement(
  36. ContextMenu,
  37. {
  38. theme: theme,
  39. placement: placement,
  40. align: align,
  41. triggerNode: triggerNode,
  42. domNodeToAttachTo: domNodeToAttachTo,
  43. onClose: onClose,
  44. onChange: onChange
  45. },
  46. this._renderMenuItems(contextMenuItems)
  47. );
  48. };
  49. ContextMenuWrapper.prototype._renderMenuItems = function _renderMenuItems(items) {
  50. var _this2 = this;
  51. if (items) {
  52. return items.map(function (section, index) {
  53. return _this2._renderMenuSection(section, index);
  54. });
  55. }
  56. };
  57. ContextMenuWrapper.prototype._renderMenuSection = function _renderMenuSection(section, key) {
  58. if (Array.isArray(section.items)) {
  59. var _section$name = section.name,
  60. name = _section$name === undefined ? 'menu' : _section$name,
  61. label = section.label,
  62. items = section.items;
  63. return React.createElement(ContextMenu.List, {
  64. key: key,
  65. content: items,
  66. name: name,
  67. label: label,
  68. clickSelection: true });
  69. } else {
  70. return React.createElement(ContextMenu.Separator, {
  71. key: key
  72. });
  73. }
  74. };
  75. return ContextMenuWrapper;
  76. }(Component);
  77. ContextMenuWrapper.propTypes = {
  78. contextMenuItems: PropTypes.array,
  79. placement: PropTypes.string,
  80. align: PropTypes.string,
  81. triggerNode: PropTypes.object,
  82. style: PropTypes.object,
  83. domNodeToAttachTo: PropTypes.object,
  84. theme: PropTypes.bool,
  85. onClose: PropTypes.func,
  86. onChange: PropTypes.func
  87. };
  88. return ContextMenuWrapper;
  89. });
  90. //# sourceMappingURL=ContextMenuWrapper.js.map