UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

44 lines 2.05 kB
import * as tslib_1 from "tslib"; import CodeIcon from '@atlaskit/icon/glyph/editor/code'; import * as React from 'react'; import { PureComponent } from 'react'; import { analyticsDecorator as analytics } from '../../analytics'; import ToolbarButton from '../ToolbarButton'; import { toggleCode, tooltip } from '../../keymaps'; var ToolbarInlineCode = (function (_super) { tslib_1.__extends(ToolbarInlineCode, _super); function ToolbarInlineCode() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = {}; _this.handlePluginStateChange = function (pluginState) { _this.setState({ isActive: pluginState.codeActive, isDisabled: pluginState.codeDisabled, isEnabled: !pluginState.codeHidden, }); }; _this.handleOnClick = function () { if (!_this.state.isDisabled) { return _this.props.pluginState.toggleCode(_this.props.editorView); } return false; }; return _this; } ToolbarInlineCode.prototype.componentDidMount = function () { this.props.pluginState.subscribe(this.handlePluginStateChange); }; ToolbarInlineCode.prototype.componentWillUnmount = function () { this.props.pluginState.unsubscribe(this.handlePluginStateChange); }; ToolbarInlineCode.prototype.render = function () { var _a = this.state, isDisabled = _a.isDisabled, isEnabled = _a.isEnabled; return !isEnabled ? null : (React.createElement(ToolbarButton, { disabled: isDisabled || this.props.disabled, onClick: this.handleOnClick, selected: this.state.isActive, title: tooltip(toggleCode), iconBefore: React.createElement(CodeIcon, { label: "Code" }) })); }; return ToolbarInlineCode; }(PureComponent)); export default ToolbarInlineCode; tslib_1.__decorate([ analytics('atlassian.editor.format.code.toggle') ], ToolbarInlineCode.prototype, "handleOnClick", void 0); //# sourceMappingURL=index.js.map