Skip to content

Commit

Permalink
fix: react preset types
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Feb 7, 2024
1 parent d0fc1a7 commit a67beb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
1 change: 0 additions & 1 deletion packages/bbob-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@bbob/plugin-helper": "workspace:*"
},
"peerDependencies": {
"prop-types": "> 15.0",
"react": "> 15.0"
},
"devDependencies": {
Expand Down
46 changes: 16 additions & 30 deletions packages/bbob-react/src/Component.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { ReactNode } from 'react';
import type { BBobPlugins, BBobCoreOptions } from '@bbob/core';
import { render } from './render';

const content = (children, plugins, options) => React.Children.map(children, (child) => (typeof child === 'string' ? render(child, plugins, options) : child));
const content = (children: ReactNode, plugins?: BBobPlugins, options?: BBobCoreOptions) => React.Children.map(children, (child) => (typeof child === 'string' ? render(child, plugins, options) : child));

export type BBobReactComponentProps = {
children: ReactNode
container: string
componentProps: Record<string, unknown>
plugins?: BBobPlugins
options?: BBobCoreOptions
}

const Component = ({
container,
componentProps,
container = 'span',
componentProps = {},
children,
plugins,
options,
}) => React.createElement(
plugins = [],
options = {},
}: BBobReactComponentProps) => 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: [],
Expand Down

0 comments on commit a67beb4

Please sign in to comment.