@@ -1075,6 +1075,76 @@ def navbar_options(
10751075 """
10761076 Configure the appearance and behavior of the navbar.
10771077
1078+ ## Navbar style with Bootstrap 5 and Bootswatch themes
1079+
1080+ In `shiny` v1.3.0, the default navbar colors for Bootswatch themes are less
1081+ opinionated by default and follow light or dark mode (see
1082+ :func:`~shiny.ui.input_dark_mode`).
1083+
1084+ You can use `ui.navbar_options()` to adjust the colors of the navbar when using a
1085+ Bootswatch preset theme with Bootstrap 5. For example, the [Bootswatch documentation
1086+ for the Flatly theme](https://bootswatch.com/flatly/) shows 4 navbar variations.
1087+ Inspecting the source code for the first example reveals the following markup:
1088+
1089+ ```html
1090+ <nav class="navbar navbar-expand-lg bg-primary" data-bs-theme="dark">
1091+ <!-- all of the navbar html -->
1092+ </nav>
1093+ ```
1094+
1095+ Note that this navbar uses the `bg-primary` class for a dark navy background. The
1096+ navbar's white text is controlled by the `data-bs-theme="dark"` attribute, which is
1097+ used by Bootstrap for light text on a _dark_ background. In Shiny, you can achieve
1098+ this look with:
1099+
1100+ ```python
1101+ ui.page_navbar(
1102+ theme=ui.Theme(version=5, preset="flatly"),
1103+ navbar_options=ui.navbar_options(class="bg-primary", theme="dark")
1104+ )
1105+ ```
1106+
1107+ This particular combination of `class="bg-primary"` and `theme="dark"` works well
1108+ for most Bootswatch presets.
1109+
1110+ Another variation from the Flatly documentation features a navar with dark text on a
1111+ light background:
1112+
1113+ ```python
1114+ ui.page_navbar(
1115+ theme = ui.Theme(version=5, preset="flatly"),
1116+ navbar_options = ui.navbar_options(class="bg-light", theme="light")
1117+ )
1118+ ```
1119+
1120+ The above options set navbar foreground and background colors that are always the
1121+ same in both light and dark modes. To customize the navbar colors used in light or
1122+ dark mode, you can use the `$navbar-light-bg` and `$navbar-dark-bg` Sass variables.
1123+ When provided, Shiny will automatically choose to use light or dark text as the
1124+ foreground color.
1125+
1126+ ```python
1127+ ui.page_navbar(
1128+ theme=(
1129+ ui.Theme(version=5, preset = "flatly")
1130+ .add_defaults(
1131+ navbar_light_bg="#18BC9C", # flatly's success color (teal)
1132+ navbar_dark_bg="#2C3E50" # flatly's primary color (navy)
1133+ )
1134+ )
1135+ )
1136+ )
1137+ ```
1138+
1139+ Finally, you can also use the `$navbar-bg` Sass variable to set the navbar
1140+ background color for both light and dark modes:
1141+
1142+ ```python
1143+ ui.page_navbar(
1144+ theme=ui.Theme(version=5, preset="flatly").add_defaults(navbar_bg="#E74C3C") # flatly's red
1145+ )
1146+ ```
1147+
10781148 Parameters
10791149 -----------
10801150 position
@@ -1095,7 +1165,7 @@ def navbar_options(
10951165 collapsible
10961166 If `True`, automatically collapses the elements into an expandable menu on
10971167 mobile devices or narrow window widths.
1098- ** attrs : dict
1168+ attrs
10991169 Additional HTML attributes to apply to the navbar container element.
11001170
11011171 Returns:
0 commit comments