@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
123 lines (122 loc) • 4.57 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
// If you make any change here, copy it to above file as well
// and notify about the change in #team-fc-editor-ai-dev channel.
/**
* @jsxRuntime classic
* @jsx jsx
*/
import React, { useCallback } from 'react';
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
import { css, jsx } from '@emotion/react';
import { FabricChannel } from '@atlaskit/analytics-listeners/types';
import Tooltip from '@atlaskit/tooltip';
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../../analytics';
import { ToolTipContent } from '../../keymaps';
import Button from './styles';
var buttonWrapper = css({
display: 'flex',
height: '100%'
});
var ToolbarButton = /*#__PURE__*/React.forwardRef(function (props, ref) {
var buttonId = props.buttonId,
testId = props.testId,
_props$className = props.className,
className = _props$className === void 0 ? '' : _props$className,
href = props.href,
iconAfter = props.iconAfter,
iconBefore = props.iconBefore,
disabled = props.disabled,
selected = props.selected,
spacing = props.spacing,
target = props.target,
children = props.children,
hideTooltip = props.hideTooltip,
title = props.title,
keymap = props.keymap,
_props$titlePosition = props.titlePosition,
titlePosition = _props$titlePosition === void 0 ? 'top' : _props$titlePosition,
item = props.item,
rel = props.rel,
ariaLabel = props['aria-label'],
ariaHasPopup = props['aria-haspopup'],
ariaExpanded = props['aria-expanded'],
ariaPressed = props['aria-pressed'],
ariaKeyShortcuts = props['aria-keyshortcuts'],
ariaControls = props['aria-controls'],
dataDsLevel = props['data-ds--level'],
onClick = props.onClick,
onKeyDown = props.onKeyDown,
onItemClick = props.onItemClick,
onFocus = props.onFocus,
onBlur = props.onBlur,
onMouseEnter = props.onMouseEnter,
onMouseLeave = props.onMouseLeave;
var handleClick = useCallback(function (event, analyticsEvent) {
if (disabled) {
return;
}
if (buttonId) {
analyticsEvent.update(function (payload) {
return _objectSpread(_objectSpread({}, payload), {}, {
action: ACTION.CLICKED,
actionSubject: ACTION_SUBJECT.TOOLBAR_BUTTON,
actionSubjectId: buttonId,
eventType: EVENT_TYPE.UI
});
}).fire(FabricChannel.editor);
}
if (onClick) {
onClick(event);
}
if (item && onItemClick) {
onItemClick(item);
}
}, [disabled, onClick, onItemClick, item, buttonId]);
var button = jsx(Button, {
ref: ref,
appearance: "subtle",
testId: testId
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: className,
href: href,
iconAfter: iconAfter,
iconBefore: iconBefore,
isDisabled: disabled,
isSelected: selected,
onClick: handleClick,
spacing: spacing || 'default',
target: target,
shouldFitContainer: true,
"aria-expanded": ariaExpanded,
"aria-controls": ariaControls,
"aria-haspopup": ariaHasPopup,
"aria-label": ariaLabel,
"aria-pressed": ariaPressed,
"aria-keyshortcuts": ariaKeyShortcuts,
onKeyDown: onKeyDown,
onFocus: onFocus,
onBlur: onBlur,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
"data-ds--level": dataDsLevel,
rel: rel
}, children);
if (!title) {
return button;
}
var tooltipContent = hideTooltip ? null : jsx(ToolTipContent, {
description: title,
keymap: keymap
});
return jsx(Tooltip, {
content: tooltipContent,
hideTooltipOnClick: true,
position: titlePosition
}, jsx("div", {
css: buttonWrapper
}, button));
});
export default ToolbarButton;