choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
63 lines (56 loc) • 2.57 kB
JavaScript
import _typeof from "@babel/runtime/helpers/typeof";
import { Children } from 'react';
export function getKeyFromChildrenIndex(child, menuEventKey, index) {
var prefix = menuEventKey || '';
return child.key || "".concat(prefix, "item_").concat(index);
}
export function getMenuIdFromSubMenuEventKey(eventKey) {
return "".concat(eventKey, "-menu-");
}
export function loopMenuItem(children, cb) {
var index = -1;
Children.forEach(children, function (c) {
index++;
if (c && c.type && c.type.isMenuItemGroup) {
Children.forEach(c.props.children, function (c2) {
index++;
cb(c2, index);
});
} else {
cb(c, index);
}
});
}
export function loopMenuItemRecursively(children, keys, ret) {
if (!children || ret.find) {
return;
}
Children.forEach(children, function (c) {
if (c) {
var construct = c.type;
if (!construct || !(construct.isSubMenu || construct.isMenuItem || construct.isMenuItemGroup)) {
return;
}
if (keys.indexOf(c.key) !== -1) {
ret.find = true;
} else if (c.props.children) {
loopMenuItemRecursively(c.props.children, keys, ret);
}
}
});
}
export var menuAllProps = ['defaultSelectedKeys', 'selectedKeys', 'defaultOpenKeys', 'openKeys', 'mode', 'getPopupContainer', 'onSelect', 'onDeselect', 'onDestroy', 'openTransitionName', 'openAnimation', 'subMenuOpenDelay', 'subMenuCloseDelay', 'forceSubMenuRender', 'triggerSubMenuAction', 'level', 'selectable', 'multiple', 'onOpenChange', 'visible', 'focusable', 'defaultActiveFirst', 'prefixCls', 'inlineIndent', 'parentMenu', 'title', 'rootPrefixCls', 'eventKey', 'active', 'onItemHover', 'onTitleMouseEnter', 'onTitleMouseLeave', 'onTitleClick', 'popupAlign', 'popupOffset', 'isOpen', 'renderMenuItem', 'manualRef', 'subMenuKey', 'disabled', 'index', 'isSelected', 'store', 'activeKey', 'builtinPlacements', 'overflowedIndicator', // the following keys found need to be removed from test regression
'attribute', 'value', 'popupClassName', 'inlineCollapsed', 'menu', 'theme', 'itemIcon', 'expandIcon', 'checkable', 'rippleDisabled'];
export var getWidth = function getWidth(elem) {
var width = elem && typeof elem.getBoundingClientRect === 'function' && elem.getBoundingClientRect().width;
if (width) {
width = +width.toFixed(6);
}
return width || 0;
};
export var setStyle = function setStyle(elem, styleProperty, value) {
if (elem && _typeof(elem.style) === 'object') {
elem.style[styleProperty] = value;
}
};
//# sourceMappingURL=util.js.map