mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
chore: fix lint issues
This commit is contained in:
parent
83eaa5f838
commit
21447d22a1
|
@ -19,7 +19,7 @@ const DropDownItem = withProps<{ active: boolean }>(styled.li)`
|
|||
background-color: #eee;
|
||||
}
|
||||
cursor: pointer;
|
||||
text-overflow: ellipsis;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
`;
|
||||
|
||||
|
@ -93,7 +93,7 @@ const Button = styled.button`
|
|||
|
||||
export interface ComboBoxProps {
|
||||
onChange?: (val: string) => void;
|
||||
options: { value: string; label: string }[];
|
||||
options: Array<{ value: string; label: string }>;
|
||||
placeholder?: string;
|
||||
value?: string;
|
||||
}
|
||||
|
@ -142,6 +142,10 @@ export default class ComboBox extends React.Component<ComboBoxProps, ComboBoxSta
|
|||
this.close();
|
||||
}
|
||||
|
||||
handleTryItClick = () => {
|
||||
this.handleSelect(this.state.value);
|
||||
};
|
||||
|
||||
handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.keyCode === 13) {
|
||||
this.handleSelect(e.currentTarget.value);
|
||||
|
@ -176,8 +180,27 @@ export default class ComboBox extends React.Component<ComboBoxProps, ComboBoxSta
|
|||
});
|
||||
};
|
||||
|
||||
renderOption = (option: { value: string; label: string }, idx: number) => {
|
||||
return (
|
||||
<DropDownItem
|
||||
active={idx === this.state.activeItemIdx}
|
||||
key={option.value}
|
||||
// tslint:disable-next-line
|
||||
onMouseDown={() => {
|
||||
this.handleItemClick(option.value, idx);
|
||||
}}
|
||||
>
|
||||
<small>
|
||||
<strong>{option.label}</strong>
|
||||
</small>
|
||||
<br />
|
||||
{option.value}
|
||||
</DropDownItem>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { open, value, activeItemIdx } = this.state;
|
||||
const { open, value } = this.state;
|
||||
const { options, placeholder } = this.props;
|
||||
return (
|
||||
<ComboBoxWrap>
|
||||
|
@ -189,26 +212,8 @@ export default class ComboBox extends React.Component<ComboBoxProps, ComboBoxSta
|
|||
onBlur={this.handleBlur}
|
||||
onKeyDown={this.handleKeyPress}
|
||||
/>
|
||||
<Button onClick={() => this.handleSelect(this.state.value)}> TRY IT </Button>
|
||||
{open && (
|
||||
<DropDownList>
|
||||
{options.map((option, idx) => (
|
||||
<DropDownItem
|
||||
active={idx == activeItemIdx}
|
||||
key={option.value}
|
||||
onMouseDown={() => {
|
||||
this.handleItemClick(option.value, idx);
|
||||
}}
|
||||
>
|
||||
<small>
|
||||
<strong>{option.label}</strong>
|
||||
</small>
|
||||
<br />
|
||||
{option.value}
|
||||
</DropDownItem>
|
||||
))}
|
||||
</DropDownList>
|
||||
)}
|
||||
<Button onClick={this.handleTryItClick}> TRY IT </Button>
|
||||
{open && <DropDownList>{options.map(this.renderOption)}</DropDownList>}
|
||||
</ComboBoxWrap>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import styled from 'styled-components';
|
||||
import { resolve as urlResolve } from 'url';
|
||||
import { RedocStandalone } from '../';
|
||||
import ComboBox from './ComboBox';
|
||||
import * as url from 'url';
|
||||
|
||||
const demos = [
|
||||
{ value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram' },
|
||||
|
@ -61,7 +61,7 @@ class DemoApp extends React.Component<
|
|||
toggleCors = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const cors = e.currentTarget.checked;
|
||||
this.setState({
|
||||
cors: cors,
|
||||
cors,
|
||||
});
|
||||
window.history.pushState(
|
||||
undefined,
|
||||
|
@ -75,7 +75,7 @@ class DemoApp extends React.Component<
|
|||
let proxiedUrl = specUrl;
|
||||
if (specUrl !== DEFAULT_SPEC) {
|
||||
proxiedUrl = cors
|
||||
? '\\\\cors.apis.guru/' + url.resolve(window.location.href, specUrl)
|
||||
? '\\\\cors.apis.guru/' + urlResolve(window.location.href, specUrl)
|
||||
: specUrl;
|
||||
}
|
||||
return (
|
||||
|
@ -155,7 +155,7 @@ render(<DemoApp />, document.getElementById('container'));
|
|||
/* ====== Helpers ====== */
|
||||
function updateQueryStringParameter(uri, key, value) {
|
||||
const keyValue = value === '' ? key : key + '=' + value;
|
||||
var re = new RegExp('([?|&])' + key + '=?.*?(&|#|$)', 'i');
|
||||
const re = new RegExp('([?|&])' + key + '=?.*?(&|#|$)', 'i');
|
||||
if (uri.match(re)) {
|
||||
if (value !== undefined) {
|
||||
return uri.replace(re, '$1' + keyValue + '$2');
|
||||
|
@ -171,12 +171,12 @@ function updateQueryStringParameter(uri, key, value) {
|
|||
if (value === undefined) {
|
||||
return uri;
|
||||
}
|
||||
var hash = '';
|
||||
let hash = '';
|
||||
if (uri.indexOf('#') !== -1) {
|
||||
hash = uri.replace(/.*#/, '#');
|
||||
uri = uri.replace(/#.*/, '');
|
||||
}
|
||||
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
||||
const separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
||||
return uri + separator + keyValue + hash;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { OpenAPIInfo } from '../../types';
|
||||
import { LogoImgEl, LogoWrap, LinkWrap } from './styled.elements';
|
||||
import { LinkWrap, LogoImgEl, LogoWrap } from './styled.elements';
|
||||
|
||||
@observer
|
||||
export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> {
|
||||
|
|
|
@ -2,8 +2,8 @@ import { Component } from 'react';
|
|||
|
||||
import { AppStore } from '../services/';
|
||||
import { RedocRawOptions } from '../services/RedocNormalizedOptions';
|
||||
import { loadAndBundleSpec } from '../utils';
|
||||
import { OpenAPISpec } from '../types';
|
||||
import { loadAndBundleSpec } from '../utils';
|
||||
|
||||
interface StoreProviderProps {
|
||||
specUrl?: string;
|
||||
|
|
Loading…
Reference in New Issue
Block a user