@lyra/form-builder
Version:
Lyra form builder
72 lines (54 loc) • 1.61 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Text;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _Blockquote = require('./Blockquote');
var _Blockquote2 = _interopRequireDefault(_Blockquote);
var _Header = require('./Header');
var _Header2 = _interopRequireDefault(_Header);
var _Normal = require('./Normal');
var _Normal2 = _interopRequireDefault(_Normal);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*:: import type {Node, ComponentType} from 'react'*/
const HEADER_STYLES = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
/*:: type Props = {
attributes?: {},
style: string,
children: Node,
styleComponent?: ComponentType<*>
}*/
function Text(props /*: Props*/) {
const style = props.style,
styleComponent = props.styleComponent;
const attributes = props.attributes || {};
if (styleComponent) {
const CustomStyle = styleComponent;
return _react2.default.createElement(
CustomStyle,
{ attributes: attributes },
props.children
);
}
if (HEADER_STYLES.includes(style)) {
return _react2.default.createElement(
_Header2.default,
{ style: style, attributes: attributes },
props.children
);
}
if (style === 'blockquote') {
return _react2.default.createElement(
_Blockquote2.default,
{ attributes: attributes },
props.children
);
}
return _react2.default.createElement(
_Normal2.default,
{ attributes: attributes },
props.children
);
}