Skip to content

Commit

Permalink
added bs themes with Nord palette
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jun 17, 2024
1 parent a6980dc commit 5d28c24
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ URL: https://github.com/dreamRs/fresh
BugReports: https://github.com/dreamRs/fresh/issues
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports:
bslib,
htmltools,
rstudioapi,
sass,
shiny
Suggests:
bsicons,
shinyWidgets,
shinydashboard,
bs4Dash,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export(bs4dash_sidebar_light)
export(bs4dash_status)
export(bs4dash_vars)
export(bs4dash_yiq)
export(bs_theme_nord_dark)
export(bs_theme_nord_light)
export(bs_vars)
export(bs_vars_alert)
export(bs_vars_badge)
Expand Down
59 changes: 59 additions & 0 deletions R/bs_theme_nord.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

#' Bootstrap Theme based on Nord palette
#'
#' @param version The major version of Bootstrap to use, see [bslib::bs_theme()].
#' @param preset The name of a theme preset, default to "bootstrap".
#'
#' @return Returns a [sass::sass_bundle()] (list-like) object.
#' @export
#'
#' @name bs-theme-nord
#'
#' @example examples/bs_theme_nord-ex.R
bs_theme_nord_light <- function(version = bslib::version_default(), preset = "bootstrap") {
bs_theme(
version = version,
preset = preset,
primary = "#5E81AC",
secondary = "#B48EAD",
info = "#88C0D0",
danger = "#BF616A",
warning = "#D08770",
success = "#A3BE8C",
"navbar-bg" = "#5E81AC",
"navbar-dark-color" = "#ECEFF4",
"navbar-dark-color" = "#ECEFF4",
"navbar-dark-active-color" = "#E5E9F0",
"navbar-dark-hover-color" = "#D8DEE9",
"bslib-sidebar-bg" = "#D8DEE9",
"body-bg" = "#ECEFF4",
"body-color" = "#2E3440"
)
}

#' @export
#'
#' @rdname bs-theme-nord
bs_theme_nord_dark <- function(version = bslib::version_default(), preset = "bootstrap") {
bs_theme(
version = version,
preset = preset,
primary = "#5E81AC",
secondary = "#B48EAD",
info = "#88C0D0",
danger = "#BF616A",
warning = "#D08770",
success = "#A3BE8C",
"navbar-bg" = "#2E3440",
"navbar-dark-color" = "#ECEFF4",
"navbar-dark-color" = "#ECEFF4",
"navbar-dark-active-color" = "#E5E9F0",
"navbar-dark-hover-color" = "#D8DEE9",
"bslib-sidebar-bg" = "#3B4252",
"bslib-sidebar-fg" = "#ECEFF4",
"body-bg" = "#434C5E",
"body-color" = "#ECEFF4",
"card-bg" = "#4C566A",
"body-emphasis-color" = "#ECEFF4"
)
}
6 changes: 3 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Test environments
* local OS Windows 10 install, R 3.6.3
* ubuntu 16.04 (on Github Actions), R 4.0.0
* macOS latest (on Github Actions), R 4.0.0
* local OS Windows 10 install, R 4.3.3
* ubuntu 16.04 (on Github Actions), R 4.4.1
* macOS latest (on Github Actions), R 4.4.1
* win-builder (devel and release)

## R CMD check results
Expand Down
130 changes: 130 additions & 0 deletions examples/bs_theme_nord-ex.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@

library(shiny)
library(bslib)
library(bsicons)

make_btns <- function(outline = FALSE) {
lapply(
X = c("primary", "secondary", "success", "danger", "warning", "info"),
FUN = function(x) {
if (outline)
x <- paste0("outline-", x)
actionButton(paste0("btn", x), paste("Button", x), class = paste("btn", x, sep = "-"))
}
)
}

ui <- page_navbar(
title = "Nord theme",

theme = bs_theme_nord_light(),

fillable = FALSE,
sidebar = sidebar(
"Sidebar",
selectInput("id", "Choice:", month.name)
),
nav_panel(
"Page 1",

make_btns(),
tags$br(), tags$br(),
make_btns(TRUE),
tags$br(), tags$br(),

layout_column_wrap(
width = 1 / 5,
value_box(
title = "1st value",
value = "123",
showcase = bs_icon("bar-chart"),
theme = "primary",
p("The 1st detail")
),
value_box(
title = "2nd value",
value = "456",
showcase = bs_icon("graph-up"),
theme = "success",
p("The 2nd detail"),
p("The 3rd detail")
),
value_box(
title = "3rd value",
value = "789",
showcase = bs_icon("pie-chart"),
theme = "danger",
p("The 4th detail"),
p("The 5th detail"),
p("The 6th detail")
),
value_box(
title = "4th value",
value = "123",
showcase = bs_icon("bar-chart"),
theme = "warning",
p("The 1st detail")
),
value_box(
title = "5th value",
value = "123",
showcase = bs_icon("bar-chart"),
theme = "info",
p("The 1st detail")
)
),
layout_column_wrap(
width = 1 / 5,
card(
card_header(
class = "bg-primary",
"A header"
),
card_body("Some content")
),
card(
card_header(
class = "bg-success",
"A header"
),
card_body("Some content")
),
card(
card_header(
class = "bg-danger",
"A header"
),
card_body("Some content")
),
card(
card_header(
class = "bg-warning",
"A header"
),
card_body("Some content")
),
card(
card_header(
class = "bg-info",
"A header"
),
card_body("Some content")
)
)
),
nav_panel("Page 2", "Page 2 content"),
nav_spacer(),
nav_item(
input_switch("dark_mode", "Dark mode", width = "120px")
)
)

server <- function(input, output, session) {
observe(session$setCurrentTheme(
if (isTRUE(input$dark_mode)) bs_theme_nord_dark() else bs_theme_nord_light()
))
}

if (interactive())
shinyApp(ui, server)

155 changes: 155 additions & 0 deletions man/bs-theme-nord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d28c24

Please sign in to comment.