Skip to content

Commit

Permalink
UnderlineNav no longer accepts styled system props (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuchs committed Nov 22, 2021
1 parent 79f3133 commit 1820587
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-hounds-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

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

## System props

<Note variant="warning">

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

</Note>

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

## Component props

### UnderlineNav

| 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 |

### UnderlineNav.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 |
9 changes: 3 additions & 6 deletions src/UnderlineNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import classnames from 'classnames'
import * as History from 'history'
import React from 'react'
import styled from 'styled-components'
import {COMMON, get, SystemCommonProps} from './constants'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

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

const UnderlineNavBase = styled.nav`
const UnderlineNavBase = styled.nav<SxProp>`
display: flex;
justify-content: space-between;
border-bottom: 1px solid ${get('colors.border.muted')};
Expand Down Expand Up @@ -39,7 +39,6 @@ const UnderlineNavBase = styled.nav`
align-self: center;
}
${COMMON};
${sx};
`

Expand All @@ -63,8 +62,7 @@ function UnderlineNav({actions, className, align, children, full, label, theme,
type StyledUnderlineNavLinkProps = {
to?: History.LocationDescriptor
selected?: boolean
} & SystemCommonProps &
SxProp
} & SxProp

const UnderlineNavLink = styled.a.attrs<StyledUnderlineNavLinkProps>(props => ({
activeClassName: typeof props.to === 'string' ? 'selected' : '',
Expand Down Expand Up @@ -100,7 +98,6 @@ const UnderlineNavLink = styled.a.attrs<StyledUnderlineNavLinkProps>(props => ({
}
}
${COMMON};
${sx};
`

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

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

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

0 comments on commit 1820587

Please sign in to comment.