Skip to content

Commit 5b28350

Browse files
committed
refactor(react): component props type
1 parent ff9afbc commit 5b28350

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
2-
"@pandacss/generator": patch
2+
'@pandacss/generator': patch
33
---
44

5-
Fix type issue where `withRootProvider` from style context incorrectly allowed JSX style props to be passed through to the root component. The root provider now correctly accepts only component props, unstyled prop, and recipe variant props, excluding JSX style props.
5+
- **Style Context**: Fix type issue where `withRootProvider` from style context incorrectly allowed JSX style props to
6+
be passed through to the root component.
7+
8+
- **React**: Fix issue where combining wrapping a style context component with `styled` caused `ref` to be incorrectly
9+
typed

packages/generator/src/artifacts/react-jsx/create-style-context.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ export function generateReactCreateStyleContext(ctx: Context) {
113113
dts: outdent`
114114
${ctx.file.importType('SlotRecipeRuntimeFn, RecipeVariantProps', '../types/recipe')}
115115
${ctx.file.importType('JsxHTMLProps, JsxStyleProps, Assign', '../types/system-types')}
116-
${ctx.file.importType('JsxFactoryOptions', '../types/jsx')}
117-
import type { ComponentType, ElementType, ComponentPropsWithoutRef, ElementRef, Ref } from 'react'
116+
${ctx.file.importType('JsxFactoryOptions, ComponentProps', '../types/jsx')}
117+
import type { ComponentType, ElementType } from 'react'
118118
119119
interface UnstyledProps {
120120
unstyled?: boolean | undefined
@@ -130,10 +130,6 @@ export function generateReactCreateStyleContext(ctx: Context) {
130130
131131
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
132132
133-
type ComponentProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'ref'> & {
134-
ref?: Ref<ElementRef<T>> | undefined
135-
}
136-
137133
interface WithProviderOptions<P = {}> {
138134
defaultProps?: Partial<P> | undefined
139135
}

packages/generator/src/artifacts/react-jsx/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ${ctx.file.importType(upperName, '../types/jsx')}
1010
export declare const ${factoryName}: ${upperName}
1111
`,
1212
jsxType: outdent`
13-
import type { ComponentPropsWithoutRef, ElementType, ElementRef, JSX, Ref } from 'react'
13+
import type { ElementType, JSX, ComponentPropsWithRef, ComponentType, Component } from 'react'
1414
${ctx.file.importType('RecipeDefinition, RecipeSelection, RecipeVariantRecord', './recipe')}
1515
${ctx.file.importType(
1616
'Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty',
@@ -35,9 +35,9 @@ export interface AsProps {
3535
as?: ElementType | undefined
3636
}
3737
38-
export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
39-
ref?: Ref<ElementRef<T>>
40-
}
38+
export type ComponentProps<T extends ElementType> = T extends ComponentType<infer P> | Component<infer P>
39+
? JSX.LibraryManagedAttributes<T, P>
40+
: ComponentPropsWithRef<T>
4141
4242
export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
4343
(props: JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<JsxStyleProps, P>>): JSX.Element

packages/studio/styled-system/jsx/create-style-context.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable */
22
import type { SlotRecipeRuntimeFn, RecipeVariantProps } from '../types/recipe';
33
import type { JsxHTMLProps, JsxStyleProps, Assign } from '../types/system-types';
4-
import type { JsxFactoryOptions } from '../types/jsx';
5-
import type { ComponentType, ElementType, ComponentPropsWithoutRef, ElementRef, Ref } from 'react'
4+
import type { JsxFactoryOptions, ComponentProps } from '../types/jsx';
5+
import type { ComponentType, ElementType } from 'react'
66

77
interface UnstyledProps {
88
unstyled?: boolean | undefined
@@ -18,10 +18,6 @@ type SlotRecipe = SvaFn | SlotRecipeFn
1818

1919
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
2020

21-
type ComponentProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'ref'> & {
22-
ref?: Ref<ElementRef<T>> | undefined
23-
}
24-
2521
interface WithProviderOptions<P = {}> {
2622
defaultProps?: Partial<P> | undefined
2723
}

packages/studio/styled-system/types/jsx.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import type { ComponentPropsWithoutRef, ElementType, ElementRef, JSX, Ref } from 'react'
2+
import type { ElementType, JSX, ComponentPropsWithRef, ComponentType, Component } from 'react'
33
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe';
44
import type { Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty } from './system-types';
55

@@ -21,9 +21,9 @@ export interface AsProps {
2121
as?: ElementType | undefined
2222
}
2323

24-
export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
25-
ref?: Ref<ElementRef<T>>
26-
}
24+
export type ComponentProps<T extends ElementType> = T extends ComponentType<infer P> | Component<infer P>
25+
? JSX.LibraryManagedAttributes<T, P>
26+
: ComponentPropsWithRef<T>
2727

2828
export interface PandaComponent<T extends ElementType, P extends Dict = {}> {
2929
(props: JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<JsxStyleProps, P>>): JSX.Element
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
import { useRef } from 'react'
2+
import { styled } from '../../styled-system/jsx'
13
import { stack } from '../../styled-system/patterns'
24
import * as Custom from '../components/custom'
35

6+
const Root = styled(Custom.Root, {
7+
base: {
8+
color: 'pink',
9+
},
10+
})
11+
412
export default function Home() {
13+
const ref = useRef<HTMLDivElement | null>(null)
514
return (
615
<div className={stack({ fontSize: '2xl', fontWeight: 'bold', padding: '4' })}>
7-
<Custom.Root>
16+
<Root ref={ref}>
817
<Custom.Label>Hello</Custom.Label>
9-
</Custom.Root>
18+
</Root>
1019
</div>
1120
)
1221
}

0 commit comments

Comments
 (0)