Skip to content

Commit 3968da0

Browse files
committed
apply the new pattern for polymorphic component
1 parent 18b57ab commit 3968da0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/styled-react/src/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SegmentedControl as PrimerSegmentedControl,
1919
type SegmentedControlButtonProps as PrimerSegmentedControlButtonProps,
2020
type SegmentedControlIconButtonProps as PrimerSegmentedControlIconButtonProps,
21+
sx,
2122
} from '@primer/react'
2223
import React, {forwardRef, type PropsWithChildren} from 'react'
2324
import type {ForwardRefComponent} from './polymorphic'
@@ -33,6 +34,7 @@ import type {
3334
SpaceProps,
3435
TypographyProps,
3536
} from 'styled-system'
37+
import styled from 'styled-components'
3638

3739
type StyledProps = SxProp &
3840
SpaceProps &
@@ -139,10 +141,11 @@ const ToggleSwitch = forwardRef<HTMLButtonElement, ToggleSwitchProps>(function T
139141

140142
type TruncateProps = PropsWithChildren<PrimerTruncateProps> & SxProp
141143

142-
const Truncate = forwardRef<HTMLDivElement, TruncateProps>(function Truncate(props, ref) {
143-
// @ts-ignore - PrimerTruncate is polymorphic and functionally compatible with Box's as prop
144-
return <Box as={PrimerTruncate} ref={ref} {...props} />
145-
}) as ForwardRefComponent<'div', TruncateProps>
144+
const Truncate: ForwardRefComponent<'div', TruncateProps> = styled(PrimerTruncate).withConfig<TruncateProps>({
145+
shouldForwardProp: prop => prop !== 'sx',
146+
})`
147+
${sx}
148+
`
146149

147150
export {RadioGroup, SegmentedControl, StateLabel, SubNav, ToggleSwitch, Truncate}
148151

0 commit comments

Comments
 (0)