UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

196 lines (195 loc) • 8.6 kB
import _extends from "@babel/runtime/helpers/extends"; /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 import { css, jsx } from '@emotion/react'; import classnames from 'classnames'; import { defineMessages, FormattedMessage } from 'react-intl-next'; import CustomizeIcon from '@atlaskit/icon/core/customize'; import { Box, xcss } from '@atlaskit/primitives'; import Tooltip from '@atlaskit/tooltip'; var containerStyles = css({ textAlign: 'left', zIndex: 1, position: 'relative', // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.bodied': { marginTop: "var(--ds-space-300, 24px)" } }); var labelStyles = css({ opacity: 0, // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography lineHeight: 1, display: 'inline-flex', justifyContent: 'left', position: 'absolute', width: 'max-content', // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview top: '-28px', // When updating this value, make sure to also update the value in EditToggle.tsx, buttonContainerStyles // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.show-label': { cursor: 'pointer', opacity: 1 }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.nested': { // Need to add indent if the node is nested since we removed previous indentation styles to make it fit properly // in the nested component marginLeft: "var(--ds-space-150, 12px)" }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.inline': { // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview top: '-27px' }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.bodied-background': { background: "var(--ds-surface, #FFFFFF)" }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.bodied-border': { boxShadow: "0 0 0 1px ".concat("var(--ds-border, #091E4224)") }, minHeight: "var(--ds-space-300, 24px)", alignItems: 'center', borderRadius: "var(--ds-border-radius, 3px)", paddingLeft: "var(--ds-space-100, 8px)", paddingRight: "var(--ds-space-100, 8px)", color: "var(--ds-text-subtle, #44546F)", backgroundColor: "var(--ds-background-accent-gray-subtlest, #F1F2F4)", // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.remove-left-margin': { marginLeft: "var(--ds-space-negative-150, -12px)" }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.remove-nested-left-margin': { marginLeft: 0 }, font: "var(--ds-font-body, normal 400 14px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, system-ui, \"Helvetica Neue\", sans-serif)", // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.with-bodied-macro-live-page-styles': { backgroundColor: "var(--ds-background-neutral-subtle, #00000000)", boxShadow: "0 0 0 1px ".concat("var(--ds-border, #091E4224)") } }); var spacerStyles = xcss({ height: 'space.200', position: 'absolute', width: '100%' }); var iconStyles = css({ marginLeft: "var(--ds-space-075, 6px)", // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '&.hide-icon': { display: 'none' } }); var i18n = defineMessages({ configure: { id: 'editor-common-extensibility.macro.button.configure', defaultMessage: 'Configure {macroName}', description: 'Text in tooltip that tells user they can configure the specific macro.' } }); export var getShouldShowBodiedMacroLabel = function getShouldShowBodiedMacroLabel(isBodiedMacro, isNodeHovered, showLivePagesBodiedMacrosRendererView, showBodiedExtensionRendererView, showUpdatedLivePages1PBodiedExtensionUI // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/max-params ) { // Bodied macros show the label by default except for the new live pages 1P bodied macro experience where we only show it on hover if (!isBodiedMacro || showUpdatedLivePages1PBodiedExtensionUI) { return isNodeHovered; } if (!showLivePagesBodiedMacrosRendererView) { return true; } // Keep showing labels as usual for default experience for bodied macros return !!(isNodeHovered && !showBodiedExtensionRendererView); // For the new live pages bodied macro experience, we only show the label on hover in the "edit" view }; export var ExtensionLabel = function ExtensionLabel(_ref) { var text = _ref.text, extensionName = _ref.extensionName, isNodeHovered = _ref.isNodeHovered, customContainerStyles = _ref.customContainerStyles, isNodeNested = _ref.isNodeNested, setIsNodeHovered = _ref.setIsNodeHovered, isBodiedMacro = _ref.isBodiedMacro, showUpdatedLivePages1PBodiedExtensionUI = _ref.showUpdatedLivePages1PBodiedExtensionUI, showLivePagesBodiedMacrosRendererView = _ref.showLivePagesBodiedMacrosRendererView, showBodiedExtensionRendererView = _ref.showBodiedExtensionRendererView; var isInlineExtension = extensionName === 'inlineExtension'; var showDefaultBodiedStyles = isBodiedMacro && !isNodeHovered; var shouldShowBodiedMacroLabel = getShouldShowBodiedMacroLabel(isBodiedMacro, isNodeHovered, showLivePagesBodiedMacrosRendererView, showBodiedExtensionRendererView, showUpdatedLivePages1PBodiedExtensionUI); var containerClassNames = classnames({ bodied: isBodiedMacro }); var labelClassNames = classnames('extension-label', { nested: isNodeNested, inline: isInlineExtension, bodied: isBodiedMacro, 'bodied-border': showDefaultBodiedStyles, 'bodied-background': showDefaultBodiedStyles, 'show-label': shouldShowBodiedMacroLabel, 'with-bodied-macro-live-page-styles': isBodiedMacro && showLivePagesBodiedMacrosRendererView, 'always-hide-label': isBodiedMacro && showBodiedExtensionRendererView, // Need this separate class since we don't ever want to show the label during view mode 'remove-left-margin': !isBodiedMacro && !isInlineExtension && !isNodeNested, 'remove-nested-left-margin': isNodeNested && !isBodiedMacro && !isInlineExtension }); var iconClassNames = classnames({ 'hide-icon': isBodiedMacro && !isNodeHovered }); return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions jsx("div", { // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 css: containerStyles // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , className: containerClassNames // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766 , style: customContainerStyles // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events , onMouseOver: function onMouseOver() { setIsNodeHovered === null || setIsNodeHovered === void 0 || setIsNodeHovered(true); }, onMouseLeave: function onMouseLeave() { setIsNodeHovered === null || setIsNodeHovered === void 0 || setIsNodeHovered(false); }, "data-testid": "new-lozenge-container" }, jsx(Tooltip, { content: jsx(FormattedMessage // Ignored via go/ees005 // eslint-disable-next-line react/jsx-props-no-spreading , _extends({}, i18n.configure, { values: { macroName: text } })), position: "top" }, function (tooltipProps) { return jsx("span", _extends({ "data-testid": "new-lozenge-button" // Ignored via go/ees005 // eslint-disable-next-line react/jsx-props-no-spreading }, tooltipProps, { css: labelStyles // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , className: labelClassNames }), text, jsx("span", { css: iconStyles, className: iconClassNames, "data-testid": "config-icon" }, jsx(CustomizeIcon, { label: "" }))); }), jsx(Box, { xcss: spacerStyles })) ); };