mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-11 03:16:48 +03:00
Implement hideHostname option
This commit is contained in:
parent
95f82b5e87
commit
e85718225d
|
@ -1,3 +1,4 @@
|
||||||
|
import { ComponentWithOptions } from '../OptionsProvider';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { OperationModel } from '../../services';
|
import { OperationModel } from '../../services';
|
||||||
import { ShelfIcon } from '../../common-elements';
|
import { ShelfIcon } from '../../common-elements';
|
||||||
|
@ -15,13 +16,15 @@ import {
|
||||||
|
|
||||||
export interface EndpointProps {
|
export interface EndpointProps {
|
||||||
operation: OperationModel;
|
operation: OperationModel;
|
||||||
|
|
||||||
|
hideHostname?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EndpointState {
|
export interface EndpointState {
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Endpoint extends React.PureComponent<EndpointProps, EndpointState> {
|
export class Endpoint extends ComponentWithOptions<EndpointProps, EndpointState> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -37,6 +40,8 @@ export class Endpoint extends React.PureComponent<EndpointProps, EndpointState>
|
||||||
const { operation } = this.props;
|
const { operation } = this.props;
|
||||||
const { expanded } = this.state;
|
const { expanded } = this.state;
|
||||||
|
|
||||||
|
const hideHostname = this.props.hideHostname || this.options.hideHostname;
|
||||||
|
|
||||||
// TODO: highlight server variables, e.g. https://{user}.test.com
|
// TODO: highlight server variables, e.g. https://{user}.test.com
|
||||||
return (
|
return (
|
||||||
<OperationEndpointWrap>
|
<OperationEndpointWrap>
|
||||||
|
@ -57,7 +62,7 @@ export class Endpoint extends React.PureComponent<EndpointProps, EndpointState>
|
||||||
<div>{server.description}</div>
|
<div>{server.description}</div>
|
||||||
<SelectOnClick>
|
<SelectOnClick>
|
||||||
<ServerUrl>
|
<ServerUrl>
|
||||||
<span>{server.url}</span>
|
{!hideHostname && <span>{server.url}</span>}
|
||||||
{operation.path}
|
{operation.path}
|
||||||
</ServerUrl>
|
</ServerUrl>
|
||||||
</SelectOnClick>
|
</SelectOnClick>
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import * as PropTypes from 'prop-types';
|
import * as PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { RedocNormalizedOptions } from '../services/RedocNormalizedOptions';
|
import { RedocNormalizedOptions, RedocRawOptions } from '../services/RedocNormalizedOptions';
|
||||||
import { ThemeInterface } from '../theme';
|
|
||||||
|
|
||||||
export interface RedocRawOptions {
|
|
||||||
theme?: ThemeInterface;
|
|
||||||
scrollYOffset?: number | string | Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OptionsProviderProps {
|
export interface OptionsProviderProps {
|
||||||
options: RedocRawOptions;
|
options: RedocRawOptions;
|
||||||
|
|
|
@ -9,8 +9,9 @@ import { ApiLogo } from '../ApiLogo/ApiLogo';
|
||||||
import { SideMenu } from '../SideMenu/SideMenu';
|
import { SideMenu } from '../SideMenu/SideMenu';
|
||||||
import { ContentItems } from '../ContentItems/ContentItems';
|
import { ContentItems } from '../ContentItems/ContentItems';
|
||||||
import { AppStore } from '../../services';
|
import { AppStore } from '../../services';
|
||||||
import { OptionsProvider, RedocRawOptions } from '../OptionsProvider';
|
import { OptionsProvider } from '../OptionsProvider';
|
||||||
import { StickySidebar } from '../StickySidebar/StickySidebar';
|
import { StickySidebar } from '../StickySidebar/StickySidebar';
|
||||||
|
import { RedocRawOptions } from '../../services/RedocNormalizedOptions';
|
||||||
|
|
||||||
import defaultTheme from '../../theme';
|
import defaultTheme from '../../theme';
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Stickyfill from 'stickyfill';
|
import Stickyfill from 'stickyfill';
|
||||||
|
|
||||||
import { ComponentWithOptions, RedocRawOptions } from '../OptionsProvider';
|
import { ComponentWithOptions } from '../OptionsProvider';
|
||||||
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
|
import { RedocNormalizedOptions, RedocRawOptions } from '../../services/RedocNormalizedOptions';
|
||||||
import styled from '../../styled-components';
|
import styled from '../../styled-components';
|
||||||
|
|
||||||
export interface StickySidebarProps {
|
export interface StickySidebarProps {
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
import { RedocRawOptions } from '../components/OptionsProvider';
|
|
||||||
import { ThemeInterface } from '../theme';
|
import { ThemeInterface } from '../theme';
|
||||||
import { isNumeric } from '../utils/helpers';
|
import { isNumeric } from '../utils/helpers';
|
||||||
|
|
||||||
|
export interface RedocRawOptions {
|
||||||
|
theme?: ThemeInterface;
|
||||||
|
scrollYOffset?: number | string | Function;
|
||||||
|
hideHostname?: boolean | string;
|
||||||
|
}
|
||||||
|
|
||||||
export class RedocNormalizedOptions {
|
export class RedocNormalizedOptions {
|
||||||
theme: ThemeInterface;
|
theme: ThemeInterface;
|
||||||
scrollYOffset: () => number;
|
scrollYOffset: () => number;
|
||||||
|
hideHostname: boolean;
|
||||||
|
|
||||||
constructor(raw: RedocRawOptions) {
|
constructor(raw: RedocRawOptions) {
|
||||||
this.scrollYOffset = RedocNormalizedOptions.normalizeScrollYOffset(raw.scrollYOffset);
|
this.scrollYOffset = RedocNormalizedOptions.normalizeScrollYOffset(raw.scrollYOffset);
|
||||||
|
this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static normalizeHideHostname(value: RedocRawOptions['hideHostname']): boolean {
|
||||||
|
return !!value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static normalizeScrollYOffset(value: RedocRawOptions['scrollYOffset']): () => number {
|
static normalizeScrollYOffset(value: RedocRawOptions['scrollYOffset']): () => number {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user