@atlaskit/menu
Version:
A list of options to help users navigate, or perform actions.
91 lines (89 loc) • 3.92 kB
JavaScript
/* custom-item.tsx generated by @compiled/babel-plugin v0.36.1 */
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["component", "isDisabled", "isSelected", "isTitleHeading", "onClick", "testId", "children", "description", "iconAfter", "iconBefore", "onMouseDown", "shouldTitleWrap", "shouldDescriptionWrap", "className", "UNSAFE_isDraggable", "interactionName"];
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { forwardRef, memo, useCallback, useContext } from 'react';
import InteractionContext from '@atlaskit/interaction-context';
import MenuItemPrimitive from '../internal/components/menu-item-primitive';
var preventEvent = function preventEvent(e) {
e.preventDefault();
};
// Dirty hack to get generics working with forward ref [1/2]
/**
* __Custom item__
*
* A custom item is used to populate a menu with items that can be any element.
*
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/menu/docs/custom-item)
* - [Code](https://atlaskit.atlassian.com/packages/design-system/menu)
*/
var CustomItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
var Component = _ref.component,
_ref$isDisabled = _ref.isDisabled,
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
_ref$isSelected = _ref.isSelected,
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
_ref$isTitleHeading = _ref.isTitleHeading,
isTitleHeading = _ref$isTitleHeading === void 0 ? false : _ref$isTitleHeading,
onClick = _ref.onClick,
testId = _ref.testId,
children = _ref.children,
description = _ref.description,
iconAfter = _ref.iconAfter,
iconBefore = _ref.iconBefore,
onMouseDown = _ref.onMouseDown,
shouldTitleWrap = _ref.shouldTitleWrap,
shouldDescriptionWrap = _ref.shouldDescriptionWrap,
UNSAFE_className = _ref.className,
UNSAFE_isDraggable = _ref.UNSAFE_isDraggable,
interactionName = _ref.interactionName,
rest = _objectWithoutProperties(_ref, _excluded);
var onMouseDownHandler = onMouseDown;
var interactionContext = useContext(InteractionContext);
var handleClick = useCallback(function (e) {
interactionContext === null || interactionContext === void 0 || interactionContext.tracePress(interactionName, e.timeStamp);
onClick === null || onClick === void 0 || onClick(e);
}, [onClick, interactionContext, interactionName]);
if (!Component) {
return null;
}
return /*#__PURE__*/React.createElement(MenuItemPrimitive
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
, _extends({
className: UNSAFE_className
}, rest, {
description: description,
iconAfter: iconAfter,
title: children,
iconBefore: iconBefore,
isSelected: isSelected,
isDisabled: isDisabled,
isTitleHeading: isTitleHeading,
shouldTitleWrap: shouldTitleWrap,
shouldDescriptionWrap: shouldDescriptionWrap,
testId: testId && "".concat(testId, "--primitive")
}), function (_ref2) {
var children = _ref2.children,
className = _ref2.className;
return /*#__PURE__*/React.createElement(Component, _extends({
"data-testid": testId
}, rest, {
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
className: className,
ref: ref
}, UNSAFE_isDraggable ? {} : {
draggable: false,
onDragStart: preventEvent
}, {
onMouseDown: isDisabled ? preventEvent : onMouseDownHandler,
onClick: isDisabled ? preventEvent : handleClick,
tabIndex: isDisabled ? -1 : undefined,
"aria-disabled": isDisabled
}), children);
});
})
// Dirty hack to get generics working with forward ref [2/2]
);
export default CustomItem;