forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBadge.tsx
More file actions
76 lines (67 loc) · 1.56 KB
/
Badge.tsx
File metadata and controls
76 lines (67 loc) · 1.56 KB
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
73
74
75
76
import React from 'react';
import styled from 'styled-components';
import Tooltip from '../../components/Tooltip';
import getBadge from '.';
const NameContainer = styled.div`
display: inline-block;
text-align: center;
`;
const Image = styled.img<{ visible: boolean }>`
transition: 0.3s ease all;
margin-bottom: -0.4em;
opacity: ${props => (props.visible ? 1 : 0.5)};
cursor: pointer;
&:hover {
${props => !props.visible && `opacity: .75;`};
}
`;
type Props = {
badge: {
id: string;
name: string;
visible: boolean;
};
size: number;
onClick?: Function;
tooltip?: string | false;
visible?: boolean;
};
export default class Badge extends React.Component<Props> {
handleClick = () => {
if (this.props.onClick) {
this.props.onClick(this.props.badge);
}
};
render() {
const { visible, badge, tooltip, size, onClick, ...props } = this.props;
const innerContent = (
<Image
{...props}
width={size}
src={getBadge(badge.id)}
alt={badge.name}
visible={visible || badge.visible}
onClick={this.handleClick}
/>
);
if (tooltip !== false) {
return (
<Tooltip
style={{
display: 'block',
}}
content={tooltip || badge.name}
>
{/* Margin Bottom to compensate for the tooltip */}
{innerContent}
</Tooltip>
);
}
return (
<NameContainer>
{innerContent}
<div style={{ marginTop: '0.5rem' }}>{badge.name}</div>
</NameContainer>
);
}
}