redoc/src/components/ApiLogo/ApiLogo.tsx

25 lines
724 B
TypeScript
Raw Normal View History

import { OpenAPIInfo } from '../../types';
2017-10-12 00:01:37 +03:00
import * as React from 'react';
import { observer } from 'mobx-react';
2017-11-23 12:38:18 +03:00
import { LogoImgEl, LogoWrap } from './styled.elements';
2017-10-12 00:01:37 +03:00
const LinkWrap = url => Component => <a href={url}>{Component}</a>;
@observer
export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> {
2017-10-12 00:01:37 +03:00
render() {
const { info } = this.props;
2017-10-12 00:01:37 +03:00
const logoInfo = info['x-logo'];
if (!logoInfo || !logoInfo.url) return null;
const logo = (
<LogoImgEl src={logoInfo.url} style={{ backgroundColor: logoInfo.backgroundColor }} />
);
2017-11-23 12:38:18 +03:00
return (
<LogoWrap>
{info.contact && info.contact.url ? LinkWrap(info.contact.url)(logo) : logo}{' '}
</LogoWrap>
);
2017-10-12 00:01:37 +03:00
}
}