office-ui-fabric-react
Version: 
Reusable React components for building experiences for Office 365.
103 lines (102 loc) • 6.72 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
define(["require", "exports", 'react', '../../utilities/css', '../../Persona', '../../utilities/properties', './Facepile.scss'], function (require, exports, React, css_1, Persona_1, properties_1) {
    "use strict";
    var Facepile = (function (_super) {
        __extends(Facepile, _super);
        function Facepile() {
            _super.apply(this, arguments);
        }
        Facepile.prototype.render = function () {
            var _this = this;
            this.numPersonasToShow = this._calulateNumPersonasToShow();
            var personalDetailsHidden = this.props.personas.length > 1;
            return (React.createElement("div", {className: 'ms-Facepile'}, 
                React.createElement("div", {className: 'ms-Facepile-members'}, 
                    this.props.showAddButton ? this._getAddNewElement() : null, 
                    this._getPersonasToDisplay().map(function (persona, index) {
                        var personaControl = _this._getPersonaControl(persona);
                        return persona.onClick ?
                            _this._getElementWithOnClickEvent(personaControl, persona, index) :
                            _this._getElementWithoutOnClickEvent(personaControl, persona, index);
                    }), 
                    this.props.overflowButtonProps ? this._getOverflowElement() : null, 
                    this.props.chevronButtonProps && personalDetailsHidden ? this._getChevronElement() : null)
            ));
        };
        Facepile.prototype._getPersonasToDisplay = function () {
            var personasToShow = this.props.personas.slice(0, this.numPersonasToShow);
            return personasToShow;
        };
        Facepile.prototype._getPersonasNotToDisplay = function () {
            var personasToShow = this.props.personas.slice(this.numPersonasToShow);
            return personasToShow;
        };
        Facepile.prototype._calulateNumPersonasToShow = function () {
            var maxShownPersonas = this.props.maxDisplayablePersonas != null ? this.props.maxDisplayablePersonas : Facepile.defaultProps.maxDisplayablePersonas;
            return this.props.personas.length < maxShownPersonas ? this.props.personas.length : maxShownPersonas;
        };
        Facepile.prototype._getPersonaControl = function (persona) {
            var personalDetailsHidden = this.props.personas.length > 1;
            return React.createElement(Persona_1.Persona, {imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, primaryText: persona.personaName, size: Persona_1.PersonaSize.extraSmall, hidePersonaDetails: personalDetailsHidden});
        };
        Facepile.prototype._getElementWithOnClickEvent = function (personaControl, persona, index) {
            return React.createElement("button", __assign({}, properties_1.getNativeProps(persona, properties_1.buttonProperties), {className: 'ms-Facepile-itemBtn ms-Facepile-itemBtn--member', title: persona.personaName, key: (!!persona.imageUrl ? 'i' : '') + index, onClick: this._onPersonaClick.bind(this, persona), onMouseMove: this._onPersonaMouseMove.bind(this, persona), onMouseOut: this._onPersonaMouseOut.bind(this, persona)}), personaControl);
        };
        Facepile.prototype._getElementWithoutOnClickEvent = function (personaControl, persona, index) {
            return React.createElement("div", __assign({}, properties_1.getNativeProps(persona, properties_1.divProperties), {className: 'ms-Facepile-itemBtn ms-Facepile-itemBtn--member', title: persona.personaName, key: (!!persona.imageUrl ? 'i' : '') + index, onMouseMove: this._onPersonaMouseMove.bind(this, persona), onMouseOut: this._onPersonaMouseOut.bind(this, persona)}), personaControl);
        };
        Facepile.prototype._getOverflowElement = function () {
            var numPersonasNotPictured = this.props.personas.length - this.numPersonasToShow;
            var hasPersonasNotPictured = numPersonasNotPictured > 0;
            if (!this.props.overflowButtonProps || !hasPersonasNotPictured) {
                return null;
            }
            return React.createElement("button", __assign({}, properties_1.getNativeProps(this.props.overflowButtonProps, properties_1.buttonProperties), {className: css_1.css('ms-Facepile-overflowBtn', 'ms-Facepile-itemBtn', 'ms-Persona-initials'), title: this._getPersonasNotToDisplay().map(function (persona, index) {
                return persona.personaName;
            }).join(', ')}), '+' + numPersonasNotPictured);
        };
        Facepile.prototype._getAddNewElement = function () {
            return React.createElement("button", __assign({}, properties_1.getNativeProps(this.props.addButtonProps, properties_1.buttonProperties), {className: css_1.css('ms-Facepile-addBtn', 'ms-Facepile-itemBtn', 'ms-Persona-initials')}), 
                React.createElement("i", {className: 'ms-Icon msIcon ms-Icon--AddFriend', "aria-hidden": 'true'})
            );
        };
        Facepile.prototype._getChevronElement = function () {
            return React.createElement("button", __assign({}, properties_1.getNativeProps(this.props.chevronButtonProps, properties_1.buttonProperties), {className: css_1.css('ms-Facepile-chevronBtn', 'ms-Facepile-itemBtn')}), 
                React.createElement("i", {className: 'ms-Icon msIcon ms-Icon--ChevronDown', "aria-hidden": 'true'})
            );
        };
        Facepile.prototype._onPersonaClick = function (persona, ev) {
            persona.onClick(ev, persona);
            ev.preventDefault();
            ev.stopPropagation();
        };
        Facepile.prototype._onPersonaMouseMove = function (persona, ev) {
            if (!!persona.onMouseMove) {
                persona.onMouseMove(ev, persona);
            }
        };
        Facepile.prototype._onPersonaMouseOut = function (persona, ev) {
            if (!!persona.onMouseOut) {
                persona.onMouseOut(ev, persona);
            }
        };
        Facepile.defaultProps = {
            maxDisplayablePersonas: 5,
            personas: []
        };
        return Facepile;
    }(React.Component));
    exports.Facepile = Facepile;
});