|
1 | 1 | import styled from 'styled-components'
|
| 2 | +import React, {type ComponentProps} from 'react' |
| 3 | +import {clsx} from 'clsx' |
2 | 4 | 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' |
6 | 11 |
|
7 | 12 | /**
|
8 | 13 | * @deprecated
|
9 | 14 | */
|
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 | +} |
18 | 37 |
|
19 | 38 | /**
|
20 | 39 | * @deprecated
|
21 | 40 | */
|
22 |
| -export type PageheadProps = ComponentProps<typeof Pagehead> |
| 41 | +export type PageheadProps = ComponentProps<typeof StyledComponentPagehead> & SxProp |
23 | 42 | export default Pagehead
|
0 commit comments