Skip to content

Instantly share code, notes, and snippets.

@josephmisiti
Created January 22, 2016 15:42
Show Gist options
  • Save josephmisiti/8e6120b1df417819fa69 to your computer and use it in GitHub Desktop.
Save josephmisiti/8e6120b1df417819fa69 to your computer and use it in GitHub Desktop.
var React = require('react');
var Router = require('react-router');
var Constants = require("../../constants/Constants")
var If = require("../common/If.react")
var Accordion = React.createClass({
propTypes: {
title: React.PropTypes.string,
buttonTitle: React.PropTypes.string,
identifier: React.PropTypes.string,
getBody: React.PropTypes.func,
onSubmitForm: React.PropTypes.func,
},
getDefaultProps: function() {
var accordingClass = 'panel-collapse collapse';
if (Constants.DEFAULTS.ExpandAccordions) {
accordingClass= 'panel-collapse collapse in';
}
return {
useFooter: false,
buttonTitle: Constants.DEFAULTS.ButtonTitle,
onSubmitForm: function() { alert("implement clicked"); },
useSearch: false,
accordingClass: accordingClass,
};
},
handleUpdates: function(ev){
ev.stopPropagation();
this.props.onSubmitForm();
},
render: function() {
var href = '#' + this.props.identifier;
var body = this.props.getBody();
return (
<div className="panel-group">
<div className="panel panel-default">
<div className="panel-heading">
<h4 className="panel-title">
<a data-toggle="collapse" href={href}>
{this.props.title}
</a>
</h4>
<br/>
<div id={this.props.identifier} className={this.props.accordingClass}>
<If test={this.props.useFooter}>
<form onSubmit={this.props.onSubmitForm}>
{body}
<div className="panel-footer">
<button type="submit"
className="btn btn-danger">{this.props.buttonTitle}</button>
<If test={this.props.useSearch}>
<button type="submit"
className="btn btn-danger">Submit</button>
</If>
</div>
</form>
</If>
<If test={!this.props.useFooter}>
<div>
{body}
</div>
</If>
</div>
</div>
</div>
</div>);
},
});
module.exports = Accordion;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment