-
-
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 2 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
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,122 @@ | ||
import { | ||
AppstoreOutlined, | ||
MailOutlined, | ||
SettingOutlined, | ||
} from '@ant-design/icons'; | ||
import { Menu } from 'antd'; | ||
import * as React from 'react'; | ||
|
||
import Drawer from 'rc-drawer'; | ||
|
||
import 'antd/lib/menu/style'; | ||
import 'antd/lib/style'; | ||
QdabuliuQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import '../../assets/index.less'; | ||
import './assets/index.less'; | ||
import motionProps from './motion'; | ||
|
||
const { SubMenu } = Menu; | ||
const MenuItemGroup = Menu.ItemGroup; | ||
|
||
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} | ||
onClose={() => setOpen(false)} | ||
resizable={resizable} | ||
{...motionProps} | ||
> | ||
<Menu | ||
defaultSelectedKeys={['1']} | ||
defaultOpenKeys={['sub1']} | ||
mode="inline" | ||
> | ||
<SubMenu | ||
key="sub1" | ||
title={ | ||
<span> | ||
<MailOutlined /> | ||
<span>导航一</span> | ||
</span> | ||
} | ||
> | ||
<MenuItemGroup key="g1" title="分组1"> | ||
<Menu.Item key="1">选项1</Menu.Item> | ||
<Menu.Item key="2">选项2</Menu.Item> | ||
</MenuItemGroup> | ||
<MenuItemGroup key="g2" title="分组2"> | ||
<Menu.Item key="3">选项3</Menu.Item> | ||
<Menu.Item key="4">选项4</Menu.Item> | ||
</MenuItemGroup> | ||
</SubMenu> | ||
<SubMenu | ||
key="sub2" | ||
title={ | ||
<span> | ||
<AppstoreOutlined /> | ||
<span>导航二</span> | ||
</span> | ||
} | ||
> | ||
<Menu.Item key="5">选项5</Menu.Item> | ||
<Menu.Item key="6">选项6</Menu.Item> | ||
<SubMenu key="sub3" title="子菜单"> | ||
<Menu.Item key="7">选项7</Menu.Item> | ||
<Menu.Item key="8">选项8</Menu.Item> | ||
</SubMenu> | ||
</SubMenu> | ||
<SubMenu | ||
key="sub4" | ||
title={ | ||
<span> | ||
<SettingOutlined /> | ||
<span>导航三</span> | ||
</span> | ||
} | ||
> | ||
<Menu.Item key="9">选项9</Menu.Item> | ||
<Menu.Item key="10">选项10</Menu.Item> | ||
<Menu.Item key="11">选项11</Menu.Item> | ||
<Menu.Item key="12">选项12</Menu.Item> | ||
</SubMenu> | ||
</Menu> | ||
<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.