Skip to content

Commit c54264c

Browse files
committed
fix jsx runtime
1 parent 2dec174 commit c54264c

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/types.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ComponentProps, ElementType } from "react";
2+
13
export type Prettify<T> = {
24
[K in keyof T]: T[K];
35
} & {};
@@ -33,9 +35,9 @@ export type PropsWithSlots<
3335
? {}
3436
: {
3537
slots?: {
36-
[K in ArgSlots[number]]?: React.ElementType;
38+
[K in ArgSlots[number]]?: ElementType;
3739
};
3840
slotProps?: {
39-
[K in ArgSlots[number]]?: React.ComponentProps<React.ElementType>;
41+
[K in ArgSlots[number]]?: ComponentProps<ElementType>;
4042
};
4143
});

src/use-slot.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import { useMemo } from "react";
1+
import React, {
2+
type ComponentProps,
3+
type ElementType,
4+
type FC,
5+
type PropsWithChildren,
6+
} from "react";
27
import type { Prettify } from "./types";
38

49
// eslint-disable-next-line react-refresh/only-export-components
5-
const SlotFragment: React.FC<React.PropsWithChildren<{ [x: string]: any }>> = ({
10+
const SlotFragment: FC<PropsWithChildren<{ [x: string]: any }>> = ({
611
children,
712
}) => {
813
// eslint-disable-next-line react/jsx-no-useless-fragment
914
return <>{children}</>;
1015
};
1116
SlotFragment.displayName = "@zemd/react-slottable/SlotFragment";
1217

13-
type SlotOptions<T extends React.ElementType> = {
18+
type SlotOptions<T extends ElementType> = {
1419
slot?: T;
1520
};
1621

17-
type SlotsProps<T extends Record<string, React.ElementType>> = {
22+
type SlotsProps<T extends Record<string, ElementType>> = {
1823
slots?: T;
1924
};
2025

@@ -26,12 +31,12 @@ type SlotPropsProps<T extends Record<string, any>> = {
2631
* A hook that returns a component for a given slot.
2732
*/
2833
export function useSlot<
29-
ArgSlotType extends React.ElementType,
34+
ArgSlotType extends ElementType,
3035
ArgSlotOptions extends SlotOptions<ArgSlotType>,
3136
ReturnComponent extends ArgSlotOptions extends SlotOptions<infer T>
3237
? T
33-
: React.ElementType,
34-
ArgSlotsKeys extends Record<string, React.ElementType>,
38+
: ElementType,
39+
ArgSlotsKeys extends Record<string, ElementType>,
3540
>(
3641
name: keyof ArgSlotsKeys,
3742
props: Prettify<
@@ -41,15 +46,15 @@ export function useSlot<
4146
): ReturnComponent {
4247
const { slots, slotProps } = props;
4348

44-
const Slot = useMemo(() => {
49+
const Slot = React.useMemo(() => {
4550
return (slots?.[name] ?? options.slot ?? SlotFragment) as ReturnComponent;
4651
}, [name, slots, options.slot]);
4752

48-
return useMemo<ReturnComponent>(() => {
49-
const WrappedComponent: React.FC<React.ComponentProps<ReturnComponent>> = (
53+
return React.useMemo<ReturnComponent>(() => {
54+
const WrappedComponent: FC<ComponentProps<ReturnComponent>> = (
5055
wrappedProps,
5156
) => {
52-
const mergedProps: React.ComponentProps<ReturnComponent> = {
57+
const mergedProps: ComponentProps<ReturnComponent> = {
5358
...slotProps?.[name],
5459
...wrappedProps,
5560
};

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"extends": "@zemd/tsconfig/tsconfig-react.json",
44
"compilerOptions": {
5-
"noPropertyAccessFromIndexSignature": false
5+
"noPropertyAccessFromIndexSignature": false,
6+
"jsx": "preserve"
67
},
78
"include": ["**/*.ts", "**/*.tsx"],
89
"exclude": ["node_modules"]

tsup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export default defineConfig({
77
clean: true,
88
dts: true,
99
format: ["cjs", "esm"],
10+
external: ["react"],
1011
});

0 commit comments

Comments
 (0)