UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

100 lines 4.23 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral"; var _templateObject; 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; } // This file is copied to `packages/editor/editor-plugin-ai/src/ui/components/AtlassianIntelligenceToolbarButton/ToolbarButton/index.tsx` // 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. /** @jsx jsx */ import React, { useCallback } from 'react'; import { css, jsx } from '@emotion/react'; import { FabricChannel } from '@atlaskit/analytics-listeners'; import Tooltip from '@atlaskit/tooltip'; import { ACTION, ACTION_SUBJECT, EVENT_TYPE, TOOLBAR_ACTION_SUBJECT_ID } from '../../analytics'; import Button from './styles'; export var TOOLBAR_BUTTON = TOOLBAR_ACTION_SUBJECT_ID; var buttonWrapper = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n height: 100%;\n"]))); 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, _props$titlePosition = props.titlePosition, titlePosition = _props$titlePosition === void 0 ? 'top' : _props$titlePosition, item = props.item, ariaLabel = props['aria-label'], ariaHasPopup = props['aria-haspopup'], ariaExpanded = props['aria-expanded'], ariaPressed = props['aria-pressed'], ariaKeyShortcuts = props['aria-keyshortcuts'], onClick = props.onClick, onKeyDown = props.onKeyDown, onItemClick = props.onItemClick; 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 id = buttonId ? "editor-toolbar__".concat(buttonId) : undefined; var button = jsx(Button, { id: id, ref: ref, appearance: "subtle", testId: testId, 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-haspopup": ariaHasPopup, "aria-label": ariaLabel, "aria-pressed": ariaPressed, "aria-keyshortcuts": ariaKeyShortcuts, onKeyDown: onKeyDown }, children); if (!title) { return button; } var tooltipContent = !hideTooltip ? title : null; return jsx(Tooltip, { content: tooltipContent, hideTooltipOnClick: true, position: titlePosition }, jsx("div", { css: buttonWrapper }, button)); }); export default ToolbarButton;