Skip to content

Commit

Permalink
Provide configurability in Navbar dashboard UI component to turn
Browse files Browse the repository at this point in the history
on or off alpha sort of menu links within each menu section.

GitOrigin-RevId: 16878383651b1094e8d1b978ed8b82fed35c65b7
  • Loading branch information
adrw authored and svc-squareup-copybara committed Jan 8, 2025
1 parent 406178a commit 40102ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions misk-tailwind/api/misk-tailwind.api
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public final class misk/tailwind/pages/MenuSection {
}

public final class misk/tailwind/pages/NavbarKt {
public static final fun Navbar (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lwisp/deployment/Deployment;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun Navbar$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lwisp/deployment/Deployment;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun Navbar (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lwisp/deployment/Deployment;Ljava/lang/String;Ljava/util/List;ZLkotlin/jvm/functions/Function1;)V
public static synthetic fun Navbar$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lwisp/deployment/Deployment;Ljava/lang/String;Ljava/util/List;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
}

14 changes: 10 additions & 4 deletions misk-tailwind/src/main/kotlin/misk/tailwind/pages/Navbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun TagConsumer<*>.Navbar(
deployment: Deployment,
homeHref: String,
menuSections: List<MenuSection> = listOf(),
sortedMenuLinks: Boolean = true,
content: TagConsumer<*>.() -> Unit = {}
) {
div("bg-gray-900") {
Expand Down Expand Up @@ -111,7 +112,7 @@ fun TagConsumer<*>.Navbar(
// )
// }
// }
NavMenu(menuSections)
NavMenu(menuSections, sortedMenuLinks)
}
}
}
Expand All @@ -130,7 +131,7 @@ fun TagConsumer<*>.Navbar(
}
}
}
NavMenu(menuSections)
NavMenu(menuSections, sortedMenuLinks)
}
}
div("xl:pl-72") {
Expand Down Expand Up @@ -187,7 +188,7 @@ private fun Deployment.asBorderColor() = when {
else -> "border-b-blue-500"
}

private fun TagConsumer<*>.NavMenu(menuSections: List<MenuSection>) {
private fun TagConsumer<*>.NavMenu(menuSections: List<MenuSection>, sortedMenuLinks: Boolean) {
if (menuSections.isNotEmpty()) {
nav("flex flex-1 flex-col") {
menuSections.mapIndexed { index, section ->
Expand All @@ -198,7 +199,12 @@ private fun TagConsumer<*>.NavMenu(menuSections: List<MenuSection>) {
role = "list"

li {
section.links.sortedBy { it.label }.map { link ->
val sectionLinks = if (sortedMenuLinks) {
section.links.sortedBy { it.label }
} else {
section.links
}
sectionLinks.map { link ->
ul("-mx-2 py-1") {
role = "list"
li {
Expand Down

0 comments on commit 40102ac

Please sign in to comment.