@@ -12,34 +12,39 @@ import { css } from '@patternfly/react-styles'
1212import accessibleStyles from '@patternfly/react-styles/css/utilities/Accessibility/accessibility'
1313import textStyles from '@patternfly/react-styles/css/utilities/Text/text'
1414
15- type ComponentProp = {
15+ export type ComponentProp = {
1616 name : string
1717 isRequired ?: boolean
1818 isBeta ?: boolean
19+ isHidden ?: boolean
1920 isDeprecated ?: boolean
2021 type ?: string
2122 defaultValue ?: string
22- description : string
23+ description ? : string
2324}
2425
2526type PropsTableProps = {
2627 componentName : string
28+ headingLevel ?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
2729 componentDescription ?: string
2830 componentProps ?: ComponentProp [ ]
2931}
3032
3133export const PropsTable : React . FunctionComponent < PropsTableProps > = ( {
3234 componentName,
35+ headingLevel = 'h3' ,
3336 componentDescription,
3437 componentProps,
3538} ) => {
36- const hasPropsToRender = ! ! componentProps ?. length
39+ const SectionHeading = headingLevel
40+ const publicProps = componentProps ?. filter ( ( prop ) => ! prop . isHidden )
41+ const hasPropsToRender = ! ! publicProps ?. length
3742 const betaDeprecatedProps = hasPropsToRender
38- ? componentProps . filter ( ( prop ) => prop . isBeta && prop . isDeprecated )
43+ ? publicProps . filter ( ( prop ) => prop . isBeta && prop . isDeprecated )
3944 : [ ]
4045
4146 if ( betaDeprecatedProps . length ) {
42- throw new Error (
47+ console . error (
4348 `The following ${ componentName } props have both the isBeta and isDeprecated tag: ${ betaDeprecatedProps . map ( ( prop ) => prop . name ) . join ( ', ' ) } ` ,
4449 )
4550 }
@@ -64,16 +69,19 @@ export const PropsTable: React.FunctionComponent<PropsTableProps> = ({
6469
6570 return (
6671 < >
67- < h3 > { componentName } </ h3 >
72+ < SectionHeading > { componentName } </ SectionHeading >
6873 < Stack hasGutter >
6974 { componentDescription && (
70- < div className = { css ( textStyles . textColorSubtle ) } >
75+ < div
76+ data-testid = "component-description"
77+ className = { css ( textStyles . textColorSubtle ) }
78+ >
7179 { componentDescription }
7280 </ div >
7381 ) }
7482 { hasPropsToRender && (
7583 < >
76- < div id = { `${ componentName } -required` } >
84+ < div id = { `${ componentName } -required-description ` } >
7785 < span className = { css ( textStyles . textColorRequired ) } > *</ span > { ' ' }
7886 < span className = { css ( textStyles . textColorSubtle ) } >
7987 indicates a required prop
@@ -82,19 +90,19 @@ export const PropsTable: React.FunctionComponent<PropsTableProps> = ({
8290 < Table
8391 variant = "compact"
8492 aria-label = { `Props for ${ componentName } ` }
85- aria-describedby = { `${ componentName } -required` }
93+ aria-describedby = { `${ componentName } -required-description ` }
8694 gridBreakPoint = "grid-lg"
8795 >
8896 < Thead >
8997 < Tr >
9098 < Th width = { 20 } > Name</ Th >
9199 < Th width = { 20 } > Type</ Th >
92- < Th > Default</ Th >
100+ < Th width = { 10 } > Default</ Th >
93101 < Th > Description</ Th >
94102 </ Tr >
95103 </ Thead >
96104 < Tbody >
97- { componentProps ? .map ( ( prop : ComponentProp ) => (
105+ { publicProps . map ( ( prop : ComponentProp ) => (
98106 < Tr key = { prop . name } >
99107 < Td >
100108 < TableText wrapModifier = "breakWord" >
@@ -121,17 +129,17 @@ export const PropsTable: React.FunctionComponent<PropsTableProps> = ({
121129 </ Td >
122130 < Td >
123131 < TableText wrapModifier = "breakWord" >
124- { prop . type || 'No type info' }
132+ { prop . type || 'No type info available ' }
125133 </ TableText >
126134 </ Td >
127135 < Td >
128136 < TableText wrapModifier = "breakWord" >
129- { prop . defaultValue }
137+ { prop . defaultValue || '-' }
130138 </ TableText >
131139 </ Td >
132140 < Td >
133141 < TableText wrapModifier = "breakWord" >
134- { prop . description }
142+ { prop . description || 'No description available.' }
135143 </ TableText >
136144 </ Td >
137145 </ Tr >
0 commit comments