UNPKG

@massds/mayflower-react

Version:

React versions of Mayflower design system UI components

40 lines 2 kB
const _excluded = ["children", "description"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; } /** * 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, _excluded); 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;