2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-15 11:59:37 +03:00

feat(react): allow pass custom options to react component

This commit is contained in:
Nikolay Kostyurin
2018-10-25 16:39:49 +02:00
parent 6d37793001
commit 77b30f3d44
3 changed files with 10 additions and 8 deletions
+2 -2
View File
@@ -88,7 +88,7 @@ import {render} from 'react-dom'
import bbobReactRender from '@bbob/react/es/render'
import presetReact from '@bbob/preset-react'
console.log(render(<span>{bbobReactRender(`[i]Text[/i]`, presetReact())}</span>)); // <span><span style="font-style: italic;">Text</span></span>
console.log(render(<span>{bbobReactRender(`[i]Text[/i]`, presetReact(), { onlyAllowTags: ['i'] })}</span>)); // <span><span style="font-style: italic;">Text</span></span>
```
### Presets <a name="basic"></a>
@@ -165,7 +165,7 @@ import BBCode from '@bbob/react/es/Component'
import reactPreset from '@bbob/preset-react/es'
const MyComponent = () => (
<BBCode plugins={[reactPreset()]}>
<BBCode plugins={[reactPreset()]} options={{ onlyAllowTags: ['i'] }}>
[quote]Text[/quote]
</BBCode>
)
+4 -3
View File
@@ -2,11 +2,11 @@ import React from 'react';
import PropTypes from 'prop-types';
import { render } from './render';
const content = (children, plugins) => React.Children.map(children, child =>
(typeof child === 'string' ? render(child, plugins) : child));
const content = (children, plugins, options) => React.Children.map(children, child =>
(typeof child === 'string' ? render(child, plugins, options) : child));
const Component = props =>
React.createElement(props.container, {}, content(props.children, props.plugins));
React.createElement(props.container, {}, content(props.children, props.plugins, props.options));
if (process.env.NODE_ENV !== 'production') {
Component.propTypes = {
@@ -19,6 +19,7 @@ if (process.env.NODE_ENV !== 'production') {
Component.defaultProps = {
container: 'span',
plugins: [],
options: {},
};
export default Component;
+4 -3
View File
@@ -4,8 +4,9 @@ import * as html from '@bbob/html';
import { isTagNode, isStringNode } from '@bbob/plugin-helper';
const toAST = (source, plugins) => core(plugins)
const toAST = (source, plugins, options) => core(plugins)
.process(source, {
...options,
render: input => html.render(input, { stripTags: true }),
}).tree;
@@ -32,8 +33,8 @@ function renderToReactNodes(nodes) {
return els;
}
function render(source, plugins) {
return renderToReactNodes(toAST(source, plugins));
function render(source, plugins, options) {
return renderToReactNodes(toAST(source, plugins, options));
}
export { render };