Skip to content

Commit d5c5ecf

Browse files
forward Underline.Tab, Underline.Panels from @primer/react (#6931)
Co-authored-by: Copilot <[email protected]>
1 parent 9201d93 commit d5c5ecf

File tree

6 files changed

+26
-76
lines changed

6 files changed

+26
-76
lines changed

.changeset/chilly-lemons-promise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@primer/react": major
33
---
44

5-
Remove sx from UnderlinePanels
5+
Remove sx from UnderlinePanels

.changeset/rude-windows-bathe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@primer/react": patch
3+
"@primer/styled-react": patch
4+
---
5+
6+
use UnderlinePanels.Tab, UnderlinePanels.Panel from @primer/react

packages/react/src/experimental/UnderlinePanels/UnderlinePanels.tsx

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ import React, {
77
type FC,
88
type PropsWithChildren,
99
useEffect,
10+
type ElementType,
1011
} from 'react'
1112
import {TabContainerElement} from '@github/tab-container-element'
1213
import type {IconProps} from '@primer/octicons-react'
1314
import {createComponent} from '../../utils/create-component'
14-
import {UnderlineItemList, UnderlineWrapper, UnderlineItem} from '../../internal/components/UnderlineTabbedInterface'
15+
import {
16+
UnderlineItemList,
17+
UnderlineWrapper,
18+
UnderlineItem,
19+
type UnderlineItemProps,
20+
} from '../../internal/components/UnderlineTabbedInterface'
1521
import {useId} from '../../hooks'
1622
import {invariant} from '../../utils/invariant'
1723
import {type SxProp} from '../../sx'
@@ -97,44 +103,24 @@ const UnderlinePanels: FC<UnderlinePanelsProps> = ({
97103
let panelIndex = 0
98104

99105
const childrenWithProps = Children.map(children, child => {
100-
if (
101-
isValidElement(child) &&
102-
(typeof child.type === 'function' || typeof child.type === 'object') &&
103-
'displayName' in child.type &&
104-
child.type.displayName === 'UnderlinePanels.Tab'
105-
) {
106+
if (isValidElement<UnderlineItemProps<ElementType>>(child) && child.type === Tab) {
106107
return cloneElement(child, {id: `${parentId}-tab-${tabIndex++}`, loadingCounters, iconsVisible})
107108
}
108109

109-
if (
110-
isValidElement(child) &&
111-
(typeof child.type === 'function' || typeof child.type === 'object') &&
112-
'displayName' in child.type &&
113-
child.type.displayName === 'UnderlinePanels.Panel'
114-
) {
110+
if (isValidElement<PanelProps>(child) && child.type === Panel) {
115111
const childPanel = child as React.ReactElement<PanelProps>
116112
return cloneElement(childPanel, {'aria-labelledby': `${parentId}-tab-${panelIndex++}`})
117113
}
118114
return child
119115
})
120116

121117
const newTabs = Children.toArray(childrenWithProps).filter(child => {
122-
return (
123-
isValidElement(child) &&
124-
(typeof child.type === 'function' || typeof child.type === 'object') &&
125-
'displayName' in child.type &&
126-
child.type.displayName === 'UnderlinePanels.Tab'
127-
)
118+
return isValidElement(child) && child.type === Tab
128119
})
129120

130-
const newTabPanels = Children.toArray(childrenWithProps).filter(child => {
131-
return (
132-
isValidElement(child) &&
133-
(typeof child.type === 'function' || typeof child.type === 'object') &&
134-
'displayName' in child.type &&
135-
child.type.displayName === 'UnderlinePanels.Panel'
136-
)
137-
})
121+
const newTabPanels = Children.toArray(childrenWithProps).filter(
122+
child => isValidElement(child) && child.type === Panel,
123+
)
138124

139125
setTabs(newTabs)
140126
setTabPanels(newTabPanels)

packages/styled-react/src/__tests__/primer-react-experimental.browser.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,4 @@ describe('@primer/react/experimental', () => {
3737
)
3838
expect(window.getComputedStyle(screen.getByTestId('component')).backgroundColor).toBe('rgb(255, 0, 0)')
3939
})
40-
41-
test('UnderlinePanels.Panel supports `sx` prop', () => {
42-
render(
43-
<UnderlinePanels>
44-
<UnderlinePanels.Tab>tab</UnderlinePanels.Tab>
45-
<UnderlinePanels.Panel data-testid="component" sx={{background: 'red'}}>
46-
panel
47-
</UnderlinePanels.Panel>
48-
</UnderlinePanels>,
49-
)
50-
expect(window.getComputedStyle(screen.getByTestId('component')).backgroundColor).toBe('rgb(255, 0, 0)')
51-
})
5240
})
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
UnderlinePanels as PrimerUnderlinePanels,
33
type UnderlinePanelsProps as PrimerUnderlinePanelsProps,
4-
type UnderlinePanelsPanelProps as PrimerUnderlinePanelsPanelProps,
5-
type UnderlinePanelsTabProps as PrimerUnderlinePanelsTabProps,
4+
type UnderlinePanelsPanelProps,
5+
type UnderlinePanelsTabProps,
66
} from '@primer/react/experimental'
77
import styled from 'styled-components'
88
import {sx, type SxProp} from '../sx'
@@ -22,38 +22,9 @@ const UnderlinePanelsImpl = ({as, ...props}: UnderlinePanelsProps) => (
2222

2323
UnderlinePanelsImpl.displayName = 'UnderlinePanels'
2424

25-
type UnderlinePanelsPanelProps = PrimerUnderlinePanelsPanelProps & SxProp
26-
27-
const StyledUnderlinePanelsPanel = styled(PrimerUnderlinePanels.Panel).withConfig<UnderlinePanelsPanelProps>({
28-
shouldForwardProp: prop => prop !== 'sx',
29-
})`
30-
${sx}
31-
`
32-
33-
// @ts-ignore forwardedAs is valid here but I don't know how to fix the typescript error
34-
const UnderlinePanelsPanel = ({as, ...props}: UnderlinePanelsPanelProps) => {
35-
return <StyledUnderlinePanelsPanel forwardedAs={as} {...props} />
36-
}
37-
38-
UnderlinePanelsPanel.displayName = 'UnderlinePanels.Panel'
39-
40-
type UnderlinePanelsTabProps = PrimerUnderlinePanelsTabProps & SxProp
41-
42-
const StyledUnderlinePanelsTab = styled(PrimerUnderlinePanels.Tab).withConfig<UnderlinePanelsTabProps>({
43-
shouldForwardProp: prop => prop !== 'sx',
44-
})`
45-
${sx}
46-
`
47-
// @ts-ignore forwardedAs is valid here but I don't know how to fix the typescript error
48-
const UnderlinePanelsTab = ({as, ...props}: UnderlinePanelsTabProps) => (
49-
<StyledUnderlinePanelsTab forwardedAs={as} {...props} />
50-
)
51-
52-
UnderlinePanelsTab.displayName = 'UnderlinePanels.Tab'
53-
5425
const UnderlinePanels = Object.assign(UnderlinePanelsImpl, {
55-
Tab: UnderlinePanelsTab,
56-
Panel: UnderlinePanelsPanel,
26+
Tab: PrimerUnderlinePanels.Tab,
27+
Panel: PrimerUnderlinePanels.Panel,
5728
})
5829

5930
export {UnderlinePanels, type UnderlinePanelsProps, type UnderlinePanelsTabProps, type UnderlinePanelsPanelProps}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
export {Dialog, type DialogProps} from './components/Dialog'
2-
32
export {
43
PageHeader,
54
type PageHeaderProps,
65
type PageHeaderActionsProps,
76
type PageHeaderTitleProps,
87
} from './components/PageHeader'
98

9+
export {Tooltip, type TooltipProps} from './components/Tooltip'
10+
1011
export {
1112
UnderlinePanels,
1213
type UnderlinePanelsProps,
1314
type UnderlinePanelsTabProps,
1415
type UnderlinePanelsPanelProps,
1516
} from './components/UnderlinePanels'
1617

17-
export {Tooltip, type TooltipProps} from './components/Tooltip'
18-
1918
export {Table} from '@primer/react/experimental'

0 commit comments

Comments
 (0)