Skip to content
Merged
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
24 changes: 13 additions & 11 deletions src/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum DrawerType {
Normal = 'normal',
}

interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
interface BaseDrawerProps extends Omit<AntdDrawerProps, 'placement' | 'children'> {
size?: 'small' | 'default' | 'large';
loading?: boolean;
bodyClassName?: string;
Expand All @@ -33,35 +33,35 @@ interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
type?: DrawerType;
}

interface TabsDrawerProps<T extends readOnlyTab> extends Omit<NormalDrawerProps, 'children'> {
export interface DrawerProps<T extends readOnlyTab = any> extends BaseDrawerProps {
tabs?: T;
defaultKey?: TabKey<T>;
activeKey?: TabKey<T>;
children?: (key: TabKey<T>) => React.ReactNode;
children?: React.ReactNode | ((key: TabKey<T>) => React.ReactNode);
onChange?: (key: TabKey<T>) => void;
}

function isFunction<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
function isFunction<T extends readOnlyTab>(
props: DrawerProps<T>
): props is DrawerProps<T> & { children: (key: string) => React.ReactNode } {
return typeof props.children === 'function';
}

function isTabMode<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
function isTabMode<T extends readOnlyTab>(props: DrawerProps<T>): props is DrawerProps<T> {
return 'tabs' in props;
}

function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is TabsDrawerProps<T> {
function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is DrawerProps<T> {
return 'activeKey' in props;
}

export type DrawerProps<T extends readOnlyTab> = TabsDrawerProps<T> | NormalDrawerProps;

const getWidthFromSize = (size: NormalDrawerProps['size']) => {
const getWidthFromSize = (size: DrawerProps['size']) => {
if (size === 'small') return 720;
if (size === 'large') return 1256;
return 1000;
};

const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProps['message'] => {
const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['message'] => {
if (typeof banner === 'object') return React.isValidElement(banner);
return true;
};
Expand Down Expand Up @@ -163,7 +163,9 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
className={classNames(`${slidePrefixCls}-body`, bodyClassName)}
style={bodyStyle}
>
{isFunction(props) ? props.children?.(currentKey ?? '') : props.children}
{isFunction(props)
? props.children?.(currentKey ?? '')
: (props.children as React.ReactNode)}
</div>
{footer ? (
<div className={classNames(`${slidePrefixCls}-footer`)}>{footer}</div>
Expand Down
Loading