2017-11-20 19:02:49 +03:00
|
|
|
import * as PropTypes from 'prop-types';
|
2018-01-22 21:30:53 +03:00
|
|
|
import * as React from 'react';
|
2017-11-20 19:02:49 +03:00
|
|
|
|
2017-11-21 14:00:33 +03:00
|
|
|
import { RedocNormalizedOptions } from '../services/RedocNormalizedOptions';
|
2017-11-20 19:02:49 +03:00
|
|
|
|
|
|
|
export interface OptionsProviderProps {
|
2017-11-21 14:00:33 +03:00
|
|
|
options: RedocNormalizedOptions;
|
2017-11-20 19:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export class OptionsProvider extends React.Component<OptionsProviderProps> {
|
|
|
|
static childContextTypes = {
|
|
|
|
redocOptions: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
2017-11-21 14:00:33 +03:00
|
|
|
redocOptions: this.props.options,
|
2017-11-20 19:02:49 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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 || {};
|
|
|
|
}
|
|
|
|
}
|