redoc/src/components/RedocStandalone.tsx

55 lines
1.4 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import { ThemeInterface } from '../theme';
import { LoadingWrap } from './LoadingWrap/LoadingWrap';
import { StoreProvider } from './StoreProvider';
import { ErrorBoundary } from './ErrorBoundary';
import { Redoc } from './Redoc/Redoc';
2017-11-19 22:27:44 +03:00
export interface RedocStandaloneProps {
2017-11-20 16:02:35 +03:00
spec?: object;
specUrl?: string;
options?: {
theme?: ThemeInterface;
};
}
2017-11-19 22:27:44 +03:00
export class RedocStandalone extends React.Component<RedocStandaloneProps> {
static propTypes = {
spec: (props, _, componentName) => {
if (!props.spec && !props.specUrl) {
return new Error(
`One of props 'spec' or 'specUrlurl' 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;
},
};
render() {
2017-11-20 16:02:35 +03:00
const { spec, specUrl, options } = this.props;
return (
<ErrorBoundary>
<StoreProvider spec={spec} specUrl={specUrl}>
{({ loading, store }) => (
<LoadingWrap loading={loading}>
<Redoc store={store} options={options} />
</LoadingWrap>
)}
</StoreProvider>
</ErrorBoundary>
);
}
}