diff --git a/R/shiny-material-text-box.R b/R/shiny-material-text-box.R index 7a1f8a4..b48d9e4 100644 --- a/R/shiny-material-text-box.R +++ b/R/shiny-material-text-box.R @@ -3,77 +3,56 @@ #' Build a shinymaterial text box. #' @param input_id String. The input identifier used to access the value. #' @param label String. The text box label. +#' @param value String. Initial value. #' @param color String. The accent color of the text box. Leave empty for the default color. Visit \url{http://materializecss.com/color.html} for a list of available colors. \emph{This input requires using color hex codes, rather than the word form. E.g., "#ef5350", rather than "red lighten-1".} #' @param icon String. The name of the icon. Leave empty for no icon. Visit \url{http://materializecss.com/icons.html} for a list of available icons. +#' @param disabled FALSE by default, if TRUE the text box is disable. #' @seealso \code{\link{update_material_text_box}} #' @examples #' material_text_box( #' input_id = "example_text_box", #' label = "text box", #' icon = "search", -#' color = "#ef5350" +#' color = "#ef5350", +#' disabled = FALSE #' ) -material_text_box <- function(input_id, label, color = NULL, icon = NULL){ - if (!is.null(color)) { - - if (!is.null(icon)) { - icon_style_color <- paste0( - "#", input_id, "_text_box.input-field .prefix.active { - color: ", color, "; - }" - ) - } else { - icon_style_color <- "" - } - - text_box_style <- - shiny::tagList( - shiny::tags$head( - shiny::tags$style( - paste0( - " - #", input_id, "_text_box.input-field input[type=text]:focus + label { - color: ", color, "; - } - #", input_id, "_text_box.input-field input[type=text]:focus { - border-bottom: 1px solid ", color, "; - box-shadow: 0 1px 0 0 ", color, "; - } - ", - icon_style_color - ) +material_text_box <- function(input_id, label, value = "", color = NULL, icon = NULL, disable = FALSE){ + + css_id <- paste0("#", input_id, "_text_box.input-field") + text_box_style <- if (!is.null(color)) + shiny::tagList( + shiny::tags$head( + shiny::tags$style( + paste0( + css_id, " input[type=text]:focus + label {color: ", color, ";}", + css_id, " input[type=text]:focus {border-bottom: 1px solid ", color, ";box-shadow: 0 1px 0 0 ", color, ";}", + if (!is.null(icon)) + paste0(css_id, " .prefix.active {color: ", color, ";}") ) ) ) - - } else { - text_box_style <- shiny::tags$div() - } - - if (!is.null(icon)) { - text_box_icon <- shiny::tags$i(class = "material-icons prefix", icon) - } else { - text_box_icon <- shiny::tags$div() - } - + ) + + text_box_icon <- if(!is.null(icon)) + shiny::tags$i(class = "material-icons prefix", icon) + + text_box_input <- shiny::tags$input( + id = input_id, type = "text", + class = "validate", value = value + ) + + if (disable) text_box_input <- shiny::HTML(sub("