Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export JSX namespace from automatic runtime entries #2078

Merged
merged 1 commit into from
Nov 9, 2020
Merged
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
1 change: 1 addition & 0 deletions packages/react/jsx-dev-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./dist/react.cjs.js": "./dist/react.browser.cjs.js",
"./dist/react.esm.js": "./dist/react.browser.esm.js"
},
"types": "../types/jsx-dev-runtime",
"preconstruct": {
"source": "../src/jsx-dev-runtime",
"umdName": "emotionReactJSXDevRuntime"
Expand Down
1 change: 1 addition & 0 deletions packages/react/jsx-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./dist/react.cjs.js": "./dist/react.browser.cjs.js",
"./dist/react.esm.js": "./dist/react.browser.esm.js"
},
"types": "../types/jsx-runtime",
"preconstruct": {
"source": "../src/jsx-runtime",
"umdName": "emotionReactJSXRuntime"
Expand Down
43 changes: 12 additions & 31 deletions packages/react/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '@emotion/serialize'
import {
ClassAttributes,
ComponentClass,
Context,
Provider,
FC,
Expand All @@ -23,6 +22,7 @@ import {
Ref,
createElement
} from 'react'
import { EmotionJSX } from './jsx-namespace'

export {
ArrayInterpolation,
Expand Down Expand Up @@ -92,41 +92,22 @@ export interface ClassNamesProps {
*/
export function ClassNames(props: ClassNamesProps): ReactElement

type WithConditionalCSSProp<P> = 'className' extends keyof P
? (P extends { className?: string } ? P & { css?: Interpolation<Theme> } : P)
: P

// unpack all here to avoid infinite self-referencing when defining our own JSX namespace
type ReactJSXElement = JSX.Element
type ReactJSXElementClass = JSX.ElementClass
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
type ReactJSXIntrinsicElements = JSX.IntrinsicElements

export const jsx: typeof createElement
export namespace jsx {
namespace JSX {
interface Element extends ReactJSXElement {}
interface ElementClass extends ReactJSXElementClass {}
interface Element extends EmotionJSX.Element {}
interface ElementClass extends EmotionJSX.ElementClass {}
interface ElementAttributesProperty
extends ReactJSXElementAttributesProperty {}
extends EmotionJSX.ElementAttributesProperty {}
interface ElementChildrenAttribute
extends ReactJSXElementChildrenAttribute {}

type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
ReactJSXLibraryManagedAttributes<C, P>

interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
extends EmotionJSX.ElementChildrenAttribute {}
type LibraryManagedAttributes<C, P> = EmotionJSX.LibraryManagedAttributes<
C,
P
>
interface IntrinsicAttributes extends EmotionJSX.IntrinsicAttributes {}
interface IntrinsicClassAttributes<T>
extends ReactJSXIntrinsicClassAttributes<T> {}

type IntrinsicElements = {
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
css?: Interpolation<Theme>
}
}
extends EmotionJSX.IntrinsicClassAttributes<T> {}
type IntrinsicElements = EmotionJSX.IntrinsicElements
}
}
1 change: 1 addition & 0 deletions packages/react/types/jsx-dev-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmotionJSX as JSX } from './jsx-namespace'
38 changes: 38 additions & 0 deletions packages/react/types/jsx-namespace.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'react'
import { Interpolation } from '@emotion/serialize'
import { Theme } from './index'

type WithConditionalCSSProp<P> = 'className' extends keyof P
? (P extends { className?: string } ? P & { css?: Interpolation<Theme> } : P)
: P

// unpack all here to avoid infinite self-referencing when defining our own JSX namespace
type ReactJSXElement = JSX.Element
type ReactJSXElementClass = JSX.ElementClass
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
type ReactJSXIntrinsicElements = JSX.IntrinsicElements

export namespace EmotionJSX {
interface Element extends ReactJSXElement {}
interface ElementClass extends ReactJSXElementClass {}
interface ElementAttributesProperty
extends ReactJSXElementAttributesProperty {}
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}

type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
ReactJSXLibraryManagedAttributes<C, P>

interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
interface IntrinsicClassAttributes<T>
extends ReactJSXIntrinsicClassAttributes<T> {}

type IntrinsicElements = {
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
css?: Interpolation<Theme>
}
}
}
1 change: 1 addition & 0 deletions packages/react/types/jsx-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmotionJSX as JSX } from './jsx-namespace'