fix: markdown in examples descriptions + minor ui tweaks

This commit is contained in:
Roman Hotsiy 2019-07-07 20:29:10 +03:00
parent 995e557d6d
commit f52d9e875b
5 changed files with 31 additions and 30 deletions

View File

@ -55,7 +55,7 @@ export const StyledDropdown = styled(Dropdown)`
display: block; display: block;
height: 0; height: 0;
position: absolute; position: absolute;
right: 0.35em; right: 0.6em;
top: 50%; top: 50%;
margin-top: -0.125em; margin-top: -0.125em;
width: 0; width: 0;

View File

@ -12,6 +12,8 @@ export interface MediaTypeChildProps {
export interface MediaTypesSwitchProps { export interface MediaTypesSwitchProps {
content?: MediaContentModel; content?: MediaContentModel;
withLabel?: boolean;
renderDropdown: (props: DropdownProps) => JSX.Element; renderDropdown: (props: DropdownProps) => JSX.Element;
children: (activeMime: MediaTypeModel) => JSX.Element; children: (activeMime: MediaTypeModel) => JSX.Element;
} }
@ -38,16 +40,25 @@ export class MediaTypesSwitch extends React.Component<MediaTypesSwitchProps> {
}; };
}); });
return ( const Wrapper = ({ children }) =>
<> this.props.withLabel ? (
<DropdownWrapper> <DropdownWrapper>
<DropdownLabel>Content type</DropdownLabel> <DropdownLabel>Content type</DropdownLabel>
{children}
</DropdownWrapper>
) : (
children
);
return (
<>
<Wrapper>
{this.props.renderDropdown({ {this.props.renderDropdown({
value: options[activeMimeIdx], value: options[activeMimeIdx],
options, options,
onChange: this.switchMedia, onChange: this.switchMedia,
})} })}
</DropdownWrapper> </Wrapper>
{this.props.children(content.active)} {this.props.children(content.active)}
</> </>
); );

View File

@ -2,9 +2,9 @@ import * as React from 'react';
import { DropdownProps } from '../../common-elements'; import { DropdownProps } from '../../common-elements';
import { MediaTypeModel } from '../../services/models'; import { MediaTypeModel } from '../../services/models';
import { Markdown } from '../Markdown/Markdown';
import { Example } from './Example'; import { Example } from './Example';
import { Description, DropdownLabel, DropdownWrapper, NoSampleLabel } from './styled.elements'; import { DropdownLabel, DropdownWrapper, NoSampleLabel } from './styled.elements';
export interface PayloadSamplesProps { export interface PayloadSamplesProps {
mediaType: MediaTypeModel; mediaType: MediaTypeModel;
@ -35,6 +35,7 @@ export class MediaTypeSamples extends React.Component<PayloadSamplesProps, Media
if (examplesNames.length === 0) { if (examplesNames.length === 0) {
return noSample; return noSample;
} }
if (examplesNames.length > 1) { if (examplesNames.length > 1) {
const options = examplesNames.map((name, idx) => { const options = examplesNames.map((name, idx) => {
return { return {
@ -42,6 +43,10 @@ export class MediaTypeSamples extends React.Component<PayloadSamplesProps, Media
value: idx.toString(), value: idx.toString(),
}; };
}); });
const example = examples[examplesNames[activeIdx]];
const description = example.description;
return ( return (
<> <>
<DropdownWrapper> <DropdownWrapper>
@ -52,27 +57,18 @@ export class MediaTypeSamples extends React.Component<PayloadSamplesProps, Media
onChange: this.switchMedia, onChange: this.switchMedia,
})} })}
</DropdownWrapper> </DropdownWrapper>
{examplesNames.map(name => { <div>
const description = examples[name].description; {description && <Markdown source={description} />}
const activeValue = options[activeIdx].label; <Example example={example} mimeType={mimeType} />
return (
(name === activeValue || examples[name].summary === activeValue) && (
<div key={name}>
{description && <Description>{description}</Description>}
<Example example={examples[name]} mimeType={mimeType} />
</div> </div>
)
);
})}
</> </>
); );
} else { } else {
const name = examplesNames[0]; const example = examples[examplesNames[0]];
return ( return (
<div> <div>
{examples[name].description && <Description>{examples[name].description}</Description>} {example.description && <Markdown source={example.description} />}
<Example example={examples[name]} mimeType={mimeType} /> <Example example={example} mimeType={mimeType} />
</div> </div>
); );
} }

View File

@ -22,7 +22,7 @@ export class PayloadSamples extends React.Component<PayloadSamplesProps> {
} }
return ( return (
<MediaTypesSwitch content={mimeContent} renderDropdown={this.renderDropdown}> <MediaTypesSwitch content={mimeContent} renderDropdown={this.renderDropdown} withLabel={true}>
{mediaType => ( {mediaType => (
<SamplesWrapper> <SamplesWrapper>
<MediaTypeSamples <MediaTypeSamples

View File

@ -32,7 +32,6 @@ export const InvertedSimpleDropdown = styled(StyledDropdown)`
margin-left: 10px; margin-left: 10px;
text-transform: none; text-transform: none;
font-size: 0.929em; font-size: 0.929em;
padding: 12px;
margin: 0 0 10px 0; margin: 0 0 10px 0;
display: block; display: block;
background-color: ${({ theme }) => transparentize(0.6, theme.rightPanel.backgroundColor)}; background-color: ${({ theme }) => transparentize(0.6, theme.rightPanel.backgroundColor)};
@ -43,7 +42,7 @@ export const InvertedSimpleDropdown = styled(StyledDropdown)`
.Dropdown-control:hover { .Dropdown-control:hover {
font-size: 1em; font-size: 1em;
border: none; border: none;
padding: 0 1.2em 0 0; padding: 0.9em 1.6em 0.9em 0.9em;
background: transparent; background: transparent;
color: ${({ theme }) => theme.rightPanel.textColor}; color: ${({ theme }) => theme.rightPanel.textColor};
box-shadow: none; box-shadow: none;
@ -63,8 +62,3 @@ export const NoSampleLabel = styled.div`
font-size: 12px; font-size: 12px;
color: #ee807f; color: #ee807f;
`; `;
export const Description = styled.span`
font-size: 12px;
color: ${({ theme }) => transparentize(0.6, theme.rightPanel.textColor)};
`;