@@ -41,9 +41,55 @@ 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
+ items
48
+ -> Js .Array2 .map (item => {
49
+ switch item {
50
+ | Value ({name , deprecated }) as kind | Type ({name , deprecated }) as kind =>
51
+ let (icon , textColor , bgColor , href ) = switch kind {
52
+ | Type (_ ) => ("t" , "text-fire-30" , "bg-fire-5" , ` #type-${name}` )
53
+ | Value (_ ) => ("v" , "text-sky-30" , "bg-sky-5" , ` #value-${name}` )
54
+ }
55
+ let deprecatedIcon = switch deprecated -> Js .Null .toOption {
56
+ | Some (_ ) =>
57
+ <div
58
+ 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` }>
59
+ <span className = {"text-[10px] text-orange-400" }> {"D" -> React .string } </span >
60
+ </div >-> Some
61
+ | None => None
62
+ }
63
+ let title = ` ${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : "" }` ++ name
64
+ let result =
65
+ <li className = "my-3" >
66
+ <a
67
+ title
68
+ className = "flex items-center w-full font-normal text-14 text-gray-40 leading-tight hover:text-gray-80"
69
+ href >
70
+ <div
71
+ className = {` ${bgColor} min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl` }>
72
+ <span className = {"text-[10px] font-normal " ++ textColor }>
73
+ {icon -> React .string }
74
+ </span >
75
+ </div >
76
+ <span className = {"truncate" }> {React .string (name )} </span >
77
+ {switch deprecatedIcon {
78
+ | Some (icon ) => icon
79
+ | None => React .null
80
+ }}
81
+ </a >
82
+ </li >
83
+ result
84
+ }
85
+ })
86
+ -> React .array
87
+ }
88
+ }
89
+
44
90
module SidebarTree = {
45
91
@react.component
46
- let make = (~isOpen : bool , ~toggle : unit => unit , ~node : node ) => {
92
+ let make = (~isOpen : bool , ~toggle : unit => unit , ~node : node , ~ items : array < item > ) => {
47
93
let router = Next .Router .useRouter ()
48
94
49
95
let moduleRoute =
@@ -54,6 +100,16 @@ module SidebarTree = {
54
100
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
101
let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70"
56
102
103
+ let subMenu = switch items -> Js .Array2 .length > 0 {
104
+ | true =>
105
+ <div className = {"xl:hidden ml-5" }>
106
+ <ul className = {"list-none py-0.5" }>
107
+ <RightSidebar items />
108
+ </ul >
109
+ </div >
110
+ | false => React .null
111
+ }
112
+
57
113
let rec renderNode = node => {
58
114
let isCurrentRoute =
59
115
Js .Array2 .joinWith (moduleRoute , "/" ) === Js .Array2 .joinWith (node .path , "/" )
@@ -63,6 +119,8 @@ module SidebarTree = {
63
119
let hasChildren = node .children -> Js .Array2 .length > 0
64
120
let href = node .path -> Js .Array2 .joinWith ("/" )
65
121
122
+ let tocModule = isCurrentRoute ? subMenu : React .null
123
+
66
124
switch hasChildren {
67
125
| true =>
68
126
let open_ =
@@ -77,6 +135,7 @@ module SidebarTree = {
77
135
{node .name -> React .string }
78
136
</Next .Link >
79
137
</summary >
138
+ tocModule
80
139
{if hasChildren {
81
140
<ul className = {"ml-5" }>
82
141
{node .children
@@ -92,6 +151,7 @@ module SidebarTree = {
92
151
<summary className = {summaryClassName ++ classNameActive }>
93
152
<Next .Link className = {"block" } href > {node .name -> React .string } </Next .Link >
94
153
</summary >
154
+ tocModule
95
155
</li >
96
156
}
97
157
}
@@ -160,6 +220,7 @@ module SidebarTree = {
160
220
href = {node .path -> Js .Array2 .joinWith ("/" )}>
161
221
{node .name -> React .string }
162
222
</Next .Link >
223
+ {moduleRoute -> Js .Array2 .length === 1 ? subMenu : React .null }
163
224
</div >
164
225
<div className = "hl-overline text-gray-80 mt-5 mb-2" > {"submodules" -> React .string } </div >
165
226
{node .children
@@ -277,54 +338,17 @@ let default = (props: props) => {
277
338
278
339
let rightSidebar = switch props {
279
340
| 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
- })
318
341
<div className = "hidden xl:block lg:w-1/5 md:h-auto md:relative overflow-y-visible bg-white" >
319
342
<aside
320
343
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
344
<div className = "hl-overline block text-gray-80 mt-16 mb-2" >
322
345
{"Types and values" -> React .string }
323
346
</div >
324
- <ul > {valuesAndTypes -> React .array } </ul >
347
+ <ul >
348
+ <RightSidebar items />
349
+ </ul >
325
350
</aside >
326
351
</div >
327
-
328
352
| _ => React .null
329
353
}
330
354
@@ -334,7 +358,8 @@ let default = (props: props) => {
334
358
}
335
359
336
360
let sidebar = switch props {
337
- | Ok ({toctree }) => <SidebarTree isOpen = isSidebarOpen toggle = toggleSidebar node = {toctree } />
361
+ | Ok ({toctree , module_ : {items }}) =>
362
+ <SidebarTree isOpen = isSidebarOpen toggle = toggleSidebar node = {toctree } items />
338
363
| Error (_ ) => React .null
339
364
}
340
365
0 commit comments