UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

114 lines (112 loc) 4.08 kB
import _extends from "@babel/runtime/helpers/extends"; /** * @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 const withTooltip = WrapperComponent => { return class WithSortableColumn extends React.Component { constructor(props) { super(props); } render() { const { label } = this.props; 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)) ); } }; }; export const CustomButton = props => { const { allowInteractiveExpand, expanded, intl } = props; const useTheme = useCallback( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any (currentTheme, themeProps) => { const { buttonStyles, ...rest } = currentTheme(themeProps); return { buttonStyles: { ...buttonStyles, height: '100%', '& svg': { transform: props.expanded ? 'transform: rotate(90deg);' : 'transform: rotate(0deg);', transition: `transform 0.2s ${akEditorSwoopCubicBezier};` } }, ...rest }; }, [props]); const label = expanded ? expandMessages.collapseNode : expandMessages.expandNode; const 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 }); }; const ButtonWithTooltip = withTooltip(CustomButton); const ButtonWithoutTooltip = CustomButton; export const ExpandIconButton = props => { const { expanded, intl } = props; const message = expanded ? expandMessages.collapseNode : expandMessages.expandNode; const label = intl && intl.formatMessage(message) || message.defaultMessage; // check to ensure device supports any-hover const supportsAnyHover = !!window.matchMedia ? window.matchMedia('(any-hover: hover)').matches !== window.matchMedia('(any-hover: none)').matches : false; const 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))) ); };