Created
April 11, 2016 21:16
-
-
Save ColadaFF/3ac7a368873f8c430d782a655776ef3b to your computer and use it in GitHub Desktop.
implementation of modal using react, redux and bootstrap styles.
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
import * as actions from './constants'; | |
export function toggleModal(){ | |
return { | |
type: actions.TOGGLE_MODAL | |
}; | |
} |
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
export const TOGGLE_MODAL = "TOGGLE_MODAL"; |
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
import React,{Component} from 'react'; | |
import {connect} from 'react-redux'; | |
import ButtonComponent from './buttonModalComponent'; | |
import Modal from 'react-modal'; | |
import {toggleModal} from './actions'; | |
import {bindActionCreators} from 'redux'; | |
class ModalComponentDialog extends Component{ | |
constructor(props){ | |
super(props); | |
this.closeModal = this.closeModal.bind(this); | |
} | |
closeModal(){ | |
this.props.toggleModal(); | |
} | |
render(){ | |
const {modalStatus} = this.props; | |
const status = modalStatus ? "Verdadero": "Falso"; | |
return ( | |
<div> | |
<ButtonComponent/> | |
<Modal | |
isOpen={modalStatus} | |
onRequestClose={this.closeModal} | |
className="modal-dialog" | |
> | |
<div className="modal-content"> | |
<div className="modal-header"> | |
<button type="button" className="close" data-dismiss="modal" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
<h4 className="modal-title">Modal title</h4> | |
</div> | |
<div className="modal-body"> | |
<p>One fine body…</p> | |
</div> | |
<div className="modal-footer"> | |
<button type="button" className="btn btn-secondary" data-dismiss="modal" onClick={this.closeModal}>Close</button> | |
<button type="button" className="btn btn-primary" onClick={this.closeModal}>Save changes</button> | |
</div> | |
</div> | |
</Modal> | |
</div> | |
); | |
} | |
} | |
function mapStateToProps({modal}){ | |
return { | |
modalStatus: modal.get('modalState') | |
}; | |
} | |
function mapDispatchToProps(dispatch){ | |
return bindActionCreators({ | |
toggleModal | |
}, dispatch); | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(ModalComponentDialog); |
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
import * as actions from './constants'; | |
import Immutable from 'immutable'; | |
const initialState = Immutable.Map({ | |
modalState: false | |
}); | |
export default function(state = initialState, action){ | |
switch(action.type){ | |
case actions.TOGGLE_MODAL: | |
const actualState = state.get('modalState'); | |
const newState = actualState === false ? true : false; | |
return state.set('modalState', newState); | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment