UNPKG

fk-react-ui-components

Version:

Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should

169 lines (143 loc) 8.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 _react = require("react"); var _react2 = _interopRequireDefault(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _checkboxTree = require("../styles/checkbox-tree"); var _Layout = require("../../Layout"); var _lodash = require("lodash"); var _lodash2 = _interopRequireDefault(_lodash); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } /** * Created by manoraj.k on 17/08/17. */ var CheckboxTreeItem = function (_React$Component) { _inherits(CheckboxTreeItem, _React$Component); function CheckboxTreeItem(props) { _classCallCheck(this, CheckboxTreeItem); var _this = _possibleConstructorReturn(this, (CheckboxTreeItem.__proto__ || Object.getPrototypeOf(CheckboxTreeItem)).call(this, props)); _lodash2.default.bindAll(_this, 'onCheck', 'onExpand', 'getCheckboxIcon', 'getCollapseBtn'); return _this; } _createClass(CheckboxTreeItem, [{ key: "onCheck", value: function onCheck() { if (this.props.disabled || this.props.noCheckbox) { return true; } var isChecked = this.props.checked === 0 || this.props.checked === 2; this.props.onCheck({ value: this.props.value, checked: isChecked, children: this.props.listChildren }); } }, { key: "onExpand", value: function onExpand() { if (this.props.expandDisabled) { return true; } this.props.onExpand({ value: this.props.value, expanded: !this.props.expanded, children: this.props.listChildren }); } }, { key: "getCheckboxIcon", value: function getCheckboxIcon() { var _props = this.props, getCheckboxIcon = _props.getCheckboxIcon, checked = _props.checked; if (getCheckboxIcon && typeof getCheckboxIcon === "function") { return getCheckboxIcon(checked); } else { var iconName = void 0; switch (checked) { case 0: iconName = "fa fa-square-o"; break; case 1: iconName = "fa fa-check-square"; break; default: iconName = "fa fa-check-square-o"; break; } return _react2.default.createElement("i", { className: iconName }); } } }, { key: "getCollapseBtn", value: function getCollapseBtn() { var _props2 = this.props, getCollapseIcon = _props2.getCollapseIcon, expanded = _props2.expanded; var icon = ""; if (getCollapseIcon && typeof getCollapseIcon === "function") { icon = getCollapseIcon(expanded); } else if (expanded) { icon = _react2.default.createElement("i", { className: "fa fa-chevron-up" }); } else { icon = _react2.default.createElement("i", { className: "fa fa-chevron-down" }); } return _react2.default.createElement( _Layout.FlexCell, { flex: "0.6" }, _react2.default.createElement( "button", { className: "checkbox-tree-collapse-btn", onClick: this.onExpand }, icon ) ); } }, { key: "render", value: function render() { var _props3 = this.props, expanded = _props3.expanded, listChildren = _props3.listChildren, label = _props3.label, labelClassName = _props3.labelClassName, className = _props3.className, noCheckbox = _props3.noCheckbox; return _react2.default.createElement( "li", { className: "checkbox-tree-item " + (className || "") }, _react2.default.createElement( _Layout.Flex, null, _react2.default.createElement( _Layout.FlexCell, { flex: "1.3", onClick: this.onCheck }, _react2.default.createElement( "span", { className: "checkbox-tree-box " + (noCheckbox ? "hide-checkbox" : "") }, this.getCheckboxIcon() ), _react2.default.createElement( "span", { className: "checkbox-tree-label " + (labelClassName || "") }, label ) ), listChildren ? this.getCollapseBtn() : "" ), expanded && _react2.default.createElement( "div", { className: "child-list" }, this.props.children ) ); } }]); return CheckboxTreeItem; }(_react2.default.Component); exports.default = CheckboxTreeItem;