mirror of
https://github.com/Redocly/redoc.git
synced 2024-12-03 22:03:43 +03:00
35 lines
793 B
TypeScript
35 lines
793 B
TypeScript
import * as PropTypes from 'prop-types';
|
|
import * as React from 'react';
|
|
|
|
import { RedocNormalizedOptions } from '../services/RedocNormalizedOptions';
|
|
|
|
export interface OptionsProviderProps {
|
|
options: RedocNormalizedOptions;
|
|
}
|
|
|
|
export class OptionsProvider extends React.Component<OptionsProviderProps> {
|
|
static childContextTypes = {
|
|
redocOptions: PropTypes.object.isRequired,
|
|
};
|
|
|
|
getChildContext() {
|
|
return {
|
|
redocOptions: this.props.options,
|
|
};
|
|
}
|
|
|
|
render() {
|
|
return React.Children.only(this.props.children);
|
|
}
|
|
}
|
|
|
|
export class ComponentWithOptions<P = {}, S = {}> extends React.Component<P, S> {
|
|
static contextTypes = {
|
|
redocOptions: PropTypes.object,
|
|
};
|
|
|
|
get options(): RedocNormalizedOptions {
|
|
return this.context.redocOptions || {};
|
|
}
|
|
}
|