From 16d4e062397a35b7e1e6464c839d9df5048b7e75 Mon Sep 17 00:00:00 2001 From: LuckyFBB <976060700@qq.com> Date: Wed, 22 Jan 2025 15:15:52 +0800 Subject: [PATCH] fix(drawer): use percent width --- .../__tests/__snapshots__/index.test.tsx.snap | 2 +- src/drawer/__tests/index.test.tsx | 2 +- src/drawer/index.tsx | 32 +++++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/drawer/__tests/__snapshots__/index.test.tsx.snap b/src/drawer/__tests/__snapshots__/index.test.tsx.snap index 7fb97c0c2..f3410dfdc 100644 --- a/src/drawer/__tests/__snapshots__/index.test.tsx.snap +++ b/src/drawer/__tests/__snapshots__/index.test.tsx.snap @@ -18,7 +18,7 @@ exports[`test Drawer snapshot match 1`] = ` />
{ ); expect(document.querySelector('.dtc-drawer-content-wrapper')).toHaveStyle({ - width: '1256px', + width: `${(1256 / 1440) * 100}%`, }); }); test('should render className/style correct', () => { diff --git a/src/drawer/index.tsx b/src/drawer/index.tsx index 41b704c57..114bc29e4 100644 --- a/src/drawer/index.tsx +++ b/src/drawer/index.tsx @@ -22,6 +22,12 @@ export enum DrawerType { Normal = 'normal', } +enum DrawerSize { + Small = 720, + Default = 1000, + Large = 1256, +} + interface BaseDrawerProps extends Omit { size?: 'small' | 'default' | 'large'; loading?: boolean; @@ -56,9 +62,9 @@ function isControlled(props: DrawerProps): props is Dr } const getWidthFromSize = (size: DrawerProps['size']) => { - if (size === 'small') return 720; - if (size === 'large') return 1256; - return 1000; + if (size === 'small') return `${(DrawerSize.Small / 1440) * 100}%`; + if (size === 'large') return `${(DrawerSize.Large / 1440) * 100}%`; + return `${(DrawerSize.Default / 1440) * 100}%`; }; const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['message'] => { @@ -67,7 +73,7 @@ const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['mes }; const Drawer = (props: DrawerProps) => { - const slidePrefixCls = 'dtc-drawer'; + const drawerPrefixCls = 'dtc-drawer'; const { open, @@ -89,7 +95,7 @@ const Drawer = (props: DrawerProps) => { const finalWidth = width ?? getWidthFromSize(size); const isFormType = type === DrawerType.Form; - const [internalTabKey, setInternalTabKey] = useState(''); + const [internalTabKey, setInternalTabKey] = useState>(''); useEffect(() => { open && @@ -102,7 +108,7 @@ const Drawer = (props: DrawerProps) => { const renderButton = () => { return ( closeBtn(props: DrawerProps) => { mask={isFormType ? true : mask} maskClosable={isFormType ? false : maskClosable} width={finalWidth} - prefixCls={slidePrefixCls} + prefixCls={drawerPrefixCls} onClose={onClose} {...rest} {...motionProps} > {!isFormType && renderButton()} - + {title && ( -
+
{title} {isFormType && ( )} @@ -152,7 +158,7 @@ const Drawer = (props: DrawerProps) => { destroyInactiveTabPane activeKey={currentKey} onChange={handleChangeKey} - className={`${slidePrefixCls}-tabs`} + className={`${drawerPrefixCls}-tabs`} > {props.tabs?.map((tab: { key: string; title: React.ReactNode }) => ( @@ -160,7 +166,7 @@ const Drawer = (props: DrawerProps) => { )}
{isFunction(props) @@ -168,7 +174,7 @@ const Drawer = (props: DrawerProps) => { : (props.children as React.ReactNode)}
{footer ? ( -
{footer}
+
{footer}
) : null}