Skip to content

Commit 7e6475d

Browse files
jonrohanjamieshark
andauthored
chore(Text): Remove the CSS modules feature flag from the Text component (#5868)
Co-authored-by: Jamie Shark <[email protected]>
1 parent cd9987d commit 7e6475d

File tree

5 files changed

+20
-146
lines changed

5 files changed

+20
-146
lines changed

.changeset/ripe-paws-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Remove the CSS modules feature flag from Text

packages/react/src/Text/Text.tsx

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import {clsx} from 'clsx'
2-
import styled, {type StyledComponent} from 'styled-components'
2+
import {type StyledComponent} from 'styled-components'
33
import React, {forwardRef} from 'react'
44
import type {SystemCommonProps, SystemTypographyProps} from '../constants'
5-
import {COMMON, TYPOGRAPHY} from '../constants'
65
import type {SxProp} from '../sx'
7-
import sx from '../sx'
8-
import {useFeatureFlag} from '../FeatureFlags'
9-
import Box from '../Box'
106
import {useRefObjectAsForwardedRef} from '../hooks'
11-
import type {ComponentProps} from '../utils/types'
12-
import {includesSystemProps} from '../utils/includeSystemProps'
137
import classes from './Text.module.css'
8+
import {toggleSxComponent} from '../internal/utils/toggleSxComponent'
149

1510
type StyledTextProps = {
1611
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -19,95 +14,30 @@ type StyledTextProps = {
1914
weight?: 'light' | 'normal' | 'medium' | 'semibold'
2015
} & SystemTypographyProps &
2116
SystemCommonProps &
22-
SxProp
23-
24-
const StyledText = styled.span<StyledTextProps>`
25-
${TYPOGRAPHY};
26-
${COMMON};
27-
28-
&:where([data-size='small']) {
29-
font-size: var(--text-body-size-small, 0.75rem);
30-
line-height: var(--text-body-lineHeight-small, 1.6666);
31-
}
32-
33-
&:where([data-size='medium']) {
34-
font-size: var(--text-body-size-medium, 0.875rem);
35-
line-height: var(--text-body-lineHeight-medium, 1.4285);
36-
}
37-
38-
&:where([data-size='large']) {
39-
font-size: var(--text-body-size-large, 1rem);
40-
line-height: var(--text-body-lineHeight-large, 1.5);
41-
}
42-
43-
&:where([data-weight='light']) {
44-
font-weight: var(--base-text-weight-light, 300);
45-
}
46-
47-
&:where([data-weight='normal']) {
48-
font-weight: var(--base-text-weight-normal, 400);
49-
}
50-
51-
&:where([data-weight='medium']) {
52-
font-weight: var(--base-text-weight-medium, 500);
53-
}
54-
55-
&:where([data-weight='semibold']) {
56-
font-weight: var(--base-text-weight-semibold, 600);
57-
}
58-
59-
${sx};
60-
`
17+
SxProp &
18+
React.HTMLAttributes<HTMLSpanElement>
6119

20+
const TextBaseComponent = toggleSxComponent('span') as React.ComponentType<StyledTextProps>
6221
const Text = forwardRef(({as: Component = 'span', className, size, weight, ...props}, forwardedRef) => {
63-
const enabled = useFeatureFlag('primer_react_css_modules_ga')
64-
6522
const innerRef = React.useRef<HTMLElement>(null)
6623
useRefObjectAsForwardedRef(forwardedRef, innerRef)
67-
if (enabled) {
68-
// If props includes TYPOGRAPHY or COMMON props, pass them to the Box component
69-
if (includesSystemProps(props)) {
70-
return (
71-
// @ts-ignore shh
72-
<Box
73-
as={Component}
74-
className={clsx(className, classes.Text)}
75-
data-size={size}
76-
data-weight={weight}
77-
{...props}
78-
// @ts-ignore shh
79-
ref={innerRef}
80-
/>
81-
)
82-
}
83-
84-
return (
85-
<Component
86-
className={clsx(className, classes.Text)}
87-
data-size={size}
88-
data-weight={weight}
89-
{...props}
90-
// @ts-ignore shh
91-
ref={innerRef}
92-
/>
93-
)
94-
}
9524

9625
return (
97-
<StyledText
26+
<TextBaseComponent
9827
as={Component}
99-
className={className}
28+
className={clsx(className, classes.Text)}
10029
data-size={size}
10130
data-weight={weight}
10231
{...props}
10332
// @ts-ignore shh
10433
ref={innerRef}
10534
/>
10635
)
36+
10737
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10838
}) as StyledComponent<'span', any, StyledTextProps, never>
10939

11040
Text.displayName = 'Text'
11141

112-
export type TextProps = ComponentProps<typeof StyledText>
42+
export type TextProps = StyledTextProps
11343
export default Text

packages/react/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -935,39 +935,8 @@ exports[`TextInputWithTokens renders a truncated set of tokens 1`] = `
935935
}
936936

937937
.c9 {
938-
font-size: 16px;
939938
color: var(--fgColor-muted,var(--color-fg-muted,#656d76));
940-
}
941-
942-
.c9:where([data-size='small']) {
943-
font-size: var(--text-body-size-small,0.75rem);
944-
line-height: var(--text-body-lineHeight-small,1.6666);
945-
}
946-
947-
.c9:where([data-size='medium']) {
948-
font-size: var(--text-body-size-medium,0.875rem);
949-
line-height: var(--text-body-lineHeight-medium,1.4285);
950-
}
951-
952-
.c9:where([data-size='large']) {
953-
font-size: var(--text-body-size-large,1rem);
954-
line-height: var(--text-body-lineHeight-large,1.5);
955-
}
956-
957-
.c9:where([data-weight='light']) {
958-
font-weight: var(--base-text-weight-light,300);
959-
}
960-
961-
.c9:where([data-weight='normal']) {
962-
font-weight: var(--base-text-weight-normal,400);
963-
}
964-
965-
.c9:where([data-weight='medium']) {
966-
font-weight: var(--base-text-weight-medium,500);
967-
}
968-
969-
.c9:where([data-weight='semibold']) {
970-
font-weight: var(--base-text-weight-semibold,600);
939+
font-size: 16px;
971940
}
972941

973942
.c7 {
@@ -1465,7 +1434,7 @@ exports[`TextInputWithTokens renders a truncated set of tokens 1`] = `
14651434
</span>
14661435
</span>
14671436
<span
1468-
className="c9"
1437+
className="c9 Text"
14691438
color="fg.muted"
14701439
fontSize={2}
14711440
>

packages/react/src/__tests__/__snapshots__/ThemeProvider.test.tsx.snap

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,12 @@
22

33
exports[`has default theme 1`] = `
44
.c0 {
5-
color: var(--fgColor-default,var(--color-fg-default,#1F2328));
65
margin-bottom: 4px;
7-
}
8-
9-
.c0:where([data-size='small']) {
10-
font-size: var(--text-body-size-small,0.75rem);
11-
line-height: var(--text-body-lineHeight-small,1.6666);
12-
}
13-
14-
.c0:where([data-size='medium']) {
15-
font-size: var(--text-body-size-medium,0.875rem);
16-
line-height: var(--text-body-lineHeight-medium,1.4285);
17-
}
18-
19-
.c0:where([data-size='large']) {
20-
font-size: var(--text-body-size-large,1rem);
21-
line-height: var(--text-body-lineHeight-large,1.5);
22-
}
23-
24-
.c0:where([data-weight='light']) {
25-
font-weight: var(--base-text-weight-light,300);
26-
}
27-
28-
.c0:where([data-weight='normal']) {
29-
font-weight: var(--base-text-weight-normal,400);
30-
}
31-
32-
.c0:where([data-weight='medium']) {
33-
font-weight: var(--base-text-weight-medium,500);
34-
}
35-
36-
.c0:where([data-weight='semibold']) {
37-
font-weight: var(--base-text-weight-semibold,600);
6+
color: var(--fgColor-default,var(--color-fg-default,#1F2328));
387
}
398
409
<span
41-
class="c0"
10+
class="c0 Text"
4211
color="fg.default"
4312
>
4413
Hello

packages/react/src/internal/utils/toggleSxComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import Box from '../../Box'
33
import {defaultSxProp} from '../../utils/defaultSxProp'
4+
import {includesSystemProps} from '../../utils/includeSystemProps'
45

56
type CSSModulesProps = {
67
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -23,7 +24,7 @@ export function toggleSxComponent<T, P extends CSSModulesProps>(
2324
{as: BaseComponent = defaultAs, sx: sxProp = defaultSxProp, ...rest},
2425
ref,
2526
) {
26-
if (sxProp !== defaultSxProp) {
27+
if (sxProp !== defaultSxProp || includesSystemProps(rest)) {
2728
return <Box as={BaseComponent} {...rest} sx={sxProp} ref={ref} />
2829
}
2930
return <BaseComponent {...rest} ref={ref} />

0 commit comments

Comments
 (0)