Skip to content

Commit 8e4beae

Browse files
authored
Remove the CSS modules feature flag from Heading (#5018)
* Remove feature flag from Heading component * Create good-years-attack.md * Update tests and snapshots
1 parent 15cb90f commit 8e4beae

File tree

5 files changed

+54
-154
lines changed

5 files changed

+54
-154
lines changed

.changeset/good-years-attack.md

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

e2e/components/Heading.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ test.describe('Heading', () => {
2424
for (const story of stories) {
2525
test.describe(story.title, () => {
2626
test('default @vrt', async ({page}) => {
27-
await visit(page, {
28-
id: story.id,
29-
globals: {
30-
featureFlags: {
31-
primer_react_css_modules_ga: true,
32-
},
33-
},
34-
})
35-
36-
// Default state
37-
expect(await page.screenshot()).toMatchSnapshot(`Heading.${story.title}.png`)
38-
})
39-
40-
test('default (styled-components) @vrt', async ({page}) => {
4127
await visit(page, {
4228
id: story.id,
4329
})
@@ -47,18 +33,6 @@ test.describe('Heading', () => {
4733
})
4834

4935
test('axe @aat', async ({page}) => {
50-
await visit(page, {
51-
id: story.id,
52-
globals: {
53-
featureFlags: {
54-
primer_react_css_modules_ga: true,
55-
},
56-
},
57-
})
58-
await expect(page).toHaveNoViolations()
59-
})
60-
61-
test('axe (styled-components) @aat', async ({page}) => {
6236
await visit(page, {
6337
id: story.id,
6438
})

packages/react/src/Heading/Heading.tsx

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
11
import {clsx} from 'clsx'
22
import React, {forwardRef, useEffect} from 'react'
3-
import styled from 'styled-components'
4-
import {get} from '../constants'
53
import {useRefObjectAsForwardedRef} from '../hooks'
64
import type {SxProp} from '../sx'
7-
import sx from '../sx'
85
import type {ComponentProps} from '../utils/types'
96
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
107
import classes from './Heading.module.css'
11-
import {useFeatureFlag} from '../FeatureFlags'
128
import Box from '../Box'
139

1410
type StyledHeadingProps = {
1511
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
1612
variant?: 'large' | 'medium' | 'small'
1713
} & SxProp
1814

19-
const StyledHeading = styled.h2<StyledHeadingProps>`
20-
font-weight: ${get('fontWeights.bold')};
21-
font-size: ${get('fontSizes.5')};
22-
margin: 0;
23-
24-
&:where([data-variant='large']) {
25-
font: var(--text-title-shorthand-large, 600 32px / 1.5 ${get('fonts.normal')});
26-
}
27-
28-
&:where([data-variant='medium']) {
29-
font: var(--text-title-shorthand-medium, 600 20px / 1.6 ${get('fonts.normal')});
30-
}
31-
32-
&:where([data-variant='small']) {
33-
font: var(--text-title-shorthand-small, 600 16px / 1.5 ${get('fonts.normal')});
34-
}
35-
36-
${sx};
37-
`
38-
3915
const Heading = forwardRef(({as: Component = 'h2', className, variant, ...props}, forwardedRef) => {
40-
const enabled = useFeatureFlag('primer_react_css_modules_ga')
4116
const innerRef = React.useRef<HTMLHeadingElement>(null)
4217
useRefObjectAsForwardedRef(forwardedRef, innerRef)
4318

@@ -57,33 +32,19 @@ const Heading = forwardRef(({as: Component = 'h2', className, variant, ...props}
5732
}, [innerRef])
5833
}
5934

60-
if (enabled) {
61-
if (props.sx) {
62-
return (
63-
<Box
64-
as={Component}
65-
className={clsx(className, classes.Heading)}
66-
data-variant={variant}
67-
{...props}
68-
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
69-
ref={innerRef}
70-
/>
71-
)
72-
}
73-
return <Component className={clsx(className, classes.Heading)} data-variant={variant} {...props} ref={innerRef} />
35+
if (props.sx) {
36+
return (
37+
<Box
38+
as={Component}
39+
className={clsx(className, classes.Heading)}
40+
data-variant={variant}
41+
{...props}
42+
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
43+
ref={innerRef}
44+
/>
45+
)
7446
}
75-
76-
return (
77-
<StyledHeading
78-
as={Component}
79-
className={className}
80-
data-variant={variant}
81-
sx={sx}
82-
{...props}
83-
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
84-
ref={innerRef}
85-
/>
86-
)
47+
return <Component className={clsx(className, classes.Heading)} data-variant={variant} {...props} ref={innerRef} />
8748
}) as PolymorphicForwardRefComponent<'h2', StyledHeadingProps>
8849

8950
Heading.displayName = 'Heading'

packages/react/src/Heading/__tests__/Heading.test.tsx

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {render, behavesAsComponent, checkExports} from '../../utils/testing'
44
import {render as HTMLRender, screen} from '@testing-library/react'
55
import axe from 'axe-core'
66
import ThemeProvider from '../../ThemeProvider'
7-
import {FeatureFlags} from '../../FeatureFlags'
87

98
const theme = {
109
breakpoints: ['400px', '640px', '960px', '1280px'],
@@ -142,54 +141,30 @@ describe('Heading', () => {
142141
).toHaveStyleRule('font-style', 'italic')
143142
})
144143

145-
describe('with primer_react_css_modules_ga enabled', () => {
146-
it('should only include css modules class', () => {
147-
HTMLRender(
148-
<FeatureFlags
149-
flags={{
150-
primer_react_css_modules_ga: true,
151-
}}
152-
>
153-
<Heading>test</Heading>
154-
</FeatureFlags>,
155-
)
156-
expect(screen.getByText('test')).toHaveClass('Heading')
157-
// Note: this is the generated class name when styled-components is used
158-
// for this component
159-
expect(screen.getByText('test')).not.toHaveClass(/^Heading__StyledHeading/)
160-
})
161-
162-
it('should support `className` on the outermost element', () => {
163-
const {container} = HTMLRender(
164-
<FeatureFlags
165-
flags={{
166-
primer_react_css_modules_ga: true,
167-
}}
168-
>
169-
<Heading className="test">test</Heading>
170-
</FeatureFlags>,
171-
)
172-
expect(container.firstChild).toHaveClass('test')
173-
})
174-
175-
it('should support overrides with sx if provided', () => {
176-
HTMLRender(
177-
<FeatureFlags
178-
flags={{
179-
primer_react_css_modules_ga: true,
180-
}}
181-
>
182-
<Heading
183-
sx={{
184-
fontWeight: '900',
185-
}}
186-
>
187-
test
188-
</Heading>
189-
</FeatureFlags>,
190-
)
191-
192-
expect(screen.getByText('test')).toHaveStyle('font-weight: 900')
193-
})
144+
it('should only include css modules class', () => {
145+
HTMLRender(<Heading>test</Heading>)
146+
expect(screen.getByText('test')).toHaveClass('Heading')
147+
// Note: this is the generated class name when styled-components is used
148+
// for this component
149+
expect(screen.getByText('test')).not.toHaveClass(/^Heading__StyledHeading/)
150+
})
151+
152+
it('should support `className` on the outermost element', () => {
153+
const {container} = HTMLRender(<Heading className="test">test</Heading>)
154+
expect(container.firstChild).toHaveClass('test')
155+
})
156+
157+
it('should support overrides with sx if provided', () => {
158+
HTMLRender(
159+
<Heading
160+
sx={{
161+
fontWeight: '900',
162+
}}
163+
>
164+
test
165+
</Heading>,
166+
)
167+
168+
expect(screen.getByText('test')).toHaveStyle('font-weight: 900')
194169
})
195170
})

packages/react/src/NavList/__snapshots__/NavList.test.tsx.snap

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,16 @@ exports[`NavList renders with groups 1`] = `
464464
margin-top: 8px;
465465
}
466466
467+
.c3 {
468+
padding-top: 6px;
469+
padding-bottom: 6px;
470+
padding-left: 16px;
471+
padding-right: 16px;
472+
font-size: 12px;
473+
font-weight: 600;
474+
color: var(--fgColor-muted,var(--color-fg-muted,#656d76));
475+
}
476+
467477
.c4 {
468478
padding-inline-start: 0;
469479
}
@@ -501,31 +511,6 @@ exports[`NavList renders with groups 1`] = `
501511
word-break: break-word;
502512
}
503513
504-
.c3 {
505-
font-weight: 600;
506-
font-size: 32px;
507-
margin: 0;
508-
padding-top: 6px;
509-
padding-bottom: 6px;
510-
padding-left: 16px;
511-
padding-right: 16px;
512-
font-size: 12px;
513-
font-weight: 600;
514-
color: var(--fgColor-muted,var(--color-fg-muted,#656d76));
515-
}
516-
517-
.c3:where([data-variant='large']) {
518-
font: var(--text-title-shorthand-large,600 32px / 1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
519-
}
520-
521-
.c3:where([data-variant='medium']) {
522-
font: var(--text-title-shorthand-medium,600 20px / 1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
523-
}
524-
525-
.c3:where([data-variant='small']) {
526-
font: var(--text-title-shorthand-small,600 16px / 1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
527-
}
528-
529514
.c0 {
530515
margin: 0;
531516
padding-inline-start: 0;
@@ -869,7 +854,7 @@ exports[`NavList renders with groups 1`] = `
869854
class="c2"
870855
>
871856
<h3
872-
class="c3"
857+
class="c3 Heading"
873858
id=":r7:"
874859
>
875860
Overview
@@ -913,7 +898,7 @@ exports[`NavList renders with groups 1`] = `
913898
class="c2"
914899
>
915900
<h3
916-
class="c3"
901+
class="c3 Heading"
917902
id=":r9:"
918903
>
919904
Components

0 commit comments

Comments
 (0)