/
Brand.tsx
58 lines (49 loc) · 1.51 KB
/
Brand.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react';
import { styled, withTheme } from '@storybook/theming';
import { StorybookLogo } from '@storybook/components';
export const StorybookLogoStyled = styled(StorybookLogo)({
width: 'auto',
height: '22px !important',
display: 'block',
});
export const Img = styled.img({
width: 'auto',
height: 'auto',
display: 'block',
maxWidth: '100%',
});
export const LogoLink = styled.a(({ theme }) => ({
display: 'inline-block',
height: '100%',
margin: '-3px -4px',
padding: '2px 3px',
border: '1px solid transparent',
borderRadius: 3,
color: 'inherit',
textDecoration: 'none',
'&:focus': {
outline: 0,
borderColor: theme.color.secondary,
},
}));
export const Brand = withTheme(({ theme }) => {
const { title = 'Storybook', url = './', image } = theme.brand;
const targetValue = url === './' ? '' : '_blank';
// When image is explicitly set to null, enable custom HTML support
if (image === null) {
if (title === null) return null;
// eslint-disable-next-line react/no-danger
if (!url) return <div dangerouslySetInnerHTML={{ __html: title }} />;
return <LogoLink href={url} target={targetValue} dangerouslySetInnerHTML={{ __html: title }} />;
}
const logo = image ? <Img src={image} alt={title} /> : <StorybookLogoStyled alt={title} />;
if (url) {
return (
<LogoLink title={title} href={url} target={targetValue}>
{logo}
</LogoLink>
);
}
// The wrapper div serves to prevent image misalignment
return <div>{logo}</div>;
});