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

支持draggable #61

Closed
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ ReactDOM.render(
<td></td>
<td>to determine where Dialog will be mounted</td>
</tr>
<tr>
<td>draggable</td>
<td>Boolean</td>
<td>false</td>
<td>control draggable</td>
</tr>
<tr>
<td>draggableProps</td>
<td>Object</td>
<td></td>
<td>draggable props from react-draggable(https://github.com/mzabriskie/react-draggable) </td>
</tr>
</tbody>
</table>

Expand Down
16 changes: 16 additions & 0 deletions examples/ant-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MyControl extends React.Component {
width: 600,
destroyOnClose: false,
center: false,
draggable: false,
};
onClick = (e) => {
this.setState({
Expand Down Expand Up @@ -43,6 +44,11 @@ class MyControl extends React.Component {
center: e.target.checked,
});
}
draggable = (e) => {
this.setState({
draggable: e.target.checked,
});
}
render() {
let dialog;
if (this.state.visible || !this.state.destroyOnClose) {
Expand All @@ -61,6 +67,7 @@ class MyControl extends React.Component {
maskAnimation="fade"
onClose={this.onClose}
style={style}
draggable={this.state.draggable}
mousePosition={this.state.mousePosition}
>
<input />
Expand Down Expand Up @@ -108,6 +115,15 @@ class MyControl extends React.Component {
onChange={this.center}
/>
</label>

&nbsp;
<label>draggable
<input
type="checkbox"
checked={this.state.draggable}
onChange={this.draggable}
/>
</label>
</p>
{dialog}
</div>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"create-react-class": "^15.5.2",
"object-assign": "~4.1.0",
"rc-animate": "2.x",
"rc-util": "^4.0.4"
"rc-util": "^4.0.4",
"react-draggable": "^2.2.6"
}
}
38 changes: 23 additions & 15 deletions src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LazyRenderBox from './LazyRenderBox';
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
import IDialogPropTypes from './IDialogPropTypes';
import assign from 'object-assign';
import Draggable from 'react-draggable';

let uuid = 0;
let openCount = 0;
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {
closable: true,
maskClosable: true,
prefixCls: 'rc-dialog',
draggable: false,
onClose: noop,
};
componentWillMount() {
Expand Down Expand Up @@ -144,6 +146,7 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {
}
}
}

getDialogElement = () => {
const props = this.props;
const closable = props.closable;
Expand Down Expand Up @@ -190,6 +193,7 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {

const style = assign({}, props.style, dest);
const transitionName = this.getTransitionName();
const draggableProps = assign({}, { onStart: () => props.draggable }, props.draggableProps);
const dialogElement = (
<LazyRenderBox
key="dialog-element"
Expand All @@ -199,22 +203,26 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {
className={`${prefixCls} ${props.className || ''}`}
visible={props.visible}
>
<div className={`${prefixCls}-content`}>
{closer}
{header}
<div
className={`${prefixCls}-body`}
style={props.bodyStyle}
ref="body"
{...props.bodyProps}
>
{props.children}
<Draggable {...draggableProps}>
<div>
<div className={`${prefixCls}-content`}>
{closer}
{header}
<div
className={`${prefixCls}-body`}
style={props.bodyStyle}
ref="body"
{...props.bodyProps}
>
{props.children}
</div>
{footer}
</div>
<div tabIndex={0} ref="sentinel" style={{ width: 0, height: 0, overflow: 'hidden' }}>
sentinel
</div>
</div>
{footer}
</div>
<div tabIndex={0} ref="sentinel" style={{ width: 0, height: 0, overflow: 'hidden' }}>
sentinel
</div>
</Draggable>
</LazyRenderBox>
);
return (
Expand Down