@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
149 lines (148 loc) • 7.43 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _typeof from "@babel/runtime/helpers/typeof";
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, { forwardRef, useCallback, useEffect } from 'react';
import Button from '@atlaskit/button/custom-theme-button';
import { componentWithCondition } from '@atlaskit/platform-feature-flags-react';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
import Tooltip from '@atlaskit/tooltip';
import { Pulse } from '../Pulse/Pulse';
import { getButtonStyles, iconOnlySpacing } from './styles';
var customSizeAndPadding = {
minWidth: "var(--ds-space-400, 32px)",
padding: "0px ".concat("var(--ds-space-050, 4px)")
};
var FloatingToolbarButton = function FloatingToolbarButton(_ref, forwardedRef) {
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,
onMount = _ref.onMount,
onUnmount = _ref.onUnmount,
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,
tooltipStyle = _ref.tooltipStyle,
testId = _ref.testId,
interactionName = _ref.interactionName,
_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,
pulse = _ref.pulse,
areAnyNewToolbarFlagsEnabled = _ref.areAnyNewToolbarFlagsEnabled;
// 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;
/**
* If it's a radio button, we need to reflect false values too, hence
* we cast it as a Boolean
*/
var ariaChecked = isRadioButton ? Boolean(isButtonPressed) : undefined;
var ariaPressed = isRadioButton ? undefined : isButtonPressed;
useEffect(function () {
onMount === null || onMount === void 0 || onMount();
return function () {
return onUnmount === null || onUnmount === void 0 ? void 0 : onUnmount();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
var handleOnClick = useCallback(function (event) {
onClick === null || onClick === void 0 || onClick(event);
}, [onClick]);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip
// Only fallback to title for tooltip if title is not shown
, {
content: tooltipContent || (iconOnly ? title : undefined),
component: tooltipStyle,
hideTooltipOnClick: hideTooltipOnClick,
position: "top"
}, /*#__PURE__*/React.createElement("div", {
onMouseEnter: expValEquals('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? undefined : onMouseEnter,
onMouseLeave: expValEquals('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? undefined : onMouseLeave
}, /*#__PURE__*/React.createElement(Pulse, {
pulse: !expValEquals('platform_editor_spotlight_migration', 'isEnabled', true) && pulse
}, /*#__PURE__*/React.createElement(Button
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop, @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
, {
className: className
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
ref: function ref(buttonElement) {
if (forwardedRef && editorExperiment('platform_synced_block', true)) {
if (typeof forwardedRef === 'function') {
forwardedRef(buttonElement);
} else if (_typeof(forwardedRef) === 'object') {
forwardedRef.current = buttonElement;
}
}
}
// eslint-disable-next-line @atlaskit/design-system/no-unsafe-style-overrides, @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
theme: function theme(adgTheme, themeProps) {
var _adgTheme = adgTheme(themeProps),
buttonStyles = _adgTheme.buttonStyles,
rest = _objectWithoutProperties(_adgTheme, _excluded);
return _objectSpread({
buttonStyles: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, buttonStyles), customSpacing), appearance === 'danger' && getButtonStyles({
appearance: appearance,
state: themeProps.state,
mode: themeProps.mode
})), areAnyNewToolbarFlagsEnabled ? customSizeAndPadding : {})
}, rest);
},
"aria-label": ariaLabel || title,
"aria-pressed": ariaPressed,
"aria-checked": ariaChecked,
role: isRadioButton ? 'radio' : undefined,
"aria-expanded": ariaHasPopup ? selected : undefined,
"aria-controls": ariaHasPopup ? areaControls : undefined,
spacing: areAnyNewToolbarFlagsEnabled ? 'default' : 'compact',
href: href,
target: target,
appearance: appearance,
"aria-haspopup": ariaHasPopup,
iconBefore: icon || undefined,
iconAfter: iconAfter,
onClick: handleOnClick,
onKeyDown: onKeyDown,
isSelected: selected,
isDisabled: disabled,
testId: testId,
interactionName: interactionName,
onMouseEnter: expValEquals('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? onMouseEnter : undefined,
onMouseLeave: expValEquals('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? onMouseLeave : undefined,
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)))));
};
// eslint-disable-next-line @typescript-eslint/ban-types
var _default_1 = componentWithCondition(function () {
return editorExperiment('platform_synced_block', true);
}, /*#__PURE__*/forwardRef(FloatingToolbarButton), FloatingToolbarButton);
export default _default_1;