@atlaskit/tag
Version:
A tag labels UI objects for quick recognition and navigation.
52 lines (50 loc) • 2.18 kB
JavaScript
/**
* Shared utilities for TagNew and AvatarTag components.
* Note: CSS styles cannot be shared due to Compiled CSS static analysis requirements.
*/
import React, { useCallback, useMemo } from 'react';
import RemoveButton from '../tag/internal/removable/remove-button';
// Props for the remove button hook
// Shared hook for remove button creation
// TODO: Fill in the hook {description}.
/**
* {description}.
*/
export function useRemoveButton(_ref) {
var isRemovable = _ref.isRemovable,
tagText = _ref.tagText,
removeButtonLabel = _ref.removeButtonLabel,
testId = _ref.testId,
handleRemoveRequest = _ref.handleRemoveRequest,
removingTag = _ref.removingTag,
showingTag = _ref.showingTag,
onKeyPress = _ref.onKeyPress,
_ref$shape = _ref.shape,
shape = _ref$shape === void 0 ? 'default' : _ref$shape,
buttonHandlers = _ref.buttonHandlers;
var handleFocus = useCallback(function () {
removingTag();
buttonHandlers === null || buttonHandlers === void 0 || buttonHandlers.onFocus();
}, [removingTag, buttonHandlers]);
var handleBlur = useCallback(function () {
showingTag();
buttonHandlers === null || buttonHandlers === void 0 || buttonHandlers.onBlur();
}, [showingTag, buttonHandlers]);
return useMemo(function () {
if (!isRemovable) {
return undefined;
}
return /*#__PURE__*/React.createElement(RemoveButton, {
"aria-label": "".concat(removeButtonLabel || 'Remove', " ").concat(tagText),
onClick: handleRemoveRequest,
onFocus: handleFocus,
onBlur: handleBlur,
onKeyPress: onKeyPress,
onMouseEnter: buttonHandlers === null || buttonHandlers === void 0 ? void 0 : buttonHandlers.onMouseEnter,
onMouseLeave: buttonHandlers === null || buttonHandlers === void 0 ? void 0 : buttonHandlers.onMouseLeave,
onMouseDown: buttonHandlers === null || buttonHandlers === void 0 ? void 0 : buttonHandlers.onMouseDown,
testId: testId ? "close-button-".concat(testId) : undefined,
shape: shape
});
}, [isRemovable, removeButtonLabel, tagText, handleRemoveRequest, handleFocus, handleBlur, onKeyPress, buttonHandlers, testId, shape]);
}