1+ /* eslint-disable react/no-danger */ 
12import  *  as  React  from  'react' ; 
3+ import  {  readFile  }  from  'node:fs/promises' ; 
24import  type  {  GetStaticPaths ,  GetStaticProps ,  InferGetStaticPropsType  }  from  'next' ; 
35import  Head  from  'next/head' ; 
6+ import  kebabCase  from  'lodash/kebabCase' ; 
47import  {  getMDXComponent  }  from  'mdx-bundler/client' ; 
58import  {  getMarkdownPage  }  from  'docs-base/src/utils/getMarkdownPage' ; 
69import  {  MasterLayout  }  from  'docs-base/src/layout/MasterLayout' ; 
@@ -29,6 +32,37 @@ export default function ComponentPage(props: InferGetStaticPropsType<typeof getS
2932        < title > { props . metadata . title } </ title > 
3033      </ Head > 
3134      < Component  components = { components }  /> 
35+ 
36+       < h2 > API Reference</ h2 > 
37+       < div > 
38+         { props . componentsApi . map ( ( apiDescription )  =>  ( 
39+           < React . Fragment  key = { apiDescription . name } > 
40+             < h3 > { apiDescription . name } </ h3 > 
41+             < p  dangerouslySetInnerHTML = { {  __html : apiDescription . description  } }  /> 
42+             < table > 
43+               < thead > 
44+                 < tr > 
45+                   < th > Prop</ th > 
46+                   < th > Type</ th > 
47+                   < th > Default</ th > 
48+                   < th > Description</ th > 
49+                 </ tr > 
50+               </ thead > 
51+               < tbody > 
52+                 { apiDescription . props . map ( ( prop )  =>  ( 
53+                   < tr  key = { prop . name } > 
54+                     < td > { prop . name } </ td > 
55+                     < td > { prop . type . name } </ td > 
56+                     < td > { prop . default } </ td > 
57+                     < td  dangerouslySetInnerHTML = { {  __html : prop . description  } }  /> 
58+                   </ tr > 
59+                 ) ) } 
60+               </ tbody > 
61+             </ table > 
62+           </ React . Fragment > 
63+         ) ) } 
64+       </ div > 
65+ 
3266      < TableOfContents  /> 
3367    </ React . Fragment > 
3468  ) ; 
@@ -42,12 +76,37 @@ export const getStaticProps = (async (context) => {
4276  } 
4377
4478  const  page  =  await  getMarkdownPage ( 'components' ,  params . slug  as  string ) ; 
79+   const  documentedComponents  =  page . metadata . components ?. split ( ',' ) . map ( ( c )  =>  c . trim ( ) )  ??  [ ] ; 
80+ 
81+   const  componentsApi  =  await  Promise . all ( 
82+     documentedComponents . map ( async  ( componentName )  =>  { 
83+       const  kebabedComponentName  =  kebabCase ( componentName ) ; 
84+       const  apiDescriptionFilePath  =  `data/base/api/${ kebabedComponentName }  ; 
85+       const  translationsFilePath  =  `data/base/translations/api-docs/${ kebabedComponentName } ${ kebabedComponentName }  ; 
86+ 
87+       const  apiDescription  =  JSON . parse ( await  readFile ( apiDescriptionFilePath ,  'utf-8' ) ) ; 
88+       const  translations  =  JSON . parse ( await  readFile ( translationsFilePath ,  'utf-8' ) ) ; 
89+ 
90+       return  { 
91+         name : componentName , 
92+         description : translations . componentDescription , 
93+         props : Object . keys ( apiDescription . props ) . map ( ( propName )  =>  ( { 
94+           name : propName , 
95+           ...apiDescription . props [ propName ] , 
96+           ...translations . propDescriptions [ propName ] , 
97+         } ) ) , 
98+       } ; 
99+     } ) , 
100+   ) ; 
101+ 
102+   console . log ( componentsApi ) ; 
45103
46104  return  { 
47105    props : { 
48106      slug : context ?. params ?. slug  ??  '' , 
49107      metadata : page . metadata , 
50108      content : page . code , 
109+       componentsApi, 
51110    } , 
52111  } ; 
53112} )  satisfies  GetStaticProps ; 
0 commit comments