Skip to content

Commit 7dab414

Browse files
committed
add right sidebar
1 parent 176d127 commit 7dab414

File tree

3 files changed

+61
-54
lines changed

3 files changed

+61
-54
lines changed

src/ApiDocs.res

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ let default = (props: props) => {
238238
| _ => "API"
239239
}
240240

241-
let item = {
241+
let children = {
242242
open Markdown
243243
switch props {
244244
| Ok({module_: {id, name, docstrings, items}}) =>
@@ -274,39 +274,58 @@ let default = (props: props) => {
274274
}
275275
}
276276

277-
// let valuesAndTypes = switch props {
278-
// | Ok({module_: {items}}) if Js.Array2.length(items) > 0 =>
279-
// let valuesAndTypes = items->Belt.Array.keepMap(item => {
280-
// switch item {
281-
// | Value({name}) as kind | Type({name}) as kind =>
282-
// let icon = switch kind {
283-
// | Type(_) => "T"
284-
// | Value(_) => "V"
285-
// }
286-
// let (textColor, bgColor) = switch kind {
287-
// | Type(_) => ("text-fire-30", "bg-fire-5")
288-
// | Value(_) => ("text-sky-30", "bg-sky-5")
289-
// }
290-
// let result =
291-
// <li className="my-3 flex">
292-
// <a
293-
// className="flex font-normal text-14 text-gray-40 leading-tight hover:text-gray-80"
294-
// href={`#${name}`}>
295-
// <div
296-
// className={`${bgColor} w-5 h-5 mr-3 flex justify-center items-center rounded-xl`}>
297-
// <span style={ReactDOM.Style.make(~fontSize="10px", ())} className=textColor>
298-
// {icon->React.string}
299-
// </span>
300-
// </div>
301-
// {React.string(name)}
302-
// </a>
303-
// </li>
304-
// Some(result)
305-
// }
306-
// })
307-
// valuesAndTypes->Some
308-
// | _ => None
309-
// }
277+
let rightSidebar = switch props {
278+
| Ok({module_: {items}}) if Js.Array2.length(items) > 0 =>
279+
let valuesAndTypes = items->Belt.Array.keepMap(item => {
280+
switch item {
281+
| Value({name, deprecated}) as kind | Type({name, deprecated}) as kind =>
282+
let (icon, textColor, bgColor, href) = switch kind {
283+
| Type(_) => ("t", "text-fire-30", "bg-fire-5", `#type-${name}`)
284+
| Value(_) => ("v", "text-sky-30", "bg-sky-5", `#value-${name}`)
285+
}
286+
let deprecatedIcon = switch deprecated->Js.Null.toOption {
287+
| Some(_) =>
288+
<div
289+
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`}>
290+
<span className={"text-[10px] text-orange-400"}> {"D"->React.string} </span>
291+
</div>->Some
292+
| None => None
293+
}
294+
let title = `${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : ""}` ++ name
295+
let result =
296+
<li className="my-3">
297+
<a
298+
title
299+
className="flex items-center w-full font-normal text-14 text-gray-40 leading-tight hover:text-gray-80"
300+
href>
301+
<div
302+
className={`${bgColor} min-w-[20px] min-h-[20px] w-5 h-5 mr-3 flex justify-center items-center rounded-xl`}>
303+
<span className={"text-[10px] font-normal " ++ textColor}>
304+
{icon->React.string}
305+
</span>
306+
</div>
307+
<span className={"truncate"}> {React.string(name)} </span>
308+
{switch deprecatedIcon {
309+
| Some(icon) => icon
310+
| None => React.null
311+
}}
312+
</a>
313+
</li>
314+
Some(result)
315+
}
316+
})
317+
<div className="hidden xl:block lg:w-1/5 md:h-auto md:relative overflow-y-visible bg-white">
318+
<aside
319+
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)]">
320+
<div className="hl-overline block text-gray-80 mt-16 mb-2">
321+
{"Types and values"->React.string}
322+
</div>
323+
<ul> {valuesAndTypes->React.array} </ul>
324+
</aside>
325+
</div>
326+
327+
| _ => React.null
328+
}
310329

311330
let version = switch Url.parse(router.asPath).version {
312331
| Latest | NoVersion => "latest"
@@ -324,32 +343,14 @@ let default = (props: props) => {
324343

325344
let breadcrumbs = ApiLayout.makeBreadcrumbs(~prefix, router.asPath)
326345

327-
let children =
328-
<>
329-
item
330-
// {switch valuesAndTypes {
331-
// | Some(elemets) =>
332-
// <div className="pt-16 relative">
333-
// <aside
334-
// className="sticky top-18 overflow-auto px-8"
335-
// style={ReactDOM.Style.make(~height="calc(100vh - 6rem)", ())}>
336-
// <span className="font-normal block text-14 text-gray-40">
337-
// {React.string("Types and Values")}
338-
// </span>
339-
// <ul> {elemets->React.array} </ul>
340-
// </aside>
341-
// </div>
342-
// | None => React.null
343-
// }}
344-
</>
345-
346346
<SidebarLayout
347347
breadcrumbs
348348
metaTitle={title ++ " | ReScript API"}
349349
theme=#Reason
350350
components=ApiMarkdown.default
351351
sidebarState=(isSidebarOpen, setSidebarOpen)
352-
sidebar>
352+
sidebar
353+
rightSidebar>
353354
children
354355
</SidebarLayout>
355356
}

src/layouts/SidebarLayout.res

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ let make = (
215215
~sidebarState: (bool, (bool => bool) => unit),
216216
// (Sidebar, toggleSidebar) ... for toggling sidebar in mobile view
217217
~sidebar: React.element,
218+
~rightSidebar: option<React.element>=?,
218219
~categories: option<array<Sidebar.Category.t>>=?,
219220
~breadcrumbs: option<list<Url.breadcrumb>>=?,
220221
~children,
@@ -325,6 +326,10 @@ let make = (
325326
</div>
326327
pagination
327328
</main>
329+
{switch rightSidebar {
330+
| Some(ele) => ele
331+
| None => React.null
332+
}}
328333
</div>
329334
</div>
330335
</div>

src/layouts/SidebarLayout.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ let make: (
7070
// (Sidebar, toggleSidebar) ... for toggling sidebar in mobile view
7171
~sidebarState: (bool, (bool => bool) => unit),
7272
~sidebar: React.element,
73+
~rightSidebar: React.element=?,
7374
~categories: array<Sidebar.Category.t>=?,
7475
~breadcrumbs: list<Url.breadcrumb>=?,
7576
~children: React.element,

0 commit comments

Comments
 (0)