UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

62 lines 3.1 kB
import * as tslib_1 from "tslib"; import BoldIcon from '@atlaskit/icon/glyph/editor/bold'; import ItalicIcon from '@atlaskit/icon/glyph/editor/italic'; import * as React from 'react'; import { PureComponent } from 'react'; import { analyticsDecorator as analytics } from '../../analytics'; import { toggleBold, toggleItalic, tooltip } from '../../keymaps'; import ToolbarButton from '../ToolbarButton'; import { ButtonGroup } from './styles'; var ToolbarTextFormatting = (function (_super) { tslib_1.__extends(ToolbarTextFormatting, _super); function ToolbarTextFormatting() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = {}; _this.handlePluginStateChange = function (pluginState) { _this.setState({ boldActive: pluginState.strongActive, boldDisabled: pluginState.strongDisabled, boldHidden: pluginState.strongHidden, italicActive: pluginState.emActive, italicDisabled: pluginState.emDisabled, italicHidden: pluginState.emHidden, }); }; _this.handleBoldClick = function () { if (!_this.state.boldDisabled) { return _this.props.pluginState.toggleStrong(_this.props.editorView); } return false; }; _this.handleItalicClick = function () { if (!_this.state.italicDisabled) { return _this.props.pluginState.toggleEm(_this.props.editorView); } return false; }; return _this; } ToolbarTextFormatting.prototype.componentDidMount = function () { this.props.pluginState.subscribe(this.handlePluginStateChange); }; ToolbarTextFormatting.prototype.componentWillUnmount = function () { this.props.pluginState.unsubscribe(this.handlePluginStateChange); }; ToolbarTextFormatting.prototype.render = function () { var disabled = this.props.disabled; return (React.createElement(ButtonGroup, null, this.state.boldHidden ? null : React.createElement(ToolbarButton, { onClick: this.handleBoldClick, selected: this.state.boldActive, disabled: disabled || this.state.boldDisabled, title: tooltip(toggleBold), iconBefore: React.createElement(BoldIcon, { label: "Bold" }) }), this.state.italicHidden ? null : React.createElement(ToolbarButton, { onClick: this.handleItalicClick, selected: this.state.italicActive, disabled: disabled || this.state.italicDisabled, title: tooltip(toggleItalic), iconBefore: React.createElement(ItalicIcon, { label: "Italic" }) }))); }; return ToolbarTextFormatting; }(PureComponent)); export default ToolbarTextFormatting; tslib_1.__decorate([ analytics('atlassian.editor.format.strong.button') ], ToolbarTextFormatting.prototype, "handleBoldClick", void 0); tslib_1.__decorate([ analytics('atlassian.editor.format.em.button') ], ToolbarTextFormatting.prototype, "handleItalicClick", void 0); //# sourceMappingURL=index.js.map