UNPKG

@formant/ava-react

Version:

React components of AVA.

75 lines 3.92 kB
var _excluded = ["spec", "pluginManager", "size", "theme", "palette"], _excluded2 = ["onClickParagraph", "onMouseEnterParagraph", "onMouseLeaveParagraph"]; function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } 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; } import React from 'react'; import { Divider } from 'antd'; import { isCustomParagraph, isHeadingParagraph, isTextParagraph, isBulletParagraph, isDividerParagraph } from '@formant/ava'; import { Heading } from "./Heading"; import { TextLine } from "./TextLine"; import { Bullets } from "./Bullets"; export function Paragraph(_ref) { var spec = _ref.spec, pluginManager = _ref.pluginManager, _ref$size = _ref.size, size = _ref$size === void 0 ? 'normal' : _ref$size, _ref$theme = _ref.theme, theme = _ref$theme === void 0 ? 'dark' : _ref$theme, palette = _ref.palette, events = _objectWithoutProperties(_ref, _excluded); var themeStyles = { size: size, theme: theme, palette: palette }; var _ref2 = events || {}, onClickParagraph = _ref2.onClickParagraph, onMouseEnterParagraph = _ref2.onMouseEnterParagraph, onMouseLeaveParagraph = _ref2.onMouseLeaveParagraph, phraseEvents = _objectWithoutProperties(_ref2, _excluded2); var onClick = function onClick() { onClickParagraph === null || onClickParagraph === void 0 || onClickParagraph(spec); }; var onMouseEnter = function onMouseEnter() { onMouseEnterParagraph === null || onMouseEnterParagraph === void 0 || onMouseEnterParagraph(spec); }; var onMouseLeave = function onMouseLeave() { onMouseLeaveParagraph === null || onMouseLeaveParagraph === void 0 || onMouseLeaveParagraph(spec); }; if (isDividerParagraph(spec)) { return /*#__PURE__*/React.createElement(Divider, { style: spec.styles, className: spec.className }); } var content = null; if (isCustomParagraph(spec)) { var descriptor = pluginManager.getBlockDescriptor(spec.customType); if (descriptor && descriptor !== null && descriptor !== void 0 && descriptor.render) content = descriptor.render(spec, themeStyles); } if (isHeadingParagraph(spec)) { content = /*#__PURE__*/React.createElement(Heading, _extends({ spec: spec, pluginManager: pluginManager }, themeStyles, phraseEvents)); } if (isTextParagraph(spec)) { content = /*#__PURE__*/React.createElement(TextLine, _extends({ spec: spec, pluginManager: pluginManager }, themeStyles, phraseEvents)); } if (isBulletParagraph(spec)) { content = /*#__PURE__*/React.createElement(Bullets, _extends({ spec: spec, pluginManager: pluginManager }, themeStyles, events)); } return content && /*#__PURE__*/React.createElement("div", { onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, content); } export { Headline } from "./Headline";