@atlaskit/menu
Version:
A list of options to help users navigate, or perform actions.
80 lines • 3.64 kB
JavaScript
/* button-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 = ["children", "description", "iconAfter", "iconBefore", "isDisabled", "isSelected", "onClick", "testId", "onMouseDown", "shouldTitleWrap", "shouldDescriptionWrap", "className", "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 { fg } from '@atlaskit/platform-feature-flags';
import MenuItemPrimitive from '../internal/components/menu-item-primitive';
/**
* __Button item__
*
* A button item is used to populate a menu with items that are buttons.
*
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/menu/docs/button-item)
* - [Code](https://atlaskit.atlassian.com/packages/design-system/menu)
*/
var ButtonItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (props, ref) {
var children = props.children,
description = props.description,
iconAfter = props.iconAfter,
iconBefore = props.iconBefore,
_props$isDisabled = props.isDisabled,
isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
_props$isSelected = props.isSelected,
isSelected = _props$isSelected === void 0 ? false : _props$isSelected,
onClick = props.onClick,
testId = props.testId,
onMouseDown = props.onMouseDown,
shouldTitleWrap = props.shouldTitleWrap,
shouldDescriptionWrap = props.shouldDescriptionWrap,
UNSAFE_className = props.className,
interactionName = props.interactionName,
rest = _objectWithoutProperties(props, _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 (!children) {
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, {
iconBefore: iconBefore,
iconAfter: iconAfter,
isDisabled: isDisabled,
isSelected: isSelected,
isTitleHeading: false,
description: description,
title: children,
shouldTitleWrap: shouldTitleWrap,
shouldDescriptionWrap: shouldDescriptionWrap,
testId: testId && "".concat(testId, "--primitive")
}), function (_ref) {
var children = _ref.children,
className = _ref.className;
return /*#__PURE__*/React.createElement("button", _extends({
"data-testid": testId
// This is intentionally placed before the `...rest` spread to prevent overriding existing usages of `aria-current`,
// which are already being passed to the button element.
,
"aria-current": isSelected && fg('platform_dst_menu_item_button_aria_current') ? 'true' : undefined
}, rest, {
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
className: className,
ref: ref,
disabled: isDisabled,
onClick: handleClick,
onMouseDown: onMouseDownHandler,
type: "button"
}), children);
});
}));
export default ButtonItem;