R/bulma-form-radio.R

Defines functions bulma_form_radio

Documented in bulma_form_radio

#' @title
#' Bulma Form: Radio
#'
#' @description
#' The mutually exclusive radio buttons in their native format. The radio class
#' is a simple wrapper around the `<input type="radio">` HTML elements. It is
#' intentionally not styled, to preserve cross-browser compatibility and the
#' user experience.
#'
#' Make sure the linked radio buttons have the same value for their name HTML
#' attribute.
#'
#' @param name (string) links together various `bulma_form_radio()`s.
#' @param checked (flag) button is selected
#' @param disabled (flag) button cannot be clicked
#' @inheritParams bulma_form_select
#'
#' @family Bulma Form Components
#' @export
bulma_form_radio <- function(name,
                             ...,
                             checked = FALSE,
                             disabled = FALSE,
                             outer_tag = tags$label,
                             inner_tag = tags$input) {

  assert_function(outer_tag)
  assert_function(inner_tag)
  assert_string(name)

  outer_tag(
    class = "radio",
    inner_tag(type = "radio", name = name) %>%
      when(disabled, bulma_disabled(.)) %>%
      when(checked, tagAppendAttributes(., checked = NA)),
    ...
  ) %>%
    add_class("bulma_form_radio")

}
tjpalanca/bulma.R documentation built on Dec. 23, 2021, 10:58 a.m.