123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2019, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['react', 'react-dom', 'ca-ui-toolkit', 'prop-types', '../../../../lib/@waca/dashboard-common/dist/ui/Toolbar', '../../../../lib/@waca/core-client/js/core-client/ui/KeyCodes'], function (React, ReactDOM, UI_TOOLKIT, PropTypes, Toolbar, KeyCodes) {
- var Container = UI_TOOLKIT.Container;
- var ToolbarSectionComponent = function (_React$Component) {
- _inherits(ToolbarSectionComponent, _React$Component);
- function ToolbarSectionComponent(props) {
- _classCallCheck(this, ToolbarSectionComponent);
- var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
- _this._setRef = _this._setRef.bind(_this);
- _this._toolbar = new Toolbar({ className: 'dockedToolbar toolbar', reactToolbar: true });
- _this._toolbarRendered = Promise.resolve();
- return _this;
- }
- ToolbarSectionComponent.prototype.componentDidMount = function componentDidMount() {
- this._callbacks = {
- state: this._updateState.bind(this),
- focus: this._focus.bind(this)
- };
- this.props.stateProvider.registerCallback(this.props.stateEvent, this._callbacks['state']);
- this.props.stateProvider.registerCallback(this.props.focusEvent, this._callbacks['focus']);
- };
- ToolbarSectionComponent.prototype.componentWillUnmount = function componentWillUnmount() {
- this.props.stateProvider.removeCallback(this.props.stateEvent, this._callbacks['state']);
- this.props.stateProvider.removeCallback(this.props.focusEvent, this._callbacks['focus']);
- };
- ToolbarSectionComponent.prototype._updateState = function _updateState(state) {
- var _this2 = this;
- this._toolbar.clearItems();
- this._toolbarRendered = this._toolbar.addItems(state.actions).then(function () {
- _this2._toolbar.ready();
- });
- };
- ToolbarSectionComponent.prototype._focus = function _focus() {
- var _this3 = this;
- this._initialFocus = document.activeElement;
- this._toolbarRendered.then(function () {
- _this3._toolbar.setFocus();
- });
- };
- ToolbarSectionComponent.prototype._onKeyDown = function _onKeyDown(e) {
- if (e.keyCode === KeyCodes.ESCAPE && this._initialFocus) {
- this._initialFocus.focus();
- this._initialFocus = null;
- }
- };
- ToolbarSectionComponent.prototype._setRef = function _setRef(element) {
- this[ToolbarSectionComponent.ROOT] = element;
- /* eslint-disable react/no-find-dom-node */
- var elementDOMNode = ReactDOM.findDOMNode(element);
- /* eslint-disable react/no-find-dom-node */
- this.props.toolbarSectionDOM.setNode(elementDOMNode);
- if (element) {
- elementDOMNode.appendChild(this._toolbar.el);
- } else if (this._toolbar.el.parentNode) {
- this._toolbar.el.parentNode.removeChild(this._toolbar.el);
- }
- };
- ToolbarSectionComponent.prototype.render = function render() {
- return React.createElement(Container, {
- className: ToolbarSectionComponent.ROOT + ' ' + this.props.className,
- ref: this._setRef,
- onKeyDown: this._onKeyDown.bind(this)
- });
- };
- return ToolbarSectionComponent;
- }(React.Component);
- ToolbarSectionComponent.ROOT = 'ToolbarSection';
- ToolbarSectionComponent.propTypes = {
- className: PropTypes.string,
- toolbarSectionDOM: PropTypes.shape({
- setNode: PropTypes.func
- }),
- stateProvider: PropTypes.shape({
- getState: PropTypes.func,
- registerCallback: PropTypes.func,
- removeCallback: PropTypes.func
- }),
- stateEvent: PropTypes.string,
- focusEvent: PropTypes.string
- };
- ToolbarSectionComponent.defaultProps = {
- focusEvent: 'null_focus'
- };
- return ToolbarSectionComponent;
- });
- //# sourceMappingURL=ToolbarSectionComponent.js.map
|