From aa113bb891ca365fc98ee86dbc89a7c53c6430f8 Mon Sep 17 00:00:00 2001 From: Mathieu Delsaut Date: Mon, 11 Mar 2019 18:31:08 +0400 Subject: [PATCH 1/2] Allow initial value into material_text_box --- R/shiny-material-text-box.R | 71 ++++++++++++------------------------- man/material_text_box.Rd | 5 ++- 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/R/shiny-material-text-box.R b/R/shiny-material-text-box.R index 7a1f8a4..d4a4bf1 100644 --- a/R/shiny-material-text-box.R +++ b/R/shiny-material-text-box.R @@ -3,6 +3,7 @@ #' 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. #' @seealso \code{\link{update_material_text_box}} @@ -13,52 +14,28 @@ #' icon = "search", #' color = "#ef5350" #' ) -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){ + + 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) + create_material_object( - js_file = - "shiny-material-text-box.js", + js_file = "shiny-material-text-box.js", material_tag_list = shiny::tagList( shiny::tags$div( @@ -66,14 +43,10 @@ material_text_box <- function(input_id, label, color = NULL, icon = NULL){ id = paste0(input_id, "_text_box"), text_box_icon, shiny::tags$input( - id = input_id, - type = "text", - class = "validate" + id = input_id, type = "text", + class = "validate", value = value ), - shiny::tags$label( - `for` = input_id, - label - ) + shiny::tags$label(`for` = input_id, label) ), text_box_style ) diff --git a/man/material_text_box.Rd b/man/material_text_box.Rd index 4480ea1..41e8bad 100644 --- a/man/material_text_box.Rd +++ b/man/material_text_box.Rd @@ -4,13 +4,16 @@ \alias{material_text_box} \title{Create a shinymaterial text box} \usage{ -material_text_box(input_id, label, color = NULL, icon = NULL) +material_text_box(input_id, label, value = "", color = NULL, + icon = NULL) } \arguments{ \item{input_id}{String. The input identifier used to access the value.} \item{label}{String. The text box label.} +\item{value}{String. Initial value.} + \item{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".}} \item{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.} From a3637c44c5860b79f84941d3c1b9be16ddd36bf6 Mon Sep 17 00:00:00 2001 From: Mathieu Delsaut Date: Thu, 30 Jan 2020 16:00:50 +0400 Subject: [PATCH 2/2] material_text_box : Allow to disable and update text box --- R/shiny-material-text-box.R | 18 ++++++++++++------ R/update-shiny-material-text-box.R | 24 +++++++++++++++--------- man/material_text_box.Rd | 15 ++++++++++++--- man/update_material_text_box.Rd | 7 +++++-- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/R/shiny-material-text-box.R b/R/shiny-material-text-box.R index d4a4bf1..b48d9e4 100644 --- a/R/shiny-material-text-box.R +++ b/R/shiny-material-text-box.R @@ -6,15 +6,17 @@ #' @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, value = "", color = NULL, icon = NULL){ +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)) @@ -34,6 +36,13 @@ material_text_box <- function(input_id, label, value = "", color = NULL, icon = 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("