This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Confirm to ConfirmDialog, add ConfirmDialogProvider.
- Loading branch information
Showing
3 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import ConfirmDialog from './ConfirmDialog.react' | ||
|
||
|
||
|
||
/** | ||
* Wrap children onClick to send a confirmation dialog. | ||
*/ | ||
export default class ConfirmDialogProvider extends React.Component { | ||
render() { | ||
const { id, style, setProps, children } = this.props; | ||
|
||
// Will lose the previous onClick of the child | ||
const wrapClick = (child) => React.cloneElement(child, {onClick: (e) => | ||
{ | ||
setProps({ | ||
send_confirm: true | ||
}); | ||
} | ||
}); | ||
|
||
const realChild = children.props ? children.props.children : children; | ||
|
||
return ( | ||
<div id={id}> | ||
{realChild && realChild.length ? realChild.map(wrapClick) : | ||
wrapClick(children.props.children)} | ||
<ConfirmDialog ref={this._dialog} {...this.props}/> | ||
</div> | ||
) | ||
} | ||
}; | ||
|
||
ConfirmDialogProvider.defaultProps = { | ||
n_clicks: 0, | ||
n_clicks_timestamp: -1, | ||
submit_n_clicks: 0, | ||
cancel_n_clicks: 0, | ||
}; | ||
|
||
ConfirmDialogProvider.propTypes = { | ||
id: PropTypes.string, | ||
|
||
/** | ||
* Message to show in the popup. | ||
*/ | ||
message: PropTypes.string, | ||
|
||
/** | ||
* Number of times the modal was submited or canceled. | ||
*/ | ||
n_clicks: PropTypes.number, | ||
/** | ||
* Last timestamp the popup was clicked. | ||
*/ | ||
n_clicks_timestamp: PropTypes.number, | ||
/** | ||
* Number of times the submit was clicked | ||
*/ | ||
submit_n_clicks: PropTypes.number, | ||
/** | ||
* Number of times the popup was canceled. | ||
*/ | ||
cancel_n_clicks: PropTypes.number, | ||
/** | ||
* Set to true to send the popup. | ||
*/ | ||
send_confirm: PropTypes.bool, | ||
/** | ||
* Is the modal currently displayed. | ||
*/ | ||
displayed: PropTypes.bool, | ||
|
||
/** | ||
* Dash-assigned callback that gets fired when the value changes. | ||
*/ | ||
setProps: PropTypes.func, | ||
children: PropTypes.any, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters