Skip to content

Commit b625129

Browse files
committed
fix(drawer): use percent width
1 parent 7a40fef commit b625129

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/drawer/index.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export enum DrawerType {
2222
Normal = 'normal',
2323
}
2424

25+
enum DrawerSize {
26+
Small = 720,
27+
Default = 1000,
28+
Large = 1256,
29+
}
30+
2531
interface NormalDrawerProps extends Omit<AntdDrawerProps, 'placement'> {
2632
size?: 'small' | 'default' | 'large';
2733
loading?: boolean;
@@ -53,12 +59,12 @@ function isControlled<T extends readOnlyTab>(props: DrawerProps<T>): props is Ta
5359
return 'activeKey' in props;
5460
}
5561

56-
export type DrawerProps<T extends readOnlyTab> = TabsDrawerProps<T> | NormalDrawerProps;
62+
export type DrawerProps<T extends readOnlyTab = any> = TabsDrawerProps<T> | NormalDrawerProps;
5763

5864
const getWidthFromSize = (size: NormalDrawerProps['size']) => {
59-
if (size === 'small') return 720;
60-
if (size === 'large') return 1256;
61-
return 1000;
65+
if (size === 'small') return `${(DrawerSize.Small / 1400) * 100}%`;
66+
if (size === 'large') return `${(DrawerSize.Large / 1400) * 100}%`;
67+
return `${(DrawerSize.Default / 1400) * 100}%`;
6268
};
6369

6470
const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProps['message'] => {
@@ -67,7 +73,7 @@ const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProp
6773
};
6874

6975
const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
70-
const slidePrefixCls = 'dtc-drawer';
76+
const drawerPrefixCls = 'dtc-drawer';
7177

7278
const {
7379
open,
@@ -89,7 +95,7 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
8995
const finalWidth = width ?? getWidthFromSize(size);
9096
const isFormType = type === DrawerType.Form;
9197

92-
const [internalTabKey, setInternalTabKey] = useState('');
98+
const [internalTabKey, setInternalTabKey] = useState<TabKey<T>>('');
9399

94100
useEffect(() => {
95101
open &&
@@ -102,7 +108,7 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
102108
const renderButton = () => {
103109
return (
104110
<img
105-
className={`${slidePrefixCls}-icon`}
111+
className={`${drawerPrefixCls}-icon`}
106112
onClick={onClose}
107113
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAABwCAYAAAAE0LDPAAAAAXNSR0IArs4c6QAAAnlJREFUaEPtmk9IVHEQx78jufpw7ykouuEaBG6dEmrXOmRRt476VgvyEngKlNqQMu3PoSU7iCBq4CW2olNdRMRr7HasnnZb0y57WGODzUDjt/RIonbeyzfQYd51h/m8+c7395u3MOSs5Xexr4dKRLt5AhYJtbPRaNO7velo/4Bf6YhoB8B0R3vzNSLaNr8ECnBRRLTc0d583kBEAJU3J5o6HG0ZkgTs1OBATAxgqqghTIoCiPBeFABQSRggZFOxg/anC0ElYq9JlUglYhVgA9RFKhGrABugLlKJWAXYAHWRSsQqwAaoi1QiVgE2gHVRejKDUKgWQ1cvmj/XbMLfA3jA42dwVvPo7+tBd/xo8ICNzQLG7y3AskIYvz2IcEO9LwhbgcmWebGCpeUcEvEYBvrOBg8ol7cxOjaP4lYJqZEkIm2NniGeKjDZ3mQ/YPbJa7S1NiI1YntuuGeAgTx8lMHqx3XYvWdwOnHMUxW+AJufC7hzdwH1VggTt64gHLZYiC+Ayfb85QoWl3KIn+jEpeS54AHlb98xOjaHYrGEG8M2DkWaqkJ8V2CyZd86mJl7hdaWg7h5PVm14f8EMJD0zxM+ePkCuo4f+WsV/ycgm3MwMy8k0d4mp4ZtRIJusmvTxMlODNgB21T8oLlXRbK3B6cS3maDZxeJXnbudb315Wvl9AZ+XbsDpzseQ3/QA+fTRgET9wVHpvmqcNbWK6PSjEy/D9vkB+mnaLDq5D5b/L6x7+8iBbBNVolUItYDKpFKxCrABqiLVCJWATZAXaQSsQqwAeoilYhVgA1QFzESCS8wia9giS6Rma1B0TU40UU+sVVEoWXK6uugPwBjVkdxauLcgwAAAABJRU5ErkJggg=="
108114
alt="closeBtn"
@@ -122,19 +128,19 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
122128
mask={isFormType ? true : mask}
123129
maskClosable={isFormType ? false : maskClosable}
124130
width={finalWidth}
125-
prefixCls={slidePrefixCls}
131+
prefixCls={drawerPrefixCls}
126132
onClose={onClose}
127133
{...rest}
128134
{...motionProps}
129135
>
130136
{!isFormType && renderButton()}
131-
<Spin wrapperClassName={`${slidePrefixCls}-nested-loading`} spinning={loading}>
137+
<Spin wrapperClassName={`${drawerPrefixCls}-nested-loading`} spinning={loading}>
132138
{title && (
133-
<div className={`${slidePrefixCls}-header`}>
139+
<div className={`${drawerPrefixCls}-header`}>
134140
{title}
135141
{isFormType && (
136142
<CloseOutlined
137-
className={`${slidePrefixCls}-header--icon`}
143+
className={`${drawerPrefixCls}-header--icon`}
138144
onClick={onClose}
139145
/>
140146
)}
@@ -152,21 +158,21 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
152158
destroyInactiveTabPane
153159
activeKey={currentKey}
154160
onChange={handleChangeKey}
155-
className={`${slidePrefixCls}-tabs`}
161+
className={`${drawerPrefixCls}-tabs`}
156162
>
157163
{props.tabs?.map((tab: { key: string; title: React.ReactNode }) => (
158164
<Tabs.TabPane tab={tab.title} key={tab.key} />
159165
))}
160166
</Tabs>
161167
)}
162168
<div
163-
className={classNames(`${slidePrefixCls}-body`, bodyClassName)}
169+
className={classNames(`${drawerPrefixCls}-body`, bodyClassName)}
164170
style={bodyStyle}
165171
>
166172
{isFunction(props) ? props.children?.(currentKey ?? '') : props.children}
167173
</div>
168174
{footer ? (
169-
<div className={classNames(`${slidePrefixCls}-footer`)}>{footer}</div>
175+
<div className={classNames(`${drawerPrefixCls}-footer`)}>{footer}</div>
170176
) : null}
171177
</Spin>
172178
</RcDrawer>

0 commit comments

Comments
 (0)