UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

42 lines • 2.18 kB
import { expandClassNames } from '@atlaskit/editor-common/styles/expand'; import { messages } from '@atlaskit/editor-common/ui-expand'; /** Update the existing control without a React portal or tooltip positioning work. */ export function renderExpandButton(container, _ref) { var _intl$formatMessage; var allowInteractiveExpand = _ref.allowInteractiveExpand, expanded = _ref.expanded, intl = _ref.intl; var button = container.querySelector(".".concat(expandClassNames.iconButton)); if (!button) { var doc = container.ownerDocument; button = doc.createElement('button'); button.type = 'button'; // Confluence comment navigation and focusIcon locate and click iconContainer. // Dropping that class broke revealing comments inside collapsed expands in ED-29205. button.className = "".concat(expandClassNames.iconButton, " ").concat(expandClassNames.iconContainer); var svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('class', expandClassNames.iconSvg); svg.setAttribute('width', '12'); svg.setAttribute('height', '12'); svg.setAttribute('viewBox', '0 0 16 16'); svg.setAttribute('aria-hidden', 'true'); svg.setAttribute('focusable', 'false'); var path = doc.createElementNS('http://www.w3.org/2000/svg', 'path'); path.setAttribute('fill', 'currentColor'); // The ADS small ChevronRightIcon, matching the existing React control. path.setAttribute('d', 'm6.03 1.47 6 6a.75.75 0 0 1 .052 1.004l-.052.056-6 6-1.06-1.06L10.44 8 4.97 2.53z'); svg.appendChild(path); button.appendChild(svg); container.appendChild(button); } var message = expanded ? messages.collapseNode : messages.expandNode; var label = (_intl$formatMessage = intl === null || intl === void 0 ? void 0 : intl.formatMessage(message)) !== null && _intl$formatMessage !== void 0 ? _intl$formatMessage : message.defaultMessage; button.setAttribute('aria-label', label); button.setAttribute('aria-expanded', String(expanded)); button.disabled = !allowInteractiveExpand; if (allowInteractiveExpand) { button.title = label; } else { button.removeAttribute('title'); } }