/
Brand.tsx
72 lines (67 loc) · 1.68 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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',
width: '100%',
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: {
brand: { title = 'Storybook', url = './', image },
},
}) => {
const targetValue = url === './' ? '' : '_blank';
if (image === undefined && url === null) {
return <StorybookLogoStyled alt={title} />;
}
if (image === undefined && url) {
return (
<LogoLink title={title} href={url} target={targetValue}>
<StorybookLogoStyled alt={title} />
</LogoLink>
);
}
if (image === null && url === null) {
return title;
}
if (image === null && url) {
return (
<LogoLink href={url} target={targetValue} dangerouslySetInnerHTML={{ __html: title }} />
);
}
if (image && url === null) {
return <Img src={image} alt={title} />;
}
if (image && url) {
return (
<LogoLink title={title} href={url} target={targetValue}>
<Img src={image} alt={title} />
</LogoLink>
);
}
return null;
}
);