Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-tigers-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

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.
40 changes: 19 additions & 21 deletions docs/content/SubNav.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,29 @@ This ensures that the NavLink gets `activeClassName='selected'`
</SubNav>
```

## System props

<Note variant="warning">

System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.

</Note>

SubNav and SubNav.Link components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

### SubNav

| Prop name | Type | Description |
| :--------- | :------ | :------------------------------------------------------------------------------------- |
| actions | Node | Place another element, such as a button, to the opposite side of the navigation items. |
| align | String | Use `right` to have navigation items aligned right. |
| full | Boolean | Used to make navigation fill the width of the container. |
| aria-label | String | Used to set the `aria-label` on the top level `<nav>` element. |
| Name | Type | Default | Description |
| :--------- | :---------------- | :-----: | :------------------------------------------------------------------------------------- |
| actions | Node | | Place another element, such as a button, to the opposite side of the navigation items. |
| align | String | | Use `right` to have navigation items aligned right. |
| full | Boolean | | Used to make navigation fill the width of the container. |
| aria-label | String | | Used to set the `aria-label` on the top level `<nav>` element. |
| sx | SystemStyleObject | {} | Style to be applied to the component |

### SubNav.Link

| Prop name | Type | Description |
| :-------- | :------ | :----------------------------------------------- |
| as | String | sets the HTML tag for the component |
| href | String | URL to be used for the Link |
| selected | Boolean | Used to style the link as selected or unselected |
| Name | Type | Default | Description |
| :------- | :---------------- | :-----: | :----------------------------------------------- |
| as | String | | sets the HTML tag for the component |
| href | String | | URL to be used for the Link |
| selected | Boolean | | Used to style the link as selected or unselected |
| sx | SystemStyleObject | {} | Style to be applied to the component |

### SubNav.Links

| Name | Type | Default | Description |
| :--- | :---------------- | :-----: | :----------------------------------- |
| sx | SystemStyleObject | {} | Style to be applied to the component |
21 changes: 8 additions & 13 deletions src/SubNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import classnames from 'classnames'
import * as History from 'history'
import React from 'react'
import styled from 'styled-components'
import {COMMON, FLEX, get, SystemBorderProps, SystemCommonProps, SystemFlexProps} from './constants'
import Box, {BoxProps} from './Box'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

const ITEM_CLASS = 'SubNav-item'
const SELECTED_CLASS = 'selected'

const SubNavBase = styled.nav<SystemFlexProps & SystemCommonProps & SxProp>`
const SubNavBase = styled.nav<SxProp>`
display: flex;
justify-content: space-between;

Expand All @@ -32,8 +31,6 @@ const SubNavBase = styled.nav<SystemFlexProps & SystemCommonProps & SxProp>`
align-self: center;
}

${COMMON};
${FLEX};
${sx};
`

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

export type SubNavLinksProps = BoxProps
export type SubNavLinksProps = SxProp

function SubNavLinks(props: SubNavLinksProps) {
return <Box display="flex" {...props} />
}
const SubNavLinks = styled.div<SubNavLinksProps>`
display: flex;
${sx};
`

type StyledSubNavLinkProps = {
to?: History.LocationDescriptor
selected?: boolean
} & SystemCommonProps &
SxProp &
SystemBorderProps
} & SxProp

const SubNavLink = styled.a.attrs<StyledSubNavLinkProps>(props => ({
activeClassName: typeof props.to === 'string' ? 'selected' : '',
Expand Down Expand Up @@ -117,7 +113,6 @@ const SubNavLink = styled.a.attrs<StyledSubNavLinkProps>(props => ({
}
}

${COMMON};
${sx};
`

Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/SubNav.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
import SubNav from '../SubNav'

export function shouldAcceptCallWithNoProps() {
return (
<>
<SubNav />
<SubNav.Link />
<SubNav.Links />
</>
)
}

export function shouldNotAcceptSystemProps() {
return (
<>
{/* @ts-expect-error system props should not be accepted */}
<SubNav backgroundColor="thistle" />
{/* @ts-expect-error system props should not be accepted */}
<SubNav.Link backgroundColor="thistle" />
{/* @ts-expect-error system props should not be accepted */}
<SubNav.Links backgroundColor="thistle" />
</>
)
}