UNPKG

wix-storybook-utils

Version:

Utilities for automated component documentation within Storybook

46 lines 2.44 kB
import React from 'react'; import { MethodsTable } from './methods-table'; import { PropsTable } from './props-table'; import SectionHelper from '../SectionHelper'; import styles from './styles.scss'; var splitDeprecated = function (props) { return Object.keys(props).reduce(function (output, name) { var prop = props[name]; var isDeprecated = (prop.tags || []).some(function (_a) { var title = _a.title; return title === 'deprecated'; }); if (isDeprecated) { output.deprecatedProps[name] = prop; } else { output.supportedProps[name] = prop; } return output; }, { deprecatedProps: {}, supportedProps: {} }); }; var Table = function (_a) { var properties = _a.properties, publicMethods = _a.publicMethods, title = _a.title, deprecated = _a.deprecated, dataHook = _a.dataHook; return (React.createElement("div", { className: styles.table }, React.createElement("div", { className: styles.title, "data-hook": dataHook }, title), deprecated && (React.createElement(SectionHelper, null, "The following properties were deprecated and will be removed in near future. Do not use them!")), publicMethods && React.createElement(MethodsTable, { methods: publicMethods }), properties && React.createElement(PropsTable, { props: properties }))); }; var AutoDocs = function (_a) { var metadata = _a.metadata; var props = metadata.props, _b = metadata.methods, methods = _b === void 0 ? [] : _b; var publicMethods = methods.filter(function (_a) { var name = _a.name; return !name.startsWith('_'); }); var _c = splitDeprecated(props), deprecatedProps = _c.deprecatedProps, supportedProps = _c.supportedProps; var containsDeprecated = Object.keys(deprecatedProps).length > 0; var containsPublicMethods = publicMethods.length > 0; return (React.createElement("div", { className: "markdown-body" }, React.createElement(Table, { properties: supportedProps, title: "Properties" }), containsPublicMethods && (React.createElement(Table, { dataHook: "autodocs-methods-table-title", title: "Public methods", publicMethods: publicMethods })), containsDeprecated && (React.createElement(Table, { properties: deprecatedProps, title: "Deprecated Props", deprecated: true })))); }; export default AutoDocs; //# sourceMappingURL=index.js.map