@massds/mayflower-react
Version:
React versions of Mayflower design system UI components
48 lines (39 loc) • 2.14 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
/**
* GenTeaserDescription module.
* @module @massds/mayflower-react/GenTeaserDescription
* @requires module:@massds/mayflower-assets/scss/03-organisms/gen-teaser
*/
import React from "react";
import PropTypes from "prop-types";
import ReactHtmlParser from "html-react-parser";
const GenTeaserDescription = props => {
const children = props.children,
description = props.description,
rest = _objectWithoutPropertiesLoose(props, ["children", "description"]);
let descriptionHTML = null;
if (typeof description === 'string') {
const parserOptions = {
replace: domNode => {
// Wrap children text nodes in spans to persist DOM relationship consistency for ReactDOM when Google Translate manipulates the DOM tree
// eslint-disable-next-line react/no-array-index-key
if (domNode.type === 'text') {
return /*#__PURE__*/React.createElement("span", null, domNode.data);
}
return null;
}
};
descriptionHTML = ReactHtmlParser(description, parserOptions);
}
return /*#__PURE__*/React.createElement("div", _extends({
className: "ma__gen-teaser__description"
}, rest), children || /*#__PURE__*/React.createElement("p", null, descriptionHTML));
};
GenTeaserDescription.propTypes = process.env.NODE_ENV !== "production" ? {
/** A html formatted or plain string of text */
description: PropTypes.string,
/** React children to render */
children: PropTypes.node
} : {};
export default GenTeaserDescription;