hbp-quickfire
Version:
A library of useful user-interface components built with React on top of React Bootstrap and MobX
88 lines (51 loc) • 12.1 kB
JavaScript
var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _dec, _class, _class2, _temp2;function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;} /*
* Copyright (c) Human Brain Project
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from "react";import Panel from "react-bootstrap/lib/Panel";import Glyphicon from "react-bootstrap/lib/Glyphicon";
import injectStyles from "react-jss";import isFunction from "lodash/isFunction";import uniqueId from "lodash/uniqueId";
var styles = {
actionButtonContainer: {
float: "right" },
actionButton: {
paddingLeft: "5px" } };var
GenericListItem = (_dec = injectStyles(styles), _dec(_class = (_temp2 = _class2 = function (_React$Component) {_inherits(GenericListItem, _React$Component);function GenericListItem() {var _ref;var _temp, _this, _ret;_classCallCheck(this, GenericListItem);for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = GenericListItem.__proto__ || Object.getPrototypeOf(GenericListItem)).call.apply(_ref, [this].concat(args))), _this), _this.
state = {
expanded: _this.props.expanded }, _temp), _possibleConstructorReturn(_this, _ret);}_createClass(GenericListItem, [{ key: "handleToggle", value: function handleToggle(
expanded) {var _this2 = this;
if (isFunction(this.props.onBeforeToggle)) {
this.props.onBeforeToggle(function () {_this2.setState({ expanded: expanded });}, expanded, this.props.item);
} else {
this.setState({ expanded: expanded });
}
if (isFunction(this.props.onToggle)) {
this.props.onToggle(expanded, this.props.item);
}
} }, { key: "render", value: function render()
{var _props =
this.props,classes = _props.classes,actions = _props.actions,item = _props.item,ItemTitle = _props.itemTitle,ItemBody = _props.itemBody;
var expanded = this.state.expanded;
var expandedIcon = expanded ? "chevron-up" : "chevron-down";
return (
React.createElement(Panel, {
expanded: expanded,
onToggle: this.handleToggle.bind(this),
className: "quickfire-generic-list-item" },
React.createElement(Panel.Heading, null,
React.createElement("div", { className: classes.actionButtonContainer },
actions.map(function (action) {return (
React.cloneElement(action, {
key: uniqueId("action_"),
onClick: function onClick() {return action.props.onClick(item);},
className: [action.props.className, classes.actionButton] }));}),
ItemBody &&
React.createElement(Panel.Toggle, { className: classes.actionButton },
React.createElement(Glyphicon, { glyph: expandedIcon }))),
React.createElement(Panel.Title, null,
React.createElement(ItemTitle, { item: item }))),
ItemBody &&
React.createElement(Panel.Body, { collapsible: true },
React.createElement(ItemBody, { item: item }))));
} }]);return GenericListItem;}(React.Component), _class2.defaultProps = { itemTitle: function itemTitle(_ref2) {var item = _ref2.item;return item;}, actions: [], items: [], expanded: false }, _temp2)) || _class);export { GenericListItem as default };