Skip to content
Closed
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
646 changes: 0 additions & 646 deletions packages/react/src/__tests__/ThemeProvider.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ exports[`@primer/react > should not update exports without a semver change 1`] =
"type BaseStylesProps",
"type BetterCssProperties",
"type BetterSystemStyleObject",
"Box",
"type BoxProps",
"BranchName",
"type BranchNameProps",
"Breadcrumb",
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export {default as ThemeProvider, useTheme, useColorSchemeVar} from './ThemeProv
export type {ThemeProviderProps} from './ThemeProvider'

// Layout
export {default as Box} from './Box'
export type {BoxProps} from './Box'
export * from './Button'
export {PageLayout} from './PageLayout'
export type {
Expand Down
1 change: 0 additions & 1 deletion packages/styled-react/src/components/Box.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {render, screen} from '@testing-library/react'
import {describe, expect, it} from 'vitest'
import Box from '../Box'
import theme from '../theme'
import React, {theme} from '@primer/react'

const breakpoints = [
null,
Expand All @@ -13,11 +13,11 @@
describe('Box', () => {
it('should support `className` on the outermost element', () => {
const Element = () => <Box className={'test-class-name'} />
expect(render(<Element />).container.firstChild).toHaveClass('test-class-name')

Check failure on line 16 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support `className` on the outermost element

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:16:19
})

it('should support margin', () => {
render(<Box data-testid="box" m={1} theme={theme} />)

Check failure on line 20 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support margin

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:20:12
const box = screen.getByTestId('box')
expect(getCSSRuleForClass(getClassName(box.className)).style.margin).toBe(theme.space[1])
})
Expand All @@ -25,7 +25,7 @@
it('should support responsive margin', () => {
const m = [0, 1, 2, 3]

render(<Box data-testid="box" m={[0, 1, 2, 3]} theme={theme} />)

Check failure on line 28 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support responsive margin

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:28:12

const box = screen.getByTestId('box')
const className = getClassName(box.className)
Expand All @@ -47,7 +47,7 @@
})

it('should support padding', () => {
render(<Box data-testid="box" p={1} theme={theme} />)

Check failure on line 50 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support padding

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:50:12
const box = screen.getByTestId('box')
expect(getCSSRuleForClass(getClassName(box.className)).style.padding).toBe(theme.space[1])
})
Expand All @@ -55,7 +55,7 @@
it('should support responsive padding', () => {
const p = [0, 1, 2, 3]

render(<Box data-testid="box" p={[0, 1, 2, 3]} theme={theme} />)

Check failure on line 58 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support responsive padding

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:58:12

const box = screen.getByTestId('box')
const className = getClassName(box.className)
Expand All @@ -77,14 +77,14 @@
})

it('should support display', () => {
render(<Box data-testid="box" display="inline" theme={theme} />)

Check failure on line 80 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support display

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:80:12
const box = screen.getByTestId('box')
expect(getCSSRuleForClass(getClassName(box.className)).style.display).toBe('inline')
})

it('should support responsive display', () => {
const display = ['none', 'inline', 'inline-block', 'block']
render(<Box data-testid="box" display={display} theme={theme} />)

Check failure on line 87 in packages/styled-react/src/components/Box/Box.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/components/Box/Box.test.tsx > Box > should support responsive display

TypeError: Cannot read properties of undefined (reading 'createElement') ❯ src/components/Box/Box.test.tsx:87:12
const box = screen.getByTestId('box')
const className = getClassName(box.className)
for (let i = 0; i < display.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import type {
TypographyProps,
} from 'styled-system'
import {background, border, color, flexbox, grid, layout, position, shadow, space, typography} from 'styled-system'
import type {SxProp} from '../sx'
import sx from '../sx'
import type {ComponentProps} from '../utils/types'
import {sx, type SxProp} from '../../sx'
import type {ComponentProps} from '../../utils/ComponentProps'

type StyledBoxProps = SxProp &
SpaceProps &
Expand Down Expand Up @@ -53,4 +52,5 @@ const Box = styled.div<StyledBoxProps>(
* @see https://github.com/primer/react/blob/main/contributor-docs/migration-from-box.md
*/
export type BoxProps = ComponentProps<typeof Box>
export {Box}
export default Box
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default} from './Box'
export {default, Box} from './Box'
export type {BoxProps} from './Box'
7 changes: 2 additions & 5 deletions packages/styled-react/src/components/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
Box,
CheckboxGroup as PrimerCheckboxGroup,
type CheckboxGroupProps as PrimerCheckboxGroupProps,
} from '@primer/react'
import {CheckboxGroup as PrimerCheckboxGroup, type CheckboxGroupProps as PrimerCheckboxGroupProps} from '@primer/react'
import React, {type PropsWithChildren} from 'react'
import type {SxProp} from '../sx'
import {Box} from '../components/Box'

export type CheckboxGroupProps = PropsWithChildren<PrimerCheckboxGroupProps> & SxProp

Expand Down
3 changes: 2 additions & 1 deletion packages/styled-react/src/components/NavList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NavList as PrimerNavList, Box} from '@primer/react'
import {NavList as PrimerNavList} from '@primer/react'
import type {
NavListProps as PrimerNavListProps,
NavListItemProps as PrimerNavListItemProps,
Expand All @@ -8,6 +8,7 @@ import type {
} from '@primer/react'
import {forwardRef, type PropsWithChildren} from 'react'
import {type SxProp} from '../sx'
import Box from './Box'

type RefComponent<E extends HTMLElement, P> = React.ForwardRefExoticComponent<P & React.RefAttributes<E>>

Expand Down
3 changes: 2 additions & 1 deletion packages/styled-react/src/components/RadioGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Box, RadioGroup as PrimerRadioGroup, type RadioGroupProps as PrimerRadioGroupProps} from '@primer/react'
import {RadioGroup as PrimerRadioGroup, type RadioGroupProps as PrimerRadioGroupProps} from '@primer/react'
import React, {type PropsWithChildren} from 'react'
import type {SxProp} from '../sx'
import Box from './Box'

export type RadioGroupProps = PropsWithChildren<PrimerRadioGroupProps> & SxProp

Expand Down
3 changes: 2 additions & 1 deletion packages/styled-react/src/components/RelativeTime.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Box, RelativeTime as PrimerRelativeTime, type RelativeTimeProps as PrimerRelativeTimeProps} from '@primer/react'
import {RelativeTime as PrimerRelativeTime, type RelativeTimeProps as PrimerRelativeTimeProps} from '@primer/react'
import React from 'react'
import type {SxProp} from '../sx'
import Box from './Box'

export type RelativeTimeProps = PrimerRelativeTimeProps & SxProp

Expand Down
9 changes: 9 additions & 0 deletions packages/styled-react/src/utils/ComponentProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Extract a component's props
*
* Source: https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase#wrappingmirroring-a-component
*
* @example ComponentProps<typeof MyComponent>
*/
export type ComponentProps<T> =
T extends React.ComponentType<React.PropsWithChildren<infer Props>> ? (Props extends object ? Props : never) : never
Loading