forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleBadge.tsx
53 lines (45 loc) · 1.31 KB
/
CircleBadge.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
import styled from 'styled-components'
import {get} from './constants'
import StyledOcticon from './StyledOcticon'
import sx, {SxProp} from './sx'
import isNumeric from './utils/isNumeric'
import {ComponentProps} from './utils/types'
const variantSizes = {
small: 56,
medium: 96,
large: 128
}
type StyledCircleBadgeProps = {
inline?: boolean
variant?: keyof typeof variantSizes
size?: number
} & SxProp
const sizeStyles = ({size, variant = 'medium'}: StyledCircleBadgeProps) => {
const calc = isNumeric(size) ? size : variantSizes[variant]
return {
width: calc,
height: calc
}
}
const CircleBadge = styled.div<StyledCircleBadgeProps>`
display: ${props => (props.inline ? 'inline-flex' : 'flex')};
align-items: center;
justify-content: center;
background-color: ${get('colors.canvas.default')};
border-radius: 50%;
box-shadow: ${get('shadows.shadow.medium')};
${sizeStyles};
${sx};
`
const CircleBadgeIcon = styled(StyledOcticon)`
height: auto;
max-width: 60%;
max-height: 55%;
`
CircleBadge.defaultProps = {
inline: false
}
CircleBadgeIcon.displayName = 'CircleBadge.Icon'
export type CircleBadgeProps = ComponentProps<typeof CircleBadge>
export type CircleBadgeIconProps = ComponentProps<typeof CircleBadgeIcon>
export default Object.assign(CircleBadge, {Icon: CircleBadgeIcon})