Skip to content

feat: support classNames #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ ReactDom.render(
| props | type | default | description |
|------------|----------------|---------|----------------|
| className | string | null | - |
| classNames | { mask?: string; wrapper?: string; } | - | pass className to target area |
| prefixCls | string | 'drawer' | prefix class |
| wrapperClassName | string | null | wrapper class name |
| width | string \| number | null | drawer content wrapper width, drawer level transition width |
| height | string \| number | null | drawer content wrapper height, drawer level transition height |
| open | boolean | false | open or close menu |
Expand Down
2 changes: 2 additions & 0 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { DrawerPanelEvents } from './DrawerPanel';
import type { DrawerPopupProps } from './DrawerPopup';
import DrawerPopup from './DrawerPopup';
import { warnCheck } from './util';
import type { DrawerClassNames } from './inter';

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

Expand All @@ -19,6 +20,7 @@ export interface DrawerProps
destroyOnClose?: boolean;
getContainer?: PortalProps['getContainer'];
panelRef?: React.Ref<HTMLDivElement>;
classNames?: DrawerClassNames;
}

const Drawer: React.FC<DrawerProps> = props => {
Expand Down
8 changes: 8 additions & 0 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DrawerContext from './context';
import type { DrawerPanelEvents } from './DrawerPanel';
import DrawerPanel from './DrawerPanel';
import { parseWidthHeight } from './util';
import type { DrawerClassNames } from './inter';

const sentinelStyle: React.CSSProperties = {
width: 0,
Expand Down Expand Up @@ -63,6 +64,9 @@ export interface DrawerPopupProps extends DrawerPanelEvents {
onClose?: (
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
) => void;

// classNames
classNames?: DrawerClassNames;
}

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

// classNames
classNames: drawerClassNames,
// Root
rootClassName,
rootStyle,
Expand Down Expand Up @@ -216,6 +222,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
className={classNames(
`${prefixCls}-mask`,
motionMaskClassName,
drawerClassNames?.mask,
maskClassName,
)}
style={{
Expand Down Expand Up @@ -285,6 +292,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
<div
className={classNames(
`${prefixCls}-content-wrapper`,
drawerClassNames?.wrapper,
motionClassName,
)}
style={{
Expand Down
4 changes: 4 additions & 0 deletions src/inter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface DrawerClassNames {
mask?: string;
wrapper?: string;
}
16 changes: 16 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,20 @@ describe('rc-drawer-menu', () => {
).toHaveAttribute('id', 'customer-id');
unmount();
});

it('should support classNames', () => {
const { unmount } = render(
<Drawer classNames={{
wrapper: 'customer-wrapper',
mask: 'customer-mask',
}} open/>
);
expect(
document.querySelector('.rc-drawer-content-wrapper')
).toHaveClass('customer-wrapper');
expect(
document.querySelector('.rc-drawer-mask')
).toHaveClass('customer-mask');
unmount();
});
});