Skip to content

Commit

Permalink
feat: delete drawer wrap (#34673)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiyu4585 committed Mar 23, 2022
1 parent 99056a7 commit 087b65c
Showing 1 changed file with 16 additions and 42 deletions.
58 changes: 16 additions & 42 deletions components/drawer/index.tsx
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import RcDrawer from 'rc-drawer';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import { ConfigContext, DirectionType } from '../config-provider';
import { ConfigContext } from '../config-provider';
import { tuple } from '../_util/type';
import useForceUpdate from '../_util/hooks/useForceUpdate';

Expand Down Expand Up @@ -64,22 +64,13 @@ export interface DrawerProps {
footer?: React.ReactNode;
footerStyle?: React.CSSProperties;
level?: string | string[] | null | undefined;
levelMove?:
| ILevelMove
| ((e: { target: HTMLElement; open: boolean }) => ILevelMove);
}

export interface IDrawerState {
push?: boolean;
}

interface InternalDrawerProps extends DrawerProps {
direction: DirectionType;
levelMove?: ILevelMove | ((e: { target: HTMLElement; open: boolean }) => ILevelMove);
children?: React.ReactNode;
}

const defaultPushState: PushState = { distance: 180 };

const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(
const Drawer = React.forwardRef<DrawerRef, DrawerProps>(
(
{
width,
Expand All @@ -95,9 +86,7 @@ const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(
closeIcon = <CloseOutlined />,
bodyStyle,
drawerStyle,
prefixCls,
className,
direction,
visible,
children,
zIndex,
Expand All @@ -108,6 +97,8 @@ const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(
onClose,
footer,
footerStyle,
prefixCls: customizePrefixCls,
getContainer: customizeGetContainer,
extra,
...rest
},
Expand All @@ -118,6 +109,14 @@ const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(
const parentDrawer = React.useContext(DrawerContext);
const destroyClose = React.useRef<boolean>(false);

const { getPopupContainer, getPrefixCls, direction } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
const getContainer =
// 有可能为 false,所以不能直接判断
customizeGetContainer === undefined && getPopupContainer
? () => getPopupContainer(document.body)
: customizeGetContainer;

React.useEffect(() => {
// fix: delete drawer in child and re-render, no push started.
// <Drawer>{show && <Drawer />}</Drawer>
Expand Down Expand Up @@ -320,6 +319,7 @@ const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(
showMask={mask}
style={getRcDrawerStyle()}
className={drawerClassName}
getContainer={getContainer}
>
{renderBody()}
</RcDrawer>
Expand All @@ -330,30 +330,4 @@ const Drawer = React.forwardRef<DrawerRef, InternalDrawerProps>(

Drawer.displayName = 'Drawer';

const DrawerWrapper: React.FC<DrawerProps> = React.forwardRef<DrawerRef, DrawerProps>(
(props, ref) => {
const { prefixCls: customizePrefixCls, getContainer: customizeGetContainer } = props;
const { getPopupContainer, getPrefixCls, direction } = React.useContext(ConfigContext);

const prefixCls = getPrefixCls('drawer', customizePrefixCls);
const getContainer =
// 有可能为 false,所以不能直接判断
customizeGetContainer === undefined && getPopupContainer
? () => getPopupContainer(document.body)
: customizeGetContainer;

return (
<Drawer
{...props}
ref={ref}
prefixCls={prefixCls}
getContainer={getContainer}
direction={direction}
/>
);
},
);

DrawerWrapper.displayName = 'DrawerWrapper';

export default DrawerWrapper;
export default Drawer;

0 comments on commit 087b65c

Please sign in to comment.