🌎 Example
- Drag with title bar.
- Resize with handle.
- Keep in bounds.
- During drag.
- During resize.
- During resize window.
- Multiple modals with managed
zIndex
. - Open from center.
- Better API for using as a controlled component.
- Open from quadrants.
- Better escape key management.
- Resize with option key.
yarn add ant-design-draggable-modal
NOTE: You must use [email protected]
and [email protected]
or higher.
import React, { useState, useCallback } from 'react'
import { Button } from 'antd'
import { DraggableModal, DraggableModalProvider } from 'ant-design-draggable-modal'
import 'antd/dist/reset.css'
import 'ant-design-draggable-modal/dist/index.css'
const ModalWithButton = () => {
const [open, setOpen] = useState(false)
const onOk = useCallback(() => setOpen(true), [])
const onCancel = useCallback(() => setOpen(false), [])
return (
<>
<Button onClick={onOk}>Open</Button>
<DraggableModal open={open} onOk={onOk} onCancel={onCancel}>
Body text.
</DraggableModal>
</>
)
}
// DraggableModalProvider manages the zIndex
// of DraggableModals rendered beneath it.
const App = () => (
<DraggableModalProvider>
<ModalWithButton />
<ModalWithButton />
<ModalWithButton />
</DraggableModalProvider>
)
You should probably try to design your app not to need to use this, apps should usually not be window managers.
MIT © DylanVann