wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
30 lines • 1.06 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import reactElementToJSXString from 'react-element-to-jsx-string';
import CodeBlock from '../CodeBlock';
import removeHOC from './remove-hoc';
import functionToString from './function-to-string';
var componentToJSX = function (component) {
return reactElementToJSXString(component, {
displayName: function (element) {
return element.type.displayName
? removeHOC(element.type.displayName)
: element.type.name || element.type;
},
showDefaultProps: false,
showFunctions: false,
functionValue: functionToString,
});
};
/**
* given react component, render a source example
*/
var ComponentSource = function (_a) {
var component = _a.component;
return (React.createElement(CodeBlock, { dataHook: "metadata-codeblock", source: componentToJSX(component) }));
};
ComponentSource.propTypes = {
component: PropTypes.node.isRequired,
};
export default ComponentSource;
//# sourceMappingURL=index.js.map