2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-24 14:04:06 +03:00
Files
bbob/packages/bbob-react/src/Component.js
T
Dan Polivy 93d802773c fix(react): adjust PropTypes for React Component container (#107)
Augments the existing PropType for the `container` prop of Component to allow for React elements and element types to be passed. The latter allows React Native to better be supported.
2021-06-23 23:27:08 +02:00

49 lines
1.1 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { render } from './render';
const content = (children, plugins, options) => React.Children.map(children, (child) => (typeof child === 'string' ? render(child, plugins, options) : child));
const Component = ({
container,
componentProps,
children,
plugins,
options,
}) => React.createElement(
container,
componentProps,
content(children, plugins, options),
);
if (process.env.NODE_ENV !== 'production') {
Component.propTypes = {
container: PropTypes.oneOfType([
PropTypes.node,
PropTypes.element,
PropTypes.elementType,
]),
children: PropTypes.node.isRequired,
plugins: PropTypes.arrayOf(PropTypes.func),
componentProps: PropTypes.shape({
className: PropTypes.string,
}),
options: PropTypes.shape({
parser: PropTypes.func,
skipParse: PropTypes.bool,
onlyAllowTags: PropTypes.arrayOf(PropTypes.string),
openTag: PropTypes.string,
closeTag: PropTypes.string,
}),
};
}
Component.defaultProps = {
container: 'span',
plugins: [],
options: {},
componentProps: {},
};
export default Component;