Skip to content
61 changes: 41 additions & 20 deletions R/showToast.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@


#' @noRd default_options
default_options <- list(
Comment thread
phoward38 marked this conversation as resolved.
Outdated
positionClass = "toast-bottom-center",
progressBar = TRUE,
timeOut = 4000,
closeButton = TRUE,
# same as defaults
newestOnTop = FALSE,
preventDuplicates = FALSE,
showDuration = 300,
hideDuration = 1000,
extendedTimeOut = 1000,
showEasing = "swing",
hideEasing = "swing",
showMethod = "fadeIn",
hideMethod = "fadeOut"
)

#' show toast message
#'
Expand All @@ -11,7 +27,9 @@
#' @param title the toast title. Defaults to \code{NULL}
#' @param keepVisible a logical. If \code{TRUE}, the toast notification will remain visible until removed with \code{\link{hideToast}}. If \code{FALSE}, the default, the toast will automatically hide once the "showDuration" option has elapsed.
#' @param .options other options to pass to the \code{toastr} JavaScript library. See
#' \url{https://codeseven.github.io/toastr/demo.html} for a full demo of options.
#' \url{https://codeseven.github.io/toastr/demo.html} for a full demo of options. Valid options are "positionClass",
#' "progressBar", "timeOut", "closeButton", "newestOnTop", "preventDuplicates", "showDuration", "hideDuration",
#' "extendedTimeOut", "showEasing", "hideEasing", "showMethod", & "hideMethod"
#' @param session the Shiny session. Defaults to \code{shiny::getDefaultReactiveDomain()}.
#'
#' @export
Expand All @@ -25,26 +43,29 @@ showToast <- function(
message,
title = NULL,
keepVisible = FALSE,
.options = list(
positionClass = "toast-bottom-center",
progressBar = TRUE,
timeOut = 4000,
closeButton = TRUE,

# same as defaults
newestOnTop = FALSE,
preventDuplicates = FALSE,
showDuration = 300,
hideDuration = 1000,
extendedTimeOut = 1000,
showEasing = "swing",
hideEasing = "swing",
showMethod = "fadeIn",
hideMethod = "fadeOut"
),
.options = list(),
session = shiny::getDefaultReactiveDomain()
) {


# Incorrect option
if (!all(names(.options) %in% names(default_options))) {
stop('Incorrect option supplied', call. = FALSE)
}

if (length(.options) == 0) {
Comment thread
phoward38 marked this conversation as resolved.
Outdated
.options <- default_options
} else {
.options <- lapply(names(default_options), function(option_name) {
if (option_name %in% names(.options)) {
return(option_name = .options[[option_name]])
} else {
return(option_name = default_options[[option_name]])
}
})

names(.options) <- names(default_options)
}

if (isTRUE(keepVisible)) {
.options$timeOut <- 0
.options$extendedTimeOut <- 0
Expand Down
9 changes: 4 additions & 5 deletions man/showToast.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.