@atlaskit/menu
Version:
A list of options to help users navigate, or perform actions.
86 lines (84 loc) • 2.87 kB
JavaScript
/* custom-item.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
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';
const 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)
*/
const CustomItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
component: Component,
isDisabled = false,
isSelected = false,
isTitleHeading = false,
onClick,
testId,
children,
description,
iconAfter,
iconBefore,
onMouseDown,
shouldTitleWrap,
shouldDescriptionWrap,
className: UNSAFE_className,
UNSAFE_isDraggable,
interactionName,
...rest
}, ref) => {
const onMouseDownHandler = onMouseDown;
const interactionContext = useContext(InteractionContext);
const handleClick = useCallback(e => {
interactionContext === null || interactionContext === void 0 ? void 0 : interactionContext.tracePress(interactionName, e.timeStamp);
onClick === null || onClick === void 0 ? 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 && `${testId}--primitive`
}), ({
children,
className
}) => /*#__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;