Skip to content

Commit

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

* feat: test

* feat: test

* feat: test

* feat: review
  • Loading branch information
crazyair committed May 30, 2024
1 parent 469280c commit 22618e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ storybook

# dumi
.dumi/tmp
.dumi/tmp-production
.dumi/tmp-production
pnpm-lock.yaml
33 changes: 19 additions & 14 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface DrawerPopupProps

// styles
styles?: DrawerStyles;
drawerRender?: (node: React.ReactNode) => React.ReactNode;
}

function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
Expand Down Expand Up @@ -121,6 +122,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
onKeyUp,

styles,
drawerRender,
} = props;

// ================================ Refs ================================
Expand Down Expand Up @@ -291,6 +293,22 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
leavedClassName={`${prefixCls}-content-wrapper-hidden`}
>
{({ className: motionClassName, style: motionStyle }, motionRef) => {
const content = (
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={classNames(className, drawerClassNames?.content)}
style={{
...style,
...styles?.content,
}}
{...pickAttrs(props, { aria: true })}
{...eventHandlers}
>
{children}
</DrawerPanel>
);
return (
<div
className={classNames(
Expand All @@ -305,20 +323,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
}}
{...pickAttrs(props, { data: true })}
>
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={classNames(className, drawerClassNames?.content)}
style={{
...style,
...styles?.content,
}}
{...pickAttrs(props, { aria: true })}
{...eventHandlers}
>
{children}
</DrawerPanel>
{drawerRender ? drawerRender(content) : content}
</div>
);
}}
Expand Down
7 changes: 7 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,11 @@ describe('rc-drawer-menu', () => {
);
unmount();
});
it('should support drawerRender', () => {
const { unmount } = render(
<Drawer drawerRender={dom => <div id="test">{dom}</div>} open />,
);
expect(document.querySelector('#test')).toBeTruthy();
unmount();
});
});

0 comments on commit 22618e8

Please sign in to comment.