@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
122 lines (120 loc) • 6.26 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
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; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/**
* @jsxRuntime classic
* @jsx jsx
*/
import React, { useCallback } from 'react';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
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';
export var withTooltip = function withTooltip(WrapperComponent) {
return /*#__PURE__*/function (_React$Component) {
function WithSortableColumn(props) {
_classCallCheck(this, WithSortableColumn);
return _callSuper(this, WithSortableColumn, [props]);
}
_inherits(WithSortableColumn, _React$Component);
return _createClass(WithSortableColumn, [{
key: "render",
value: function render() {
var label = this.props.label;
return (
// @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
jsx(Tooltip, {
content: label,
position: "top",
tag: ExpandLayoutWrapperWithRef
}, jsx(WrapperComponent
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
, this.props))
);
}
}]);
}(React.Component);
};
export var CustomButton = function CustomButton(props) {
var allowInteractiveExpand = props.allowInteractiveExpand,
expanded = props.expanded,
intl = props.intl;
var useTheme = useCallback(
// 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 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": expanded,
isDisabled: !allowInteractiveExpand
});
};
var ButtonWithTooltip = withTooltip(CustomButton);
var ButtonWithoutTooltip = CustomButton;
export var ExpandIconButton = function ExpandIconButton(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)))
);
};