R/bulma-form-input.R

Defines functions bulma_form_input

Documented in bulma_form_input

#' @title
#' Bulma Form: Input
#'
#' @description
#' The text input and its variations.
#'
#' [Input](https://bulma.io/documentation/form/input/)
#'
#' @inheritParams bulma_form_textarea
#' @param type    (str) type of the text input, defaults to `text`.
#' @param rounded (flg) whether or not this is rounded.
#'
#' @family Bulma Form Components
#' @export
bulma_form_input <- function(name,
                             ...,
                             type  = c("text", "password", "email", "tel"),
                             placeholder = NULL,
                             rounded     = FALSE,
                             readonly    = FALSE,
                             disabled    = FALSE,
                             color = c("primary", "link", "info",
                                       "success", "warning", "danger",
                                       "white", "black", "light", "dark"),
                             size  = c("small", "medium", "large", "normal"),
                             state = c("hovered", "focused", "active",
                                       "static"),
                             tag   = tags$input) {

  assert_string(name)
  assert_function(tag)
  assert_string(placeholder, null.ok = TRUE)
  color <- match_arg(color)
  size  <- match_arg(size)
  state <- match_arg(state)
  type  <- match_arg(type) %||% "text"

  tag(class = "input", type = type,
      name = name, placeholder = placeholder, ...) %>%
    bulma_color(color) %>%
    bulma_size(size) %>%
    bulma_state(state) %>%
    when(rounded, bulma_is(., "rounded")) %>%
    when(readonly, bulma_readonly(.)) %>%
    when(disabled, bulma_disabled(.)) %>%
    add_class("bulma_form_input")

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