-
-
Notifications
You must be signed in to change notification settings - Fork 101
feat: add resizable drawer feature #527
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
Changes from 3 commits
706a0fe
24cf9dd
637e2d2
6452a4c
b02938f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: resizable | ||
nav: | ||
title: Resizable | ||
path: /resizable | ||
--- | ||
|
||
<code src="../examples/resizable.tsx"></code> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from 'react'; | ||
|
||
import Drawer from 'rc-drawer'; | ||
|
||
import '../../assets/index.less'; | ||
import './assets/index.less'; | ||
import motionProps from './motion'; | ||
|
||
export default () => { | ||
const [open, setOpen] = React.useState(false); | ||
const [placement, setPlacement] = React.useState< | ||
'left' | 'right' | 'top' | 'bottom' | ||
QdabuliuQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
>('right'); | ||
const [resizable, setResizable] = React.useState(true); | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginBottom: 16 }}> | ||
<button onClick={() => setOpen(true)} style={{ marginRight: 8 }}> | ||
打开抽屉 | ||
</button> | ||
<label style={{ marginRight: 8 }}> | ||
<input | ||
type="checkbox" | ||
checked={resizable} | ||
onChange={e => setResizable(e.target.checked)} | ||
/> | ||
可拖拽调整大小 | ||
</label> | ||
<span>位置:</span> | ||
<select | ||
value={placement} | ||
onChange={e => setPlacement(e.target.value as any)} | ||
QdabuliuQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<option value="left">左侧</option> | ||
<option value="right">右侧</option> | ||
<option value="top">顶部</option> | ||
<option value="bottom">底部</option> | ||
</select> | ||
</div> | ||
<Drawer | ||
width={placement === 'left' || placement === 'right' ? 320 : undefined} | ||
height={placement === 'top' || placement === 'bottom' ? 240 : undefined} | ||
placement={placement} | ||
open={open} | ||
key={placement} | ||
onClose={() => setOpen(false)} | ||
resizable={resizable} | ||
{...motionProps} | ||
> | ||
<div style={{ marginTop: 24, color: '#888' }}> | ||
<p>你可以拖拽抽屉边缘调整大小(仅在勾选“可拖拽调整大小”时生效)。</p> | ||
</div> | ||
</Drawer> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,11 @@ export interface DrawerProps | |
panelRef?: React.Ref<HTMLDivElement>; | ||
classNames?: DrawerClassNames; | ||
styles?: DrawerStyles; | ||
/** 是否启用调整大小功能 */ | ||
QdabuliuQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resizable?: boolean; | ||
onResize?: (size: number) => void; | ||
onResizeStart?: () => void; | ||
onResizeEnd?: () => void; | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不确定是否需要一开始暴露这么多回调,看看大佬们怎么说~ 也可以说说你的想法 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的嘞,我觉得有必要暴露出去,因为 antd/drawer 组件使用的时候需要监听到 start / end 事件,取消 / 恢复 transition 过渡 antd/drawer 宽度的样式,这样在拖拽的时候可以动态开启和关闭 transition 影响。 |
||
} | ||
|
||
const Drawer: React.FC<DrawerProps> = props => { | ||
|
@@ -48,6 +53,9 @@ const Drawer: React.FC<DrawerProps> = props => { | |
onClick, | ||
onKeyDown, | ||
onKeyUp, | ||
onResize, | ||
onResizeStart, | ||
onResizeEnd, | ||
|
||
// Refs | ||
panelRef, | ||
|
@@ -114,6 +122,9 @@ const Drawer: React.FC<DrawerProps> = props => { | |
onClick, | ||
onKeyDown, | ||
onKeyUp, | ||
onResize, | ||
onResizeStart, | ||
onResizeEnd, | ||
}; | ||
const drawerPopupProps = { | ||
...props, | ||
|
Uh oh!
There was an error while loading. Please reload this page.