Skip to content

Commit 4432c49

Browse files
authored
fix(drawer): update Drawer ts type (#555)
1 parent c821f52 commit 4432c49

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/drawer/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export enum DrawerType {
2222
Normal = 'normal',
2323
}
2424

25-
interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
25+
interface BaseDrawerProps extends Omit<AntdDrawerProps, 'placement' | 'children'> {
2626
size?: 'small' | 'default' | 'large';
2727
loading?: boolean;
2828
bodyClassName?: string;
@@ -33,35 +33,35 @@ interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
3333
type?: DrawerType;
3434
}
3535

36-
interface TabsDrawerProps<T extends readOnlyTab> extends Omit<NormalDrawerProps, 'children'> {
36+
export interface DrawerProps<T extends readOnlyTab = any> extends BaseDrawerProps {
3737
tabs?: T;
3838
defaultKey?: TabKey<T>;
3939
activeKey?: TabKey<T>;
40-
children?: (key: TabKey<T>) => React.ReactNode;
40+
children?: React.ReactNode | ((key: TabKey<T>) => React.ReactNode);
4141
onChange?: (key: TabKey<T>) => void;
4242
}
4343

44-
function isFunction<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
44+
function isFunction<T extends readOnlyTab>(
45+
props: DrawerProps<T>
46+
): props is DrawerProps<T> & { children: (key: string) => React.ReactNode } {
4547
return typeof props.children === 'function';
4648
}
4749

48-
function isTabMode<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
50+
function isTabMode<T extends readOnlyTab>(props: DrawerProps<T>): props is DrawerProps<T> {
4951
return 'tabs' in props;
5052
}
5153

52-
function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
54+
function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is DrawerProps<T> {
5355
return 'activeKey' in props;
5456
}
5557

56-
export type DrawerProps<T extends readOnlyTab> = TabsDrawerProps<T> | NormalDrawerProps;
57-
58-
const getWidthFromSize = (size: NormalDrawerProps['size']) => {
58+
const getWidthFromSize = (size: DrawerProps['size']) => {
5959
if (size === 'small') return 720;
6060
if (size === 'large') return 1256;
6161
return 1000;
6262
};
6363

64-
const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProps['message'] => {
64+
const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['message'] => {
6565
if (typeof banner === 'object') return React.isValidElement(banner);
6666
return true;
6767
};
@@ -163,7 +163,9 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
163163
className={classNames(`${slidePrefixCls}-body`, bodyClassName)}
164164
style={bodyStyle}
165165
>
166-
{isFunction(props) ? props.children?.(currentKey ?? '') : props.children}
166+
{isFunction(props)
167+
? props.children?.(currentKey ?? '')
168+
: (props.children as React.ReactNode)}
167169
</div>
168170
{footer ? (
169171
<div className={classNames(`${slidePrefixCls}-footer`)}>{footer}</div>

0 commit comments

Comments
 (0)