diff --git a/.changeset/cool-tips-argue.md b/.changeset/cool-tips-argue.md new file mode 100644 index 00000000000..08fbe1d8282 --- /dev/null +++ b/.changeset/cool-tips-argue.md @@ -0,0 +1,5 @@ +--- +"@primer/react": major +--- + +Remove sx prop in UnderlinePanels diff --git a/packages/react/src/experimental/UnderlinePanels/UnderlinePanels.tsx b/packages/react/src/experimental/UnderlinePanels/UnderlinePanels.tsx index 0a9ca088c3b..2d85a997ab2 100644 --- a/packages/react/src/experimental/UnderlinePanels/UnderlinePanels.tsx +++ b/packages/react/src/experimental/UnderlinePanels/UnderlinePanels.tsx @@ -11,21 +11,13 @@ import React, { import {TabContainerElement} from '@github/tab-container-element' import type {IconProps} from '@primer/octicons-react' import {createComponent} from '../../utils/create-component' -import { - UnderlineItemList, - UnderlineWrapper, - UnderlineItem, - type UnderlineItemProps, -} from '../../internal/components/UnderlineTabbedInterface' -import {type BoxProps} from '../../Box' +import {UnderlineItemList, UnderlineWrapper, UnderlineItem} from '../../internal/components/UnderlineTabbedInterface' import {useId} from '../../hooks' import {invariant} from '../../utils/invariant' -import {type SxProp} from '../../sx' import {useResizeObserver, type ResizeObserverEntry} from '../../hooks/useResizeObserver' import useIsomorphicLayoutEffect from '../../utils/useIsomorphicLayoutEffect' import classes from './UnderlinePanels.module.css' import {clsx} from 'clsx' -import {BoxWithFallback} from '../../internal/components/BoxWithFallback' export type UnderlinePanelsProps = { /** @@ -52,7 +44,7 @@ export type UnderlinePanelsProps = { * Class name for custom styling */ className?: string -} & SxProp +} export type TabProps = PropsWithChildren<{ /** @@ -71,10 +63,9 @@ export type TabProps = PropsWithChildren<{ * Icon rendered before the tab text label */ icon?: FC -}> & - SxProp +}> -export type PanelProps = Omit +export type PanelProps = React.HTMLAttributes const TabContainerComponent = createComponent(TabContainerElement, 'tab-container') @@ -104,12 +95,14 @@ const UnderlinePanels: FC = ({ let panelIndex = 0 const childrenWithProps = Children.map(children, child => { - if (isValidElement(child) && child.type === Tab) { + if (isValidElement(child) && child.type === Tab) { return cloneElement(child, {id: `${parentId}-tab-${tabIndex++}`, loadingCounters, iconsVisible}) } if (isValidElement(child) && child.type === Panel) { - return cloneElement(child, {'aria-labelledby': `${parentId}-tab-${panelIndex++}`}) + return cloneElement(child as React.ReactElement, { + 'aria-labelledby': `${parentId}-tab-${panelIndex++}`, + }) } return child }) @@ -221,8 +214,12 @@ const Tab: FC = ({'aria-selected': ariaSelected, onSelect, ...props}) Tab.displayName = 'UnderlinePanels.Tab' -const Panel: FC = props => { - return +const Panel: FC = ({children, ...rest}) => { + return ( +
+ {children} +
+ ) } Panel.displayName = 'UnderlinePanels.Panel' diff --git a/packages/react/src/internal/components/UnderlineTabbedInterface.tsx b/packages/react/src/internal/components/UnderlineTabbedInterface.tsx index a2887dd13ad..5ac5df8ef12 100644 --- a/packages/react/src/internal/components/UnderlineTabbedInterface.tsx +++ b/packages/react/src/internal/components/UnderlineTabbedInterface.tsx @@ -1,16 +1,14 @@ // Used for UnderlineNav and UnderlinePanels components -import type React from 'react' -import {forwardRef, type FC, type PropsWithChildren} from 'react' +import React from 'react' +import {forwardRef, type FC, type PropsWithChildren, type ElementType} from 'react' import {isElement} from 'react-is' import type {IconProps} from '@primer/octicons-react' import CounterLabel from '../../CounterLabel' -import {type SxProp} from '../../sx' import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../../utils/polymorphic' import classes from './UnderlineTabbedInterface.module.css' import {clsx} from 'clsx' -import {BoxWithFallback} from './BoxWithFallback' // The gap between the list items. It is a constant because the gap is used to calculate the possible number of items that can fit in the container. export const GAP = 8 @@ -19,15 +17,15 @@ type UnderlineWrapperProps = { slot?: string as?: React.ElementType className?: string - ref?: React.Ref -} & SxProp + ref?: React.Ref +} -export const UnderlineWrapper = forwardRef( - ({children, className, ...rest}: PropsWithChildren, forwardedRef) => { +export const UnderlineWrapper = forwardRef>( + ({children, className, ...rest}, forwardedRef) => { return ( - +
{children} - +
) }, ) @@ -44,8 +42,8 @@ export const LoadingCounter = () => { return } -export type UnderlineItemProps = { - as?: React.ElementType | 'a' | 'button' +export type UnderlineItemProps = { + as?: As | 'a' | 'button' className?: string iconsVisible?: boolean loadingCounters?: boolean @@ -53,42 +51,29 @@ export type UnderlineItemProps = { icon?: FC | React.ReactElement id?: string ref?: React.Ref -} & SxProp +} & React.ComponentPropsWithoutRef -export const UnderlineItem = forwardRef( - ( - { - as = 'a', - children, - counter, - icon: Icon, - iconsVisible, - loadingCounters, - className, - ...rest - }: PropsWithChildren, - forwardedRef, - ) => { - return ( - - {iconsVisible && Icon && {isElement(Icon) ? Icon : }} - {children && ( - - {children} +export const UnderlineItem = React.forwardRef((props, ref) => { + const {as: Component = 'a', children, counter, icon: Icon, iconsVisible, loadingCounters, className, ...rest} = props + return ( + + {iconsVisible && Icon && {isElement(Icon) ? Icon : }} + {children && ( + + {children} + + )} + {counter !== undefined ? ( + loadingCounters ? ( + + - )} - {counter !== undefined ? ( - loadingCounters ? ( - - - - ) : ( - - {counter} - - ) - ) : null} - - ) - }, -) as PolymorphicForwardRefComponent<'a', UnderlineItemProps> + ) : ( + + {counter} + + ) + ) : null} + + ) +}) as PolymorphicForwardRefComponent>