@massds/mayflower-react
Version:
React versions of Mayflower design system UI components
52 lines (43 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; }
/**
* GenTeaserTitle module.
* @module @massds/mayflower-react/GenTeaserTitle
* @requires module:@massds/mayflower-assets/scss/03-organisms/gen-teaser
*/
import React from "react";
import PropTypes from "prop-types";
import * as Icon from "../Icon/index.mjs";
import DecorativeLink from "../DecorativeLink/index.mjs";
/**
* Title Link
*/
const GenTeaserTitle = props => {
const level = props.level,
_props$title = props.title,
title = _props$title === void 0 ? {} : _props$title,
children = props.children,
rest = _objectWithoutPropertiesLoose(props, ["level", "title", "children"]);
const decorativeProps = JSON.parse(JSON.stringify(title));
if (title.icon) {
const IconComponent = Icon[title.icon];
decorativeProps.icon = /*#__PURE__*/React.createElement(IconComponent, {
width: 15,
height: 15,
"aria-hidden": "true"
});
}
const Element = "h" + (level || 2);
return /*#__PURE__*/React.createElement(Element, _extends({
className: "ma__gen-teaser__title"
}, rest), children || /*#__PURE__*/React.createElement(DecorativeLink, decorativeProps));
};
GenTeaserTitle.propTypes = process.env.NODE_ENV !== "production" ? {
/** The heading level of the title */
level: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** The title object (text, info, href) */
title: PropTypes.shape(DecorativeLink.propTypes),
/** React children to render */
children: PropTypes.node
} : {};
export default GenTeaserTitle;