UNPKG

@momentum-ui/react-collaboration

Version:

Cisco Momentum UI Framework for React Collaboration Applications

161 lines 7.82 kB
/** @component content-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; }; import React from 'react'; import PropTypes from 'prop-types'; import ChatContentItem from './ChatContent'; import FileContentItem from './FileContent'; import IconContent from './IconContent'; import omit from 'lodash/omit'; /** * @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 ContentItem = /** @class */ (function (_super) { __extends(ContentItem, _super); function ContentItem() { return _super !== null && _super.apply(this, arguments) || this; } ContentItem.prototype.render = function () { var _a = this.props, actionNode = _a.actionNode, aspect = _a.aspect, className = _a.className, content = _a.content, failedText = _a.failedText, fileSize = _a.fileSize, height = _a.height, icon = _a.icon, isProtected = _a.isProtected, loading = _a.loading, loadingText = _a.loadingText, style = _a.style, subtitle = _a.subtitle, title = _a.title, type = _a.type, width = _a.width, props = __rest(_a, ["actionNode", "aspect", "className", "content", "failedText", "fileSize", "height", "icon", "isProtected", "loading", "loadingText", "style", "subtitle", "title", "type", "width"]); var otherProps = omit(__assign({}, props), ['gifIcon']); var findAspect = function (width, height) { if (width && height) { var aspectRatioObj = { 1: 'oneOne', 0.75: 'threeFour', 0.66: 'twoThree', 0.4: 'tall', 4.35: 'wide', 1.33: 'fourThree', 1.5: 'threeTwo', 1.78: 'sixteenNine', }; var providedAspectRatio_1 = width / height; var closestAspectRatio = Object.keys(aspectRatioObj).reduce(function (prev, curr) { return Math.abs(curr - providedAspectRatio_1) < Math.abs(prev - providedAspectRatio_1) ? curr : prev; }); return aspectRatioObj[closestAspectRatio]; } return type === 'chat' ? 'sixteenNine' : 'threeTwo'; }; var chosenItem = function () { if (failedText && type === 'chat') { return (React.createElement("div", { className: 'md-content md-content--failed' + "".concat((className && " ".concat(className)) || '') }, React.createElement("div", { className: "md-content--failed-container" }, React.createElement("i", { className: "icon icon-warning_28 md-content--failed-warning" }), React.createElement("p", { className: "md-content--failed-message" }, failedText)))); } else if (type === 'chat') { return (React.createElement(ChatContentItem, __assign({ actionNode: actionNode, aspect: aspect ? aspect : findAspect(width, height), className: className, content: content, fileSize: fileSize, height: height, isProtected: isProtected, loading: loading, subtitle: subtitle, style: style, title: title, type: type, width: width }, props))); } else if (type === 'file' && !icon) { return (React.createElement(FileContentItem, __assign({ actionNode: actionNode, aspect: aspect ? aspect : findAspect(width, height), className: className, content: content, height: height, icon: icon, isProtected: isProtected, loading: loading, loadingText: loadingText, subtitle: subtitle, title: title, type: type, width: width }, props))); } else if (icon) { return (React.createElement(IconContent, __assign({ actionNode: actionNode, className: className, icon: icon, isProtected: isProtected, loading: loading, subtitle: subtitle, title: title }, otherProps))); } }; return React.createElement("div", null, chosenItem()); }; return ContentItem; }(React.PureComponent)); ContentItem.displayName = 'ContentItem'; ContentItem.defaultProps = { actionNode: null, aspect: null, className: '', content: null, failedText: '', fileSize: '', icon: '', isProtected: false, loading: false, loadingText: 'Loading', style: null, subtitle: '', title: '', type: 'chat', }; ContentItem.propTypes = { /** @prop Node to render buttons inside Content Item | null */ actionNode: PropTypes.node, /** @prop Set the Content Item's aspect size | null */ aspect: PropTypes.oneOf([ 'fourThree', 'nineSixteen', 'oneOne', 'sixteenNine', 'tall', 'threeFour', 'threeTwo', 'twoThree', 'wide', ]), /** @prop Optional css class string | '' */ className: PropTypes.string, /** @prop Set the image/gif of the Content Item | '' */ content: PropTypes.string, /** @prop Set the failed text to show when content fails to load | '' */ failedText: PropTypes.string, /** @prop Show the size of the file | '' */ fileSize: PropTypes.string, /** @prop Show icon at top right corner of Content Item */ gifIcon: PropTypes.string, /** @prop Height of the image in px */ height: PropTypes.number, /** @prop Set the type of icon to show | '' */ icon: PropTypes.string, /** @prop Show visibility of action node buttons | false */ isProtected: PropTypes.bool, /** @prop Show loading spinner | false */ loading: PropTypes.bool, /** @prop Change loading text */ loadingText: PropTypes.string, /** @prop Additional css styling applied to the button | null */ style: PropTypes.object, /** @prop Set the subtitle of the Content Item | '' */ subtitle: PropTypes.node, /** @prop Set the title of the Content Item | '' */ title: PropTypes.string, /** @prop Set the type of Content Item to display */ type: PropTypes.oneOf(['chat', 'file']), /** @prop Width of the image in px */ width: PropTypes.number, }; export default ContentItem; //# sourceMappingURL=index.js.map