11import type { FC } from "hono/jsx" ;
22import { basePath } from "../../metadata" ;
33import { Translation } from "../../translation/" ;
4- import type { Func } from "../../types/model" ;
4+ import type { Param } from "../../types/model" ;
5+ import { normalizeDetailBlocks } from "../../utils/normalizeModel" ;
56import { joinPath } from "../../utils/path" ;
67import { ChevronRightIcon } from "../icons" ;
78import { HtmlContent } from "./HtmlContent" ;
@@ -10,7 +11,9 @@ import { TypeIcon } from "./TypeIcon";
1011import { buildParamId , type2href } from "./type2href" ;
1112
1213type FunctionParametersProps = {
13- func : Func ;
14+ params : Param [ ] ;
15+ /** Whether these parameter are global attributes */
16+ globalAttributes ?: boolean ;
1417 /**
1518 * The prefix for IDs
1619 *
@@ -20,17 +23,19 @@ type FunctionParametersProps = {
2023} ;
2124
2225export const FunctionParameters : FC < FunctionParametersProps > = ( {
23- func,
26+ params,
27+ globalAttributes = false ,
2428 prefix = undefined ,
2529} ) => {
30+ const Heading = globalAttributes ? "h3" : "h4" ;
2631 return (
2732 < div class = "space-y-6" >
28- { func . params . map ( ( param , _index ) => (
33+ { params . map ( ( param , _index ) => (
2934 < div
3035 key = { param . name }
3136 class = "bg-gray-50 rounded-md p-4 border border-gray-100"
3237 >
33- < h4
38+ < Heading
3439 id = { buildParamId ( param . name , prefix ) }
3540 class = "flex flex-wrap items-center gap-2 mb-3"
3641 >
@@ -56,24 +61,37 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
5661 { param . variadic && < Tooltip kind = "variadic" /> }
5762 { param . settable && < Tooltip kind = "settable" /> }
5863 </ div >
59- </ h4 >
64+ </ Heading >
6065
61- < div class = "mb-3 text-gray-700" >
62- < HtmlContent html = { param . details } />
63- </ div >
64-
65- { param . default && (
66- < p class = "mt-3 text-sm" >
67- < span class = "font-medium" >
68- < Translation translationKey = "defaultValue" />
69- </ span > { " " }
70- < span class = "text-gray-700" >
71- < HtmlContent html = { param . default } />
72- </ span >
73- </ p >
74- ) }
75-
76- { /* Put all collapsible blocks after non-collapsible blocks. */ }
66+ { normalizeDetailBlocks ( param ) . map ( ( block ) => {
67+ switch ( block . kind ) {
68+ case "html" :
69+ return (
70+ < div class = "text-gray-700" >
71+ < HtmlContent html = { block . content } />
72+ </ div >
73+ ) ;
74+ case "example" :
75+ return (
76+ < details class = "folding-example group" >
77+ < summary class = "flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800" >
78+ < div class = "w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90" >
79+ < ChevronRightIcon />
80+ </ div >
81+ < Translation
82+ translationKey = "showExample"
83+ title = { block . content . title }
84+ />
85+ </ summary >
86+ < div class = "mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm" >
87+ < HtmlContent html = { block . content . body } />
88+ </ div >
89+ </ details >
90+ ) ;
91+ default :
92+ return null ;
93+ }
94+ } ) }
7795
7896 { param . strings . length > 0 && (
7997 < details
@@ -104,18 +122,15 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
104122 </ details >
105123 ) }
106124
107- { param . example && (
108- < details class = "my-4 folding-example group" >
109- < summary class = "flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800" >
110- < div class = "w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90" >
111- < ChevronRightIcon />
112- </ div >
113- < Translation translationKey = "showExample" />
114- </ summary >
115- < div class = "mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm" >
116- < HtmlContent html = { param . example } />
117- </ div >
118- </ details >
125+ { param . default && (
126+ < p class = "mt-5 text-sm" >
127+ < span class = "font-medium" >
128+ < Translation translationKey = "defaultValue" />
129+ </ span > { " " }
130+ < span class = "text-gray-700" >
131+ < HtmlContent html = { param . default } />
132+ </ span >
133+ </ p >
119134 ) }
120135 </ div >
121136 ) ) }
0 commit comments