Skip to content

Commit 402d172

Browse files
committed
SubNav no longer accepts styled system props (#1574)
1 parent 24a796c commit 402d172

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

.changeset/new-tigers-yawn.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+
SubNav 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/SubNav.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,29 @@ This ensures that the NavLink gets `activeClassName='selected'`
7272
</SubNav>
7373
```
7474

75-
## System props
76-
77-
<Note variant="warning">
78-
79-
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
80-
81-
</Note>
82-
83-
SubNav and SubNav.Link components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
84-
8575
## Component props
8676

8777
### SubNav
8878

89-
| Prop name | Type | Description |
90-
| :--------- | :------ | :------------------------------------------------------------------------------------- |
91-
| actions | Node | Place another element, such as a button, to the opposite side of the navigation items. |
92-
| align | String | Use `right` to have navigation items aligned right. |
93-
| full | Boolean | Used to make navigation fill the width of the container. |
94-
| aria-label | String | Used to set the `aria-label` on the top level `<nav>` element. |
79+
| Name | Type | Default | Description |
80+
| :--------- | :---------------- | :-----: | :------------------------------------------------------------------------------------- |
81+
| actions | Node | | Place another element, such as a button, to the opposite side of the navigation items. |
82+
| align | String | | Use `right` to have navigation items aligned right. |
83+
| full | Boolean | | Used to make navigation fill the width of the container. |
84+
| aria-label | String | | Used to set the `aria-label` on the top level `<nav>` element. |
85+
| sx | SystemStyleObject | {} | Style to be applied to the component |
9586

9687
### SubNav.Link
9788

98-
| Prop name | Type | Description |
99-
| :-------- | :------ | :----------------------------------------------- |
100-
| as | String | sets the HTML tag for the component |
101-
| href | String | URL to be used for the Link |
102-
| selected | Boolean | Used to style the link as selected or unselected |
89+
| Name | Type | Default | Description |
90+
| :------- | :---------------- | :-----: | :----------------------------------------------- |
91+
| as | String | | sets the HTML tag for the component |
92+
| href | String | | URL to be used for the Link |
93+
| selected | Boolean | | Used to style the link as selected or unselected |
94+
| sx | SystemStyleObject | {} | Style to be applied to the component |
95+
96+
### SubNav.Links
97+
98+
| Name | Type | Default | Description |
99+
| :--- | :---------------- | :-----: | :----------------------------------- |
100+
| sx | SystemStyleObject | {} | Style to be applied to the component |

src/SubNav.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import classnames from 'classnames'
33
import * as History from 'history'
44
import React from 'react'
55
import styled from 'styled-components'
6-
import {COMMON, FLEX, get, SystemBorderProps, SystemCommonProps, SystemFlexProps} from './constants'
7-
import Box, {BoxProps} from './Box'
6+
import {get} from './constants'
87
import sx, {SxProp} from './sx'
98
import {ComponentProps} from './utils/types'
109

1110
const ITEM_CLASS = 'SubNav-item'
1211
const SELECTED_CLASS = 'selected'
1312

14-
const SubNavBase = styled.nav<SystemFlexProps & SystemCommonProps & SxProp>`
13+
const SubNavBase = styled.nav<SxProp>`
1514
display: flex;
1615
justify-content: space-between;
1716
@@ -32,8 +31,6 @@ const SubNavBase = styled.nav<SystemFlexProps & SystemCommonProps & SxProp>`
3231
align-self: center;
3332
}
3433
35-
${COMMON};
36-
${FLEX};
3734
${sx};
3835
`
3936

@@ -54,18 +51,17 @@ function SubNav({actions, className, children, label, ...rest}: SubNavProps) {
5451
)
5552
}
5653

57-
export type SubNavLinksProps = BoxProps
54+
export type SubNavLinksProps = SxProp
5855

59-
function SubNavLinks(props: SubNavLinksProps) {
60-
return <Box display="flex" {...props} />
61-
}
56+
const SubNavLinks = styled.div<SubNavLinksProps>`
57+
display: flex;
58+
${sx};
59+
`
6260

6361
type StyledSubNavLinkProps = {
6462
to?: History.LocationDescriptor
6563
selected?: boolean
66-
} & SystemCommonProps &
67-
SxProp &
68-
SystemBorderProps
64+
} & SxProp
6965

7066
const SubNavLink = styled.a.attrs<StyledSubNavLinkProps>(props => ({
7167
activeClassName: typeof props.to === 'string' ? 'selected' : '',
@@ -117,7 +113,6 @@ const SubNavLink = styled.a.attrs<StyledSubNavLinkProps>(props => ({
117113
}
118114
}
119115
120-
${COMMON};
121116
${sx};
122117
`
123118

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import SubNav from '../SubNav'
3+
4+
export function shouldAcceptCallWithNoProps() {
5+
return (
6+
<>
7+
<SubNav />
8+
<SubNav.Link />
9+
<SubNav.Links />
10+
</>
11+
)
12+
}
13+
14+
export function shouldNotAcceptSystemProps() {
15+
return (
16+
<>
17+
{/* @ts-expect-error system props should not be accepted */}
18+
<SubNav backgroundColor="thistle" />
19+
{/* @ts-expect-error system props should not be accepted */}
20+
<SubNav.Link backgroundColor="thistle" />
21+
{/* @ts-expect-error system props should not be accepted */}
22+
<SubNav.Links backgroundColor="thistle" />
23+
</>
24+
)
25+
}

0 commit comments

Comments
 (0)