import React from 'react'; import { Method } from '../typings/metadata'; import { Prop } from '../typings/prop'; import { MethodsTable } from './methods-table'; import { PropsTable } from './props-table'; import SectionHelper from '../SectionHelper'; import { AutoDocsProps } from './index.types'; import styles from './styles.scss'; interface PropObject { [s: string]: Prop; } const splitDeprecated: ( PropObject, ) => { deprecatedProps: PropObject; supportedProps: PropObject } = props => Object.keys(props).reduce( (output, name) => { const prop = props[name]; const isDeprecated = ((prop as Prop).tags || []).some( ({ title }) => title === 'deprecated', ); if (isDeprecated) { output.deprecatedProps[name] = prop; } else { output.supportedProps[name] = prop; } return output; }, { deprecatedProps: {}, supportedProps: {} }, ); const Table = ({ properties, publicMethods, title, deprecated, dataHook, }: { title: string; properties?: Record; publicMethods?: Method[]; deprecated?: boolean; dataHook?: string; }) => { return (
{title}
{deprecated && ( The following properties were deprecated and will be removed in near future. Do not use them! )} {publicMethods && } {properties && }
); }; const AutoDocs: React.FunctionComponent = ({ metadata }) => { const { props, methods = [] } = metadata; const publicMethods = methods.filter(({ name }) => !name.startsWith('_')); const { deprecatedProps, supportedProps } = splitDeprecated(props); const containsDeprecated = Object.keys(deprecatedProps).length > 0; const containsPublicMethods = publicMethods.length > 0; return (
{containsPublicMethods && (
)} {containsDeprecated && (
)} ); }; export default AutoDocs;