forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Label.tsx
100 lines (92 loc) · 2.08 KB
/
Label.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import styled from 'styled-components'
import {variant} from 'styled-system'
import sx, {SxProp, BetterSystemStyleObject} from './sx'
import {get} from './constants'
export type LabelProps = {
/** The color of the label */
variant?: LabelColorOptions
/** How large the label is rendered */
size?: LabelSizeKeys
} & SxProp
export type LabelColorOptions =
| 'default'
| 'primary'
| 'secondary'
| 'accent'
| 'success'
| 'attention'
| 'severe'
| 'danger'
| 'done'
| 'sponsors'
type LabelSizeKeys = 'small' | 'large'
export const variants: Record<LabelColorOptions, BetterSystemStyleObject> = {
default: {
borderColor: 'border.default'
},
primary: {
borderColor: 'fg.default'
},
secondary: {
borderColor: 'border.muted',
color: 'fg.muted'
},
accent: {
borderColor: 'accent.emphasis',
color: 'accent.fg'
},
success: {
borderColor: 'success.emphasis',
color: 'success.fg'
},
attention: {
borderColor: 'attention.emphasis',
color: 'attention.fg'
},
severe: {
borderColor: 'severe.emphasis',
color: 'severe.fg'
},
danger: {
borderColor: 'danger.emphasis',
color: 'danger.fg'
},
done: {
borderColor: 'done.fg',
color: 'done.emphasis'
},
sponsors: {
borderColor: 'sponsors.fg',
color: 'sponsors.emphasis'
}
}
const sizes: Record<LabelSizeKeys, BetterSystemStyleObject> = {
small: {
height: '20px',
padding: '0 7px' // hard-coded to align with Primer ViewComponents and Primer CSS
},
large: {
height: '24px',
padding: '0 10px' // hard-coded to align with Primer ViewComponents and Primer CSS
}
}
const Label = styled.span<LabelProps>`
align-items: center;
background-color: transparent;
border-width: 1px;
border-radius: 999px;
border-style: solid;
display: inline-flex;
font-weight: ${get('fontWeights.bold')};
font-size: ${get('fontSizes.0')};
line-height: 1;
white-space: nowrap;
${variant({variants})};
${variant({prop: 'size', variants: sizes})};
${sx};
`
Label.defaultProps = {
size: 'small',
variant: 'default'
}
export default Label