1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __decorate, __extends, __rest } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { polyfill } from "react-lifecycles-compat";
|
20 | import { AbstractPureComponent2, Classes, Position } from "../../common";
|
21 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
22 | import { Icon } from "../icon/icon";
|
23 | import { Popover, PopoverInteractionKind } from "../popover/popover";
|
24 | import { Text } from "../text/text";
|
25 |
|
26 |
|
27 | import { Menu } from "./menu";
|
28 | var MenuItem = (function (_super) {
|
29 | __extends(MenuItem, _super);
|
30 | function MenuItem() {
|
31 | return _super !== null && _super.apply(this, arguments) || this;
|
32 | }
|
33 | MenuItem.prototype.render = function () {
|
34 | var _a, _b;
|
35 | var _c = this.props, active = _c.active, className = _c.className, children = _c.children, disabled = _c.disabled, icon = _c.icon, intent = _c.intent, labelClassName = _c.labelClassName, labelElement = _c.labelElement, multiline = _c.multiline, popoverProps = _c.popoverProps, shouldDismissPopover = _c.shouldDismissPopover, text = _c.text, textClassName = _c.textClassName, _d = _c.tagName, tagName = _d === void 0 ? "a" : _d, htmlTitle = _c.htmlTitle, htmlProps = __rest(_c, ["active", "className", "children", "disabled", "icon", "intent", "labelClassName", "labelElement", "multiline", "popoverProps", "shouldDismissPopover", "text", "textClassName", "tagName", "htmlTitle"]);
|
36 | var hasSubmenu = children != null;
|
37 | var intentClass = Classes.intentClass(intent);
|
38 | var anchorClasses = classNames(Classes.MENU_ITEM, intentClass, (_a = {},
|
39 | _a[Classes.ACTIVE] = active,
|
40 | _a[Classes.INTENT_PRIMARY] = active && intentClass == null,
|
41 | _a[Classes.DISABLED] = disabled,
|
42 |
|
43 | _a[Classes.POPOVER_DISMISS] = shouldDismissPopover && !disabled && !hasSubmenu,
|
44 | _a), className);
|
45 | var target = React.createElement(tagName, __assign(__assign(__assign({ tabIndex: 0 }, htmlProps), (disabled ? DISABLED_PROPS : {})), { className: anchorClasses }), React.createElement(Icon, { icon: icon }), React.createElement(Text, { className: classNames(Classes.FILL, textClassName), ellipsize: !multiline, title: htmlTitle }, text), this.maybeRenderLabel(labelElement), hasSubmenu ? React.createElement(Icon, { title: "Open sub menu", icon: "caret-right" }) : undefined);
|
46 | var liClasses = classNames((_b = {}, _b[Classes.MENU_SUBMENU] = hasSubmenu, _b));
|
47 | return React.createElement("li", { className: liClasses }, this.maybeRenderPopover(target, children));
|
48 | };
|
49 | MenuItem.prototype.maybeRenderLabel = function (labelElement) {
|
50 | var _a = this.props, label = _a.label, labelClassName = _a.labelClassName;
|
51 | if (label == null && labelElement == null) {
|
52 | return null;
|
53 | }
|
54 | return (React.createElement("span", { className: classNames(Classes.MENU_ITEM_LABEL, labelClassName) },
|
55 | label,
|
56 | labelElement));
|
57 | };
|
58 | MenuItem.prototype.maybeRenderPopover = function (target, children) {
|
59 | if (children == null) {
|
60 | return target;
|
61 | }
|
62 | var _a = this.props, disabled = _a.disabled, popoverProps = _a.popoverProps;
|
63 | return (
|
64 |
|
65 | React.createElement(Popover, __assign({ autoFocus: false, captureDismiss: false, disabled: disabled, enforceFocus: false, hoverCloseDelay: 0, interactionKind: PopoverInteractionKind.HOVER, modifiers: SUBMENU_POPOVER_MODIFIERS, position: Position.RIGHT_TOP, usePortal: false }, popoverProps, { content: React.createElement(Menu, null, children), minimal: true, popoverClassName: classNames(Classes.MENU_SUBMENU, popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.popoverClassName), target: target })));
|
66 | };
|
67 | MenuItem.defaultProps = {
|
68 | disabled: false,
|
69 | multiline: false,
|
70 | popoverProps: {},
|
71 | shouldDismissPopover: true,
|
72 | text: "",
|
73 | };
|
74 | MenuItem.displayName = DISPLAYNAME_PREFIX + ".MenuItem";
|
75 | MenuItem = __decorate([
|
76 | polyfill
|
77 | ], MenuItem);
|
78 | return MenuItem;
|
79 | }(AbstractPureComponent2));
|
80 | export { MenuItem };
|
81 | var SUBMENU_POPOVER_MODIFIERS = {
|
82 |
|
83 | flip: { boundariesElement: "viewport", padding: 20 },
|
84 |
|
85 | offset: { offset: -5 },
|
86 | preventOverflow: { boundariesElement: "viewport", padding: 20 },
|
87 | };
|
88 |
|
89 | var DISABLED_PROPS = {
|
90 | href: undefined,
|
91 | onClick: undefined,
|
92 | onMouseDown: undefined,
|
93 | onMouseEnter: undefined,
|
94 | onMouseLeave: undefined,
|
95 | tabIndex: -1,
|
96 | };
|
97 |
|
\ | No newline at end of file |