diff --git a/NAMESPACE b/NAMESPACE
index 07849ae..ba4c05f 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -3,6 +3,7 @@
export(append_cpg_properties)
export(assign_classification)
export(assign_pathogenicity_evidence)
+export(bs_icon2)
export(check_variant2cancer_phenotype)
export(combine_novel_and_preclassified)
export(exclude_vars_by_maf)
diff --git a/R/bsicons.R b/R/bsicons.R
new file mode 100644
index 0000000..aef6059
--- /dev/null
+++ b/R/bsicons.R
@@ -0,0 +1,92 @@
+# Copied from https://github.com/rstudio/bsicons/blob/f7dca31/R/icons.R
+icon_info_mini <- list(
+ name = c(
+ "bullseye",
+ "check-square"
+ ),
+ contents = c(
+ " \n \n \n ",
+ " \n "
+ )
+)
+
+#' Use Bootstrap icons (as inline SVG)
+#'
+#' Copied from https://github.com/rstudio/bsicons.
+#' @param name The name of the Bootstrap icon. Whitespace is replaced with `-`
+#' (that way, `"arrow up"` can be used to refer to the "actual name" of
+#' `"arrow-up"`). For a searchable list of names, see
+#' @param size Any valid CSS unit defining both the height and width of the
+#' icon.
+#' @param class Additional CSS classes to add to the `` element. Consider
+#' providing Bootstrap 5+ utility classes (e.g., `text-success`) here to
+#' stylize the icon (but also note that those utility classes will only work
+#' when Bootstrap 5+ is on the page).
+#' @param title If provided (highly recommended), `a11y` defaults to `"sem"`,
+#' meaning the title is used for on-hover text and screen reader
+#' announcements.
+#' @param a11y Cases that distinguish the role of the icon and inform which
+#' accessibility attributes to be used. Icons can either be `"deco"`
+#' (decorative, the default case), `"sem"` (semantic), `"none"` (no
+#' accessibility features). The default, `"auto"`, resolves to `"sem"` if a
+#' `title` is provided (and `"deco"` otherwise).
+#' @param ... additional CSS properties (e.g., `margin`, `position`, etc.)
+#' placed on the `` tag.
+#'
+#' @return An [htmltools::HTML()] string containing the SVG icon.
+#' @export
+bs_icon2 <- function(name, size = "1em", class = NULL, title = NULL,
+ a11y = c("auto", "deco", "sem", "none"), ...) {
+ if (length(name) != 1) {
+ rlang::abort("The number of icons specified in `name` must be 1.")
+ }
+
+ "%||%" <- function(x, y) {
+ if (is.null(x)) y else x
+ }
+
+ name <- sub("\\s+", "-", tolower(name))
+ idx <- match(name, tolower(icon_info_mini$name))
+ stopifnot(!is.na(idx))
+ svg_children <- icon_info_mini$contents[idx]
+ size <- htmltools::validateCssUnit(size)
+ style_attr <- paste0(
+ "height:", size, ";",
+ "width:", size, ";",
+ "fill:currentColor;",
+ # Better default vertical positioning of icons in a inline context (inspired by fontawesome::fa())
+ "vertical-align:-0.125em;",
+ htmltools::css(...)
+ )
+
+ # Generate accessibility attributes if either of
+ # the "deco" or "sem" cases are chosen
+ a11y <- rlang::arg_match(a11y)
+ a11y_attrs <- ""
+
+ if (a11y == "auto") {
+ a11y <- if (is.null(title)) "deco" else "sem"
+ }
+
+ if (a11y == "deco") {
+ a11y_attrs <- 'aria-hidden="true" role="img" '
+ } else if (a11y == "sem") {
+ title <- title %||% name
+ a11y_attrs <- sprintf(
+ 'aria-label="%s" role="img" ',
+ htmltools::htmlEscape(title, attribute = TRUE)
+ )
+ }
+
+ res <- sprintf(
+ '%s%s ',
+ name,
+ paste(class, collapse = " "),
+ style_attr,
+ a11y_attrs,
+ if (is.null(title)) "" else paste0("", htmltools::htmlEscape(title), " "),
+ svg_children
+ )
+
+ htmltools::browsable(htmltools::HTML(res))
+}
diff --git a/inst/templates/quarto/cpsr_summary.qmd b/inst/templates/quarto/cpsr_summary.qmd
index 29bb71d..26364d5 100644
--- a/inst/templates/quarto/cpsr_summary.qmd
+++ b/inst/templates/quarto/cpsr_summary.qmd
@@ -90,7 +90,7 @@ bslib::layout_column_wrap(
"N = ",
cps_report$content$snv_indel$v_stat_cpg$n_p +
cps_report$content$snv_indel$v_stat_cpg$n_lp),
- showcase = bsicons::bs_icon("bullseye"),
+ showcase = cpsr::bs_icon2("bullseye"),
theme = bslib::value_box_theme(
bg = color_lp, fg = "#fff"),
showcase_layout = "left center"
@@ -98,7 +98,7 @@ bslib::layout_column_wrap(
bslib::value_box(
title = "Genes affected by pathogenic variants",
value = genes_value_box,
- showcase = bsicons::bs_icon("bullseye"),
+ showcase = cpsr::bs_icon2("bullseye"),
theme = bslib::value_box_theme(
bg = color_lp, fg = "#fff"),
showcase_layout = "left center"
@@ -106,7 +106,7 @@ bslib::layout_column_wrap(
bslib::value_box(
title = "Secondary findings",
value = value_sf,
- showcase = bsicons::bs_icon("bullseye"),
+ showcase = cpsr::bs_icon2("bullseye"),
theme = bslib::value_box_theme(
bg = color_sf, fg = "#fff"),
showcase_layout = "left center"
@@ -119,7 +119,7 @@ bslib::layout_column_wrap(
bslib::value_box(
title = "Pre-classified variants (ClinVar)",
value = paste0("N = ", n_clinvar),
- showcase = bsicons::bs_icon("check-square"),
+ showcase = cpsr::bs_icon2("check-square"),
theme = bslib::value_box_theme(
bg = color_clinvar, fg = "#fff"),
showcase_layout = "left center"
@@ -127,7 +127,7 @@ bslib::layout_column_wrap(
bslib::value_box(
title = "Novel variants",
value = paste0("N = ", n_novel),
- showcase = bsicons::bs_icon("check-square"),
+ showcase = cpsr::bs_icon2("check-square"),
theme = bslib::value_box_theme(
bg = color_novel, fg = "#fff"),
showcase_layout = "left center"
@@ -135,7 +135,7 @@ bslib::layout_column_wrap(
bslib::value_box(
title = "VUS variants",
value = paste0("N = ", n_vus),
- showcase = bsicons::bs_icon("check-square"),
+ showcase = cpsr::bs_icon2("check-square"),
theme = bslib::value_box_theme(
bg = color_vus, fg = "#fff"),
showcase_layout = "left center"
diff --git a/man/bs_icon2.Rd b/man/bs_icon2.Rd
new file mode 100644
index 0000000..40f9c33
--- /dev/null
+++ b/man/bs_icon2.Rd
@@ -0,0 +1,47 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/bsicons.R
+\name{bs_icon2}
+\alias{bs_icon2}
+\title{Use Bootstrap icons (as inline SVG)}
+\usage{
+bs_icon2(
+ name,
+ size = "1em",
+ class = NULL,
+ title = NULL,
+ a11y = c("auto", "deco", "sem", "none"),
+ ...
+)
+}
+\arguments{
+\item{name}{The name of the Bootstrap icon. Whitespace is replaced with \code{-}
+(that way, \code{"arrow up"} can be used to refer to the "actual name" of
+\code{"arrow-up"}). For a searchable list of names, see \url{https://icons.getbootstrap.com/}}
+
+\item{size}{Any valid CSS unit defining both the height and width of the
+icon.}
+
+\item{class}{Additional CSS classes to add to the \verb{} element. Consider
+providing Bootstrap 5+ utility classes (e.g., \code{text-success}) here to
+stylize the icon (but also note that those utility classes will only work
+when Bootstrap 5+ is on the page).}
+
+\item{title}{If provided (highly recommended), \code{a11y} defaults to \code{"sem"},
+meaning the title is used for on-hover text and screen reader
+announcements.}
+
+\item{a11y}{Cases that distinguish the role of the icon and inform which
+accessibility attributes to be used. Icons can either be \code{"deco"}
+(decorative, the default case), \code{"sem"} (semantic), \code{"none"} (no
+accessibility features). The default, \code{"auto"}, resolves to \code{"sem"} if a
+\code{title} is provided (and \code{"deco"} otherwise).}
+
+\item{...}{additional CSS properties (e.g., \code{margin}, \code{position}, etc.)
+placed on the \verb{} tag.}
+}
+\value{
+An \code{\link[htmltools:HTML]{htmltools::HTML()}} string containing the SVG icon.
+}
+\description{
+Copied from https://github.com/rstudio/bsicons.
+}