@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
197 lines • 11.2 kB
JavaScript
/** @component list-item */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__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;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import React from 'react';
import PropTypes from 'prop-types';
import uniqueId from 'lodash/uniqueId';
import { Avatar, Icon, ListItem, ListItemSection } from '@momentum-ui/react-collaboration';
/**
* @deprecated - Components in the legacy folder (/src/legacy) are deprecated. Please use a component from the components folder (/src/components) instead. Legacy components may not follow accessibility standards.
**/
var SpaceListItem = /** @class */ (function (_super) {
__extends(SpaceListItem, _super);
function SpaceListItem() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
id: _this.props.id || uniqueId('md-space-list-item-'),
};
return _this;
}
SpaceListItem.prototype.render = function () {
var _a = this.props, attachments = _a.attachments, className = _a.className, childrenLeft = _a.childrenLeft, childrenRight = _a.childrenRight, header = _a.header, headerSecondary = _a.headerSecondary, highlightColor = _a.highlightColor, isAlertOn = _a.isAlertOn, isBold = _a.isBold, isDecrypting = _a.isDecrypting, isMentioned = _a.isMentioned, isMuted = _a.isMuted, isOverview = _a.isOverview, isUnread = _a.isUnread, resultRight = _a.resultRight, searchTerm = _a.searchTerm, subheader = _a.subheader, theme = _a.theme, title = _a.title, type = _a.type, props = __rest(_a, ["attachments", "className", "childrenLeft", "childrenRight", "header", "headerSecondary", "highlightColor", "isAlertOn", "isBold", "isDecrypting", "isMentioned", "isMuted", "isOverview", "isUnread", "resultRight", "searchTerm", "subheader", "theme", "title", "type"]);
var id = this.state.id;
var getTitle = !title && typeof header === 'string' ? header : title;
var getIcon = function () {
if (isMuted) {
return React.createElement(Icon, { color: "white-60", name: "alert-muted_12" });
}
else if (isUnread) {
return React.createElement(Icon, { color: "blue-50", name: "unread-badge_12" });
}
else if (isMentioned) {
return React.createElement(Icon, { color: "blue-50", name: "mention_12" });
}
else if (isAlertOn) {
return React.createElement(Icon, { color: "white-60", name: "alert_12" });
}
return null;
};
var leftSection = isOverview ? (React.createElement(Avatar, { className: "md-list-item__avatar", isOverview: true, icon: React.createElement(Icon, { name: "handset_24" }) })) : (childrenLeft);
var rightSection = (React.createElement(ListItemSection, { key: "child-2", position: "right" }, childrenRight ? childrenRight : getIcon()));
var addEscapes = function (text) { return (text && text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')) || ''; };
var highlightSubheader = function () {
var escapedTerm = addEscapes(searchTerm);
var re = new RegExp("(".concat(escapedTerm, ")"), 'gi');
return searchTerm && typeof subheader === 'string'
? subheader.split(re).map(function (ele, idx) {
return ele.match(re) ? (React.createElement("span", { key: "subheader-".concat(idx), className: "md-list-item__subheader--highlight", style: { color: highlightColor } }, ele)) : (ele);
})
: subheader;
};
var highlightHeader = function () {
var escapedTerm = addEscapes(searchTerm);
var re = new RegExp("(".concat(escapedTerm, ")"), 'gi');
return searchTerm && typeof header === 'string'
? header.split(re).map(function (ele, idx) {
return ele.match(re) ? (React.createElement("span", { key: "header-".concat(idx), className: "md-list-item__header--highlight", style: { color: highlightColor } }, ele)) : (ele);
})
: header;
};
var getHeader = ['search', 'filter', 'flag', 'filter-search'].includes(type)
? [
React.createElement("span", { key: "header-0", className: "md-list-item__header-main" }, header),
headerSecondary && (React.createElement("span", { className: "md-list-item__header-secondary", key: "header-1" }, headerSecondary)),
]
: highlightHeader();
var children = __spreadArray([
React.createElement(ListItemSection, { key: "child-0", position: "left" }, leftSection || React.createElement(Avatar, { title: "NA" })),
React.createElement(ListItemSection, { key: "child-1", position: "center" },
React.createElement("div", { className: 'md-list-item__header' +
"".concat(((searchTerm || isOverview) && " md-list-item__header--overview") || '') +
"".concat((isDecrypting && " md-decrypting") || '') }, getHeader),
['search', 'filter', 'flag', 'filter-search'].includes(type) ? (React.createElement(ListItemSection, { position: "center", className: "md-list-item__result-container" }, ['flag'].includes(type) ? (React.createElement(ListItemSection, { position: "center", key: "attachment-line-1", className: "md-list-item__attachment" },
React.createElement("div", { className: "md-list-item__attachment--top" },
React.createElement(ListItemSection, { position: "center", className: "md-list-item__attachment--top-left" }, highlightSubheader(subheader)),
resultRight && (React.createElement(ListItemSection, { position: "right", className: "md-list-item__attachment--top-right" }, resultRight))),
attachments && attachments.length && (React.createElement("div", { className: "md-list-item__attachment--bottom" }, attachments[0])))) : (React.createElement("div", { className: "md-list-item__result" }, highlightSubheader(subheader))))) : (React.createElement("div", { className: 'md-list-item__subheader' + "".concat((isDecrypting && " md-decrypting") || '') }, subheader)))
], (!type ? [rightSection] : []), true);
return (React.createElement(ListItem, __assign({ className: "".concat((isBold && " md-list-item--unread") || '') +
"".concat((type && " md-list-item--space-".concat(type)) || '') +
"".concat((theme && " md-list-item--space-".concat(theme)) || '') +
"".concat((className && " ".concat(className)) || ''), id: id, title: getTitle, type: "space" }, props), children));
};
return SpaceListItem;
}(React.PureComponent));
SpaceListItem.propTypes = {
/** @prop SpaceListItem Attachment Array | null */
attachments: PropTypes.arrayOf(PropTypes.node),
/** @prop Children nodes to render for left section | null */
childrenLeft: PropTypes.node,
/** @prop Children nodes to render for right section | null */
childrenRight: PropTypes.node,
/** @prop Optional HTML class string | '' */
className: PropTypes.string,
/** @prop ListItem header node */
header: PropTypes.node.isRequired,
/** @prop Secondary header for center section | '' */
headerSecondary: PropTypes.string,
/** @prop Highlight Color for Regex | '' */
highlightColor: PropTypes.string,
/** @prop HTML ID for SpaceListItem | '' */
id: PropTypes.string,
/** @prop Determines if SpaceListItem's Alert is on | false */
isAlertOn: PropTypes.bool,
/** @prop Determines if SpaceListItem is Bolded | false */
isBold: PropTypes.bool,
/** @prop Determines if SpaceListItem decrypting | false */
isDecrypting: PropTypes.bool,
/** @prop Determines if SpaceListItem has been mentioned | false */
isMentioned: PropTypes.bool,
/** @prop Determines if SpaceListItem has been muted | false */
isMuted: PropTypes.bool,
/** @prop Determines if SpaceListItem is an Overview item | false */
isOverview: PropTypes.bool,
/** @prop Determines if SpaceListItem is unread | false */
isUnread: PropTypes.bool,
/** @prop Children node for result right section | null */
resultRight: PropTypes.node,
/** @prop Word used for search | '' */
searchTerm: PropTypes.string,
/** @prop SpaceListItem subheader node | ''s */
subheader: PropTypes.node,
/** @prop SpaceListItem theme | '' */
theme: PropTypes.string,
/** @prop SpaceListItem title | '' */
title: PropTypes.string,
/** @prop SpaceListItem type | '' */
type: PropTypes.oneOf(['', 'filter', 'filter-search', 'filter-summary', 'flag', 'search']),
};
SpaceListItem.defaultProps = {
attachments: null,
childrenLeft: null,
childrenRight: null,
className: '',
headerSecondary: '',
highlightColor: '',
id: '',
isAlertOn: false,
isBold: false,
isDecrypting: false,
isMentioned: false,
isMuted: false,
isOverview: false,
isUnread: false,
resultRight: null,
searchTerm: '',
subheader: '',
title: '',
theme: '',
type: '',
};
SpaceListItem.displayName = 'SpaceListItem';
export default SpaceListItem;
//# sourceMappingURL=index.js.map