Skip to content

Commit c57edaa

Browse files
authored
feat: support classNames (#426)
* feat: support classNames * docs: update docs * docs: remove wrapperClassName in document
1 parent 77de1ca commit c57edaa

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ ReactDom.render(
4444
| props | type | default | description |
4545
|------------|----------------|---------|----------------|
4646
| className | string | null | - |
47+
| classNames | { mask?: string; wrapper?: string; } | - | pass className to target area |
4748
| prefixCls | string | 'drawer' | prefix class |
48-
| wrapperClassName | string | null | wrapper class name |
4949
| width | string \| number | null | drawer content wrapper width, drawer level transition width |
5050
| height | string \| number | null | drawer content wrapper height, drawer level transition height |
5151
| open | boolean | false | open or close menu |

src/Drawer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { DrawerPanelEvents } from './DrawerPanel';
77
import type { DrawerPopupProps } from './DrawerPopup';
88
import DrawerPopup from './DrawerPopup';
99
import { warnCheck } from './util';
10+
import type { DrawerClassNames } from './inter';
1011

1112
export type Placement = 'left' | 'top' | 'right' | 'bottom';
1213

@@ -19,6 +20,7 @@ export interface DrawerProps
1920
destroyOnClose?: boolean;
2021
getContainer?: PortalProps['getContainer'];
2122
panelRef?: React.Ref<HTMLDivElement>;
23+
classNames?: DrawerClassNames;
2224
}
2325

2426
const Drawer: React.FC<DrawerProps> = props => {

src/DrawerPopup.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import DrawerContext from './context';
99
import type { DrawerPanelEvents } from './DrawerPanel';
1010
import DrawerPanel from './DrawerPanel';
1111
import { parseWidthHeight } from './util';
12+
import type { DrawerClassNames } from './inter';
1213

1314
const sentinelStyle: React.CSSProperties = {
1415
width: 0,
@@ -63,6 +64,9 @@ export interface DrawerPopupProps extends DrawerPanelEvents {
6364
onClose?: (
6465
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
6566
) => void;
67+
68+
// classNames
69+
classNames?: DrawerClassNames;
6670
}
6771

6872
function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
@@ -76,6 +80,8 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
7680
autoFocus,
7781
keyboard,
7882

83+
// classNames
84+
classNames: drawerClassNames,
7985
// Root
8086
rootClassName,
8187
rootStyle,
@@ -216,6 +222,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
216222
className={classNames(
217223
`${prefixCls}-mask`,
218224
motionMaskClassName,
225+
drawerClassNames?.mask,
219226
maskClassName,
220227
)}
221228
style={{
@@ -285,6 +292,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
285292
<div
286293
className={classNames(
287294
`${prefixCls}-content-wrapper`,
295+
drawerClassNames?.wrapper,
288296
motionClassName,
289297
)}
290298
style={{

src/inter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface DrawerClassNames {
2+
mask?: string;
3+
wrapper?: string;
4+
}

tests/index.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,20 @@ describe('rc-drawer-menu', () => {
395395
).toHaveAttribute('id', 'customer-id');
396396
unmount();
397397
});
398+
399+
it('should support classNames', () => {
400+
const { unmount } = render(
401+
<Drawer classNames={{
402+
wrapper: 'customer-wrapper',
403+
mask: 'customer-mask',
404+
}} open/>
405+
);
406+
expect(
407+
document.querySelector('.rc-drawer-content-wrapper')
408+
).toHaveClass('customer-wrapper');
409+
expect(
410+
document.querySelector('.rc-drawer-mask')
411+
).toHaveClass('customer-mask');
412+
unmount();
413+
});
398414
});

0 commit comments

Comments
 (0)