Skip to content

Commit

Permalink
Merge e247b44 into bd99a71
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrohan authored Oct 7, 2024
2 parents bd99a71 + e247b44 commit f1ba468
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-apples-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Correctly pass styled system typography and common props to the `Box` component in the `Text` component when the CSS modules feature flag is enabled.
19 changes: 15 additions & 4 deletions packages/react/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,27 @@ const StyledText = styled.span<StyledTextProps>`
${sx};
`

const COMMON_PROP_NAMES = new Set(Object.keys(COMMON))
const TYPOGRAPHY_PROP_NAMES = new Set(Object.keys(TYPOGRAPHY))

const includesSystemProps = (props: StyledTextProps) => {
if (props.sx) {
return true
}

return Object.keys(props).some(prop => {
return TYPOGRAPHY_PROP_NAMES.has(prop) || COMMON_PROP_NAMES.has(prop)
})
}

const Text = forwardRef(({as: Component = 'span', className, size, weight, ...props}, forwardedRef) => {
const enabled = useFeatureFlag('primer_react_css_modules_ga')

const innerRef = React.useRef<HTMLElement>(null)
useRefObjectAsForwardedRef(forwardedRef, innerRef)

if (enabled) {
if (props.sx) {
// If props includes TYPOGRAPHY or COMMON props, pass them to the Box component
if (includesSystemProps(props)) {
return (
// @ts-ignore shh
<Box
Expand All @@ -81,7 +94,6 @@ const Text = forwardRef(({as: Component = 'span', className, size, weight, ...pr
}

return (
// @ts-ignore shh
<Component
className={clsx(className, classes.Text)}
data-size={size}
Expand All @@ -94,7 +106,6 @@ const Text = forwardRef(({as: Component = 'span', className, size, weight, ...pr
}

return (
// @ts-ignore shh
<StyledText
as={Component}
className={className}
Expand Down

0 comments on commit f1ba468

Please sign in to comment.