mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 06:04:56 +03:00
Basic implementation finished
This commit is contained in:
parent
b10616c340
commit
0623298d0d
|
@ -1,18 +1,18 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { render } from 'react-dom';
|
import {render} from 'react-dom';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { resolve as urlResolve } from 'url';
|
import {resolve as urlResolve} from 'url';
|
||||||
import { RedocStandalone } from '../src';
|
import {RedocStandalone} from '../src';
|
||||||
import ComboBox from './ComboBox';
|
import ComboBox from './ComboBox';
|
||||||
|
|
||||||
const demos = [
|
const demos = [
|
||||||
{ value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram' },
|
{value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram'},
|
||||||
{
|
{
|
||||||
value: 'https://api.apis.guru/v2/specs/googleapis.com/calendar/v3/swagger.yaml',
|
value: 'https://api.apis.guru/v2/specs/googleapis.com/calendar/v3/swagger.yaml',
|
||||||
label: 'Google Calendar',
|
label: 'Google Calendar',
|
||||||
},
|
},
|
||||||
{ value: 'https://api.apis.guru/v2/specs/slack.com/1.0.6/swagger.yaml', label: 'Slack' },
|
{value: 'https://api.apis.guru/v2/specs/slack.com/1.0.6/swagger.yaml', label: 'Slack'},
|
||||||
{ value: 'https://api.apis.guru/v2/specs/zoom.us/2.0.0/swagger.yaml', label: 'Zoom.us' },
|
{value: 'https://api.apis.guru/v2/specs/zoom.us/2.0.0/swagger.yaml', label: 'Zoom.us'},
|
||||||
{
|
{
|
||||||
value: 'https://api.apis.guru/v2/specs/graphhopper.com/1.0/swagger.yaml',
|
value: 'https://api.apis.guru/v2/specs/graphhopper.com/1.0/swagger.yaml',
|
||||||
label: 'GraphHopper',
|
label: 'GraphHopper',
|
||||||
|
@ -21,10 +21,8 @@ const demos = [
|
||||||
|
|
||||||
const DEFAULT_SPEC = 'openapi.yaml';
|
const DEFAULT_SPEC = 'openapi.yaml';
|
||||||
|
|
||||||
class DemoApp extends React.Component<
|
class DemoApp extends React.Component<{},
|
||||||
{},
|
{ specUrl: string; dropdownOpen: boolean; cors: boolean }> {
|
||||||
{ specUrl: string; dropdownOpen: boolean; cors: boolean }
|
|
||||||
> {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
@ -71,7 +69,7 @@ class DemoApp extends React.Component<
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { specUrl, cors } = this.state;
|
const {specUrl, cors} = this.state;
|
||||||
let proxiedUrl = specUrl;
|
let proxiedUrl = specUrl;
|
||||||
if (specUrl !== DEFAULT_SPEC) {
|
if (specUrl !== DEFAULT_SPEC) {
|
||||||
proxiedUrl = cors
|
proxiedUrl = cors
|
||||||
|
@ -82,7 +80,7 @@ class DemoApp extends React.Component<
|
||||||
<>
|
<>
|
||||||
<Heading>
|
<Heading>
|
||||||
<a href=".">
|
<a href=".">
|
||||||
<Logo src="https://github.com/Redocly/redoc/raw/master/docs/images/redoc-logo.png" />
|
<Logo src="https://github.com/Redocly/redoc/raw/master/docs/images/redoc-logo.png"/>
|
||||||
</a>
|
</a>
|
||||||
<ControlsContainer>
|
<ControlsContainer>
|
||||||
<ComboBox
|
<ComboBox
|
||||||
|
@ -92,7 +90,7 @@ class DemoApp extends React.Component<
|
||||||
value={specUrl === DEFAULT_SPEC ? '' : specUrl}
|
value={specUrl === DEFAULT_SPEC ? '' : specUrl}
|
||||||
/>
|
/>
|
||||||
<CorsCheckbox title="Use CORS proxy">
|
<CorsCheckbox title="Use CORS proxy">
|
||||||
<input id="cors_checkbox" type="checkbox" onChange={this.toggleCors} checked={cors} />
|
<input id="cors_checkbox" type="checkbox" onChange={this.toggleCors} checked={cors}/>
|
||||||
<label htmlFor="cors_checkbox">CORS</label>
|
<label htmlFor="cors_checkbox">CORS</label>
|
||||||
</CorsCheckbox>
|
</CorsCheckbox>
|
||||||
</ControlsContainer>
|
</ControlsContainer>
|
||||||
|
@ -104,7 +102,7 @@ class DemoApp extends React.Component<
|
||||||
height="30px"
|
height="30px"
|
||||||
/>
|
/>
|
||||||
</Heading>
|
</Heading>
|
||||||
<RedocStandalone specUrl={proxiedUrl} options={{ scrollYOffset: 'nav' }} />
|
<RedocStandalone specUrl={proxiedUrl} options={{scrollYOffset: 'nav', disableInfiniteScroll: true}}/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import {observer} from 'mobx-react';
|
||||||
|
import * as React from 'react';
|
||||||
|
import {IMenuItem, MenuStore} from '../../services';
|
||||||
|
import {ContentItems} from './ContentItems';
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class SingleContentItem extends React.Component<{
|
||||||
|
menu: MenuStore;
|
||||||
|
}> {
|
||||||
|
|
||||||
|
extractActive(menu: MenuStore): IMenuItem[] {
|
||||||
|
const active = menu.flatItems[menu.activeItemIdx];
|
||||||
|
if (!active) {
|
||||||
|
return [menu.flatItems[0]];
|
||||||
|
}
|
||||||
|
if (active.type !== 'operation') {
|
||||||
|
return [
|
||||||
|
{...active, items: []},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [active];
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { menu } = this.props;
|
||||||
|
const activeItems = this.extractActive(menu);
|
||||||
|
return (
|
||||||
|
<ContentItems items={activeItems as any} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import * as React from 'react';
|
||||||
import { ThemeProvider } from '../../styled-components';
|
import { ThemeProvider } from '../../styled-components';
|
||||||
import { OptionsProvider } from '../OptionsProvider';
|
import { OptionsProvider } from '../OptionsProvider';
|
||||||
|
|
||||||
import { AppStore } from '../../services';
|
import {AppStore} from '../../services';
|
||||||
import { ApiInfo } from '../ApiInfo/';
|
import { ApiInfo } from '../ApiInfo/';
|
||||||
import { ApiLogo } from '../ApiLogo/ApiLogo';
|
import { ApiLogo } from '../ApiLogo/ApiLogo';
|
||||||
import { ContentItems } from '../ContentItems/ContentItems';
|
import { ContentItems } from '../ContentItems/ContentItems';
|
||||||
|
@ -12,6 +12,7 @@ import { SideMenu } from '../SideMenu/SideMenu';
|
||||||
import { StickyResponsiveSidebar } from '../StickySidebar/StickyResponsiveSidebar';
|
import { StickyResponsiveSidebar } from '../StickySidebar/StickyResponsiveSidebar';
|
||||||
import { ApiContentWrap, BackgroundStub, RedocWrap } from './styled.elements';
|
import { ApiContentWrap, BackgroundStub, RedocWrap } from './styled.elements';
|
||||||
|
|
||||||
|
import {SingleContentItem} from '../ContentItems/SingleContentItem';
|
||||||
import { SearchBox } from '../SearchBox/SearchBox';
|
import { SearchBox } from '../SearchBox/SearchBox';
|
||||||
import { StoreProvider } from '../StoreBuilder';
|
import { StoreProvider } from '../StoreBuilder';
|
||||||
|
|
||||||
|
@ -57,7 +58,10 @@ export class Redoc extends React.Component<RedocProps> {
|
||||||
</StickyResponsiveSidebar>
|
</StickyResponsiveSidebar>
|
||||||
<ApiContentWrap className="api-content">
|
<ApiContentWrap className="api-content">
|
||||||
<ApiInfo store={store} />
|
<ApiInfo store={store} />
|
||||||
<ContentItems items={menu.items as any} />
|
{options.disableInfiniteScroll
|
||||||
|
? <SingleContentItem menu={menu}/>
|
||||||
|
: <ContentItems items={menu.items as any}/>
|
||||||
|
}
|
||||||
</ApiContentWrap>
|
</ApiContentWrap>
|
||||||
<BackgroundStub />
|
<BackgroundStub />
|
||||||
</RedocWrap>
|
</RedocWrap>
|
||||||
|
|
|
@ -18,13 +18,13 @@ export class ScrollService {
|
||||||
|
|
||||||
bind() {
|
bind() {
|
||||||
this._prevOffsetY = this.scrollY();
|
this._prevOffsetY = this.scrollY();
|
||||||
if (this._scrollParent) {
|
if (this._scrollParent && !this.options.disableInfiniteScroll) {
|
||||||
this._scrollParent.addEventListener('scroll', this.handleScroll);
|
this._scrollParent.addEventListener('scroll', this.handleScroll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
if (this._scrollParent) {
|
if (this._scrollParent && !this.options.disableInfiniteScroll) {
|
||||||
this._scrollParent.removeEventListener('scroll', this.handleScroll);
|
this._scrollParent.removeEventListener('scroll', this.handleScroll);
|
||||||
}
|
}
|
||||||
this._emiter.removeAllListeners(EVENT);
|
this._emiter.removeAllListeners(EVENT);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user