UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

44 lines (43 loc) 1.92 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React from 'react'; import ChromeCollapsed from '../ChromeCollapsed'; import { IntlProviderIfMissingWrapper } from '../IntlProviderIfMissingWrapper/IntlProviderIfMissingWrapper'; // Ignored via go/ees005 // eslint-disable-next-line @repo/internal/react/no-class-components export default class CollapsedEditor extends React.Component { constructor(...args) { super(...args); _defineProperty(this, "handleEditorRef", (editorRef, editorRefCallback) => { if (editorRefCallback && typeof editorRefCallback === 'function') { editorRefCallback(editorRef); } this.editorComponent = editorRef; }); } componentDidUpdate() { if (this.props.isExpanded && (this.editorComponent || this.functionalEditor) && (!this.previouslyExpanded || this.previouslyExpanded === undefined)) { var _this$props$onExpand, _this$props; (_this$props$onExpand = (_this$props = this.props).onExpand) === null || _this$props$onExpand === void 0 ? void 0 : _this$props$onExpand.call(_this$props); } this.previouslyExpanded = this.props.isExpanded; } // eslint-disable-next-line @typescript-eslint/no-explicit-any render() { const child = React.Children.only(this.props.children); this.functionalEditor = typeof child.type === 'function'; if (!this.props.isExpanded) { return /*#__PURE__*/React.createElement(IntlProviderIfMissingWrapper, null, /*#__PURE__*/React.createElement(ChromeCollapsed, { onFocus: this.props.onFocus, text: this.props.placeholder, label: this.props.assistiveLabel })); } // Let's avoid ref logic for functional Editor if (this.functionalEditor) { return child; } return /*#__PURE__*/React.cloneElement(child, { ref: editorComponent => this.handleEditorRef(editorComponent, child.ref) }); } }