UNPKG

electrode-houseparty-example-component

Version:
132 lines (98 loc) 4.14 kB
"use strict"; exports.__esModule = true; var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn"); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require("babel-runtime/helpers/inherits"); var _inherits3 = _interopRequireDefault(_inherits2); var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _houseParty = require("../../src/styles/house-party.css"); var _houseParty2 = _interopRequireDefault(_houseParty); var _renderFriend = require("./render-friend"); var _renderFriend2 = _interopRequireDefault(_renderFriend); var _guestList = require("./guest-list"); var _guestList2 = _interopRequireDefault(_guestList); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var HouseParty = function (_Component) { (0, _inherits3.default)(HouseParty, _Component); function HouseParty(props) { (0, _classCallCheck3.default)(this, HouseParty); return (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props)); } HouseParty.prototype.renderFriends = function renderFriends(friends, party) { var invitees = this.props.invitees; var partyTime = party ? _houseParty2.default.party : ""; return friends.filter(function (friend) { return !!invitees.filter(function (invitee) { return invitee.name === friend.name && invitee.invited; }).length; }).map(function (friend) { return _react2.default.createElement(_renderFriend2.default, { className: partyTime, key: friend.name, friend: friend }); }); }; HouseParty.prototype.viewState = function viewState(view) { if (view) { return view; } return { intro: true, invite: true }; }; HouseParty.prototype.houseParty = function houseParty(invitees, party) { return party ? _houseParty2.default.houseParty + " " + _houseParty2.default.house : _houseParty2.default.house; }; HouseParty.prototype.render = function render() { var _props = this.props; var ourFriends = _props.ourFriends; var invitees = _props.invitees; var view = _props.view; var message = _props.message; var _toggleGuest = _props.toggleGuest; var party = invitees.length === invitees.filter(function (invitee) { return invitee.invited; }).length && invitees.length > 0; var _viewState = this.viewState(view); var invite = _viewState.invite; var intro = _viewState.intro; var houseParty = this.houseParty(invitees, party); return _react2.default.createElement( "div", null, invite && invitees.length > 0 && _react2.default.createElement(_guestList2.default, { invitees: invitees, toggleGuest: function toggleGuest(invitee) { return _toggleGuest(invitee); } }), _react2.default.createElement( "div", { className: _houseParty2.default.container }, intro && !invitees.filter(function (invitee) { return invitee.invited; }).length && message(_houseParty2.default.message), _react2.default.createElement( "div", { className: houseParty }, _react2.default.createElement( "div", { className: _houseParty2.default.room }, this.renderFriends(ourFriends, party) ) ) ) ); }; return HouseParty; }(_react.Component); exports.default = HouseParty; HouseParty.displayName = "HouseParty"; HouseParty.propTypes = { ourFriends: _react.PropTypes.array, message: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.funct]), invitees: _react.PropTypes.array, view: _react.PropTypes.object, toggleGuest: _react.PropTypes.func }; HouseParty.defaultProps = { message: "<p>Let's party! Un-comment the all the commented-out lines in the\n playground then check the boxes on the GuestList to invite our friends to the party!</p>" };