Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 13, 2018
1 parent 83eaa5f commit 21447d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
51 changes: 28 additions & 23 deletions demo/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DropDownItem = withProps<{ active: boolean }>(styled.li)`
background-color: #eee;
}
cursor: pointer;
text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
`;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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>
Expand All @@ -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>
);
}
Expand Down
12 changes: 6 additions & 6 deletions demo/index.tsx
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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');
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/components/ApiLogo/ApiLogo.tsx
Original file line number Diff line number Diff line change
@@ -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 }> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/StoreProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 21447d2

Please sign in to comment.