UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

46 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var code_1 = require("@atlaskit/icon/glyph/editor/code"); var React = require("react"); var react_1 = require("react"); var analytics_1 = require("../../analytics"); var ToolbarButton_1 = require("../ToolbarButton"); var keymaps_1 = require("../../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_1.default, { disabled: isDisabled || this.props.disabled, onClick: this.handleOnClick, selected: this.state.isActive, title: keymaps_1.tooltip(keymaps_1.toggleCode), iconBefore: React.createElement(code_1.default, { label: "Code" }) })); }; return ToolbarInlineCode; }(react_1.PureComponent)); tslib_1.__decorate([ analytics_1.analyticsDecorator('atlassian.editor.format.code.toggle') ], ToolbarInlineCode.prototype, "handleOnClick", void 0); exports.default = ToolbarInlineCode; //# sourceMappingURL=index.js.map