UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

94 lines 4.64 kB
import * as tslib_1 from "tslib"; import BulletListIcon from '@atlaskit/icon/glyph/editor/bullet-list'; import NumberListIcon from '@atlaskit/icon/glyph/editor/number-list'; import * as React from 'react'; import { PureComponent } from 'react'; import { analyticsDecorator as analytics } from '../../analytics'; import { toggleBulletList, toggleOrderedList, tooltip } from '../../keymaps'; import ToolbarButton from '../ToolbarButton'; import { ButtonGroup } from './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(ButtonGroup, null, this.state.bulletListHidden ? null : React.createElement(ToolbarButton, { onClick: this.handleBulletListClick, selected: this.state.bulletListActive, disabled: this.state.bulletListDisabled || this.props.disabled, title: tooltip(toggleBulletList), iconBefore: React.createElement(BulletListIcon, { label: "Unordered list" }) }), this.state.orderedListHidden ? null : React.createElement(ToolbarButton, { onClick: this.handleOrderedListClick, selected: this.state.orderedListActive, disabled: this.state.orderedListDisabled || this.props.disabled, title: tooltip(toggleOrderedList), iconBefore: React.createElement(NumberListIcon, { label: "Ordered list" }) }))); }; return ToolbarLists; }(PureComponent)); export default ToolbarLists; tslib_1.__decorate([ analytics('atlassian.editor.format.list.bullet.button') ], ToolbarLists.prototype, "handleBulletListClick", void 0); tslib_1.__decorate([ analytics('atlassian.editor.format.list.numbered.button') ], ToolbarLists.prototype, "handleOrderedListClick", void 0); //# sourceMappingURL=index.js.map