diff --git a/src/ApiDocs.res b/src/ApiDocs.res index 600d62d5a..ba683bcba 100644 --- a/src/ApiDocs.res +++ b/src/ApiDocs.res @@ -41,9 +41,55 @@ type item = detail: Js.Null.t, }) +module RightSidebar = { + @react.component + let make = (~items: array) => { + items + ->Js.Array2.map(item => { + switch item { + | Value({name, deprecated}) as kind | Type({name, deprecated}) as kind => + let (icon, textColor, bgColor, href) = switch kind { + | Type(_) => ("t", "text-fire-30", "bg-fire-5", `#type-${name}`) + | Value(_) => ("v", "text-sky-30", "bg-sky-5", `#value-${name}`) + } + let deprecatedIcon = switch deprecated->Js.Null.toOption { + | Some(_) => +
+ {"D"->React.string} +
->Some + | None => None + } + let title = `${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : ""}` ++ name + let result = +
  • + +
    + + {icon->React.string} + +
    + {React.string(name)} + {switch deprecatedIcon { + | Some(icon) => icon + | None => React.null + }} +
    +
  • + result + } + }) + ->React.array + } +} + module SidebarTree = { @react.component - let make = (~isOpen: bool, ~toggle: unit => unit, ~node: node) => { + let make = (~isOpen: bool, ~toggle: unit => unit, ~node: node, ~items: array) => { let router = Next.Router.useRouter() let moduleRoute = @@ -54,6 +100,16 @@ module SidebarTree = { 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 " let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70" + let subMenu = switch items->Js.Array2.length > 0 { + | true => +
    +
      + +
    +
    + | false => React.null + } + let rec renderNode = node => { let isCurrentRoute = Js.Array2.joinWith(moduleRoute, "/") === Js.Array2.joinWith(node.path, "/") @@ -63,6 +119,8 @@ module SidebarTree = { let hasChildren = node.children->Js.Array2.length > 0 let href = node.path->Js.Array2.joinWith("/") + let tocModule = isCurrentRoute ? subMenu : React.null + switch hasChildren { | true => let open_ = @@ -77,6 +135,7 @@ module SidebarTree = { {node.name->React.string} + tocModule {if hasChildren {
      {node.children @@ -92,6 +151,7 @@ module SidebarTree = { {node.name->React.string} + tocModule } } @@ -160,6 +220,7 @@ module SidebarTree = { href={node.path->Js.Array2.joinWith("/")}> {node.name->React.string} + {moduleRoute->Js.Array2.length === 1 ? subMenu : React.null}
      {"submodules"->React.string}
      {node.children @@ -277,54 +338,17 @@ let default = (props: props) => { let rightSidebar = switch props { | Ok({module_: {items}}) if Js.Array2.length(items) > 0 => - let valuesAndTypes = items->Belt.Array.keepMap(item => { - switch item { - | Value({name, deprecated}) as kind | Type({name, deprecated}) as kind => - let (icon, textColor, bgColor, href) = switch kind { - | Type(_) => ("t", "text-fire-30", "bg-fire-5", `#type-${name}`) - | Value(_) => ("v", "text-sky-30", "bg-sky-5", `#value-${name}`) - } - let deprecatedIcon = switch deprecated->Js.Null.toOption { - | Some(_) => -
      - {"D"->React.string} -
      ->Some - | None => None - } - let title = `${Belt.Option.isSome(deprecatedIcon) ? "Deprecated " : ""}` ++ name - let result = -
    • - -
      - - {icon->React.string} - -
      - {React.string(name)} - {switch deprecatedIcon { - | Some(icon) => icon - | None => React.null - }} -
      -
    • - Some(result) - } - })
      - | _ => React.null } @@ -334,7 +358,8 @@ let default = (props: props) => { } let sidebar = switch props { - | Ok({toctree}) => + | Ok({toctree, module_: {items}}) => + | Error(_) => React.null }