@@ -2,6 +2,13 @@ const config = require('../docusaurus.config');
22
33const { baseUrl, customFields } = config ;
44
5+ function renderBadge ( annotation ) {
6+ const [ annotType , ...annotLabel ] = annotation . split ( ' ' ) ;
7+
8+ // eslint-disable-next-line prettier/prettier
9+ return `<span class="badge badge-${ annotType . replace ( '@' , '' ) } "><span class="badge-text">${ annotLabel . join ( ' ' ) } </span></span>` ;
10+ }
11+
512function generateKnownIssues ( componentName ) {
613 const componentKnownIssues = customFields . knownIssues [ componentName ] ;
714
@@ -79,6 +86,54 @@ function generateScreenshots(componentName, screenshotData) {
7986 ` ;
8087}
8188
89+ function generatePropsTable ( data , link ) {
90+ const ANNOTATION_OPTIONAL = '@optional' ;
91+ const ANNOTATION_INTERNAL = '@internal' ;
92+
93+ const props = Object . entries ( data )
94+ . map ( ( [ prop , value ] ) => {
95+ if ( ! value . description ) {
96+ value . description = '' ;
97+ }
98+ // Remove @optional annotations from descriptions.
99+ if ( value . description . includes ( ANNOTATION_OPTIONAL ) ) {
100+ value . description = value . description . replace ( ANNOTATION_OPTIONAL , '' ) ;
101+ }
102+ // Hide props with @internal annotations.
103+ if ( value . description . includes ( ANNOTATION_INTERNAL ) ) {
104+ return ;
105+ }
106+
107+ let leadingBadge = '' ;
108+ let descriptionByLines = value . description ?. split ( '\n' ) ;
109+
110+ // Find leading badge and put it next after prop name.
111+ if ( descriptionByLines ?. [ 0 ] . includes ( '@' ) ) {
112+ leadingBadge = descriptionByLines [ 0 ] ;
113+ }
114+
115+ return `
116+ <div>
117+
118+ ### ${ prop } ${ value . required ? '(required)' : '' } ${
119+ leadingBadge && renderBadge ( leadingBadge )
120+ }
121+
122+ </div>
123+
124+ <PropTable componentLink="${ link } " prop="${ prop } " />
125+
126+ ---
127+ ` ;
128+ } )
129+ . join ( '' ) ;
130+
131+ return `
132+ ## Props
133+ ${ props }
134+ ` ;
135+ }
136+
82137function generatePageMDX ( doc , link ) {
83138 const summaryRegex = / ( [ \s \S ] * ?) # # U s a g e / ;
84139
@@ -111,11 +166,9 @@ ${generateScreenshots(doc.title, screenshotData)}
111166
112167${ usage }
113168
114- ${ generateMoreExamples ( doc . title ) }
115-
116- ## Props
169+ ${ generatePropsTable ( doc . data . props , link ) }
117170
118- <PropTable link=" ${ link } " />
171+ ${ generateMoreExamples ( doc . title ) }
119172
120173${ generateThemeColors ( doc . title , themeColorsData ) }
121174
0 commit comments