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 9bd34832a..e061c0324 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 NormalDrawerProps extends Omit
{
size?: 'small' | 'default' | 'large';
loading?: boolean;
@@ -53,12 +59,12 @@ function isControlled(props: DrawerProps): props is Ta
return 'activeKey' in props;
}
-export type DrawerProps = TabsDrawerProps | NormalDrawerProps;
+export type DrawerProps = TabsDrawerProps | NormalDrawerProps;
const getWidthFromSize = (size: NormalDrawerProps['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: NormalDrawerProps['banner']): banner is AlertProps['message'] => {
@@ -67,7 +73,7 @@ const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProp
};
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 (
(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,13 +166,13 @@ const Drawer = (props: DrawerProps) => {
)}
{isFunction(props) ? props.children?.(currentKey ?? '') : props.children}
{footer ? (
- {footer}
+ {footer}
) : null}