Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/show toast options #46

Merged
merged 11 commits into from
Aug 6, 2020
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ importFrom(shiny,is.reactive)
importFrom(shiny,isTruthy)
importFrom(shiny,reactive)
importFrom(shiny,renderText)
importFrom(utils,modifyList)
importFrom(utils,packageVersion)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# shinyFeedback 0.2.0.9001

- updated ".options" argument to showToast to use the `shinyFeedback` default options for
any options not included in the list passed to ".options" (#46)
- new function `hideToast()` to programatically hide all toasts (#44)
- simplified and deduped JavaScript (#42) - Thanks @jcheng5!
- added input feedback support for `shiny::fileInput()` (#41)
Expand Down
56 changes: 36 additions & 20 deletions R/showToast.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@


#' @noRd showToast_default_options
showToast_default_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"
)

#' show toast message
#'
Expand All @@ -11,12 +27,15 @@
#' @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
#'
#' @importFrom shiny getDefaultReactiveDomain
#' @importFrom utils modifyList
#'
#' @return `invisible()`
#'
Expand All @@ -25,26 +44,23 @@ 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()
) {


if (!is.list(.options)) {
stop("`.options` must be a list", call. = FALSE)
}

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

# Update default options
.options <- modifyList(showToast_default_options, .options)

# Argument `keepVisible = TRUE`
if (isTRUE(keepVisible)) {
.options$timeOut <- 0
.options$extendedTimeOut <- 0
Expand Down
2 changes: 1 addition & 1 deletion inst/assets/toastr/js/toastr.js.map
100644 → 100755

Large diffs are not rendered by default.

Empty file modified inst/assets/toastr/js/toastr.min.js
100644 → 100755
Empty file.
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.