@readme/markdown
Version:
ReadMe's React-based Markdown parser
48 lines (41 loc) • 1.24 kB
JSX
const React = require('react');
const PropTypes = require('prop-types');
const Callout = props => {
let { children } = props;
const { attributes, theme, title, icon } = props;
if (!(title || children)) return '';
let content;
if (title) {
[children, ...content] = children;
} else {
[children, content] = ['', children];
}
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
<h3 className={`callout-heading ${!title && 'empty'}`}>
<span className="callout-icon">{icon}</span>
{children}
</h3>
{(content && content.length && content) || (!title && children)}
</blockquote>
);
};
Callout.propTypes = {
attributes: PropTypes.shape({}),
calloutStyle: PropTypes.string,
children: PropTypes.arrayOf(PropTypes.any).isRequired,
icon: PropTypes.string,
node: PropTypes.shape(),
theme: PropTypes.string,
title: PropTypes.string,
};
Callout.defaultProps = {
attributes: null,
calloutStyle: 'info',
node: null,
};
module.exports = sanitizeSchema => {
sanitizeSchema.attributes['rdme-callout'] = ['icon', 'theme', 'title', 'value'];
return Callout;
};