@@ -204,6 +204,8 @@ function ParamOrTypeDetails({ paramOrType }: { paramOrType: object }) {
204
204
? getSubDetails ( paramOrType )
205
205
: undefined
206
206
207
+ const defaultOpen = isDefaultExpanded ( paramOrType )
208
+
207
209
return (
208
210
< >
209
211
< div className = "flex flex-wrap items-baseline gap-3" >
@@ -228,7 +230,9 @@ function ParamOrTypeDetails({ paramOrType }: { paramOrType: object }) {
228
230
< MDXRemoteBase source = { description } customPreprocess = { normalizeMarkdown } />
229
231
</ div >
230
232
) }
231
- { subContent && subContent . length > 0 && < TypeSubDetails details = { subContent } /> }
233
+ { subContent && subContent . length > 0 && (
234
+ < TypeSubDetails details = { subContent } defaultOpen = { defaultOpen } />
235
+ ) }
232
236
</ >
233
237
)
234
238
}
@@ -240,6 +244,7 @@ export function ReturnTypeDetails({ returnType }: { returnType: MethodTypes['ret
240
244
if ( isNameOnlyType ) return
241
245
242
246
const subContent = getSubDetails ( returnType )
247
+ const isDefaultOpen = isDefaultExpanded ( returnType )
243
248
244
249
return (
245
250
< div >
@@ -254,7 +259,9 @@ export function ReturnTypeDetails({ returnType }: { returnType: MethodTypes['ret
254
259
/>
255
260
</ div >
256
261
) }
257
- { subContent && subContent . length > 0 && < TypeSubDetails details = { subContent } /> }
262
+ { subContent && subContent . length > 0 && (
263
+ < TypeSubDetails defaultOpen = { isDefaultOpen } details = { subContent } />
264
+ ) }
258
265
</ div >
259
266
</ div >
260
267
)
@@ -263,12 +270,14 @@ export function ReturnTypeDetails({ returnType }: { returnType: MethodTypes['ret
263
270
function TypeSubDetails ( {
264
271
details,
265
272
className,
273
+ defaultOpen = false ,
266
274
} : {
267
275
details : Array < SubContent > | Array < CustomTypePropertyType > | Array < TypeDetails >
268
276
className ?: string
277
+ defaultOpen ?: boolean
269
278
} ) {
270
279
return (
271
- < Collapsible_Shadcn_ >
280
+ < Collapsible_Shadcn_ defaultOpen = { defaultOpen } >
272
281
< CollapsibleTrigger_Shadcn_
273
282
className = { cn (
274
283
'group' ,
@@ -616,7 +625,7 @@ function getTypeName(parameter: object): string {
616
625
// @ts -ignore
617
626
return `Promise<${ getTypeName ( { type : type . awaited } ) } >`
618
627
case 'union' :
619
- return 'Union: expand to see options'
628
+ return 'One of the following options'
620
629
case 'index signature' :
621
630
// Needs an extra level of wrapping to fake the wrapping parameter
622
631
// @ts -ignore
@@ -667,15 +676,15 @@ function getSubDetails(parentType: MethodTypes['params'][number] | MethodTypes['
667
676
break
668
677
case 'union' :
669
678
subDetails = parentType . type . subTypes . map ( ( subType , index ) => ( {
670
- name : `union option ${ index + 1 } ` ,
679
+ name : `Option ${ index + 1 } ` ,
671
680
type : { ...subType } ,
672
681
isOptional : 'NA' ,
673
682
} ) )
674
683
break
675
684
case 'promise' :
676
685
if ( parentType . type . awaited . type === 'union' ) {
677
686
subDetails = parentType . type . awaited . subTypes . map ( ( subType , index ) => ( {
678
- name : `union option ${ index + 1 } ` ,
687
+ name : `Option ${ index + 1 } ` ,
679
688
type : { ...subType } ,
680
689
isOptional : 'NA' ,
681
690
} ) )
@@ -693,7 +702,7 @@ function getSubDetails(parentType: MethodTypes['params'][number] | MethodTypes['
693
702
case 'array' :
694
703
if ( parentType . type . elemType ?. type === 'union' ) {
695
704
subDetails = parentType . type . elemType . subTypes . map ( ( subType , index ) => ( {
696
- name : `union option ${ index + 1 } ` ,
705
+ name : `Option ${ index + 1 } ` ,
697
706
type : { ...subType } ,
698
707
isOptional : 'NA' ,
699
708
} ) )
@@ -871,3 +880,17 @@ function applyParameterMergeStrategy(
871
880
}
872
881
}
873
882
}
883
+
884
+ function isDefaultExpanded ( meta : object ) {
885
+ return (
886
+ 'type' in meta &&
887
+ typeof meta . type === 'object' &&
888
+ 'type' in meta . type &&
889
+ ( meta . type . type == 'union' ||
890
+ ( meta . type . type === 'promise' &&
891
+ 'awaited' in meta . type &&
892
+ typeof meta . type . awaited === 'object' &&
893
+ 'type' in meta . type . awaited &&
894
+ meta . type . awaited . type === 'union' ) )
895
+ )
896
+ }
0 commit comments