Skip to content

Commit d6d25dc

Browse files
jonrohanjoshblackCopilot
authored
refactor(SubNav): Remove sx support from SubNav component (#6602)
Co-authored-by: Josh Black <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 77a60e7 commit d6d25dc

File tree

4 files changed

+22
-113
lines changed

4 files changed

+22
-113
lines changed

.changeset/proud-chairs-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": major
3+
---
4+
5+
Remove sx support from SubNav component

e2e/components/SubNav.test.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ test.describe('SubNav', () => {
2121
}
2222
})
2323

24-
test.describe('Dev: With Sx', () => {
25-
for (const theme of themes) {
26-
test.describe(theme, () => {
27-
test('default @vrt', async ({page}) => {
28-
await visit(page, {
29-
id: 'components-subnav-dev--with-sx',
30-
globals: {
31-
colorScheme: theme,
32-
},
33-
})
34-
35-
// Default state
36-
expect(await page.screenshot()).toMatchSnapshot(`SubNav.Dev.WithSx.${theme}.png`)
37-
})
38-
})
39-
}
40-
})
41-
4224
test.describe('Dev: With CSS', () => {
4325
for (const theme of themes) {
4426
test.describe(theme, () => {
@@ -56,22 +38,4 @@ test.describe('SubNav', () => {
5638
})
5739
}
5840
})
59-
60-
test.describe('Dev: With Sx and CSS', () => {
61-
for (const theme of themes) {
62-
test.describe(theme, () => {
63-
test('default @vrt', async ({page}) => {
64-
await visit(page, {
65-
id: 'components-subnav-dev--with-sx-and-css',
66-
globals: {
67-
colorScheme: theme,
68-
},
69-
})
70-
71-
// Default state
72-
expect(await page.screenshot()).toMatchSnapshot(`SubNav.Dev.WithSxAndCSS.${theme}.png`)
73-
})
74-
})
75-
}
76-
})
7741
})

packages/react/src/SubNav/SubNav.dev.stories.tsx

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,3 @@ export const WithCss = () => (
2727
</SubNav.Links>
2828
</SubNav>
2929
)
30-
31-
export const WithSx = () => (
32-
<SubNav aria-label="Main" sx={{p: 1, display: 'flex', border: '2px solid', borderColor: 'border.default'}}>
33-
<SubNav.Links sx={{m: 2}}>
34-
<SubNav.Link
35-
href="#home"
36-
selected
37-
sx={{color: 'accent.fg', fontWeight: 'bold', '&:is([data-selected])': {backgroundColor: 'danger.fg'}}}
38-
>
39-
Home
40-
</SubNav.Link>
41-
<SubNav.Link href="#documentation" sx={{color: 'accent.fg', fontWeight: 'bold'}}>
42-
Documentation
43-
</SubNav.Link>
44-
<SubNav.Link href="#support" sx={{color: 'accent.fg', fontWeight: 'bold'}}>
45-
Support
46-
</SubNav.Link>
47-
</SubNav.Links>
48-
</SubNav>
49-
)
50-
51-
export const WithSxAndCSS = () => (
52-
<SubNav
53-
aria-label="Main"
54-
sx={{p: 1, display: 'flex', border: '2px solid', borderColor: 'border.default'}}
55-
className={styles.SubNavDev}
56-
>
57-
<SubNav.Links sx={{m: 2}} className={styles.SubNavLinksDev}>
58-
<SubNav.Link
59-
href="#home"
60-
selected
61-
className={styles.SubNavLinkDev}
62-
sx={{'&:is([data-selected])': {backgroundColor: 'danger.fg'}}}
63-
>
64-
Home
65-
</SubNav.Link>
66-
<SubNav.Link href="#documentation" className={styles.SubNavLinkDev}>
67-
Documentation
68-
</SubNav.Link>
69-
<SubNav.Link href="#support" sx={{color: 'accent.fg', fontWeight: 'bold'}} className={styles.SubNavLinkDev}>
70-
Support
71-
</SubNav.Link>
72-
</SubNav.Links>
73-
</SubNav>
74-
)

packages/react/src/SubNav/SubNav.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,60 @@
11
import {clsx} from 'clsx'
22
import type {To} from 'history'
33
import React from 'react'
4-
import type {ComponentProps} from '../utils/types'
54

65
import styles from './SubNav.module.css'
7-
import type {SxProp} from '../sx'
8-
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
96

10-
type StyledSubNavProps = React.ComponentProps<'nav'> & {
7+
export type SubNavProps = React.ComponentProps<'nav'> & {
118
actions?: React.ReactNode
129
align?: 'right'
1310
full?: boolean
1411
label?: string
15-
} & SxProp
16-
type StyledSubNavLinksProps = React.ComponentProps<'div'> & SxProp
17-
type StyledSubNavLinkProps = React.ComponentProps<'a'> & {to?: To; selected?: boolean} & SxProp
12+
}
13+
export type SubNavLinksProps = React.ComponentProps<'div'>
14+
export type SubNavLinkProps = React.ComponentProps<'a'> & {to?: To; selected?: boolean}
1815

19-
const SubNav = React.forwardRef<HTMLElement, StyledSubNavProps>(function SubNav(
16+
const SubNav = React.forwardRef<HTMLElement, SubNavProps>(function SubNav(
2017
{actions, className, children, label, ...rest},
2118
forwardRef,
2219
) {
2320
return (
24-
<BoxWithFallback
25-
as="nav"
26-
ref={forwardRef}
27-
className={clsx(className, 'SubNav', styles.SubNav)}
28-
aria-label={label}
29-
{...rest}
30-
>
21+
<nav ref={forwardRef} className={clsx(className, 'SubNav', styles.SubNav)} aria-label={label} {...rest}>
3122
<div className={clsx('SubNav-body', styles.Body)}>{children}</div>
3223
{actions && <div className={clsx('SubNav-actions', styles.Actions)}>{actions}</div>}
33-
</BoxWithFallback>
24+
</nav>
3425
)
3526
})
3627
SubNav.displayName = 'SubNav'
3728

3829
// SubNav.Links
3930

40-
const SubNavLinks = React.forwardRef<HTMLDivElement, StyledSubNavLinksProps>(
41-
({children, className, ...rest}, forwardRef) => {
42-
return (
43-
<BoxWithFallback ref={forwardRef} className={clsx(className, styles.Links)} {...rest}>
44-
{children}
45-
</BoxWithFallback>
46-
)
47-
},
48-
)
31+
const SubNavLinks = React.forwardRef<HTMLDivElement, SubNavLinksProps>(({children, className, ...rest}, forwardRef) => {
32+
return (
33+
<div ref={forwardRef} className={clsx(className, styles.Links)} {...rest}>
34+
{children}
35+
</div>
36+
)
37+
})
4938
SubNavLinks.displayName = 'SubNav.Links'
5039

5140
// SubNav.Link
5241

53-
const SubNavLink = React.forwardRef<HTMLAnchorElement, StyledSubNavLinkProps>(
42+
const SubNavLink = React.forwardRef<HTMLAnchorElement, SubNavLinkProps>(
5443
({children, className, ...rest}, forwardRef) => {
5544
return (
56-
<BoxWithFallback
57-
as="a"
45+
<a
5846
ref={forwardRef}
5947
className={clsx(className, styles.Link)}
6048
data-selected={rest.selected}
6149
aria-current={rest.selected}
6250
{...rest}
6351
>
6452
{children}
65-
</BoxWithFallback>
53+
</a>
6654
)
6755
},
6856
)
6957

7058
SubNavLink.displayName = 'SubNav.Link'
7159

72-
export type SubNavProps = ComponentProps<typeof SubNav>
73-
export type SubNavLinksProps = ComponentProps<typeof SubNavLinks>
74-
export type SubNavLinkProps = ComponentProps<typeof SubNavLink>
7560
export default Object.assign(SubNav, {Link: SubNavLink, Links: SubNavLinks})

0 commit comments

Comments
 (0)