UNPKG

@atlaskit/tag

Version:

A tag labels UI objects for quick recognition and navigation.

52 lines (50 loc) • 1.89 kB
/** * 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({ isRemovable, tagText, removeButtonLabel, testId, handleRemoveRequest, removingTag, showingTag, onKeyPress, shape = 'default', buttonHandlers }) { const handleFocus = useCallback(() => { removingTag(); buttonHandlers === null || buttonHandlers === void 0 ? void 0 : buttonHandlers.onFocus(); }, [removingTag, buttonHandlers]); const handleBlur = useCallback(() => { showingTag(); buttonHandlers === null || buttonHandlers === void 0 ? void 0 : buttonHandlers.onBlur(); }, [showingTag, buttonHandlers]); return useMemo(() => { if (!isRemovable) { return undefined; } return /*#__PURE__*/React.createElement(RemoveButton, { "aria-label": `${removeButtonLabel || 'Remove'} ${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-${testId}` : undefined, shape: shape }); }, [isRemovable, removeButtonLabel, tagText, handleRemoveRequest, handleFocus, handleBlur, onKeyPress, buttonHandlers, testId, shape]); }