Skip to content

Commit

Permalink
feat(Pagehead): Convert Pagehead component to CSS Modules behind fe…
Browse files Browse the repository at this point in the history
…ature flag (#5197)

* initial commit

* add changeset

* format

* update changeset
  • Loading branch information
randall-krauskopf authored Oct 31, 2024
1 parent 8d9a357 commit ad84d4f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
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
return <Pagehead backgroundColor="orchid" />
}

0 comments on commit ad84d4f

Please sign in to comment.