Skip to content

Commit 655e5e6

Browse files
committed
SideNav no longer accepts styled system props (#1572)
1 parent b170920 commit 655e5e6

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

.changeset/tender-beds-learn.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+
SideNav 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/SideNav.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,33 +147,25 @@ If using React Router, you can use the `as` prop to render the element as a `Nav
147147
<SideNav.Link as={NavLink} to="...">...</SideNav.Link>
148148
```
149149

150-
## System props
151-
152-
<Note variant="warning">
153-
154-
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
155-
156-
</Note>
157-
158-
`SideNav` components get `COMMON`, `BORDER`, `LAYOUT`, and `FLEX` system props. `SideNav.Link` components get `COMMON` and `TYPOGRAPHY` system props. Read our [System Props](/system-props) doc page for a full list of available props.
159-
160150
## Component props
161151

162152
### SideNav
163153

164-
| Name | Type | Default | Description |
165-
| :------- | :------ | :------: | :----------------------------------------------------------------------------- |
166-
| as | String | 'nav' | Sets the HTML tag for the component. |
167-
| bordered | Boolean | false | Renders the component with a border. |
168-
| variant | String | 'normal' | Set to `lightweight` to render [in a lightweight style](#lightweight-variant). |
154+
| Name | Type | Default | Description |
155+
| :------- | :---------------- | :------: | :----------------------------------------------------------------------------- |
156+
| as | String | 'nav' | Sets the HTML tag for the component. |
157+
| bordered | Boolean | false | Renders the component with a border. |
158+
| variant | String | 'normal' | Set to `lightweight` to render [in a lightweight style](#lightweight-variant). |
159+
| sx | SystemStyleObject | {} | Style to be applied to the component |
169160

170161
### SideNav.Link
171162

172-
| Name | Type | Default | Description |
173-
| :-------- | :------ | :------: | :------------------------------------------------------------------------------------------------ |
174-
| as | String | 'a' | Sets the HTML tag for the component. |
175-
| href | String | | URL to be used for the Link |
176-
| muted | Boolean | false | Uses a less prominent shade for Link color, and the default link shade on hover |
177-
| selected | Boolean | false | Sets the link as selected, giving it a different style and setting the `aria-current` attribute. |
178-
| underline | Boolean | false | Adds underline to the Link |
179-
| variant | String | 'normal' | Set to `full` to render [a full variant](#full-variant), suitable for including icons and labels. |
163+
| Name | Type | Default | Description |
164+
| :-------- | :---------------- | :------: | :------------------------------------------------------------------------------------------------ |
165+
| as | String | 'a' | Sets the HTML tag for the component. |
166+
| href | String | | URL to be used for the Link |
167+
| muted | Boolean | false | Uses a less prominent shade for Link color, and the default link shade on hover |
168+
| selected | Boolean | false | Sets the link as selected, giving it a different style and setting the `aria-current` attribute. |
169+
| underline | Boolean | false | Adds underline to the Link |
170+
| variant | String | 'normal' | Set to `full` to render [a full variant](#full-variant), suitable for including icons and labels. |
171+
| sx | SystemStyleObject | {} | Style to be applied to the component |

src/SideNav.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
// eslint-disable-next-line import/no-namespace
22
import * as History from 'history'
33

4-
import {COMMON, get} from './constants'
4+
import {get} from './constants'
55
import styled, {css} from 'styled-components'
66

77
import Box from './Box'
88
import {ComponentProps} from './utils/types'
99
import Link from './Link'
1010
import React from 'react'
1111
import classnames from 'classnames'
12-
import sx from './sx'
12+
import sx, {SxProp} from './sx'
1313

1414
type SideNavBaseProps = {
1515
variant?: 'lightweight' | 'normal'
1616
bordered?: boolean
17-
} & ComponentProps<typeof Box>
17+
className?: string
18+
children?: React.ReactNode
19+
'aria-label'?: string
20+
}
1821

19-
function SideNavBase({variant, className, bordered, children, ...props}: SideNavBaseProps) {
22+
function SideNavBase({variant, className, bordered, children, 'aria-label': ariaLabel}: SideNavBaseProps) {
2023
const variantClassName = variant === 'lightweight' ? 'lightweight' : 'normal'
2124
const newClassName = classnames(className, `variant-${variantClassName}`)
2225

23-
if (!bordered) {
24-
props = {...props, borderWidth: 0}
25-
}
26-
2726
return (
2827
<Box
29-
borderWidth="1px"
28+
borderWidth={bordered ? '1px' : 0}
3029
borderStyle="solid"
3130
borderColor="border.default"
3231
borderRadius={2}
3332
as="nav"
3433
className={newClassName}
35-
{...props}
34+
aria-label={ariaLabel}
3635
>
3736
{children}
3837
</Box>
3938
)
4039
}
4140

42-
const SideNav = styled(SideNavBase)`
41+
const SideNav = styled(SideNavBase)<SxProp>`
4342
background-color: ${get('colors.canvas.subtle')};
4443
4544
${props =>
@@ -53,7 +52,6 @@ const SideNav = styled(SideNavBase)`
5352
}
5453
`}
5554
56-
${COMMON};
5755
${sx};
5856
`
5957
type StyledSideNavLinkProps = {
@@ -85,7 +83,7 @@ const SideNavLink = styled(Link).attrs<StyledSideNavLinkProps>(props => {
8583
} else {
8684
return {}
8785
}
88-
})<StyledSideNavLinkProps>`
86+
})<StyledSideNavLinkProps & SxProp>`
8987
position: relative;
9088
display: block;
9189
${props =>

src/__tests__/SideNav.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 SideNav from '../SideNav'
3+
4+
export function shouldAcceptCallWithNoProps() {
5+
return <SideNav />
6+
}
7+
8+
export function shouldNotAcceptSystemProps() {
9+
// @ts-expect-error system props should not be accepted
10+
return <SideNav backgroundColor="aliceblue" />
11+
}

0 commit comments

Comments
 (0)