From 89db2913dd58c53be867f8774474a84031f5030c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 9 May 2024 08:44:20 -0500 Subject: [PATCH] Improve & test iconset code --- R/navbar.R | 8 +++++++- tests/testthat/_snaps/navbar.md | 6 +++--- tests/testthat/test-navbar.R | 11 +++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/R/navbar.R b/R/navbar.R index 861d7da39..91724590a 100644 --- a/R/navbar.R +++ b/R/navbar.R @@ -341,8 +341,14 @@ bs4_navbar_links_tags <- function(links, depth = 0L, side = "left") { bs4_navbar_link_text <- function(x, ...) { if (!is.null(x$icon)) { + # Find the icon set + classes <- strsplit(x$icon, " ")[[1]] + icon_classes <- classes[grepl("-", classes)] + iconset <- purrr::map_chr(strsplit(icon_classes, "-"), 1) + class <- paste0(unique(c(iconset, classes)), collapse = " ") + text <- paste0(if (!is.null(x$text)) " ", x$text) - htmltools::tagList(htmltools::tags$span(class = x$icon), text, ...) + htmltools::tagList(htmltools::tags$span(class = class), text, ...) } else { htmltools::tagList(x$text, ...) } diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 8ee2d318c..a94089a0f 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -138,7 +138,7 @@ data_navbar(pkg)[c("left", "right")] Output $left - [1] "
  • \n \n \n \n \n
  • \n
  • \n\n
  • " + [1] "
  • \n \n \n \n
  • \n
  • \n\n
  • " $right [1] "
  • \n Changelog\n
  • " @@ -245,7 +245,7 @@ Reference