From 1ff18159a0755c412e110e351c5f9015e42cfeba Mon Sep 17 00:00:00 2001 From: Mathieu Delsaut Date: Thu, 6 Feb 2020 09:17:53 +0400 Subject: [PATCH] Centered icon for button when empty label --- R/shiny-material-button.R | 17 ++++------- R/shiny-material-modal.R | 61 +++++++++------------------------------ 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/R/shiny-material-button.R b/R/shiny-material-button.R index cda37f7..57dea6e 100644 --- a/R/shiny-material-button.R +++ b/R/shiny-material-button.R @@ -18,10 +18,11 @@ material_button <- function(input_id, label, icon = NULL, depth = NULL, color = NULL) { if(!is.null(icon)){ + empty_label <- label == "" || is.null(label) icon_tag <- shiny::HTML( paste0( - '', + '', icon, '') ) @@ -36,18 +37,10 @@ material_button <- function(input_id, label, icon = NULL, depth = NULL, color = shiny::tagList( shiny::tags$button( class = - paste0( + paste( "waves-effect waves-light btn shiny-material-button", - ifelse( - is.null(depth), - "", - paste0(" z-depth-", depth) - ), - ifelse( - is.null(color), - "", - paste0(" ", color) - ) + if(!is.null(depth)) paste0("z-depth-", depth), + if(!is.null(color)) color ), id = input_id, value = 0, diff --git a/R/shiny-material-modal.R b/R/shiny-material-modal.R index 8ad12eb..056fbdb 100644 --- a/R/shiny-material-modal.R +++ b/R/shiny-material-modal.R @@ -22,10 +22,11 @@ material_modal <- function(modal_id, button_text, title, ..., button_icon = NULL, floating_button = FALSE, button_depth = NULL, button_color = NULL, close_button_label = "Close", display_button = TRUE){ if(!is.null(button_icon)){ + empty_button_text <- button_text == "" || is.null(button_text) icon_tag <- shiny::HTML( paste0( - '', + '', button_icon, '') ) @@ -33,33 +34,13 @@ material_modal <- function(modal_id, button_text, title, ..., button_icon = NULL icon_tag <- NULL } - button_class <- - paste0( - "waves-effect waves-light shiny-material-modal-trigger modal-trigger", - ifelse(is.null(button_color), - "", - paste0(" ", button_color) - ), - ifelse( - is.null(button_depth), - "", - paste0(" z-depth-", button_depth) - ) - ) - - if(!floating_button){ - button_class <- - paste0( - button_class, - " btn" - ) - } else { - button_class <- - paste0( - button_class, - " btn-floating btn-large waves-effect waves-light z-depth-3" - ) - } + button_class <- paste( + "waves-effect waves-light shiny-material-modal-trigger modal-trigger", + if (!is.null(button_color)) button_color, + if (!is.null(button_depth)) paste0("z-depth-", button_depth), + if (floating_button) "btn-floating btn-large waves-effect waves-light z-depth-3" + else "btn shiny-material-button" + ) create_material_object( js_file = @@ -68,32 +49,18 @@ material_modal <- function(modal_id, button_text, title, ..., button_icon = NULL shiny::tagList( shiny::tags$div( class = - ifelse( - floating_button, - "fixed-action-btn", - "" - ), + if(floating_button) "fixed-action-btn", shiny::tags$button( `data-target` = modal_id, display = ifelse(display_button, "inline-block", "none"), class = button_class, style = - paste0( - ifelse( - floating_button, - "background-color:#F06C71;", - "" - ), - ifelse(display_button, - "", - " display:none;") + paste( + if(floating_button) "background-color:#F06C71;", + if(!display_button) "display:none;" ), icon_tag, - ifelse( - floating_button, - "", - button_text - ) + if(!floating_button) button_text ) ), shiny::tags$div(