|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +Object.defineProperty(exports, "__esModule", { |
| 4 | + value: true |
| 5 | +}); |
| 6 | + |
| 7 | +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; }; })(); |
| 8 | + |
| 9 | +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; |
| 10 | + |
| 11 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
| 12 | + |
| 13 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 14 | + |
| 15 | +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; } |
| 16 | + |
| 17 | +var _react = require("react"); |
| 18 | + |
| 19 | +var _react2 = _interopRequireDefault(_react); |
| 20 | + |
| 21 | +function isTrue(test) { |
| 22 | + var didMatch = false; |
| 23 | + |
| 24 | + if (test) { |
| 25 | + if (test.call) { |
| 26 | + //it's a function |
| 27 | + didMatch = test(); |
| 28 | + } else { |
| 29 | + didMatch = test; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + return didMatch ? true : false; |
| 34 | +} |
| 35 | + |
| 36 | +var Condition = (function (_React$Component) { |
| 37 | + _inherits(Condition, _React$Component); |
| 38 | + |
| 39 | + function Condition(props) { |
| 40 | + _classCallCheck(this, Condition); |
| 41 | + |
| 42 | + _get(Object.getPrototypeOf(Condition.prototype), "constructor", this).call(this, props); |
| 43 | + } |
| 44 | + |
| 45 | + _createClass(Condition, [{ |
| 46 | + key: "render", |
| 47 | + value: function render() { |
| 48 | + |
| 49 | + var childToRender = null; |
| 50 | + |
| 51 | + var child; |
| 52 | + for (var i = 0; i < this.props.children.length; i++) { |
| 53 | + child = this.props.children[i]; |
| 54 | + |
| 55 | + if (isTrue(child.props.test) || child.props["default"]) { |
| 56 | + childToRender = child; |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return childToRender; |
| 62 | + } |
| 63 | + }]); |
| 64 | + |
| 65 | + return Condition; |
| 66 | +})(_react2["default"].Component); |
| 67 | + |
| 68 | +exports.Condition = Condition; |
| 69 | + |
| 70 | +var Case = (function (_React$Component2) { |
| 71 | + _inherits(Case, _React$Component2); |
| 72 | + |
| 73 | + function Case(props) { |
| 74 | + _classCallCheck(this, Case); |
| 75 | + |
| 76 | + _get(Object.getPrototypeOf(Case.prototype), "constructor", this).call(this, props); |
| 77 | + |
| 78 | + this.match = false; |
| 79 | + } |
| 80 | + |
| 81 | + _createClass(Case, [{ |
| 82 | + key: "didMatch", |
| 83 | + value: function didMatch() { |
| 84 | + return this.match; |
| 85 | + } |
| 86 | + }, { |
| 87 | + key: "render", |
| 88 | + value: function render() { |
| 89 | + |
| 90 | + this.match = isTrue(this.props.test) || this.props["default"]; |
| 91 | + |
| 92 | + if (!this.match) { |
| 93 | + return null; |
| 94 | + } |
| 95 | + |
| 96 | + return _react2["default"].createElement( |
| 97 | + "span", |
| 98 | + null, |
| 99 | + this.props.children |
| 100 | + ); |
| 101 | + } |
| 102 | + }]); |
| 103 | + |
| 104 | + return Case; |
| 105 | +})(_react2["default"].Component); |
| 106 | + |
| 107 | +exports.Case = Case; |
| 108 | + |
0 commit comments