UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

122 lines 8.6 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { BaseComponent, buttonProperties, css, divProperties, getId, getNativeProps } from '../../Utilities'; import { OverflowButtonType } from './Facepile.types'; import { FocusZone, FocusZoneDirection } from '../../FocusZone'; import { FacepileButton } from './FacepileButton'; import { Icon } from '../../Icon'; import { PersonaCoin, PersonaSize, PersonaInitialsColor } from '../../PersonaCoin'; import * as stylesImport from './Facepile.scss'; var styles = stylesImport; var Facepile = /** @class */ (function (_super) { tslib_1.__extends(Facepile, _super); function Facepile(props) { var _this = _super.call(this, props) || this; _this._ariaDescriptionId = getId(); return _this; } Facepile.prototype.render = function () { var _this = this; var _a = this.props, overflowButtonProps = _a.overflowButtonProps, overflowButtonType = _a.overflowButtonType; var _b = this.props, chevronButtonProps = _b.chevronButtonProps, maxDisplayablePersonas = _b.maxDisplayablePersonas, className = _b.className, personas = _b.personas, showAddButton = _b.showAddButton; var numPersonasToShow = Math.min(personas.length, maxDisplayablePersonas); // Added for deprecating chevronButtonProps. Can remove after v1.0 if (chevronButtonProps && !overflowButtonProps) { overflowButtonProps = chevronButtonProps; overflowButtonType = OverflowButtonType.downArrow; } return (React.createElement("div", { className: css('ms-Facepile', styles.root, className) }, React.createElement("div", { className: css('ms-Facepile-itemContainer', styles.itemContainer) }, showAddButton ? this._getAddNewElement() : null, this.onRenderAriaDescription(), React.createElement(FocusZone, { ariaDescribedBy: this._ariaDescriptionId, role: 'listbox', className: css('ms-Facepile-members', styles.members), direction: FocusZoneDirection.horizontal }, personas.slice(0, numPersonasToShow).map(function (persona, index) { var personaControl = _this._getPersonaControl(persona); return persona.onClick ? _this._getElementWithOnClickEvent(personaControl, persona, index) : _this._getElementWithoutOnClickEvent(personaControl, persona, index); })), overflowButtonProps ? this._getOverflowElement(numPersonasToShow) : null))); }; Facepile.prototype.onRenderAriaDescription = function () { var ariaDescription = this.props.ariaDescription; // If ariaDescription is given, descriptionId will be assigned to ariaDescriptionSpan, // otherwise it will be assigned to descriptionSpan. return ariaDescription && (React.createElement("span", { className: styles.screenReaderOnly, id: this._ariaDescriptionId }, ariaDescription)); }; Facepile.prototype._getPersonaControl = function (persona) { var _a = this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize; return (React.createElement(PersonaCoin, tslib_1.__assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, primaryText: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null)))); }; Facepile.prototype._getElementWithOnClickEvent = function (personaControl, persona, index) { return (React.createElement(FacepileButton, tslib_1.__assign({}, getNativeProps(persona, buttonProperties), { key: (!!persona.imageUrl ? 'i' : '') + index, "data-is-focusable": true, role: 'option', className: css('ms-Facepile-itemButton ms-Facepile-person', styles.itemButton), title: persona.personaName, 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", tslib_1.__assign({}, getNativeProps(persona, divProperties), { key: (!!persona.imageUrl ? 'i' : '') + index, "data-is-focusable": true, role: 'option', className: css('ms-Facepile-itemButton ms-Facepile-person', styles.itemButton), title: persona.personaName, onMouseMove: this._onPersonaMouseMove.bind(this, persona), onMouseOut: this._onPersonaMouseOut.bind(this, persona) }), personaControl)); }; Facepile.prototype._getOverflowElement = function (numPersonasToShow) { switch (this.props.overflowButtonType) { case OverflowButtonType.descriptive: return this._getDescriptiveOverflowElement(numPersonasToShow); case OverflowButtonType.downArrow: return this._getIconElement('ChevronDown'); case OverflowButtonType.more: return this._getIconElement('More'); default: return null; } }; Facepile.prototype._getDescriptiveOverflowElement = function (numPersonasToShow) { var _a = this.props, overflowButtonProps = _a.overflowButtonProps, personas = _a.personas, personaSize = _a.personaSize; var numPersonasNotPictured = personas.length - numPersonasToShow; if (!overflowButtonProps || numPersonasNotPictured < 1) { return null; } var personaNames = personas.slice(numPersonasToShow).map(function (p) { return p.personaName; }).join(', '); return (React.createElement(FacepileButton, tslib_1.__assign({}, overflowButtonProps, { ariaDescription: personaNames, className: css('ms-Facepile-descriptiveOverflowButton', 'ms-Facepile-itemButton', styles.descriptiveOverflowButton, styles.itemButton) }), React.createElement(PersonaCoin, { title: personaNames, size: personaSize, onRenderInitials: this._renderInitialsNotPictured(numPersonasNotPictured), initialsColor: PersonaInitialsColor.transparent }))); }; Facepile.prototype._getIconElement = function (icon) { var _a = this.props, overflowButtonProps = _a.overflowButtonProps, personaSize = _a.personaSize; var overflowInitialsIcon = true; return (React.createElement(FacepileButton, tslib_1.__assign({}, overflowButtonProps, { className: css('ms-Facepile-overflowButton', 'ms-Facepile-itemButton', styles.overflowButton, styles.itemButton) }), React.createElement(PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials(icon, overflowInitialsIcon), initialsColor: PersonaInitialsColor.transparent }))); }; Facepile.prototype._getAddNewElement = function () { var _a = this.props, addButtonProps = _a.addButtonProps, personaSize = _a.personaSize; return (React.createElement(FacepileButton, tslib_1.__assign({}, addButtonProps, { className: css('ms-Facepile-addButton', 'ms-Facepile-itemButton', styles.itemButton, styles.addButton) }), React.createElement(PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials('AddFriend') }))); }; 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.prototype._renderInitials = function (iconName, overflowButton) { return function () { return (React.createElement(Icon, { iconName: iconName, className: overflowButton ? styles.overflowInitialsIcon : '' })); }; }; Facepile.prototype._renderInitialsNotPictured = function (numPersonasNotPictured) { return function () { return (React.createElement("span", { className: styles.overflowInitialsIcon }, '+' + numPersonasNotPictured)); }; }; Facepile.defaultProps = { maxDisplayablePersonas: 5, personas: [], personaSize: PersonaSize.size32 }; return Facepile; }(BaseComponent)); export { Facepile }; //# sourceMappingURL=Facepile.js.map