From 8fcf7fbbff6e6afe8010176cc25aa8b6c695bc08 Mon Sep 17 00:00:00 2001 From: Mark McPherson Date: Wed, 15 Nov 2023 10:17:47 +0000 Subject: [PATCH] Add documentation + bump version + linting --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/utils_accessibility.R | 50 +++++++++++++++++---------- man/accessible_action_link.Rd | 27 +++++++++++++++ man/accessible_radio_button.Rd | 63 ++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 man/accessible_action_link.Rd create mode 100644 man/accessible_radio_button.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a058292..05a30da 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nhsbsaShinyR Title: Template for NHSBSA {shiny} apps -Version: 0.0.0.9002 +Version: 0.0.0.9003 Authors@R: c(person(given = "DALL", family = "", diff --git a/NAMESPACE b/NAMESPACE index d097394..32367ac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,8 @@ # Generated by roxygen2: do not edit by hand export("%>%") +export(accessible_action_link) +export(accessible_radio_button) export(h1_tabstop) export(h2_tabstop) export(h3_tabstop) diff --git a/R/utils_accessibility.R b/R/utils_accessibility.R index 09e2f36..f7de758 100644 --- a/R/utils_accessibility.R +++ b/R/utils_accessibility.R @@ -126,53 +126,65 @@ nhs_card_tabstop <- function(header, tabindex = 0, ...) { } - - - - - #' accessible_radio_button #' -#' @param ... radio content +#' @inheritParams shiny::radioButtons #' -#' @noRd +#' @return HTML +#' @export #' +#' @examples +#' accessible_radio_button("rb", "Choose one:", +#' choiceNames = list( +#' "apple", +#' "banana", +#' "cherry" +#' ), +#' choiceValues = list( +#' "A", "B", "C" +#' )) +# Begin Exclude Linting accessible_radio_button <- function(inputId, label, choices = NULL, selected = NULL, inline = FALSE, width = NULL, choiceNames = NULL, choiceValues = NULL) { + # End Exclude Linting args <- shiny:::normalizeChoicesArgs(choices, choiceNames, choiceValues) - - selected <- shiny::restoreInput(id = inputId, default = selected) - + + selected <- restoreInput(id = inputId, default = selected) + selected <- if (is.null(selected)) args$choiceValues[[1]] else as.character(selected) if (length(selected) > 1) stop("The 'selected' argument must be of length 1") - + options <- shiny:::generateOptions( inputId, selected, inline, "radio", args$choiceNames, args$choiceValues ) - - divClass <- "form-group shiny-input-radiogroup shiny-input-container" - if (inline) divClass <- paste(divClass, "shiny-input-container-inline") - + + div_class <- "form-group shiny-input-radiogroup shiny-input-container" + if (inline) div_class <- paste(div_class, "shiny-input-container-inline") + tags$fieldset( tags$legend(label), tags$div( id = inputId, style = htmltools::css(width = validateCssUnit(width)), - class = divClass, + class = div_class, role = "radiogroup", options ) ) } + #' accessible_action_link #' -#' @param ... action link text +#' @inheritParams shiny::actionLink #' -#' @noRd +#' @return HTML +#' @export #' -accessible_action_link <- function(inputId, label, icon = NULL, ...) { +#' @examples +#' accessible_action_link("infoLink", "Information Link", class = "btn-info") +accessible_action_link <- function(inputId, label, icon = NULL, ...) { # Exclude Linting value <- restoreInput(id = inputId, default = NULL) tags$a(id = inputId, href = "#", class = "action-button", `data-val` = value, style = "color: #004280; text-decoration: underline;", diff --git a/man/accessible_action_link.Rd b/man/accessible_action_link.Rd new file mode 100644 index 0000000..962aa2d --- /dev/null +++ b/man/accessible_action_link.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_accessibility.R +\name{accessible_action_link} +\alias{accessible_action_link} +\title{accessible_action_link} +\usage{ +accessible_action_link(inputId, label, icon = NULL, ...) +} +\arguments{ +\item{inputId}{The \code{input} slot that will be used to access the value.} + +\item{label}{The contents of the button or link--usually a text label, but +you could also use any other HTML, like an image.} + +\item{icon}{An optional \code{\link[shiny:icon]{icon()}} to appear on the button.} + +\item{...}{Named attributes to be applied to the button or link.} +} +\value{ +HTML +} +\description{ +accessible_action_link +} +\examples{ +accessible_action_link("infoLink", "Information Link", class = "btn-info") +} diff --git a/man/accessible_radio_button.Rd b/man/accessible_radio_button.Rd new file mode 100644 index 0000000..91703ea --- /dev/null +++ b/man/accessible_radio_button.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_accessibility.R +\name{accessible_radio_button} +\alias{accessible_radio_button} +\title{accessible_radio_button} +\usage{ +accessible_radio_button( + inputId, + label, + choices = NULL, + selected = NULL, + inline = FALSE, + width = NULL, + choiceNames = NULL, + choiceValues = NULL +) +} +\arguments{ +\item{inputId}{The \code{input} slot that will be used to access the value.} + +\item{label}{Display label for the control, or \code{NULL} for no label.} + +\item{choices}{List of values to select from (if elements of the list are +named then that name rather than the value is displayed to the user). If +this argument is provided, then \code{choiceNames} and \code{choiceValues} must not +be provided, and vice-versa. The values should be strings; other types +(such as logicals and numbers) will be coerced to strings.} + +\item{selected}{The initially selected value. If not specified, then it +defaults to the first item in \code{choices}. To start with no items selected, +use \code{character(0)}.} + +\item{inline}{If \code{TRUE}, render the choices inline (i.e. horizontally)} + +\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; +see \code{\link[shiny:validateCssUnit]{validateCssUnit()}}.} + +\item{choiceNames, choiceValues}{List of names and values, respectively, that +are displayed to the user in the app and correspond to the each choice (for +this reason, \code{choiceNames} and \code{choiceValues} must have the same length). +If either of these arguments is provided, then the other \emph{must} be provided +and \code{choices} \emph{must not} be provided. The advantage of using both of these +over a named list for \code{choices} is that \code{choiceNames} allows any type of UI +object to be passed through (tag objects, icons, HTML code, ...), instead +of just simple text. See Examples.} +} +\value{ +HTML +} +\description{ +accessible_radio_button +} +\examples{ +accessible_radio_button("rb", "Choose one:", + choiceNames = list( + "apple", + "banana", + "cherry" + ), + choiceValues = list( + "A", "B", "C" + )) +}