Skip to content

Commit c8e4d73

Browse files
committed
Label no longer accepts styled system props (#1564)
1 parent 97f9119 commit c8e4d73

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

.changeset/rotten-apricots-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': major
3+
---
4+
5+
Label no longer accepts styled-system props. Please use the `sx` prop to extend Primer component styling instead. See also https://primer.style/react/overriding-styles for information about `sx` and https://primer.style/react/system-props for context on the removal.

docs/content/Label.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,42 @@ The Label component is used to add contextual metadata to a design. Visually it
88

99
```jsx live
1010
<>
11-
<Label variant="small" outline sx={{borderColor: "danger.emphasis", mr: 2, color: "danger.fg"}}>small</Label>
12-
<Label variant="medium" sx={{mr: 2}}>medium (default)</Label>
13-
<Label variant="large" sx={{mr: 2}}>large</Label>
11+
<Label variant="small" outline sx={{borderColor: 'danger.emphasis', mr: 2, color: 'danger.fg'}}>
12+
small
13+
</Label>
14+
<Label variant="medium" sx={{mr: 2}}>
15+
medium (default)
16+
</Label>
17+
<Label variant="large" sx={{mr: 2}}>
18+
large
19+
</Label>
1420
<Label variant="xl">xl label</Label>
1521

16-
<Box mt={4}/>
17-
<Label variant="medium" sx={{bg:"#A575FF", m: 1}}>good first issue</Label>
18-
<Label variant="medium" sx={{bg:"#FF75C8", m: 1}}>🚂 deploy: train</Label>
19-
<Label variant="medium" sx={{bg:"#1C90FA", m: 1}}>css</Label>
20-
<Label variant="medium" sx={{bg:"#FFF06C", color:"#24292E", m: 1}}>documentation</Label>
21-
<Label variant="medium" sx={{bg: "#656BFE", m: 1}}>primer</Label>
22+
<Box mt={4} />
23+
<Label variant="medium" sx={{bg: '#A575FF', m: 1}}>
24+
good first issue
25+
</Label>
26+
<Label variant="medium" sx={{bg: '#FF75C8', m: 1}}>
27+
🚂 deploy: train
28+
</Label>
29+
<Label variant="medium" sx={{bg: '#1C90FA', m: 1}}>
30+
css
31+
</Label>
32+
<Label variant="medium" sx={{bg: '#FFF06C', color: '#24292E', m: 1}}>
33+
documentation
34+
</Label>
35+
<Label variant="medium" sx={{bg: '#656BFE', m: 1}}>
36+
primer
37+
</Label>
2238
</>
2339
```
2440

25-
## System props
26-
27-
<Note variant="warning">
28-
29-
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
30-
31-
</Note>
32-
33-
Label components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
34-
3541
## Component props
3642

37-
| Name | Type | Default | Description |
38-
| :--------- | :------ | :--------------------: | :----------------------------------------------------------------------------- |
39-
| outline | Boolean | | Creates an outline style label |
40-
| variant | String | 'medium' | Can be one of `small`, `medium` (default), `large` or `xl` . |
41-
| dropshadow | Boolean | | Adds a dropshadow to the label |
42-
| bg | String | 'label.primary.border' | Part of the `COMMON` system props, used to change the background of the label. |
43+
| Name | Type | Default | Description |
44+
| :--------- | :---------------- | :--------------------: | :----------------------------------------------------------------------------- |
45+
| outline | Boolean | | Creates an outline style label |
46+
| variant | String | 'medium' | Can be one of `small`, `medium` (default), `large` or `xl` . |
47+
| dropshadow | Boolean | | Adds a dropshadow to the label |
48+
| bg | String | 'label.primary.border' | Part of the `COMMON` system props, used to change the background of the label. |
49+
| sx | SystemStyleObject | {} | Style to be applied to the component |

src/Label.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled, {css} from 'styled-components'
22
import {borderColor, BorderColorProps, variant} from 'styled-system'
3-
import {COMMON, get, SystemCommonProps} from './constants'
3+
import {get} from './constants'
44
import sx, {SxProp} from './sx'
55
import {ComponentProps} from './utils/types'
66

@@ -11,7 +11,6 @@ const outlineStyles = css`
1111
border: ${get('borderWidths.1')} solid ${get('colors.border.default')};
1212
box-shadow: none;
1313
${borderColor};
14-
${COMMON};
1514
background-color: transparent;
1615
`
1716

@@ -47,27 +46,25 @@ const Label = styled.span<
4746
dropshadow?: boolean
4847
outline?: boolean
4948
} & BorderColorProps &
50-
SystemCommonProps &
5149
SxProp
5250
>`
5351
display: inline-block;
5452
font-weight: ${get('fontWeights.semibold')};
5553
color: ${get('colors.fg.onEmphasis')};
5654
border-radius: ${get('radii.3')};
55+
background-color: ${get('colors.neutral.emphasis')};
5756
5857
&:hover {
5958
text-decoration: none;
6059
}
6160
6261
${sizeVariant}
63-
${COMMON}
6462
${props => (props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '')}
6563
${props => (props.outline ? outlineStyles : '')} // must be last to override other values
6664
${sx}
6765
`
6866

6967
Label.defaultProps = {
70-
bg: 'neutral.emphasis',
7168
variant: 'medium'
7269
}
7370

src/__tests__/Label.types.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
import Label from '../Label'
3+
4+
export function shouldAcceptCallWithNoProps() {
5+
return <Label />
6+
}
7+
8+
export function shouldNotAcceptSystemProps() {
9+
// @ts-expect-error system props should not be accepted
10+
return <Label backgroundColor="mintcream" />
11+
}

src/__tests__/__snapshots__/Label.test.tsx.snap

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ exports[`Label renders consistently 1`] = `
66
font-weight: 500;
77
color: #ffffff;
88
border-radius: 100px;
9+
background-color: #6e7781;
910
font-size: 12px;
1011
line-height: 20px;
1112
padding: 0 8px;
12-
background-color: #6e7781;
1313
}
1414
1515
.c0:hover {
@@ -28,16 +28,15 @@ exports[`Label respects the "outline" prop 1`] = `
2828
font-weight: 500;
2929
color: #ffffff;
3030
border-radius: 100px;
31+
background-color: #6e7781;
3132
font-size: 12px;
3233
line-height: 20px;
3334
padding: 0 8px;
34-
background-color: #6e7781;
3535
margin-top: -1px;
3636
margin-bottom: -1px;
3737
color: #57606a;
3838
border: 1px solid #d0d7de;
3939
box-shadow: none;
40-
background-color: #6e7781;
4140
background-color: transparent;
4241
}
4342
@@ -57,10 +56,10 @@ exports[`Label respects the "variant" prop 1`] = `
5756
font-weight: 500;
5857
color: #ffffff;
5958
border-radius: 100px;
59+
background-color: #6e7781;
6060
font-size: 14px;
6161
line-height: 16px;
6262
padding: 8px 12px;
63-
background-color: #6e7781;
6463
}
6564
6665
.c0:hover {

0 commit comments

Comments
 (0)