|
|
|
import * as React from 'react';
|
|
|
|
import RcDrawer from 'rc-drawer';
|
|
|
|
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
|
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import omit from 'omit.js';
|
|
|
|
|
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
|
|
|
import { withConfigConsumer, ConfigConsumer } from '../config-provider/context';
|
|
|
|
import { tuple } from '../_util/type';
|
|
|
|
|
|
|
|
const DrawerContext = React.createContext<Drawer | null>(null);
|
|
|
|
|
|
|
|
type EventType =
|
|
|
|
| React.KeyboardEvent<HTMLDivElement>
|
|
|
|
| React.MouseEvent<HTMLDivElement | HTMLButtonElement>;
|
|
|
|
|
|
|
|
type getContainerFunc = () => HTMLElement;
|
|
|
|
|
|
|
|
const PlacementTypes = tuple('top', 'right', 'bottom', 'left');
|
|
|
|
type placementType = typeof PlacementTypes[number];
|
|
|
|
export interface DrawerProps {
|
|
|
|
closable?: boolean;
|
|
|
|
closeIcon?: React.ReactNode;
|
|
|
|
destroyOnClose?: boolean;
|
|
|
|
forceRender?: boolean;
|
|
|
|
getContainer?: string | HTMLElement | getContainerFunc | false;
|
|
|
|
maskClosable?: boolean;
|
|
|
|
mask?: boolean;
|
|
|
|
maskStyle?: React.CSSProperties;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
/** wrapper dom node style of header and body */
|
|
|
|
drawerStyle?: React.CSSProperties;
|
|
|
|
headerStyle?: React.CSSProperties;
|
|
|
|
bodyStyle?: React.CSSProperties;
|
|
|
|
title?: React.ReactNode;
|
|
|
|
visible?: boolean;
|
|
|
|
width?: number | string;
|
|
|
|
height?: number | string;
|
|
|
|
zIndex?: number;
|
|
|
|
prefixCls?: string;
|
|
|
|
push?: boolean;
|
|
|
|
placement?: placementType;
|
|
|
|
onClose?: (e: EventType) => void;
|
|
|
|
afterVisibleChange?: (visible: boolean) => void;
|
|
|
|
className?: string;
|
|
|
|
handler?: React.ReactNode;
|
|
|
|
keyboard?: boolean;
|
|
|
|
footer?: React.ReactNode;
|
|
|
|
footerStyle?: React.CSSProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IDrawerState {
|
|
|
|
push?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerState> {
|
|
|
|
static defaultProps = {
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
|
|
|
closable: true,
|
|
|
|
placement: 'right' as placementType,
|
|
|
|
maskClosable: true,
|
|
|
|
mask: true,
|
|
|
|
level: null,
|
|
|
|
keyboard: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
readonly state = {
|
|
|
|
push: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
parentDrawer: Drawer | null;
|
|
|
|
|
|
|
|
destroyClose: boolean;
|
|
|
|
|
|