UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

48 lines (47 loc) • 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderExpandButton = renderExpandButton; var _expand = require("@atlaskit/editor-common/styles/expand"); var _uiExpand = require("@atlaskit/editor-common/ui-expand"); /** Update the existing control without a React portal or tooltip positioning work. */ function renderExpandButton(container, _ref) { var _intl$formatMessage; var allowInteractiveExpand = _ref.allowInteractiveExpand, expanded = _ref.expanded, intl = _ref.intl; var button = container.querySelector(".".concat(_expand.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(_expand.expandClassNames.iconButton, " ").concat(_expand.expandClassNames.iconContainer); var svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('class', _expand.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 ? _uiExpand.messages.collapseNode : _uiExpand.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'); } }