import { Label, Stack } from '@patternfly/react-core' import { Table, Thead, Th, Tr, Tbody, Td, TableText, } from '@patternfly/react-table' import { css } from '@patternfly/react-styles' import accessibleStyles from '@patternfly/react-styles/css/utilities/Accessibility/accessibility' import textStyles from '@patternfly/react-styles/css/utilities/Text/text' import { Content } from '@patternfly/react-core' export type ComponentProp = { name: string isRequired?: boolean isBeta?: boolean isHidden?: boolean isDeprecated?: boolean type?: string defaultValue?: string description?: string } interface PropsTableProps extends React.HTMLProps { componentName: string headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' componentDescription?: string componentProps?: ComponentProp[] } export const PropsTable: React.FunctionComponent = ({ componentName, headingLevel = 'h3', componentDescription, componentProps, }) => { const publicProps = componentProps?.filter((prop) => !prop.isHidden) const hasPropsToRender = !!publicProps?.length const renderTagLabel = (componentProp: ComponentProp) => { const { name, isBeta, isDeprecated } = componentProp if (!isBeta && !isDeprecated) { return null } if (isBeta && isDeprecated) { // eslint-disable-next-line no-console console.error( `The ${name} prop for ${componentName} has both the isBeta and isDeprecated tag.`, ) } return ( ) } const renderRequiredDescription = (isRequired: boolean | undefined) => { if (!isRequired) { return null } return ( <> required ) } return (
{componentName} {componentDescription && (
{componentDescription}
)} {hasPropsToRender && ( <>
*{' '} indicates a required prop
{publicProps.map((prop: ComponentProp) => ( ))}
Name Type Default Description
{prop.name} {renderRequiredDescription(prop.isRequired)}{' '} {renderTagLabel(prop)} {prop.type || 'No type info available'} {prop.defaultValue || '-'} {prop.description || 'No description available.'}
)}
) }