@@ -41,9 +41,58 @@ type item =
41
41
detail : Js .Null .t <detail >,
42
42
})
43
43
44
+ module RightSidebar = {
45
+ @react.component
46
+ let make = (~items : array <item >) => {
47
+ switch items -> Js .Array2 .length === 0 {
48
+ | true => React .null
49
+ | false =>
50
+ let valuesAndTypes = items -> Js .Array2 .map (item => {
51
+ switch item {
52
+ | Value ({name , deprecated }) as kind | Type ({name , deprecated }) as kind =>
53
+ let (icon , textColor , bgColor , href ) = switch kind {
54
+ | Type (_ ) => ("t" , "text-fire-30" , "bg-fire-5" , ` #type-${name}` )
55
+ | Value (_ ) => ("v" , "text-sky-30" , "bg-sky-5" , ` #value-${name}` )
56
+ }
57
+ let deprecatedIcon = switch deprecated -> Js .Null .toOption {
58
+ | Some (_ ) =>
59
+ <div
60
+ className = {` bg-orange-100 min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl ml-auto` }>
61
+ <span className = {"text-[10px] text-orange-400" }> {"D" -> React .string } </span >
62
+ </div >-> Some
63
+ | None => None
64
+ }
65
+ let title = ` ${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : "" }` ++ name
66
+ let result =
67
+ <li className = "my-3" >
68
+ <a
69
+ title
70
+ className = "flex items-center w-full font-normal text-14 text-gray-40 leading-tight hover:text-gray-80"
71
+ href >
72
+ <div
73
+ className = {` ${bgColor} min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl` }>
74
+ <span className = {"text-[10px] font-normal " ++ textColor }>
75
+ {icon -> React .string }
76
+ </span >
77
+ </div >
78
+ <span className = {"truncate" }> {React .string (name )} </span >
79
+ {switch deprecatedIcon {
80
+ | Some (icon ) => icon
81
+ | None => React .null
82
+ }}
83
+ </a >
84
+ </li >
85
+ result
86
+ }
87
+ })
88
+ valuesAndTypes -> React .array
89
+ }
90
+ }
91
+ }
92
+
44
93
module SidebarTree = {
45
94
@react.component
46
- let make = (~isOpen : bool , ~toggle : unit => unit , ~node : node ) => {
95
+ let make = (~isOpen : bool , ~toggle : unit => unit , ~node : node , ~ items : array < item > ) => {
47
96
let router = Next .Router .useRouter ()
48
97
49
98
let moduleRoute =
@@ -54,6 +103,16 @@ module SidebarTree = {
54
103
let summaryClassName = "truncate py-1 md:h-auto tracking-tight text-gray-60 font-medium text-14 rounded-sm hover:bg-gray-20 hover:-ml-2 hover:py-1 hover:pl-2 "
55
104
let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70"
56
105
106
+ let subMenu = switch items -> Js .Array2 .length > 0 {
107
+ | true =>
108
+ <div className = {"xl:hidden ml-5" }>
109
+ <ul className = {"list-none py-0.5" }>
110
+ <RightSidebar items />
111
+ </ul >
112
+ </div >
113
+ | false => React .null
114
+ }
115
+
57
116
let rec renderNode = node => {
58
117
let isCurrentRoute =
59
118
Js .Array2 .joinWith (moduleRoute , "/" ) === Js .Array2 .joinWith (node .path , "/" )
@@ -63,6 +122,8 @@ module SidebarTree = {
63
122
let hasChildren = node .children -> Js .Array2 .length > 0
64
123
let href = node .path -> Js .Array2 .joinWith ("/" )
65
124
125
+ let tocModule = isCurrentRoute ? subMenu : React .null
126
+
66
127
switch hasChildren {
67
128
| true =>
68
129
let open_ =
@@ -77,6 +138,7 @@ module SidebarTree = {
77
138
{node .name -> React .string }
78
139
</Next .Link >
79
140
</summary >
141
+ tocModule
80
142
{if hasChildren {
81
143
<ul className = {"ml-5" }>
82
144
{node .children
@@ -92,6 +154,7 @@ module SidebarTree = {
92
154
<summary className = {summaryClassName ++ classNameActive }>
93
155
<Next .Link className = {"block" } href > {node .name -> React .string } </Next .Link >
94
156
</summary >
157
+ tocModule
95
158
</li >
96
159
}
97
160
}
@@ -160,6 +223,7 @@ module SidebarTree = {
160
223
href = {node .path -> Js .Array2 .joinWith ("/" )}>
161
224
{node .name -> React .string }
162
225
</Next .Link >
226
+ {moduleRoute -> Js .Array2 .length === 1 ? subMenu : React .null }
163
227
</div >
164
228
<div className = "hl-overline text-gray-80 mt-5 mb-2" > {"submodules" -> React .string } </div >
165
229
{node .children
@@ -277,54 +341,16 @@ let default = (props: props) => {
277
341
278
342
let rightSidebar = switch props {
279
343
| Ok ({module_ : {items }}) if Js .Array2 .length (items ) > 0 =>
280
- let valuesAndTypes = items -> Belt .Array .keepMap (item => {
281
- switch item {
282
- | Value ({name , deprecated }) as kind | Type ({name , deprecated }) as kind =>
283
- let (icon , textColor , bgColor , href ) = switch kind {
284
- | Type (_ ) => ("t" , "text-fire-30" , "bg-fire-5" , ` #type-${name}` )
285
- | Value (_ ) => ("v" , "text-sky-30" , "bg-sky-5" , ` #value-${name}` )
286
- }
287
- let deprecatedIcon = switch deprecated -> Js .Null .toOption {
288
- | Some (_ ) =>
289
- <div
290
- className = {` bg-orange-100 min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl ml-auto` }>
291
- <span className = {"text-[10px] text-orange-400" }> {"D" -> React .string } </span >
292
- </div >-> Some
293
- | None => None
294
- }
295
- let title = ` ${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : "" }` ++ name
296
- let result =
297
- <li className = "my-3" >
298
- <a
299
- title
300
- className = "flex items-center w-full font-normal text-14 text-gray-40 leading-tight hover:text-gray-80"
301
- href >
302
- <div
303
- className = {` ${bgColor} min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl` }>
304
- <span className = {"text-[10px] font-normal " ++ textColor }>
305
- {icon -> React .string }
306
- </span >
307
- </div >
308
- <span className = {"truncate" }> {React .string (name )} </span >
309
- {switch deprecatedIcon {
310
- | Some (icon ) => icon
311
- | None => React .null
312
- }}
313
- </a >
314
- </li >
315
- Some (result )
316
- }
317
- })
344
+ let rightSidebar = <RightSidebar items />
318
345
<div className = "hidden xl:block lg:w-1/5 md:h-auto md:relative overflow-y-visible bg-white" >
319
346
<aside
320
347
className = "relative top-0 pl-4 w-full block md:top-16 md:pt-16 md:sticky border-l border-gray-20 overflow-y-auto pb-24 h-[calc(100vh-4.5rem)]" >
321
348
<div className = "hl-overline block text-gray-80 mt-16 mb-2" >
322
349
{"Types and values" -> React .string }
323
350
</div >
324
- <ul > {valuesAndTypes -> React . array } </ul >
351
+ <ul > {rightSidebar } </ul >
325
352
</aside >
326
353
</div >
327
-
328
354
| _ => React .null
329
355
}
330
356
@@ -334,7 +360,8 @@ let default = (props: props) => {
334
360
}
335
361
336
362
let sidebar = switch props {
337
- | Ok ({toctree }) => <SidebarTree isOpen = isSidebarOpen toggle = toggleSidebar node = {toctree } />
363
+ | Ok ({toctree , module_ : {items }}) =>
364
+ <SidebarTree isOpen = isSidebarOpen toggle = toggleSidebar node = {toctree } items />
338
365
| Error (_ ) => React .null
339
366
}
340
367
0 commit comments