Skip to content

Commit

Permalink
type: modify Default type issue. #50
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 23, 2024
1 parent 6dd9df9 commit 396c946
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 4 additions & 5 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ export declare const If: FC<PropsWithChildren<IfProps>>;
## `<Switch />` `<Case />` `<Default />` Props

```tsx
import { type FC, type PropsWithChildren } from 'react';
export declare const Switch: FC<PropsWithChildren<{}>>;

import type { FC, PropsWithChildren } from 'react';
export const Switch: FC<PropsWithChildren<{}>>;
type TagType = React.ElementType | keyof JSX.IntrinsicElements;
interface CaseElementProps<T extends TagType> {
as?: T;
readonly condition?: boolean;
}
export type CaseProps<T extends TagType> = CaseElementProps<T> & React.ComponentPropsWithoutRef<T>;
export declare const Case: <T extends TagType>(props: CaseProps<T>) => null;
export declare const Default: <T extends TagType>(props: CaseProps<T>) => null;
export const Case: <T extends TagType>(props: CaseProps<T>) => any;
export const Default: <T extends TagType>(props: Omit<CaseProps<T>, 'condition'>) => import("react/jsx-runtime").JSX.Element;
```

## Development
Expand Down
6 changes: 4 additions & 2 deletions core/src/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Switch: FC<PropsWithChildren<{}>> = ({ children }) => {
}
return false;
});
return <>{matchChild ?? defaultCase ?? null}</>;
return matchChild ?? defaultCase ?? null;
};

type TagType = React.ElementType | keyof JSX.IntrinsicElements;
Expand All @@ -37,4 +37,6 @@ export const Case = <T extends TagType>(props: CaseProps<T>) => {
return Elm ? <Elm {...reset}>{children}</Elm> : children;
};

export const Default = <T extends TagType>(props: CaseProps<T>) => <Case {...props} />;
export const Default = <T extends TagType>(props: Omit<CaseProps<T>, 'condition'>) => (
<Case {...({ ...props } as CaseProps<T>)} />
);
10 changes: 6 additions & 4 deletions core/switch.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
declare module '@uiw/react-only-when/switch' {
import { FC, PropsWithChildren } from 'react';
export declare const Switch: <T extends TagType>({ children }: PropsWithChildren) => null;
import type { FC, PropsWithChildren } from 'react';
export const Switch: FC<PropsWithChildren<{}>>;
type TagType = React.ElementType | keyof JSX.IntrinsicElements;
interface CaseElementProps<T extends TagType> {
as?: T;
readonly condition?: boolean;
}
export type CaseProps<T extends TagType> = CaseElementProps<T> & React.ComponentPropsWithoutRef<T>;
export declare const Case: <T extends TagType>(props: CaseProps<T>) => any;
export declare const Default: <T extends TagType>(props: CaseProps<T>) => any;
export const Case: <T extends TagType>(props: CaseProps<T>) => any;
export const Default: <T extends TagType>(
props: Omit<CaseProps<T>, 'condition'>,
) => import('react/jsx-runtime').JSX.Element;
}

0 comments on commit 396c946

Please sign in to comment.