1 | import { __assign, __extends } from "tslib";
|
2 | import * as React from 'react';
|
3 | import { buttonProperties, classNamesFunction, getId, getNativeProps, initializeComponentRef } from '../../Utilities';
|
4 | import { OverflowButtonType, } from './Facepile.types';
|
5 | import { FacepileButton } from './FacepileButton';
|
6 | import { Icon } from '../../Icon';
|
7 | import { Persona } from '../../Persona';
|
8 | import { PersonaCoin, PersonaSize, PersonaInitialsColor } from '../../PersonaCoin';
|
9 | var getClassNames = classNamesFunction();
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var FacepileBase = (function (_super) {
|
15 | __extends(FacepileBase, _super);
|
16 | function FacepileBase(props) {
|
17 | var _this = _super.call(this, props) || this;
|
18 | _this._classNames = getClassNames(_this.props.styles, {
|
19 | theme: _this.props.theme,
|
20 | className: _this.props.className,
|
21 | });
|
22 | _this._getPersonaControl = function (persona) {
|
23 | var _a = _this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize;
|
24 | var personaStyles = {
|
25 | details: {
|
26 | flex: '1 0 auto',
|
27 | },
|
28 | };
|
29 | return (React.createElement(Persona, __assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, allowPhoneInitials: persona.allowPhoneInitials, text: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null), { styles: personaStyles })));
|
30 | };
|
31 | _this._getPersonaCoinControl = function (persona) {
|
32 | var _a = _this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize;
|
33 | return (React.createElement(PersonaCoin, __assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, allowPhoneInitials: persona.allowPhoneInitials, text: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null))));
|
34 | };
|
35 | initializeComponentRef(_this);
|
36 | _this._ariaDescriptionId = getId();
|
37 | return _this;
|
38 | }
|
39 | FacepileBase.prototype.render = function () {
|
40 | var overflowButtonProps = this.props.overflowButtonProps;
|
41 | var _a = this.props, chevronButtonProps = _a.chevronButtonProps,
|
42 | maxDisplayablePersonas = _a.maxDisplayablePersonas, personas = _a.personas, overflowPersonas = _a.overflowPersonas, showAddButton = _a.showAddButton, ariaLabel = _a.ariaLabel, _b = _a.showTooltip, showTooltip = _b === void 0 ? true : _b;
|
43 | var _classNames = this._classNames;
|
44 |
|
45 | var numPersonasToShow = typeof maxDisplayablePersonas === 'number' ? Math.min(personas.length, maxDisplayablePersonas) : personas.length;
|
46 |
|
47 | if (chevronButtonProps && !overflowButtonProps) {
|
48 | overflowButtonProps = chevronButtonProps;
|
49 | }
|
50 | var hasOverflowPersonas = overflowPersonas && overflowPersonas.length > 0;
|
51 | var personasPrimary = hasOverflowPersonas ? personas : personas.slice(0, numPersonasToShow);
|
52 | var personasOverflow = (hasOverflowPersonas ? overflowPersonas : personas.slice(numPersonasToShow)) || [];
|
53 | return (React.createElement("div", { className: _classNames.root },
|
54 | this.onRenderAriaDescription(),
|
55 | React.createElement("div", { className: _classNames.itemContainer },
|
56 | showAddButton ? this._getAddNewElement() : null,
|
57 | React.createElement("ul", { className: _classNames.members, "aria-label": ariaLabel }, this._onRenderVisiblePersonas(personasPrimary, personasOverflow.length === 0 && personas.length === 1, showTooltip)),
|
58 | overflowButtonProps ? this._getOverflowElement(personasOverflow) : null)));
|
59 | };
|
60 | FacepileBase.prototype.onRenderAriaDescription = function () {
|
61 | var ariaDescription = this.props.ariaDescription;
|
62 | var _classNames = this._classNames;
|
63 |
|
64 |
|
65 | return (ariaDescription && (React.createElement("span", { className: _classNames.screenReaderOnly, id: this._ariaDescriptionId }, ariaDescription)));
|
66 | };
|
67 | FacepileBase.prototype._onRenderVisiblePersonas = function (personas, singlePersona, showTooltip) {
|
68 | var _this = this;
|
69 | var _a = this.props, _b = _a.onRenderPersona, onRenderPersona = _b === void 0 ? this._getPersonaControl : _b, _c = _a.onRenderPersonaCoin, onRenderPersonaCoin = _c === void 0 ? this._getPersonaCoinControl : _c;
|
70 | return personas.map(function (persona, index) {
|
71 | var personaControl = singlePersona
|
72 | ? onRenderPersona(persona, _this._getPersonaControl)
|
73 | : onRenderPersonaCoin(persona, _this._getPersonaCoinControl);
|
74 | return (React.createElement("li", { key: (singlePersona ? 'persona' : 'personaCoin') + "-" + index, className: _this._classNames.member }, persona.onClick
|
75 | ? _this._getElementWithOnClickEvent(personaControl, persona, showTooltip, index)
|
76 | : _this._getElementWithoutOnClickEvent(personaControl, persona, showTooltip, index)));
|
77 | });
|
78 | };
|
79 | FacepileBase.prototype._getElementWithOnClickEvent = function (personaControl, persona, showTooltip, index) {
|
80 | var keytipProps = persona.keytipProps;
|
81 | return (React.createElement(FacepileButton, __assign({}, getNativeProps(persona, buttonProperties), this._getElementProps(persona, showTooltip, index), { keytipProps: keytipProps,
|
82 |
|
83 | onClick: this._onPersonaClick.bind(this, persona) }), personaControl));
|
84 | };
|
85 | FacepileBase.prototype._getElementWithoutOnClickEvent = function (personaControl, persona, showTooltip, index) {
|
86 | return (React.createElement("div", __assign({}, getNativeProps(persona, buttonProperties), this._getElementProps(persona, showTooltip, index)), personaControl));
|
87 | };
|
88 | FacepileBase.prototype._getElementProps = function (persona, showTooltip, index) {
|
89 | var _classNames = this._classNames;
|
90 | return {
|
91 | key: (persona.imageUrl ? 'i' : '') + index,
|
92 | 'data-is-focusable': true,
|
93 | className: _classNames.itemButton,
|
94 | title: showTooltip ? persona.personaName : undefined,
|
95 | onMouseMove: this._onPersonaMouseMove.bind(this, persona),
|
96 | onMouseOut: this._onPersonaMouseOut.bind(this, persona),
|
97 | };
|
98 | };
|
99 | FacepileBase.prototype._getOverflowElement = function (personasOverflow) {
|
100 | switch (this.props.overflowButtonType) {
|
101 | case OverflowButtonType.descriptive:
|
102 | return this._getDescriptiveOverflowElement(personasOverflow);
|
103 | case OverflowButtonType.downArrow:
|
104 | return this._getIconElement('ChevronDown');
|
105 | case OverflowButtonType.more:
|
106 | return this._getIconElement('More');
|
107 | default:
|
108 | return null;
|
109 | }
|
110 | };
|
111 | FacepileBase.prototype._getDescriptiveOverflowElement = function (personasOverflow) {
|
112 | var personaSize = this.props.personaSize;
|
113 | if (!personasOverflow || personasOverflow.length < 1) {
|
114 | return null;
|
115 | }
|
116 | var personaNames = personasOverflow.map(function (p) { return p.personaName; }).join(', ');
|
117 | var overflowButtonProps = __assign({ title: personaNames }, this.props.overflowButtonProps);
|
118 | var numPersonasNotPictured = Math.max(personasOverflow.length, 0);
|
119 | var _classNames = this._classNames;
|
120 | return (React.createElement(FacepileButton, __assign({}, overflowButtonProps, { ariaDescription: overflowButtonProps.title, className: _classNames.descriptiveOverflowButton }),
|
121 | React.createElement(PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitialsNotPictured(numPersonasNotPictured), initialsColor: PersonaInitialsColor.transparent })));
|
122 | };
|
123 | FacepileBase.prototype._getIconElement = function (icon) {
|
124 | var _a = this.props, overflowButtonProps = _a.overflowButtonProps, personaSize = _a.personaSize;
|
125 | var overflowInitialsIcon = true;
|
126 | var _classNames = this._classNames;
|
127 | return (React.createElement(FacepileButton, __assign({}, overflowButtonProps, { className: _classNames.overflowButton }),
|
128 | React.createElement(PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials(icon, overflowInitialsIcon), initialsColor: PersonaInitialsColor.transparent })));
|
129 | };
|
130 | FacepileBase.prototype._getAddNewElement = function () {
|
131 | var _a = this.props, addButtonProps = _a.addButtonProps, personaSize = _a.personaSize;
|
132 | var _classNames = this._classNames;
|
133 | return (React.createElement(FacepileButton, __assign({}, addButtonProps, { className: _classNames.addButton }),
|
134 | React.createElement(PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials('AddFriend') })));
|
135 | };
|
136 | FacepileBase.prototype._onPersonaClick = function (persona, ev) {
|
137 | persona.onClick(ev, persona);
|
138 | ev.preventDefault();
|
139 | ev.stopPropagation();
|
140 | };
|
141 | FacepileBase.prototype._onPersonaMouseMove = function (persona, ev) {
|
142 | if (persona.onMouseMove) {
|
143 | persona.onMouseMove(ev, persona);
|
144 | }
|
145 | };
|
146 | FacepileBase.prototype._onPersonaMouseOut = function (persona, ev) {
|
147 | if (persona.onMouseOut) {
|
148 | persona.onMouseOut(ev, persona);
|
149 | }
|
150 | };
|
151 | FacepileBase.prototype._renderInitials = function (iconName, overflowButton) {
|
152 | var _classNames = this._classNames;
|
153 | return function () {
|
154 | return React.createElement(Icon, { iconName: iconName, className: overflowButton ? _classNames.overflowInitialsIcon : '' });
|
155 | };
|
156 | };
|
157 | FacepileBase.prototype._renderInitialsNotPictured = function (numPersonasNotPictured) {
|
158 | var _classNames = this._classNames;
|
159 | return function () {
|
160 | return (React.createElement("span", { className: _classNames.overflowInitialsIcon }, numPersonasNotPictured < 100 ? '+' + numPersonasNotPictured : '99+'));
|
161 | };
|
162 | };
|
163 | FacepileBase.defaultProps = {
|
164 | maxDisplayablePersonas: 5,
|
165 | personas: [],
|
166 | overflowPersonas: [],
|
167 | personaSize: PersonaSize.size32,
|
168 | };
|
169 | return FacepileBase;
|
170 | }(React.Component));
|
171 | export { FacepileBase };
|
172 |
|
\ | No newline at end of file |