Skip to content

Commit 9faa7e9

Browse files
refactor(styled-react): update structure to reduce merge conflicts (#6861)
Co-authored-by: Marie Lucca <francinelucca@github.com>
1 parent e6e2f8b commit 9faa7e9

File tree

17 files changed

+384
-313
lines changed

17 files changed

+384
-313
lines changed

packages/styled-react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ exports[`@primer/styled-react exports 1`] = `
2828
"Overlay",
2929
"PageHeader",
3030
"PageLayout",
31+
"ProgressBar",
3132
"RadioGroup",
3233
"RelativeTime",
3334
"SegmentedControl",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Checkbox as PrimerCheckbox, type CheckboxProps as PrimerCheckboxProps} from '@primer/react'
2+
import {Box} from './Box'
3+
import {forwardRef} from 'react'
4+
import {type SxProp} from '../sx'
5+
6+
export type CheckboxProps = PrimerCheckboxProps & SxProp
7+
8+
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(props, ref) {
9+
return <Box as={PrimerCheckbox} ref={ref} {...props} />
10+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {CounterLabel as PrimerCounterLabel, type CounterLabelProps as PrimerCounterLabelProps} from '@primer/react'
2+
import {Box} from './Box'
3+
import {forwardRef} from 'react'
4+
import {type SxProp} from '../sx'
5+
6+
export type CounterLabelProps = PrimerCounterLabelProps & SxProp
7+
8+
export const CounterLabel = forwardRef<HTMLSpanElement, CounterLabelProps>(function CounterLabel(props, ref) {
9+
return <Box as={PrimerCounterLabel} ref={ref} {...props} />
10+
})

packages/styled-react/src/components/PageHeader.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,35 @@ const PageHeaderTitleArea: ForwardRefComponent<'div', PageHeaderTitleAreaProps>
7575
${sx}
7676
`
7777

78-
const PageHeader = Object.assign(PageHeaderImpl, {
78+
type PageHeaderComponent = ForwardRefComponent<'div', PageHeaderProps> & {
79+
Actions: typeof PageHeaderActions
80+
ContextArea: typeof PrimerPageHeader.ContextArea
81+
ParentLink: typeof PrimerPageHeader.ParentLink
82+
ContextBar: typeof PrimerPageHeader.ContextBar
83+
TitleArea: typeof PageHeaderTitleArea
84+
ContextAreaActions: typeof PrimerPageHeader.ContextAreaActions
85+
LeadingAction: typeof PrimerPageHeader.LeadingAction
86+
Breadcrumbs: typeof PrimerPageHeader.Breadcrumbs
87+
LeadingVisual: typeof PrimerPageHeader.LeadingVisual
88+
Title: typeof PageHeaderTitle
89+
TrailingVisual: typeof PrimerPageHeader.TrailingVisual
90+
Description: typeof PrimerPageHeader.Description
91+
TrailingAction: typeof PrimerPageHeader.TrailingAction
92+
}
93+
94+
const PageHeader: PageHeaderComponent = Object.assign(PageHeaderImpl, {
7995
Actions: PageHeaderActions,
80-
Title: PageHeaderTitle,
81-
TitleArea: PageHeaderTitleArea,
8296
ContextArea: PrimerPageHeader.ContextArea,
83-
ContextAreaActions: PrimerPageHeader.ContextAreaActions,
84-
TrailingVisual: PrimerPageHeader.TrailingVisual,
85-
Description: PrimerPageHeader.Description,
97+
ParentLink: PrimerPageHeader.ParentLink,
8698
ContextBar: PrimerPageHeader.ContextBar,
99+
TitleArea: PageHeaderTitleArea,
100+
ContextAreaActions: PrimerPageHeader.ContextAreaActions,
87101
LeadingAction: PrimerPageHeader.LeadingAction,
88102
Breadcrumbs: PrimerPageHeader.Breadcrumbs,
89103
LeadingVisual: PrimerPageHeader.LeadingVisual,
104+
Title: PageHeaderTitle,
105+
TrailingVisual: PrimerPageHeader.TrailingVisual,
106+
Description: PrimerPageHeader.Description,
90107
TrailingAction: PrimerPageHeader.TrailingAction,
91108
})
92109

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {Box, RadioGroup as PrimerRadioGroup, type RadioGroupProps as PrimerRadioGroupProps} from '@primer/react'
2+
import React, {type PropsWithChildren} from 'react'
3+
import type {SxProp} from '../sx'
4+
5+
export type RadioGroupProps = PropsWithChildren<PrimerRadioGroupProps> & SxProp
6+
7+
const RadioGroupImpl = (props: RadioGroupProps) => {
8+
return <Box as={PrimerRadioGroup} {...props} />
9+
}
10+
11+
// Define local types based on the internal component props
12+
type CheckboxOrRadioGroupLabelProps = PropsWithChildren<
13+
{
14+
className?: string
15+
visuallyHidden?: boolean
16+
} & SxProp
17+
>
18+
const CheckboxOrRadioGroupLabel = (props: CheckboxOrRadioGroupLabelProps) => {
19+
return <Box as={PrimerRadioGroup.Label} {...props} />
20+
}
21+
22+
type CheckboxOrRadioGroupCaptionProps = PropsWithChildren<
23+
{
24+
className?: string
25+
} & SxProp
26+
>
27+
const CheckboxOrRadioGroupCaption = (props: CheckboxOrRadioGroupCaptionProps) => {
28+
return <Box as={PrimerRadioGroup.Caption} {...props} />
29+
}
30+
31+
type CheckboxOrRadioGroupValidationProps = PropsWithChildren<
32+
{
33+
className?: string
34+
variant: 'error' | 'success'
35+
} & SxProp
36+
>
37+
const CheckboxOrRadioGroupValidation = (props: CheckboxOrRadioGroupValidationProps) => {
38+
return <Box as={PrimerRadioGroup.Validation} {...props} />
39+
}
40+
41+
export const RadioGroup = Object.assign(RadioGroupImpl, {
42+
Label: CheckboxOrRadioGroupLabel,
43+
Caption: CheckboxOrRadioGroupCaption,
44+
Validation: CheckboxOrRadioGroupValidation,
45+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Box, RelativeTime as PrimerRelativeTime, type RelativeTimeProps as PrimerRelativeTimeProps} from '@primer/react'
2+
import React from 'react'
3+
import type {SxProp} from '../sx'
4+
5+
export type RelativeTimeProps = PrimerRelativeTimeProps & SxProp
6+
7+
export function RelativeTime(props: RelativeTimeProps) {
8+
// @ts-expect-error the types for Box are not correctly inferred here
9+
return <Box as={PrimerRelativeTime} {...props} />
10+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
type SegmentedControlProps as PrimerSegmentedControlProps,
3+
SegmentedControl as PrimerSegmentedControl,
4+
type SegmentedControlButtonProps as PrimerSegmentedControlButtonProps,
5+
type SegmentedControlIconButtonProps as PrimerSegmentedControlIconButtonProps,
6+
} from '@primer/react'
7+
import type {PropsWithChildren} from 'react'
8+
import type {SxProp} from '../sx'
9+
import {Box} from './Box'
10+
11+
type SegmentedControlProps = PropsWithChildren<PrimerSegmentedControlProps> & SxProp
12+
type SegmentedControlButtonProps = PropsWithChildren<PrimerSegmentedControlButtonProps> & SxProp
13+
type SegmentedControlIconButtonProps = PropsWithChildren<PrimerSegmentedControlIconButtonProps> & SxProp
14+
15+
const SegmentedControlButton = (props: SegmentedControlButtonProps) => {
16+
return <Box as={PrimerSegmentedControl.Button} {...props} />
17+
}
18+
19+
const SegmentedControlIconButton = (props: SegmentedControlIconButtonProps) => {
20+
return <Box as={PrimerSegmentedControl.IconButton} {...props} />
21+
}
22+
23+
const SegmentedControlImpl = (props: SegmentedControlProps) => {
24+
return <Box as={PrimerSegmentedControl} {...props} />
25+
}
26+
27+
const SegmentedControl = Object.assign(SegmentedControlImpl, {
28+
Button: SegmentedControlButton,
29+
IconButton: SegmentedControlIconButton,
30+
})
31+
32+
export {
33+
SegmentedControl,
34+
type SegmentedControlProps,
35+
type SegmentedControlButtonProps,
36+
type SegmentedControlIconButtonProps,
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Box, Spinner as PrimerSpinner, type SpinnerProps as PrimerSpinnerProps} from '@primer/react'
2+
import React from 'react'
3+
import type {SxProp} from '../sx'
4+
5+
export type SpinnerProps = PrimerSpinnerProps & SxProp
6+
7+
export function Spinner(props: SpinnerProps) {
8+
return <Box as={PrimerSpinner} {...props} />
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {StateLabel as PrimerStateLabel, type StateLabelProps as PrimerStateLabelProps} from '@primer/react'
2+
import {forwardRef} from 'react'
3+
import {Box} from './Box'
4+
import type {SxProp} from '../sx'
5+
6+
type StateLabelProps = PrimerStateLabelProps & SxProp
7+
8+
const StateLabel = forwardRef<HTMLSpanElement, StateLabelProps>(function StateLabel(props, ref) {
9+
return <Box as={PrimerStateLabel} ref={ref} {...props} />
10+
})
11+
12+
export {StateLabel, type StateLabelProps}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {StateLabel as PrimerStateLabel, type StateLabelProps as PrimerStateLabelProps} from '@primer/react'
2+
import {Box} from './Box'
3+
import {forwardRef} from 'react'
4+
import {type SxProp} from '../sx'
5+
6+
export type StateLabelProps = PrimerStateLabelProps & SxProp
7+
8+
export const StateLabel = forwardRef<HTMLSpanElement, StateLabelProps>(function StateLabel(props, ref) {
9+
return <Box as={PrimerStateLabel} ref={ref} {...props} />
10+
})

0 commit comments

Comments
 (0)