1
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
import * as React from 'react';
|
||||
import type { DrawerProps as RcDrawerProps } from '@rc-component/drawer';
|
||||
import type { Placement } from '@rc-component/drawer/lib/Drawer';
|
||||
import type { MaskType } from '../_util/hooks';
|
||||
import type { DrawerPanelProps } from './DrawerPanel';
|
||||
import type { FocusableConfig, OmitFocusType } from './useFocusable';
|
||||
declare const _SizeTypes: readonly ["default", "large"];
|
||||
type sizeType = (typeof _SizeTypes)[number];
|
||||
export interface PushState {
|
||||
distance: string | number;
|
||||
}
|
||||
export interface DrawerResizableConfig {
|
||||
onResize?: (size: number) => void;
|
||||
onResizeStart?: () => void;
|
||||
onResizeEnd?: () => void;
|
||||
}
|
||||
export interface DrawerProps extends Omit<RcDrawerProps, 'maskStyle' | 'destroyOnClose' | 'mask' | 'resizable' | 'classNames' | 'styles' | OmitFocusType>, Omit<DrawerPanelProps, 'prefixCls' | 'ariaId'> {
|
||||
size?: sizeType | number | string;
|
||||
resizable?: boolean | DrawerResizableConfig;
|
||||
open?: boolean;
|
||||
afterOpenChange?: (open: boolean) => void;
|
||||
/** @deprecated Please use `destroyOnHidden` instead */
|
||||
destroyOnClose?: boolean;
|
||||
/**
|
||||
* @since 5.25.0
|
||||
*/
|
||||
destroyOnHidden?: boolean;
|
||||
/** @deprecated Please use `mask.closable` instead */
|
||||
maskClosable?: boolean;
|
||||
mask?: MaskType;
|
||||
focusable?: FocusableConfig;
|
||||
}
|
||||
declare const Drawer: React.FC<DrawerProps> & {
|
||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||
};
|
||||
interface PurePanelInterface {
|
||||
prefixCls?: string;
|
||||
style?: React.CSSProperties;
|
||||
className?: string;
|
||||
placement?: Placement;
|
||||
}
|
||||
/** @private Internal Component. Do not use in your production. */
|
||||
declare const PurePanel: React.FC<Omit<DrawerPanelProps, 'prefixCls'> & PurePanelInterface>;
|
||||
export default Drawer;
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
"use client";
|
||||
|
||||
import * as React from 'react';
|
||||
import RcDrawer from '@rc-component/drawer';
|
||||
import useId from "@rc-component/util/es/hooks/useId";
|
||||
import { composeRef } from "@rc-component/util/es/ref";
|
||||
import { clsx } from 'clsx';
|
||||
import ContextIsolator from '../_util/ContextIsolator';
|
||||
import { useMergedMask, useMergeSemantic, useZIndex } from '../_util/hooks';
|
||||
import { isNumber } from '../_util/is';
|
||||
import { getTransitionName } from '../_util/motion';
|
||||
import { devUseWarning } from '../_util/warning';
|
||||
import zIndexContext from '../_util/zindexContext';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import { useComponentConfig } from '../config-provider/context';
|
||||
import { usePanelRef } from '../watermark/context';
|
||||
import DrawerPanel from './DrawerPanel';
|
||||
import useStyle from './style';
|
||||
import useFocusable from './useFocusable';
|
||||
const _SizeTypes = ['default', 'large'];
|
||||
const DEFAULT_PUSH_STATE = {
|
||||
distance: 180
|
||||
};
|
||||
const DEFAULT_SIZE = 378;
|
||||
const MOTION_CONFIG = {
|
||||
motionAppear: true,
|
||||
motionEnter: true,
|
||||
motionLeave: true,
|
||||
motionDeadline: 500
|
||||
};
|
||||
const Drawer = props => {
|
||||
const {
|
||||
rootClassName,
|
||||
size,
|
||||
defaultSize = DEFAULT_SIZE,
|
||||
height,
|
||||
width,
|
||||
mask: drawerMask,
|
||||
push = DEFAULT_PUSH_STATE,
|
||||
open,
|
||||
afterOpenChange,
|
||||
onClose,
|
||||
prefixCls: customizePrefixCls,
|
||||
getContainer: customizeGetContainer,
|
||||
panelRef = null,
|
||||
style,
|
||||
className,
|
||||
resizable,
|
||||
'aria-labelledby': ariaLabelledby,
|
||||
// Focus
|
||||
focusable,
|
||||
// Deprecated
|
||||
maskClosable,
|
||||
maskStyle,
|
||||
drawerStyle,
|
||||
contentWrapperStyle,
|
||||
destroyOnClose,
|
||||
destroyOnHidden,
|
||||
...rest
|
||||
} = props;
|
||||
const {
|
||||
placement
|
||||
} = rest;
|
||||
const id = useId();
|
||||
const ariaId = rest.title ? id : undefined;
|
||||
const {
|
||||
getPopupContainer,
|
||||
getPrefixCls,
|
||||
direction,
|
||||
className: contextClassName,
|
||||
style: contextStyle,
|
||||
classNames: contextClassNames,
|
||||
styles: contextStyles,
|
||||
mask: contextMask
|
||||
} = useComponentConfig('drawer');
|
||||
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
|
||||
const [hashId, cssVarCls] = useStyle(prefixCls);
|
||||
const getContainer =
|
||||
// 有可能为 false,所以不能直接判断
|
||||
customizeGetContainer === undefined && getPopupContainer ? () => getPopupContainer(document.body) : customizeGetContainer;
|
||||
// ============================ Size ============================
|
||||
const drawerSize = React.useMemo(() => {
|
||||
if (isNumber(size)) {
|
||||
return size;
|
||||
}
|
||||
if (size === 'large') {
|
||||
return 736;
|
||||
}
|
||||
if (size === 'default') {
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
if (typeof size === 'string') {
|
||||
if (/^\d+(\.\d+)?$/.test(size)) {
|
||||
return Number(size);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
if (!placement || placement === 'left' || placement === 'right') {
|
||||
return width;
|
||||
}
|
||||
return height;
|
||||
}, [size, placement, width, height]);
|
||||
// =========================== Motion ===========================
|
||||
const maskMotion = {
|
||||
motionName: getTransitionName(prefixCls, 'mask-motion'),
|
||||
...MOTION_CONFIG
|
||||
};
|
||||
const panelMotion = motionPlacement => ({
|
||||
motionName: getTransitionName(prefixCls, `panel-motion-${motionPlacement}`),
|
||||
...MOTION_CONFIG
|
||||
});
|
||||
// ============================ Refs ============================
|
||||
// Select `ant-drawer-content` by `panelRef`
|
||||
const innerPanelRef = usePanelRef();
|
||||
const mergedPanelRef = composeRef(panelRef, innerPanelRef);
|
||||
// =========================== zIndex ===========================
|
||||
const [zIndex, contextZIndex] = useZIndex('Drawer', rest.zIndex);
|
||||
// ============================ Mask ============================
|
||||
const [mergedMask, maskBlurClassName, mergedMaskClosable] = useMergedMask(drawerMask, contextMask, prefixCls, maskClosable);
|
||||
// ========================== Focusable =========================
|
||||
const mergedFocusable = useFocusable(focusable, getContainer !== false && mergedMask);
|
||||
// =========================== Render ===========================
|
||||
const {
|
||||
classNames,
|
||||
styles,
|
||||
rootStyle
|
||||
} = rest;
|
||||
const mergedProps = {
|
||||
...props,
|
||||
zIndex,
|
||||
panelRef,
|
||||
mask: mergedMask,
|
||||
maskClosable: mergedMaskClosable,
|
||||
defaultSize,
|
||||
push,
|
||||
focusable: mergedFocusable
|
||||
};
|
||||
const [mergedClassNames, mergedStyles] = useMergeSemantic([contextClassNames, classNames], [contextStyles, styles], {
|
||||
props: mergedProps
|
||||
});
|
||||
const drawerClassName = clsx({
|
||||
'no-mask': !mergedMask,
|
||||
[`${prefixCls}-rtl`]: direction === 'rtl'
|
||||
}, rootClassName, hashId, cssVarCls, mergedClassNames.root);
|
||||
// ========================== Warning ===========================
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const warning = devUseWarning('Drawer');
|
||||
[['headerStyle', 'styles.header'], ['bodyStyle', 'styles.body'], ['footerStyle', 'styles.footer'], ['contentWrapperStyle', 'styles.wrapper'], ['maskStyle', 'styles.mask'], ['drawerStyle', 'styles.section'], ['destroyInactivePanel', 'destroyOnHidden'], ['width', 'size'], ['height', 'size']].forEach(([deprecatedName, newName]) => {
|
||||
warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
|
||||
});
|
||||
if (getContainer !== undefined && props.style?.position === 'absolute') {
|
||||
process.env.NODE_ENV !== "production" ? warning(false, 'breaking', '`style` is replaced by `rootStyle` in v5. Please check that `position: absolute` is necessary.') : void 0;
|
||||
}
|
||||
warning.deprecated(!(mergedClassNames?.content || mergedStyles?.content), 'classNames.content and styles.content', 'classNames.section and styles.section');
|
||||
}
|
||||
return /*#__PURE__*/React.createElement(ContextIsolator, {
|
||||
form: true,
|
||||
space: true
|
||||
}, /*#__PURE__*/React.createElement(zIndexContext.Provider, {
|
||||
value: contextZIndex
|
||||
}, /*#__PURE__*/React.createElement(RcDrawer, {
|
||||
prefixCls: prefixCls,
|
||||
onClose: onClose,
|
||||
maskMotion: maskMotion,
|
||||
motion: panelMotion,
|
||||
...rest,
|
||||
classNames: {
|
||||
mask: clsx(mergedClassNames.mask, maskBlurClassName.mask),
|
||||
section: mergedClassNames.section,
|
||||
wrapper: mergedClassNames.wrapper,
|
||||
dragger: mergedClassNames.dragger
|
||||
},
|
||||
styles: {
|
||||
mask: {
|
||||
...mergedStyles.mask,
|
||||
...maskStyle
|
||||
},
|
||||
section: {
|
||||
...mergedStyles.section,
|
||||
...drawerStyle
|
||||
},
|
||||
wrapper: {
|
||||
...mergedStyles.wrapper,
|
||||
...contentWrapperStyle
|
||||
},
|
||||
dragger: mergedStyles.dragger
|
||||
},
|
||||
open: open,
|
||||
mask: mergedMask,
|
||||
maskClosable: mergedMaskClosable,
|
||||
push: push,
|
||||
size: drawerSize,
|
||||
defaultSize: defaultSize,
|
||||
style: {
|
||||
...contextStyle,
|
||||
...style
|
||||
},
|
||||
rootStyle: {
|
||||
...rootStyle,
|
||||
...mergedStyles.root
|
||||
},
|
||||
className: clsx(contextClassName, className),
|
||||
rootClassName: drawerClassName,
|
||||
getContainer: getContainer,
|
||||
afterOpenChange: afterOpenChange,
|
||||
panelRef: mergedPanelRef,
|
||||
zIndex: zIndex,
|
||||
...(resizable ? {
|
||||
resizable
|
||||
} : {}),
|
||||
"aria-labelledby": ariaLabelledby ?? ariaId,
|
||||
destroyOnHidden: destroyOnHidden ?? destroyOnClose,
|
||||
// Focusable
|
||||
focusTriggerAfterClose: mergedFocusable.focusTriggerAfterClose,
|
||||
focusTrap: mergedFocusable.trap
|
||||
}, /*#__PURE__*/React.createElement(DrawerPanel, {
|
||||
prefixCls: prefixCls,
|
||||
size: size,
|
||||
...rest,
|
||||
ariaId: ariaId,
|
||||
onClose: onClose
|
||||
}))));
|
||||
};
|
||||
/** @private Internal Component. Do not use in your production. */
|
||||
const PurePanel = props => {
|
||||
const {
|
||||
prefixCls: customizePrefixCls,
|
||||
style,
|
||||
className,
|
||||
placement = 'right',
|
||||
...restProps
|
||||
} = props;
|
||||
const {
|
||||
getPrefixCls
|
||||
} = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
|
||||
const [hashId, cssVarCls] = useStyle(prefixCls);
|
||||
const cls = clsx(prefixCls, `${prefixCls}-pure`, `${prefixCls}-${placement}`, hashId, cssVarCls, className);
|
||||
return /*#__PURE__*/React.createElement("div", {
|
||||
className: cls,
|
||||
style: style
|
||||
}, /*#__PURE__*/React.createElement(DrawerPanel, {
|
||||
prefixCls: prefixCls,
|
||||
...restProps
|
||||
}));
|
||||
};
|
||||
Drawer._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Drawer.displayName = 'Drawer';
|
||||
}
|
||||
export default Drawer;
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import * as React from 'react';
|
||||
import type { DrawerProps as RCDrawerProps } from '@rc-component/drawer';
|
||||
import type { DrawerProps } from '.';
|
||||
import type { ClosableType, SemanticClassNamesType, SemanticStylesType } from '../_util/hooks';
|
||||
export type DrawerSemanticName = keyof DrawerSemanticClassNames & keyof DrawerSemanticStyles;
|
||||
export type DrawerSemanticClassNames = {
|
||||
root?: string;
|
||||
mask?: string;
|
||||
header?: string;
|
||||
title?: string;
|
||||
extra?: string;
|
||||
section?: string;
|
||||
body?: string;
|
||||
footer?: string;
|
||||
wrapper?: string;
|
||||
dragger?: string;
|
||||
close?: string;
|
||||
/**
|
||||
* @deprecated please use `classNames.section` instead.
|
||||
*/
|
||||
content?: string;
|
||||
};
|
||||
export type DrawerSemanticStyles = {
|
||||
root?: React.CSSProperties;
|
||||
mask?: React.CSSProperties;
|
||||
header?: React.CSSProperties;
|
||||
title?: React.CSSProperties;
|
||||
extra?: React.CSSProperties;
|
||||
section?: React.CSSProperties;
|
||||
body?: React.CSSProperties;
|
||||
footer?: React.CSSProperties;
|
||||
wrapper?: React.CSSProperties;
|
||||
dragger?: React.CSSProperties;
|
||||
close?: React.CSSProperties;
|
||||
/**
|
||||
* @deprecated please use `styles.section` instead.
|
||||
*/
|
||||
content?: React.CSSProperties;
|
||||
};
|
||||
export type DrawerClassNamesType = SemanticClassNamesType<DrawerProps, DrawerSemanticClassNames>;
|
||||
export type DrawerStylesType = SemanticStylesType<DrawerProps, DrawerSemanticStyles>;
|
||||
export interface DrawerPanelProps {
|
||||
prefixCls: string;
|
||||
ariaId?: string;
|
||||
title?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
extra?: React.ReactNode;
|
||||
size?: DrawerProps['size'];
|
||||
/**
|
||||
* Recommend to use closeIcon instead
|
||||
*
|
||||
* e.g.
|
||||
*
|
||||
* `<Drawer closeIcon={false} />`
|
||||
*/
|
||||
closable?: boolean | (Extract<ClosableType, object> & {
|
||||
placement?: 'start' | 'end';
|
||||
});
|
||||
closeIcon?: React.ReactNode;
|
||||
onClose?: RCDrawerProps['onClose'];
|
||||
children?: React.ReactNode;
|
||||
classNames?: DrawerClassNamesType;
|
||||
styles?: DrawerStylesType;
|
||||
loading?: boolean;
|
||||
/** @deprecated Please use `styles.header` instead */
|
||||
headerStyle?: React.CSSProperties;
|
||||
/** @deprecated Please use `styles.body` instead */
|
||||
bodyStyle?: React.CSSProperties;
|
||||
/** @deprecated Please use `styles.footer` instead */
|
||||
footerStyle?: React.CSSProperties;
|
||||
/** @deprecated Please use `styles.wrapper` instead */
|
||||
contentWrapperStyle?: React.CSSProperties;
|
||||
/** @deprecated Please use `styles.mask` instead */
|
||||
maskStyle?: React.CSSProperties;
|
||||
/** @deprecated Please use `styles.content` instead */
|
||||
drawerStyle?: React.CSSProperties;
|
||||
}
|
||||
declare const DrawerPanel: React.FC<DrawerPanelProps>;
|
||||
export default DrawerPanel;
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
"use client";
|
||||
|
||||
import * as React from 'react';
|
||||
import { clsx } from 'clsx';
|
||||
import { pickClosable, useClosable, useMergeSemantic } from '../_util/hooks';
|
||||
import { isPlainObject } from '../_util/is';
|
||||
import { useComponentConfig } from '../config-provider/context';
|
||||
import Skeleton from '../skeleton';
|
||||
const DrawerPanel = props => {
|
||||
const {
|
||||
prefixCls,
|
||||
ariaId,
|
||||
title,
|
||||
footer,
|
||||
extra,
|
||||
closable,
|
||||
loading,
|
||||
onClose,
|
||||
headerStyle,
|
||||
bodyStyle,
|
||||
footerStyle,
|
||||
children,
|
||||
classNames: drawerClassNames,
|
||||
styles: drawerStyles
|
||||
} = props;
|
||||
const drawerContext = useComponentConfig('drawer');
|
||||
const {
|
||||
classNames: contextClassNames,
|
||||
styles: contextStyles,
|
||||
closable: contextClosable
|
||||
} = drawerContext;
|
||||
const [mergedClassNames, mergedStyles] = useMergeSemantic([contextClassNames, drawerClassNames], [contextStyles, drawerStyles], {
|
||||
props: {
|
||||
...props,
|
||||
closable: closable ?? contextClosable
|
||||
}
|
||||
});
|
||||
const closablePlacement = React.useMemo(() => {
|
||||
const merged = closable ?? contextClosable;
|
||||
if (merged === false) {
|
||||
return undefined;
|
||||
}
|
||||
if (isPlainObject(merged) && merged?.placement === 'end') {
|
||||
return 'end';
|
||||
}
|
||||
return 'start';
|
||||
}, [closable, contextClosable]);
|
||||
const customCloseIconRender = React.useCallback(icon => (/*#__PURE__*/React.createElement("button", {
|
||||
type: "button",
|
||||
onClick: onClose,
|
||||
className: clsx(`${prefixCls}-close`, {
|
||||
[`${prefixCls}-close-${closablePlacement}`]: closablePlacement === 'end'
|
||||
}, mergedClassNames.close),
|
||||
style: mergedStyles.close
|
||||
}, icon)), [onClose, prefixCls, closablePlacement, mergedClassNames.close, mergedStyles.close]);
|
||||
const [mergedClosable, mergedCloseIcon] = useClosable(pickClosable(props), pickClosable(drawerContext), {
|
||||
closable: true,
|
||||
closeIconRender: customCloseIconRender
|
||||
});
|
||||
const renderHeader = () => {
|
||||
if (!title && !mergedClosable) {
|
||||
return null;
|
||||
}
|
||||
return /*#__PURE__*/React.createElement("div", {
|
||||
style: {
|
||||
...mergedStyles.header,
|
||||
...headerStyle
|
||||
},
|
||||
className: clsx(`${prefixCls}-header`, mergedClassNames.header, {
|
||||
[`${prefixCls}-header-close-only`]: mergedClosable && !title && !extra
|
||||
})
|
||||
}, /*#__PURE__*/React.createElement("div", {
|
||||
className: `${prefixCls}-header-title`
|
||||
}, closablePlacement === 'start' && mergedCloseIcon, title && (/*#__PURE__*/React.createElement("div", {
|
||||
className: clsx(`${prefixCls}-title`, mergedClassNames.title),
|
||||
style: mergedStyles.title,
|
||||
id: ariaId
|
||||
}, title))), extra && (/*#__PURE__*/React.createElement("div", {
|
||||
className: clsx(`${prefixCls}-extra`, mergedClassNames.extra),
|
||||
style: mergedStyles.extra
|
||||
}, extra)), closablePlacement === 'end' && mergedCloseIcon);
|
||||
};
|
||||
const renderFooter = () => {
|
||||
if (!footer) {
|
||||
return null;
|
||||
}
|
||||
return /*#__PURE__*/React.createElement("div", {
|
||||
className: clsx(`${prefixCls}-footer`, mergedClassNames.footer),
|
||||
style: {
|
||||
...mergedStyles.footer,
|
||||
...footerStyle
|
||||
}
|
||||
}, footer);
|
||||
};
|
||||
return /*#__PURE__*/React.createElement(React.Fragment, null, renderHeader(), /*#__PURE__*/React.createElement("div", {
|
||||
className: clsx(`${prefixCls}-body`, mergedClassNames.body),
|
||||
style: {
|
||||
...mergedStyles.body,
|
||||
...bodyStyle
|
||||
}
|
||||
}, loading ? (/*#__PURE__*/React.createElement(Skeleton, {
|
||||
active: true,
|
||||
title: false,
|
||||
paragraph: {
|
||||
rows: 5
|
||||
},
|
||||
className: `${prefixCls}-body-skeleton`
|
||||
})) : children), renderFooter());
|
||||
};
|
||||
export default DrawerPanel;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import Drawer from './Drawer';
|
||||
export type { DrawerProps, DrawerResizableConfig, PushState } from './Drawer';
|
||||
export type { DrawerPanelProps, DrawerSemanticClassNames, DrawerSemanticName, DrawerSemanticStyles, } from './DrawerPanel';
|
||||
export default Drawer;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
"use client";
|
||||
|
||||
import Drawer from './Drawer';
|
||||
export default Drawer;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import type { FullToken, GetDefaultToken } from '../../theme/internal';
|
||||
export interface ComponentToken {
|
||||
/**
|
||||
* @desc 弹窗 z-index
|
||||
* @descEN z-index of drawer
|
||||
*/
|
||||
zIndexPopup: number;
|
||||
/**
|
||||
* @desc 底部区域纵向内间距
|
||||
* @descEN Vertical padding of footer
|
||||
*/
|
||||
footerPaddingBlock: number;
|
||||
/**
|
||||
* @desc 底部区域横向内间距
|
||||
* @descEN Horizontal padding of footer
|
||||
*/
|
||||
footerPaddingInline: number;
|
||||
/**
|
||||
* @desc 拖拽手柄大小
|
||||
* @descEN Size of resize handle
|
||||
*/
|
||||
draggerSize: number;
|
||||
}
|
||||
export interface DrawerToken extends FullToken<'Drawer'> {
|
||||
}
|
||||
export declare const prepareComponentToken: GetDefaultToken<'Drawer'>;
|
||||
declare const _default: (prefixCls: string, rootCls?: string) => readonly [string, string];
|
||||
export default _default;
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
import { unit } from '@ant-design/cssinjs';
|
||||
import { genFocusStyle } from '../../style';
|
||||
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
||||
import genMotionStyle from './motion';
|
||||
// =============================== Base ===============================
|
||||
const genDrawerStyle = token => {
|
||||
const {
|
||||
borderRadiusSM,
|
||||
componentCls,
|
||||
zIndexPopup,
|
||||
colorBgMask,
|
||||
colorBgElevated,
|
||||
motionDurationSlow,
|
||||
motionDurationMid,
|
||||
paddingXS,
|
||||
padding,
|
||||
paddingLG,
|
||||
fontSizeLG,
|
||||
lineHeightLG,
|
||||
lineWidth,
|
||||
lineType,
|
||||
colorSplit,
|
||||
marginXS,
|
||||
colorIcon,
|
||||
colorIconHover,
|
||||
colorBgTextHover,
|
||||
colorBgTextActive,
|
||||
colorText,
|
||||
fontWeightStrong,
|
||||
footerPaddingBlock,
|
||||
footerPaddingInline,
|
||||
draggerSize,
|
||||
calc
|
||||
} = token;
|
||||
const wrapperCls = `${componentCls}-content-wrapper`;
|
||||
const draggerCls = `${componentCls}-resizable-dragger`;
|
||||
return {
|
||||
[componentCls]: {
|
||||
position: 'fixed',
|
||||
inset: 0,
|
||||
zIndex: zIndexPopup,
|
||||
pointerEvents: 'none',
|
||||
color: colorText,
|
||||
'&-pure': {
|
||||
position: 'relative',
|
||||
background: colorBgElevated,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
pointerEvents: 'auto',
|
||||
[`&${componentCls}-left`]: {
|
||||
boxShadow: token.boxShadowDrawerLeft
|
||||
},
|
||||
[`&${componentCls}-right`]: {
|
||||
boxShadow: token.boxShadowDrawerRight
|
||||
},
|
||||
[`&${componentCls}-top`]: {
|
||||
boxShadow: token.boxShadowDrawerUp
|
||||
},
|
||||
[`&${componentCls}-bottom`]: {
|
||||
boxShadow: token.boxShadowDrawerDown
|
||||
}
|
||||
},
|
||||
'&-inline': {
|
||||
position: 'absolute'
|
||||
},
|
||||
// ====================== Mask ======================
|
||||
[`${componentCls}-mask`]: {
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
zIndex: zIndexPopup,
|
||||
background: colorBgMask,
|
||||
pointerEvents: 'auto',
|
||||
[`&${componentCls}-mask-blur`]: {
|
||||
backdropFilter: 'blur(4px)'
|
||||
}
|
||||
},
|
||||
// ==================== Content =====================
|
||||
[wrapperCls]: {
|
||||
position: 'absolute',
|
||||
zIndex: zIndexPopup,
|
||||
maxWidth: '100vw',
|
||||
transition: `all ${motionDurationSlow}`,
|
||||
'&-hidden': {
|
||||
display: 'none'
|
||||
}
|
||||
},
|
||||
// Placement
|
||||
[`&-left > ${wrapperCls}`]: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: {
|
||||
_skip_check_: true,
|
||||
value: 0
|
||||
},
|
||||
boxShadow: token.boxShadowDrawerLeft
|
||||
},
|
||||
[`&-right > ${wrapperCls}`]: {
|
||||
top: 0,
|
||||
right: {
|
||||
_skip_check_: true,
|
||||
value: 0
|
||||
},
|
||||
bottom: 0,
|
||||
boxShadow: token.boxShadowDrawerRight
|
||||
},
|
||||
[`&-top > ${wrapperCls}`]: {
|
||||
top: 0,
|
||||
insetInline: 0,
|
||||
boxShadow: token.boxShadowDrawerUp
|
||||
},
|
||||
[`&-bottom > ${wrapperCls}`]: {
|
||||
bottom: 0,
|
||||
insetInline: 0,
|
||||
boxShadow: token.boxShadowDrawerDown
|
||||
},
|
||||
[`${componentCls}-section`]: {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
overflow: 'auto',
|
||||
background: colorBgElevated,
|
||||
pointerEvents: 'auto'
|
||||
},
|
||||
// Header
|
||||
[`${componentCls}-header`]: {
|
||||
display: 'flex',
|
||||
flex: 0,
|
||||
alignItems: 'center',
|
||||
padding: `${unit(padding)} ${unit(paddingLG)}`,
|
||||
fontSize: fontSizeLG,
|
||||
lineHeight: lineHeightLG,
|
||||
borderBottom: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
|
||||
'&-title': {
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
minWidth: 0,
|
||||
minHeight: 0
|
||||
}
|
||||
},
|
||||
[`${componentCls}-extra`]: {
|
||||
flex: 'none'
|
||||
},
|
||||
[`${componentCls}-close`]: {
|
||||
display: 'inline-flex',
|
||||
width: calc(fontSizeLG).add(paddingXS).equal(),
|
||||
height: calc(fontSizeLG).add(paddingXS).equal(),
|
||||
borderRadius: borderRadiusSM,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
color: colorIcon,
|
||||
fontWeight: fontWeightStrong,
|
||||
fontSize: fontSizeLG,
|
||||
fontStyle: 'normal',
|
||||
lineHeight: 1,
|
||||
textAlign: 'center',
|
||||
textTransform: 'none',
|
||||
textDecoration: 'none',
|
||||
background: 'transparent',
|
||||
border: 0,
|
||||
cursor: 'pointer',
|
||||
transition: `all ${motionDurationMid}`,
|
||||
textRendering: 'auto',
|
||||
[`&${componentCls}-close-end`]: {
|
||||
marginInlineStart: marginXS
|
||||
},
|
||||
[`&:not(${componentCls}-close-end)`]: {
|
||||
marginInlineEnd: marginXS
|
||||
},
|
||||
'&:hover': {
|
||||
color: colorIconHover,
|
||||
backgroundColor: colorBgTextHover,
|
||||
textDecoration: 'none'
|
||||
},
|
||||
'&:active': {
|
||||
backgroundColor: colorBgTextActive
|
||||
},
|
||||
...genFocusStyle(token)
|
||||
},
|
||||
[`${componentCls}-title`]: {
|
||||
flex: 1,
|
||||
margin: 0,
|
||||
fontWeight: token.fontWeightStrong,
|
||||
fontSize: fontSizeLG,
|
||||
lineHeight: lineHeightLG
|
||||
},
|
||||
// Body
|
||||
[`${componentCls}-body`]: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
padding: paddingLG,
|
||||
overflow: 'auto',
|
||||
[`${componentCls}-body-skeleton`]: {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center'
|
||||
}
|
||||
},
|
||||
// Footer
|
||||
[`${componentCls}-footer`]: {
|
||||
flexShrink: 0,
|
||||
padding: `${unit(footerPaddingBlock)} ${unit(footerPaddingInline)}`,
|
||||
borderTop: `${unit(lineWidth)} ${lineType} ${colorSplit}`
|
||||
},
|
||||
// ==================== Resizable ===================
|
||||
[draggerCls]: {
|
||||
position: 'absolute',
|
||||
zIndex: 1,
|
||||
backgroundColor: 'transparent',
|
||||
userSelect: 'none',
|
||||
pointerEvents: 'auto',
|
||||
'&:hover': {
|
||||
backgroundColor: token.colorPrimary,
|
||||
opacity: 0.2
|
||||
},
|
||||
'&-dragging': {
|
||||
backgroundColor: token.colorPrimary,
|
||||
opacity: 0.3
|
||||
}
|
||||
},
|
||||
[`${draggerCls}-left`]: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
right: {
|
||||
_skip_check_: true,
|
||||
value: 0
|
||||
},
|
||||
width: draggerSize,
|
||||
cursor: 'col-resize'
|
||||
},
|
||||
[`${draggerCls}-right`]: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: {
|
||||
_skip_check_: true,
|
||||
value: 0
|
||||
},
|
||||
width: draggerSize,
|
||||
cursor: 'col-resize'
|
||||
},
|
||||
[`${draggerCls}-top`]: {
|
||||
insetInline: 0,
|
||||
bottom: 0,
|
||||
height: draggerSize,
|
||||
cursor: 'row-resize'
|
||||
},
|
||||
[`${draggerCls}-bottom`]: {
|
||||
insetInline: 0,
|
||||
top: 0,
|
||||
height: draggerSize,
|
||||
cursor: 'row-resize'
|
||||
},
|
||||
// Wrapper dragging state - disable transitions for smooth dragging
|
||||
[`${wrapperCls}-dragging`]: {
|
||||
userSelect: 'none',
|
||||
transition: 'none',
|
||||
willChange: 'width, height',
|
||||
[`${componentCls}-content`]: {
|
||||
pointerEvents: 'none'
|
||||
},
|
||||
[`${componentCls}-section`]: {
|
||||
pointerEvents: 'none'
|
||||
}
|
||||
},
|
||||
// ====================== RTL =======================
|
||||
'&-rtl': {
|
||||
direction: 'rtl'
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
export const prepareComponentToken = token => ({
|
||||
zIndexPopup: token.zIndexPopupBase,
|
||||
footerPaddingBlock: token.paddingXS,
|
||||
footerPaddingInline: token.padding,
|
||||
draggerSize: 4
|
||||
});
|
||||
// ============================== Export ==============================
|
||||
export default genStyleHooks('Drawer', token => {
|
||||
const drawerToken = mergeToken(token, {});
|
||||
return [genDrawerStyle(drawerToken), genMotionStyle(drawerToken)];
|
||||
}, prepareComponentToken);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { CSSObject } from '@ant-design/cssinjs';
|
||||
import type { DrawerToken } from '.';
|
||||
import type { GenerateStyle } from '../../theme/internal';
|
||||
declare const genMotionStyle: GenerateStyle<DrawerToken, CSSObject>;
|
||||
export default genMotionStyle;
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
const getMoveTranslate = direction => {
|
||||
const value = '100%';
|
||||
return {
|
||||
left: `translateX(-${value})`,
|
||||
right: `translateX(${value})`,
|
||||
top: `translateY(-${value})`,
|
||||
bottom: `translateY(${value})`
|
||||
}[direction];
|
||||
};
|
||||
const getEnterLeaveStyle = (startStyle, endStyle) => ({
|
||||
'&-enter, &-appear': {
|
||||
...startStyle,
|
||||
'&-active': endStyle
|
||||
},
|
||||
'&-leave': {
|
||||
...endStyle,
|
||||
'&-active': startStyle
|
||||
}
|
||||
});
|
||||
const getFadeStyle = (from, duration) => ({
|
||||
'&-enter, &-appear, &-leave': {
|
||||
'&-start': {
|
||||
transition: 'none'
|
||||
},
|
||||
'&-active': {
|
||||
transition: `all ${duration}`
|
||||
}
|
||||
},
|
||||
...getEnterLeaveStyle({
|
||||
opacity: from
|
||||
}, {
|
||||
opacity: 1
|
||||
})
|
||||
});
|
||||
const getPanelMotionStyles = (direction, duration) => [getFadeStyle(0.7, duration), getEnterLeaveStyle({
|
||||
transform: getMoveTranslate(direction)
|
||||
}, {
|
||||
transform: 'none'
|
||||
})];
|
||||
const genMotionStyle = token => {
|
||||
const {
|
||||
componentCls,
|
||||
motionDurationSlow
|
||||
} = token;
|
||||
return {
|
||||
[componentCls]: {
|
||||
// ======================== Mask ========================
|
||||
[`${componentCls}-mask-motion`]: getFadeStyle(0, motionDurationSlow),
|
||||
// ======================= Panel ========================
|
||||
[`${componentCls}-panel-motion`]: ['left', 'right', 'top', 'bottom'].reduce((obj, direction) => {
|
||||
return {
|
||||
...obj,
|
||||
[`&-${direction}`]: getPanelMotionStyles(direction, motionDurationSlow)
|
||||
};
|
||||
}, {})
|
||||
}
|
||||
};
|
||||
};
|
||||
export default genMotionStyle;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
export type OmitFocusType = 'focusTriggerAfterClose' | 'focusTrap' | 'autoFocusButton';
|
||||
export interface FocusableConfig {
|
||||
focusTriggerAfterClose?: boolean;
|
||||
trap?: boolean;
|
||||
}
|
||||
export default function useFocusable(focusable?: FocusableConfig, defaultTrap?: boolean, legacyFocusTriggerAfterClose?: FocusableConfig['focusTriggerAfterClose']): {
|
||||
focusTriggerAfterClose?: boolean;
|
||||
trap?: boolean;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { useMemo } from 'react';
|
||||
export default function useFocusable(focusable, defaultTrap, legacyFocusTriggerAfterClose) {
|
||||
return useMemo(() => {
|
||||
const ret = {
|
||||
trap: defaultTrap ?? true,
|
||||
focusTriggerAfterClose: legacyFocusTriggerAfterClose ?? true
|
||||
};
|
||||
return {
|
||||
...ret,
|
||||
...focusable
|
||||
};
|
||||
}, [focusable, defaultTrap, legacyFocusTriggerAfterClose]);
|
||||
}
|
||||
Reference in New Issue
Block a user