Skip to content

Commit

Permalink
Only write type/bg if set
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 22, 2024
1 parent 1a6670e commit df1da02
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ navbar_style <- function(navbar = list(), theme = "_default", bs_version = 3) {
bg <- navbar$bg %||% bootswatch_bg[[theme]] %||% "light"
type <- navbar$type %||% if (bg == "light") "light" else "dark"

list(bg = bg, is_dark = type == "dark")
list(bg = bg, type = type)
}
}

Expand Down
2 changes: 1 addition & 1 deletion inst/BS5/templates/navbar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#navbar}}
<nav class="navbar navbar-expand-lg fixed-top bg-{{{bg}}}" {{#is_dark}}data-bs-theme="dark"{{/is_dark}} aria-label="{{#translate}}{{site_nav}}{{/translate}}">
<nav class="navbar navbar-expand-lg fixed-top {{#bg}}bg-{{{.}}}{{/bg}}" {{#type}}data-bs-theme="{{{.}}}"{{/type}} aria-label="{{#translate}}{{site_nav}}{{/translate}}">
<div class="container">
{{#includes}}{{{before_title}}}{{/includes}}
<a class="navbar-brand me-2" href="{{#site}}{{root}}{{/site}}index.html">{{#site}}{{title}}{{/site}}</a>
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,20 @@ test_that("data_navbar() errors with bad left/right", {
expect_snapshot(data_navbar(pkg), error = TRUE)
})


test_that("for bs4, default bg and type come from bootswatch", {
style <- navbar_style(bs_version = 5)
expect_equal(style, list(bg = "light", is_dark = FALSE))
expect_equal(style, list(bg = "light", type = "light"))

style <- navbar_style(theme = "cyborg", bs_version = 5)
expect_equal(style, list(bg = "dark", is_dark = TRUE))
expect_equal(style, list(bg = "dark", type = "dark"))

# but can override
style <- navbar_style(list(bg = "primary"), bs_version = 5)
expect_equal(style, list(bg = "primary", is_dark = TRUE))
expect_equal(style, list(bg = "primary", type = "dark"))

style <- navbar_style(list(bg = "primary", type = "light"), bs_version = 5)
expect_equal(style, list(bg = "primary", is_dark = FALSE))
expect_equal(style, list(bg = "primary", type = "light"))
})

test_that("render_navbar_links BS3 & BS4 default", {
Expand Down

0 comments on commit df1da02

Please sign in to comment.