UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

144 lines 9.71 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { BaseComponent, buttonProperties, css, getId, getNativeProps } from '../../Utilities'; import { OverflowButtonType } from './Facepile.types'; import { FocusZone, FocusZoneDirection } from '../../FocusZone'; import { FacepileButton } from './FacepileButton'; import { Icon } from '../../Icon'; import { Persona } from '../../Persona'; import { PersonaCoin, PersonaSize, PersonaInitialsColor } from '../../PersonaCoin'; import * as stylesImport from './Facepile.scss'; var styles = stylesImport; var FacepileBase = /** @class */ (function (_super) { tslib_1.__extends(FacepileBase, _super); function FacepileBase(props) { var _this = _super.call(this, props) || this; _this._ariaDescriptionId = getId(); return _this; } FacepileBase.prototype.render = function () { var overflowButtonProps = this.props.overflowButtonProps; var _a = this.props, ariaDescription = _a.ariaDescription, chevronButtonProps = _a.chevronButtonProps, maxDisplayablePersonas = _a.maxDisplayablePersonas, className = _a.className, personas = _a.personas, overflowPersonas = _a.overflowPersonas, showAddButton = _a.showAddButton; var numPersonasToShow = Math.min(personas.length, maxDisplayablePersonas || personas.length); // Added for deprecating chevronButtonProps. Can remove after v1.0 if (chevronButtonProps && !overflowButtonProps) { overflowButtonProps = chevronButtonProps; } var hasOverflowPersonas = overflowPersonas && overflowPersonas.length > 0; var personasPrimary = hasOverflowPersonas ? personas : personas.slice(0, numPersonasToShow); var personasOverflow = (hasOverflowPersonas ? overflowPersonas : personas.slice(numPersonasToShow)) || []; return (React.createElement("div", { className: css('ms-Facepile', styles.root, className) }, this.onRenderAriaDescription(), React.createElement("div", { className: css('ms-Facepile-itemContainer', styles.itemContainer) }, showAddButton ? this._getAddNewElement() : null, React.createElement(FocusZone, { ariaDescribedBy: ariaDescription && this._ariaDescriptionId, role: 'listbox', className: css('ms-Facepile-members', styles.members), direction: FocusZoneDirection.horizontal }, this._onRenderVisiblePersonas(personasPrimary, personasOverflow.length === 0 && personas.length === 1)), overflowButtonProps ? this._getOverflowElement(personasOverflow) : null))); }; FacepileBase.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)); }; FacepileBase.prototype._onRenderVisiblePersonas = function (personas, singlePersona) { var _this = this; return personas.map(function (persona, index) { var personaControl = singlePersona ? _this._getPersonaControl(persona) : _this._getPersonaCoinControl(persona); return persona.onClick ? _this._getElementWithOnClickEvent(personaControl, persona, index) : _this._getElementWithoutOnClickEvent(personaControl, persona, index); }); }; FacepileBase.prototype._getPersonaControl = function (persona) { var _a = this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize; return (React.createElement(Persona, tslib_1.__assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, allowPhoneInitials: persona.allowPhoneInitials, text: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null)))); }; FacepileBase.prototype._getPersonaCoinControl = 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, allowPhoneInitials: persona.allowPhoneInitials, text: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null)))); }; FacepileBase.prototype._getElementWithOnClickEvent = function (personaControl, persona, index) { return (React.createElement(FacepileButton, tslib_1.__assign({}, getNativeProps(persona, buttonProperties), this._getElementProps(persona, index), { onClick: this._onPersonaClick.bind(this, persona) }), personaControl)); }; FacepileBase.prototype._getElementWithoutOnClickEvent = function (personaControl, persona, index) { return (React.createElement("div", tslib_1.__assign({}, getNativeProps(persona, buttonProperties), this._getElementProps(persona, index)), personaControl)); }; FacepileBase.prototype._getElementProps = function (persona, index) { return { 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) }; }; FacepileBase.prototype._getOverflowElement = function (personasOverflow) { switch (this.props.overflowButtonType) { case OverflowButtonType.descriptive: return this._getDescriptiveOverflowElement(personasOverflow); case OverflowButtonType.downArrow: return this._getIconElement('ChevronDown'); case OverflowButtonType.more: return this._getIconElement('More'); default: return null; } }; FacepileBase.prototype._getDescriptiveOverflowElement = function (personasOverflow) { var _a = this.props, overflowButtonProps = _a.overflowButtonProps, personaSize = _a.personaSize; if (!personasOverflow || personasOverflow.length < 1) { return null; } var personaNames = personasOverflow.map(function (p) { return p.personaName; }).join(', '); var numPersonasNotPictured = Math.max(personasOverflow.length, 0); 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 }))); }; FacepileBase.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 }))); }; FacepileBase.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') }))); }; FacepileBase.prototype._onPersonaClick = function (persona, ev) { persona.onClick(ev, persona); ev.preventDefault(); ev.stopPropagation(); }; FacepileBase.prototype._onPersonaMouseMove = function (persona, ev) { if (!!persona.onMouseMove) { persona.onMouseMove(ev, persona); } }; FacepileBase.prototype._onPersonaMouseOut = function (persona, ev) { if (!!persona.onMouseOut) { persona.onMouseOut(ev, persona); } }; FacepileBase.prototype._renderInitials = function (iconName, overflowButton) { return function () { return (React.createElement(Icon, { iconName: iconName, className: overflowButton ? styles.overflowInitialsIcon : '' })); }; }; FacepileBase.prototype._renderInitialsNotPictured = function (numPersonasNotPictured) { return function () { return (React.createElement("span", { className: styles.overflowInitialsIcon }, '+' + numPersonasNotPictured)); }; }; FacepileBase.defaultProps = { maxDisplayablePersonas: 5, personas: [], overflowPersonas: [], personaSize: PersonaSize.size32 }; return FacepileBase; }(BaseComponent)); export { FacepileBase }; //# sourceMappingURL=Facepile.base.js.map