parent
0aaec02b84
commit
03d28c2007
@ -0,0 +1,53 @@
|
||||
import React, {Component} from "react";
|
||||
import ModalConfirm from "./ModalConfirm";
|
||||
|
||||
|
||||
class ButtonWithConfirm extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._modalConfirm=React.createRef();
|
||||
this.state={
|
||||
focused:false
|
||||
}
|
||||
}
|
||||
|
||||
getComponent= (key) => {
|
||||
return this.props.children.filter( (comp) => {
|
||||
return comp.key === key;
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const classNames=this.props.className.split(" ");
|
||||
|
||||
let classNameForDiv="";
|
||||
let classNameForButton="";
|
||||
classNames.forEach(function(className){
|
||||
if(className==="input-group-prepend" || className==="input-group-append" ){
|
||||
classNameForDiv+=" "+className;
|
||||
}else{
|
||||
classNameForButton+=" "+className;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className={classNameForDiv}>
|
||||
<button
|
||||
className={classNameForButton}
|
||||
onClick={() => { this._modalConfirm.current.toggle() }}
|
||||
>{this.getComponent("button")}
|
||||
</button>
|
||||
<ModalConfirm className={this.props.modalClassName} ref={this._modalConfirm}>
|
||||
<div key="title">{this.getComponent("modal-title")}</div>
|
||||
<div key="body">{this.getComponent("modal-body")}</div>
|
||||
<div key="confirm">{this.getComponent("modal-confirm")}</div>
|
||||
<div key="cancel">{this.getComponent("modal-cancel")}</div>
|
||||
</ModalConfirm>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ButtonWithConfirm;
|
@ -0,0 +1,40 @@
|
||||
import React, {Component} from "react";
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||
|
||||
class ModalConfirm extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
modal: false
|
||||
};
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.setState({
|
||||
modal: !this.state.modal
|
||||
});
|
||||
};
|
||||
|
||||
getComponent= (key) => {
|
||||
return this.props.children.filter( (comp) => {
|
||||
return comp.key === key;
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className+" modal-dialog-centered"} >
|
||||
<ModalHeader toggle={this.toggle}>{this.getComponent("title")}</ModalHeader>
|
||||
<ModalBody>
|
||||
{this.getComponent("body")}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="primary" onClick={this.toggle}>{this.getComponent("confirm")}</Button>{' '}
|
||||
<Button color="secondary" onClick={this.toggle}>{this.getComponent("cancel")}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ModalConfirm;
|
Loading…
Reference in new issue