forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterLabel.tsx
50 lines (43 loc) · 1.23 KB
/
CounterLabel.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
import styled from 'styled-components'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
type StyledCounterLabelProps = {
scheme?: 'primary' | 'secondary'
} & SxProp
const colorStyles = ({scheme, ...props}: StyledCounterLabelProps) => {
return {
color:
scheme === 'secondary'
? get('colors.fg.default')(props)
: scheme === 'primary'
? get('colors.fg.onEmphasis')(props)
: get('colors.fg.default')(props)
}
}
const bgStyles = ({scheme, ...props}: StyledCounterLabelProps) => {
return {
backgroundColor:
scheme === 'secondary'
? get('colors.neutral.muted')(props)
: scheme === 'primary'
? get('colors.neutral.emphasis')(props)
: get('colors.neutral.muted')(props)
}
}
const CounterLabel = styled.span<StyledCounterLabelProps>`
display: inline-block;
padding: 2px 5px;
font-size: ${get('fontSizes.0')};
font-weight: ${get('fontWeights.bold')};
line-height: ${get('lineHeights.condensedUltra')};
border-radius: 20px;
${colorStyles};
${bgStyles};
&:empty {
display: none;
}
${sx};
`
export type CounterLabelProps = ComponentProps<typeof CounterLabel>
export default CounterLabel