Skip to content

Commit ad84d4f

Browse files
feat(Pagehead): Convert Pagehead component to CSS Modules behind feature flag (#5197)
* initial commit * add changeset * format * update changeset
1 parent 8d9a357 commit ad84d4f

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

.changeset/quiet-seahorses-yawn.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+
Convert `Pagehead` to CSS Modules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import type {Meta} from '@storybook/react'
3+
import Pagehead from './Pagehead'
4+
import Heading from '../Heading'
5+
6+
export default {
7+
title: 'Deprecated/Components/Pagehead/Dev',
8+
component: Pagehead,
9+
} as Meta<typeof Pagehead>
10+
11+
export const Default = () => (
12+
<Pagehead sx={{color: 'red'}}>
13+
<Heading as="h2" variant="small">
14+
Pagehead
15+
</Heading>
16+
</Pagehead>
17+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.Pagehead {
2+
position: relative;
3+
padding-top: var(--base-size-24);
4+
padding-bottom: var(--base-size-24);
5+
margin-bottom: var(--base-size-24);
6+
/* stylelint-disable-next-line primer/borders */
7+
border-bottom: 1px solid var(--borderColor-default);
8+
}
Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
import styled from 'styled-components'
2+
import React, {type ComponentProps} from 'react'
3+
import {clsx} from 'clsx'
24
import {get} from '../constants'
3-
import type {SxProp} from '../sx'
4-
import sx from '../sx'
5-
import type {ComponentProps} from '../utils/types'
5+
import sx, {type SxProp} from '../sx'
6+
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
7+
import classes from './Pagehead.module.css'
8+
import {useFeatureFlag} from '../FeatureFlags'
9+
10+
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'
611

712
/**
813
* @deprecated
914
*/
10-
const Pagehead = styled.div<SxProp>`
11-
position: relative;
12-
padding-top: ${get('space.4')};
13-
padding-bottom: ${get('space.4')};
14-
margin-bottom: ${get('space.4')};
15-
border-bottom: 1px solid ${get('colors.border.default')};
16-
${sx};
17-
`
15+
const StyledComponentPagehead = toggleStyledComponent(
16+
CSS_MODULES_FEATURE_FLAG,
17+
'div',
18+
styled.div<SxProp>`
19+
position: relative;
20+
padding-top: ${get('space.4')};
21+
padding-bottom: ${get('space.4')};
22+
margin-bottom: ${get('space.4')};
23+
border-bottom: 1px solid ${get('colors.border.default')};
24+
${sx};
25+
`,
26+
)
27+
28+
const Pagehead = ({className, ...rest}: PageheadProps) => {
29+
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
30+
31+
if (enabled) {
32+
return <StyledComponentPagehead className={clsx(classes.Pagehead, className)} {...rest} />
33+
}
34+
35+
return <StyledComponentPagehead {...rest} />
36+
}
1837

1938
/**
2039
* @deprecated
2140
*/
22-
export type PageheadProps = ComponentProps<typeof Pagehead>
41+
export type PageheadProps = ComponentProps<typeof StyledComponentPagehead> & SxProp
2342
export default Pagehead

packages/react/src/Pagehead/Pagehead.types.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ export function shouldAcceptCallWithNoProps() {
66
}
77

88
export function shouldNotAcceptSystemProps() {
9-
// @ts-expect-error system props should not be accepted
109
return <Pagehead backgroundColor="orchid" />
1110
}

0 commit comments

Comments
 (0)