UNPKG

@atlaskit/editor-plugin-floating-toolbar

Version:

Floating toolbar plugin for @atlaskit/editor-core

119 lines (114 loc) 4.07 kB
/** * @jsxRuntime classic * @jsx jsx */ import { memo } from 'react'; // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 import { css, jsx } from '@emotion/react'; // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports import { injectIntl } from 'react-intl'; import { DropdownMenuItem, DropdownSeparator } from '@atlaskit/editor-common/floating-toolbar'; import { HeadingItem } from '@atlaskit/menu'; export var menuItemDimensions = { width: 175, height: 32 }; var headingStyles = css({ padding: "var(--ds-space-200, 16px)".concat(" 0 ", "var(--ds-space-100, 8px)") }); // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview var menuContainerStyles = css({ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766 minWidth: "".concat(menuItemDimensions.width, "px"), // temporary solution to retain spacing defined by @atlaskit/Item // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '& button': { minHeight: "var(--ds-space-400, 32px)", padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-100, 8px)", " 7px"), // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '& > [data-item-elem-before]': { marginRight: "var(--ds-space-050, 4px)" } } }); // itemSpacing is used in calculations expecting a number, hence not using a space token export var itemSpacing = 4; // Extend the ButtonItem component type to allow mouse events to be accepted from the Typescript check var Dropdown = /*#__PURE__*/memo(function (props) { var hide = props.hide, dispatchCommand = props.dispatchCommand, items = props.items, intl = props.intl, editorView = props.editorView, _props$showSelected = props.showSelected, showSelected = _props$showSelected === void 0 ? true : _props$showSelected, areAnyNewToolbarFlagsEnabled = props.areAnyNewToolbarFlagsEnabled; if (areAnyNewToolbarFlagsEnabled) { return jsx("div", { css: menuContainerStyles, role: "menu" }, items // @ts-ignore .filter(function (item) { return item && (!('hidden' in item) || !item.hidden); }).map(function (item, idx) { if (!('type' in item)) { return jsx(DropdownMenuItem // Ignored via go/ees005 // eslint-disable-next-line react/no-array-index-key , { key: idx, item: item, hide: hide, dispatchCommand: dispatchCommand, editorView: editorView, showSelected: showSelected, intl: intl }); } if (item.type === 'separator') { // eslint-disable-next-line react/no-array-index-key return jsx(DropdownSeparator, { key: idx }); } if (item.type === 'overflow-dropdown-heading') { return jsx("div", { key: item.title, css: headingStyles }, jsx(HeadingItem, null, item.title)); } if (item.type === 'custom') { var dropdownMenuOptions = { hide: hide, dispatchCommand: dispatchCommand, editorView: editorView, showSelected: showSelected, intl: intl }; return item.render(editorView, dropdownMenuOptions); } })); } return jsx("div", { css: menuContainerStyles, role: "menu" }, items.filter(function (item) { return !item.hidden; }).map(function (item, idx) { return jsx(DropdownMenuItem // Ignored via go/ees005 // eslint-disable-next-line react/no-array-index-key , { key: idx, item: item, hide: hide, dispatchCommand: dispatchCommand, editorView: editorView, showSelected: showSelected, intl: intl }); })); }); var _default_1 = injectIntl(Dropdown); export default _default_1;