@navinc/base-react-components
Version:
Nav's Pattern Library
33 lines • 1.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prop_types_1 = __importDefault(require("prop-types"));
const WaitForDependencies = ({ children, ErrorContent, LoadingContent, loadingProps, hasDependencyProps }) => {
const hasAllDataDependencies = hasDependencyProps.reduce((accumulator, current) => current && accumulator, true);
const areAnyLoading = loadingProps.reduce((accumulator, current) => current || accumulator, false);
if (hasAllDataDependencies) {
return children;
}
else if (areAnyLoading && LoadingContent) {
return LoadingContent;
}
else if (ErrorContent) {
return ErrorContent;
}
return null;
};
WaitForDependencies.defaultProps = {
hasDependencyProps: [],
loadingProps: [],
};
WaitForDependencies.propTypes = {
children: prop_types_1.default.node,
ErrorContent: prop_types_1.default.node,
hasDependencyProps: prop_types_1.default.array,
LoadingContent: prop_types_1.default.node,
loadingProps: prop_types_1.default.array,
};
exports.default = WaitForDependencies;
//# sourceMappingURL=wait-for-dependencies.js.map