Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinoa committed Sep 22, 2020
2 parents 096f9cc + 24f8d47 commit 063e3ee
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
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)
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# shinyFeedback 0.2.0.9001
# shinyFeedback 0.3.0

- new function `hideToast()` to programatically hide all toasts (#44)
- 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 programmatically hide all toasts (#44)
- simplified and deduped JavaScript (#42) - Thanks @jcheng5!
- added input feedback support for `shiny::fileInput()` (#41)
- updated "shinyWidgets.AirPickerInput" name to reflect the change to `shinyWidgets`
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.

2 changes: 1 addition & 1 deletion vignettes/shinyFeedback-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ server <- function(input, output, session) {
shinyApp(ui, server)
```

The above app has one `textInput()` input in the UI. In the server function, we write the code to conditionally display a feedback message. If the text input has more than 3 characters, the feeback message is displayed.
The above app has one `textInput()` input in the UI. In the server function, we write the code to conditionally display a feedback message. If the text input has more than 3 characters, the feedback message is displayed.

# `feedback()`

Expand Down

0 comments on commit 063e3ee

Please sign in to comment.