UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

96 lines 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var bullet_list_1 = require("@atlaskit/icon/glyph/editor/bullet-list"); var number_list_1 = require("@atlaskit/icon/glyph/editor/number-list"); var React = require("react"); var react_1 = require("react"); var analytics_1 = require("../../analytics"); var keymaps_1 = require("../../keymaps"); var ToolbarButton_1 = require("../ToolbarButton"); var styles_1 = require("./styles"); var ToolbarLists = (function (_super) { tslib_1.__extends(ToolbarLists, _super); function ToolbarLists() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { bulletListActive: false, bulletListDisabled: false, bulletListHidden: false, orderedListActive: false, orderedListDisabled: false, orderedListHidden: false, }; _this.handlePluginStateChange = function (pluginState) { _this.setState({ bulletListActive: pluginState.bulletListActive, bulletListDisabled: pluginState.bulletListDisabled, bulletListHidden: pluginState.bulletListHidden, orderedListActive: pluginState.orderedListActive, orderedListDisabled: pluginState.orderedListDisabled, orderedListHidden: pluginState.orderedListHidden, }); }; _this.handleFuturePluginStateChange = function (pluginState) { _this.setState({ bulletListActive: pluginState.bulletListActive, bulletListDisabled: pluginState.bulletListDisabled, bulletListHidden: pluginState.bulletListHidden, orderedListActive: pluginState.orderedListActive, orderedListDisabled: pluginState.orderedListDisabled, orderedListHidden: pluginState.orderedListHidden, }); }; _this.handleBulletListClick = function () { if (!_this.state.bulletListDisabled) { if (_this.props.editorView) { return _this.props.pluginState.toggleBulletList(_this.props.editorView); } return _this.props.pluginState.toggleBulletList(_this.props.editorView); } return false; }; _this.handleOrderedListClick = function () { if (!_this.state.orderedListDisabled) { if (_this.props.editorView) { return _this.props.pluginState.toggleOrderedList(_this.props.editorView); } return _this.props.pluginState.toggleOrderedList(_this.props.editorView); } return false; }; return _this; } ToolbarLists.prototype.componentDidMount = function () { if (this.props.editorView) { this.props.pluginState.subscribe(this.handleFuturePluginStateChange); } else { this.props.pluginState.subscribe(this.handlePluginStateChange); } }; ToolbarLists.prototype.componentWillUnmount = function () { if (this.props.editorView) { this.props.pluginState.unsubscribe(this.handleFuturePluginStateChange); } else { this.props.pluginState.unsubscribe(this.handlePluginStateChange); } }; ToolbarLists.prototype.render = function () { return (React.createElement(styles_1.ButtonGroup, null, this.state.bulletListHidden ? null : React.createElement(ToolbarButton_1.default, { onClick: this.handleBulletListClick, selected: this.state.bulletListActive, disabled: this.state.bulletListDisabled || this.props.disabled, title: keymaps_1.tooltip(keymaps_1.toggleBulletList), iconBefore: React.createElement(bullet_list_1.default, { label: "Unordered list" }) }), this.state.orderedListHidden ? null : React.createElement(ToolbarButton_1.default, { onClick: this.handleOrderedListClick, selected: this.state.orderedListActive, disabled: this.state.orderedListDisabled || this.props.disabled, title: keymaps_1.tooltip(keymaps_1.toggleOrderedList), iconBefore: React.createElement(number_list_1.default, { label: "Ordered list" }) }))); }; return ToolbarLists; }(react_1.PureComponent)); tslib_1.__decorate([ analytics_1.analyticsDecorator('atlassian.editor.format.list.bullet.button') ], ToolbarLists.prototype, "handleBulletListClick", void 0); tslib_1.__decorate([ analytics_1.analyticsDecorator('atlassian.editor.format.list.numbered.button') ], ToolbarLists.prototype, "handleOrderedListClick", void 0); exports.default = ToolbarLists; //# sourceMappingURL=index.js.map