Skip to content

Commit

Permalink
feat: support classNames (#426)
Browse files Browse the repository at this point in the history
* feat: support classNames

* docs: update docs

* docs: remove wrapperClassName in document
  • Loading branch information
kiner-tang authored Sep 18, 2023
1 parent 77de1ca commit c57edaa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
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();
});
});

1 comment on commit c57edaa

@vercel
Copy link

@vercel vercel bot commented on c57edaa Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

drawer – ./

drawer-git-master-react-component.vercel.app
drawer.vercel.app
drawer-react-component.vercel.app

Please sign in to comment.