@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
105 lines (103 loc) • 5.02 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
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; }
/**
* @jsxRuntime classic
* @jsx jsx
*/
import React, { useCallback } from 'react';
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports
import { jsx } from '@emotion/react';
import Button from '@atlaskit/button/custom-theme-button';
import { expandClassNames } from '@atlaskit/editor-common/styles';
import { expandLayoutWrapperStyle, ExpandLayoutWrapperWithRef, expandMessages } from '@atlaskit/editor-common/ui';
import { akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
import Tooltip from '@atlaskit/tooltip';
function withTooltip(Component) {
return function WithTooltip(props) {
return (
// @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
jsx(Tooltip, {
content: props.label,
position: "top",
tag: ExpandLayoutWrapperWithRef
}, jsx(Component
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
, props))
);
};
}
export var ExpandButtonInner = function ExpandButtonInner(props) {
var useTheme = useCallback(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function (currentTheme, themeProps) {
var _currentTheme = currentTheme(themeProps),
buttonStyles = _currentTheme.buttonStyles,
rest = _objectWithoutProperties(_currentTheme, _excluded);
return _objectSpread({
buttonStyles: _objectSpread(_objectSpread({}, buttonStyles), {}, {
height: '100%',
'& svg': {
transform: props.expanded ? 'transform: rotate(90deg);' : 'transform: rotate(0deg);',
transition: "transform 0.2s ".concat(akEditorSwoopCubicBezier, ";")
}
})
}, rest);
}, [props]);
var intl = props.intl,
expanded = props.expanded;
var label = expanded ? expandMessages.collapseNode : expandMessages.expandNode;
var labelIntl = intl ? intl.formatMessage(label) : label.defaultMessage;
return jsx(Button, {
appearance: "subtle"
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: expandClassNames.iconContainer,
iconBefore: jsx(ChevronRightIcon, {
label: '',
size: "small"
}),
shouldFitContainer: true,
theme: useTheme,
"aria-label": labelIntl,
"aria-expanded": props.expanded,
isDisabled: !props.allowInteractiveExpand
});
};
var ButtonWithTooltip = withTooltip(ExpandButtonInner);
var ButtonWithoutTooltip = ExpandButtonInner;
export var ExpandButton = function ExpandButton(props) {
var expanded = props.expanded,
intl = props.intl;
var message = expanded ? expandMessages.collapseNode : expandMessages.expandNode;
var label = intl && intl.formatMessage(message) || message.defaultMessage;
// check to ensure device supports any-hover
var supportsAnyHover = !!window.matchMedia ? window.matchMedia('(any-hover: hover)').matches !== window.matchMedia('(any-hover: none)').matches : false;
var hoverEventCheck = supportsAnyHover ? window.matchMedia('(any-hover: hover)').matches : true;
// hoverEventCheck is to disable tooltips for mobile to prevent incorrect hover state causing issues on iOS
if (props.allowInteractiveExpand && hoverEventCheck) {
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
return jsx(ButtonWithTooltip, _extends({
label: label
}, props));
}
return (
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
jsx("div", {
css: expandLayoutWrapperStyle
}, jsx(ButtonWithoutTooltip, _extends({
label: label
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
}, props)))
);
};