@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
94 lines • 4.52 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["buttonStyles"];
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; }
import React from 'react';
import Button from '@atlaskit/button/custom-theme-button';
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
import Tooltip from '@atlaskit/tooltip';
import { getButtonStyles, iconOnlySpacing } from './styles';
export default (function (_ref) {
var title = _ref.title,
icon = _ref.icon,
iconAfter = _ref.iconAfter,
onClick = _ref.onClick,
onKeyDown = _ref.onKeyDown,
onMouseEnter = _ref.onMouseEnter,
onMouseLeave = _ref.onMouseLeave,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur,
selected = _ref.selected,
disabled = _ref.disabled,
href = _ref.href,
target = _ref.target,
_ref$appearance = _ref.appearance,
appearance = _ref$appearance === void 0 ? 'subtle' : _ref$appearance,
children = _ref.children,
className = _ref.className,
tooltipContent = _ref.tooltipContent,
testId = _ref.testId,
_ref$hideTooltipOnCli = _ref.hideTooltipOnClick,
hideTooltipOnClick = _ref$hideTooltipOnCli === void 0 ? true : _ref$hideTooltipOnCli,
ariaHasPopup = _ref.ariaHasPopup,
tabIndex = _ref.tabIndex,
areaControls = _ref.areaControls,
ariaLabel = _ref.ariaLabel,
isRadioButton = _ref.isRadioButton;
// Check if there's only an icon and add additional styles
var iconOnly = (icon || iconAfter) && !children;
var customSpacing = iconOnly ? iconOnlySpacing : {};
var isButtonPressed = ariaHasPopup ? undefined : selected;
var ariaChecked = isRadioButton ? isButtonPressed : undefined;
var ariaCheckedWithFF = getBooleanFF('platform.editor.a11y-floating-toolbar-markup_vexmo') ? ariaChecked : undefined;
var ariaPressed = isRadioButton ? undefined : isButtonPressed;
var ariaPressedWithFF = getBooleanFF('platform.editor.a11y-floating-toolbar-markup_vexmo') ? ariaPressed : isButtonPressed;
return /*#__PURE__*/React.createElement(Tooltip, {
content: tooltipContent || title,
hideTooltipOnClick: hideTooltipOnClick,
position: "top"
}, /*#__PURE__*/React.createElement("div", {
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave
}, /*#__PURE__*/React.createElement(Button, {
className: className,
theme: function theme(adgTheme, themeProps) {
var _adgTheme = adgTheme(themeProps),
buttonStyles = _adgTheme.buttonStyles,
rest = _objectWithoutProperties(_adgTheme, _excluded);
return _objectSpread({
buttonStyles: _objectSpread(_objectSpread(_objectSpread({}, buttonStyles), customSpacing), appearance === 'danger' && getButtonStyles({
appearance: appearance,
state: themeProps.state,
mode: themeProps.mode
}))
}, rest);
},
"aria-label": ariaLabel || title,
"aria-pressed": ariaPressedWithFF,
"aria-checked": ariaCheckedWithFF,
role: isRadioButton ? 'radio' : undefined,
"aria-expanded": ariaHasPopup ? selected : undefined,
"aria-controls": ariaHasPopup ? areaControls : undefined,
spacing: 'compact',
href: href,
target: target,
appearance: appearance,
"aria-haspopup": ariaHasPopup,
iconBefore: icon || undefined,
iconAfter: iconAfter,
onClick: onClick,
onKeyDown: onKeyDown,
isSelected: selected,
isDisabled: disabled,
testId: testId,
onFocus: onFocus,
onBlur: onBlur
// @ts-ignore
// tabIndex set as 0 by default in the design system ButtonBase component
// this is not expected for all buttons, we have to use tabIndex={null} for some cases
// should be fixed here https://a11y-internal.atlassian.net/browse/DST-287
,
tabIndex: tabIndex
}, children)));
});