@darwino/darwino-react
Version:
A set of Javascript classes and utilities
136 lines (109 loc) • 3.1 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
/*
* (c) Copyright Darwino Inc. 2014-2017.
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
/*
* This page base class accepts dynamic contributions from components
*/
class BaseMainPage extends Component {
// Context to pusblish to the children - documentForm
getChildContext() {
return {
documentForm: this
};
}
constructor(props, context) {
super(props, context);
this.registeredComponents = [];
this.resizeElements = this.resizeElements.bind(this);
this.state = {
gridHeight: 500
};
}
componentDidMount() {
if (this.isAutoResizeElements()) {
window.addEventListener('resize', this.resizeElements);
this.resizeElements(); // need to wait for the footer to be rendered once
// Also, in case of responsive UI, we need to wait for the menu to collapse
setTimeout(this.resizeElement, 200);
}
}
componentWillUnmount() {
if (this.isAutoResizeElements()) {
window.removeEventListener('resize', this.resizeElements);
}
}
isAutoResizeElements() {
return false;
}
resizeElements() {
var footerElt = this.getFooterElement();
var footerTop = (footerElt && footerElt.clientHeight > 0 ? footerElt.getBoundingClientRect().top : window.innerHeight) - 20;
var state = this.resizeElementsTo({
footerTop
}); // Is there a better way to compare state?
Object.keys(state).forEach(k => {
if (this.state[k] !== state[k]) {
var o = {};
o[k] = state[k];
this.setState(o);
}
});
}
getFooterElement() {
return document.getElementById('footer');
}
resizeElementsTo() {
return {};
}
_registerComponent(component) {
// Cannot be in the state as the state might not be updated synchronously
this.registeredComponents.push(component);
this.forceUpdate();
}
_unregisterComponent(component) {
var index = this.registeredComponents.indexOf(component);
if (index >= 0) {
this.registeredComponents.splice(index, 1);
}
}
_getRegisteredComponents() {
return this.registeredComponents;
}
getMessages() {
return this.refs.messages;
}
createActionBar() {
var children = [];
if (this.contributeActionBar) children.push(this.contributeActionBar());
this._getRegisteredComponents().forEach(f => {
if (f.contributeActionBar) {
var b = f.contributeActionBar();
if (b) children.push(b);
}
});
if (children.length) {
return this._makeActionBar(children);
}
return null;
} // Overrides
_makeActionBar(children) {
return /*#__PURE__*/React.createElement("div", {
className: "btn-toolbar action-bar",
role: "toolbar"
}, children);
}
getDialog() {
return null;
}
createMessages() {
return null;
}
}
_defineProperty(BaseMainPage, "childContextTypes", {
documentForm: PropTypes.object
});
export default BaseMainPage;
//# sourceMappingURL=BaseMainPage.js.map