@talend/react-components
Version:
Set of react components.
54 lines (53 loc) • 1.58 kB
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
import Inject from './Inject';
import { omit } from "lodash";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export function toText(props) {
if (Array.isArray(props.text)) {
return props.text.map((sentence, index) => /*#__PURE__*/_jsx("p", {
children: sentence
}, index));
}
return props.text;
}
const OMIT_PROPS = ['setState', 'deleteState', 'updateState', 'componentId', 'state', 'initState', 'getCollection', 'dispatch', 'dispatchActionCreator'];
const BLACK_LISTED_ATTR = ['childContextTypes',
// not authorized on function component
'propTypes' // already set by HOC
];
const COMPONENT_EXCEPTIONS = {
MenuItem: props => props.divider
};
function isNotBlackListedAttr(attr) {
return !BLACK_LISTED_ATTR.includes(attr);
}
export default function wrap(Component, key) {
const Wrapper = ({
getComponent,
components,
text,
...props
}) => {
const injected = Inject.all(getComponent, components);
const newprops = {
...omit(props, OMIT_PROPS)
};
if (key === 'MenuItem' && COMPONENT_EXCEPTIONS[key](props)) {
return /*#__PURE__*/_jsx(Component, {
...newprops
});
}
return /*#__PURE__*/_jsxs(Component, {
...newprops,
children: [injected('children'), toText({
text
}), props.children]
});
};
Object.keys(Component).filter(isNotBlackListedAttr).forEach(attr => {
Wrapper[attr] = Component[attr];
});
Wrapper.displayName = key;
return Wrapper;
}
//# sourceMappingURL=wrap.js.map