Skip to content
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

feat: drawer loading prop #462

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ReactDom.render(
| height | string \| number | null | drawer content wrapper height, drawer level transition height |
| open | boolean | false | open or close menu |
| defaultOpen | boolean | false | default open menu |
| loading | HTMLElement \| null | null | loading element |
| placement | string | `left` | `left` `top` `right` `bottom` |
| level | string \| array | `all` | With the drawer level element. `all`/ null / className / id / tagName / array |
| levelMove | number \| array \| func | null | level move value. default is drawer width |
Expand Down
8 changes: 8 additions & 0 deletions docs/demo/loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: loading
nav:
title: Loading
path: /loading
---

<code src="../examples/loading.tsx"></code>
39 changes: 39 additions & 0 deletions docs/examples/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useState } from 'react';
import Drawer from 'rc-drawer';
import motionProps from './motion';

const Demo = () => {
const [open, setOpen] = useState(false);
const onTouchEnd = () => {
setOpen(false);
};
const onSwitch = () => {
setOpen(c => !c);
};
return (
<div>
<Drawer
open={open}
// defaultOpen
onClose={onTouchEnd}
afterOpenChange={(c: boolean) => {
console.log('transitionEnd: ', c);
}}
placement="right"
// width={400}
width="60%"
//loading
loading={<div>Loading...</div>}
// Motion
{...motionProps}
>
content
</Drawer>
<div>
<button onClick={onSwitch}>打开</button>
</div>
</div>
);
};
export default Demo;
1 change: 1 addition & 0 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface DrawerProps
panelRef?: React.Ref<HTMLDivElement>;
classNames?: DrawerClassNames;
styles?: DrawerStyles;
loading?: React.ReactNode;
}

const Drawer: React.FC<DrawerProps> = props => {
Expand Down
4 changes: 3 additions & 1 deletion src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DrawerPopupProps
forceRender?: boolean;
autoFocus?: boolean;
keyboard?: boolean;
loading?: React.ReactNode;

// Root
rootClassName?: string;
Expand Down Expand Up @@ -86,6 +87,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
forceRender,
autoFocus,
keyboard,
loading,

// classNames
classNames: drawerClassNames,
Expand Down Expand Up @@ -317,7 +319,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
{...pickAttrs(props, { aria: true })}
{...eventHandlers}
>
{children}
{loading ? loading : children}
</DrawerPanel>
</div>
);
Expand Down