mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 21:54:53 +03:00
added try it checkbox
This commit is contained in:
parent
64119c44d4
commit
9fd292bf68
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -33,3 +33,6 @@ cli/index.js
|
|||
.ghpages-tmp
|
||||
stats.json
|
||||
/package-lock.json
|
||||
|
||||
//npmrc for local npm
|
||||
.npmrc
|
1
demo/.gitignore
vendored
Normal file
1
demo/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
intent.json
|
|
@ -68,6 +68,8 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) =
|
|||
stats: 'minimal',
|
||||
},
|
||||
|
||||
devtool: 'source-map',
|
||||
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
},
|
||||
|
|
|
@ -9,3 +9,5 @@ export * from './mixins';
|
|||
export * from './tabs';
|
||||
export * from './samples';
|
||||
export * from './perfect-scrollbar';
|
||||
export * from './toggle';
|
||||
export * from './input';
|
||||
|
|
8
src/common-elements/input.tsx
Normal file
8
src/common-elements/input.tsx
Normal file
|
@ -0,0 +1,8 @@
|
|||
import styled, { css } from '../styled-components';
|
||||
|
||||
export const TextField = styled.input`
|
||||
padding: 0.5em;
|
||||
margin: 0.5em;
|
||||
border: 1px solid rgba(38,50,56,0.5);
|
||||
border-radius: 3px;
|
||||
`;
|
10
src/common-elements/toggle.tsx
Normal file
10
src/common-elements/toggle.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import styled, { css } from '../styled-components';
|
||||
|
||||
export const Toggle = styled.input`
|
||||
padding: 0.5em;
|
||||
margin: 0.5em;
|
||||
color: palevioletred;
|
||||
background: papayawhip;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
`;
|
|
@ -11,7 +11,7 @@ import {
|
|||
PropertyNameCell,
|
||||
} from '../../common-elements/fields-layout';
|
||||
|
||||
import { ShelfIcon } from '../../common-elements/';
|
||||
import { ShelfIcon, TextField } from '../../common-elements/';
|
||||
|
||||
import { FieldModel } from '../../services/models';
|
||||
import { Schema, SchemaOptions } from '../Schema/Schema';
|
||||
|
@ -56,6 +56,9 @@ export class Field extends React.PureComponent<FieldProps> {
|
|||
<PropertyDetailsCell>
|
||||
<FieldDetails {...this.props} />
|
||||
</PropertyDetailsCell>
|
||||
{field && field.in === 'path' &&
|
||||
<td><TextField placeholder="foo" /></td>
|
||||
}
|
||||
</tr>
|
||||
{field.expanded &&
|
||||
withSubSchema && (
|
||||
|
|
|
@ -4,7 +4,7 @@ import { SecurityRequirements } from '../SecurityRequirement/SecuirityRequiremen
|
|||
|
||||
import { observer } from 'mobx-react';
|
||||
|
||||
import { Badge, DarkRightPanel, H2, MiddlePanel, Row } from '../../common-elements';
|
||||
import { Badge, DarkRightPanel, H2, MiddlePanel, Row, Toggle } from '../../common-elements';
|
||||
|
||||
import { OptionsContext } from '../OptionsProvider';
|
||||
|
||||
|
@ -39,12 +39,43 @@ interface OperationProps {
|
|||
operation: OperationType;
|
||||
}
|
||||
|
||||
export interface OperationState {
|
||||
executeMode: boolean;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class Operation extends React.Component<OperationProps> {
|
||||
export class Operation extends React.Component<OperationProps, OperationState> {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
executeMode: false,
|
||||
};
|
||||
}
|
||||
|
||||
onTry(e) {
|
||||
this.setState({
|
||||
executeMode: e.target.checked
|
||||
});
|
||||
console.log(e.target.checked + ' ' + this.props.operation);
|
||||
}
|
||||
|
||||
/*
|
||||
activate = (item: IMenuItem) => {
|
||||
this.props.menu.activateAndScroll(item, true);
|
||||
setTimeout(() => {
|
||||
if (this._updateScroll) {
|
||||
this._updateScroll();
|
||||
}
|
||||
});
|
||||
};
|
||||
*/
|
||||
|
||||
render() {
|
||||
const { operation } = this.props;
|
||||
|
||||
const { name: summary, description, deprecated } = operation;
|
||||
const { executeMode } = this.state;
|
||||
return (
|
||||
<OptionsContext.Consumer>
|
||||
{options => (
|
||||
|
@ -54,6 +85,8 @@ export class Operation extends React.Component<OperationProps> {
|
|||
<ShareLink href={'#' + operation.id} />
|
||||
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
|
||||
</H2>
|
||||
<Toggle type="checkbox" onChange={this.onTry.bind(this)} />
|
||||
<span>Try it out!</span>
|
||||
{options.pathInMiddlePanel && <Endpoint operation={operation} inverted={true} />}
|
||||
{description !== undefined && <Markdown source={description} />}
|
||||
<SecurityRequirements securities={operation.security} />
|
||||
|
@ -62,8 +95,15 @@ export class Operation extends React.Component<OperationProps> {
|
|||
</MiddlePanel>
|
||||
<DarkRightPanel>
|
||||
{!options.pathInMiddlePanel && <Endpoint operation={operation} />}
|
||||
{executeMode &&
|
||||
<div>Execute Mode</div>
|
||||
}
|
||||
{!executeMode &&
|
||||
<RequestSamples operation={operation} />
|
||||
}
|
||||
{!executeMode &&
|
||||
<ResponseSamples operation={operation} />
|
||||
}
|
||||
</DarkRightPanel>
|
||||
</OperationRow>
|
||||
)}
|
||||
|
|
Loading…
Reference in New Issue
Block a user