import * as PropTypes from 'prop-types'; import * as React from 'react'; import { RedocNormalizedOptions, RedocRawOptions } from '../services/RedocNormalizedOptions'; import { ErrorBoundary } from './ErrorBoundary'; import { Loading } from './Loading/Loading'; import { Redoc } from './Redoc/Redoc'; import { StoreProvider } from './StoreProvider'; export interface RedocStandaloneProps { spec?: object; specUrl?: string; options?: RedocRawOptions; onLoaded?: (e?: Error) => any; } export class RedocStandalone extends React.PureComponent { static propTypes = { spec: (props, _, componentName) => { if (!props.spec && !props.specUrl) { return new Error( `One of props 'spec' or 'specUrl' was not specified in '${componentName}'.`, ); } return null; }, specUrl: (props, _, componentName) => { if (!props.spec && !props.specUrl) { return new Error( `One of props 'spec' or 'specUrl' was not specified in '${componentName}'.`, ); } return null; }, options: PropTypes.object, }; render() { const { spec, specUrl, options = {}, onLoaded } = this.props; const hideLoading = options.hideLoading !== undefined; const normalizedOpts = new RedocNormalizedOptions(options); return ( {({ loading, store }) => !loading ? ( ) : hideLoading ? null : ( ) } ); } }