Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-seahorses-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Convert `Pagehead` to CSS Modules
17 changes: 17 additions & 0 deletions packages/react/src/Pagehead/Pagehead.dev.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import type {Meta} from '@storybook/react'
import Pagehead from './Pagehead'
import Heading from '../Heading'

export default {
title: 'Deprecated/Components/Pagehead/Dev',
component: Pagehead,
} as Meta<typeof Pagehead>

export const Default = () => (
<Pagehead sx={{color: 'red'}}>
<Heading as="h2" variant="small">
Pagehead
</Heading>
</Pagehead>
)
8 changes: 8 additions & 0 deletions packages/react/src/Pagehead/Pagehead.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.Pagehead {
position: relative;
padding-top: var(--base-size-24);
padding-bottom: var(--base-size-24);
margin-bottom: var(--base-size-24);
/* stylelint-disable-next-line primer/borders */
border-bottom: 1px solid var(--borderColor-default);
}
43 changes: 31 additions & 12 deletions packages/react/src/Pagehead/Pagehead.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
import styled from 'styled-components'
import React, {type ComponentProps} from 'react'
import {clsx} from 'clsx'
import {get} from '../constants'
import type {SxProp} from '../sx'
import sx from '../sx'
import type {ComponentProps} from '../utils/types'
import sx, {type SxProp} from '../sx'
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
import classes from './Pagehead.module.css'
import {useFeatureFlag} from '../FeatureFlags'

const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'

/**
* @deprecated
*/
const Pagehead = styled.div<SxProp>`
position: relative;
padding-top: ${get('space.4')};
padding-bottom: ${get('space.4')};
margin-bottom: ${get('space.4')};
border-bottom: 1px solid ${get('colors.border.default')};
${sx};
`
const StyledComponentPagehead = toggleStyledComponent(
CSS_MODULES_FEATURE_FLAG,
'div',
styled.div<SxProp>`
position: relative;
padding-top: ${get('space.4')};
padding-bottom: ${get('space.4')};
margin-bottom: ${get('space.4')};
border-bottom: 1px solid ${get('colors.border.default')};
${sx};
`,
)

const Pagehead = ({className, ...rest}: PageheadProps) => {
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)

if (enabled) {
return <StyledComponentPagehead className={clsx(classes.Pagehead, className)} {...rest} />
}

return <StyledComponentPagehead {...rest} />
}

/**
* @deprecated
*/
export type PageheadProps = ComponentProps<typeof Pagehead>
export type PageheadProps = ComponentProps<typeof StyledComponentPagehead> & SxProp
export default Pagehead
1 change: 0 additions & 1 deletion packages/react/src/Pagehead/Pagehead.types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export function shouldAcceptCallWithNoProps() {
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Torn on this change, cause it now will technically accept the system props we were blocking before. I think the change comes from the toggleStyledComponent somewhere. But this is temporary. When we remove the feature flag it will be an error again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can hold off on this and try and find a solution if you like? I don't mind, the temporary change could be in place for awhile depending on how things go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na, if we work fast enough on this, it won't make a difference. and I don't think folks are adding these attributes in dotcom much anymore. if at all

return <Pagehead backgroundColor="orchid" />
}
Loading