Skip to content

Commit

Permalink
added config_noty()
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 22, 2022
1 parent 5dda11f commit 8309152
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 17 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(add_busy_gif)
export(add_busy_spinner)
export(add_loading_state)
export(busy_start_up)
export(config_notify)
export(config_report)
export(hide_spinner)
export(html_dependency_epic)
Expand Down
120 changes: 109 additions & 11 deletions R/notify.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#' @description Send notifications to the user.
#'
#' @param text Text to be displayed.
#' @param ... Options passed to JavaScript method, see
#' [https://notiflix.github.io/documentation](https://notiflix.github.io/documentation).
#' @param ... Options passed to JavaScript method, see [config_notify()].
#' @param timeout The delay in milliseconds to hide and remove the notifications.
#' @param position Position where to display the notification.
#' @param type Type of notification: `success`, `failure`, `info` or `warning`.
Expand Down Expand Up @@ -33,6 +32,9 @@ notify <- function(text,
session = shiny::getDefaultReactiveDomain()) {
type <- match.arg(type)
position <- match.arg(position)
config <- list(timeout = timeout, position = position, ...)
idx <- vapply(X = config, FUN = inherits, what = "config_notify", FUN.VALUE = logical(1))
config <- c(config[!idx], unlist(config[idx], recursive = FALSE))
insertUI(
selector = "html",
ui = tagList(html_dependency_notify()),
Expand All @@ -44,7 +46,7 @@ notify <- function(text,
type = paste0("shinybusy-notify-", type),
message = list(
text = text,
config = list(timeout = timeout, position = position, ...)
config = config
)
)
}
Expand All @@ -54,9 +56,9 @@ notify <- function(text,
#'
#' @rdname notify
notify_success <- function(text,
...,
timeout = 3000,
position = "right-top",
...) {
position = "right-top") {
notify(
text = text,
timeout = timeout,
Expand All @@ -71,9 +73,9 @@ notify_success <- function(text,
#'
#' @rdname notify
notify_failure <- function(text,
...,
timeout = 3000,
position = "right-top",
...) {
position = "right-top") {
notify(
text = text,
timeout = timeout,
Expand All @@ -87,9 +89,9 @@ notify_failure <- function(text,
#'
#' @rdname notify
notify_info <- function(text,
...,
timeout = 3000,
position = "right-top",
...) {
position = "right-top") {
notify(
text = text,
timeout = timeout,
Expand All @@ -103,9 +105,9 @@ notify_info <- function(text,
#'
#' @rdname notify
notify_warning <- function(text,
...,
timeout = 3000,
position = "right-top",
...) {
position = "right-top") {
notify(
text = text,
timeout = timeout,
Expand All @@ -115,3 +117,99 @@ notify_warning <- function(text,
)
}



#' @title Configure options for [notify()] and others
#'
#' @description Options for [notify()] functions, see
#' [online documentation](https://notiflix.github.io/documentation)
#' for default values and examples.
#'
#' @param background Changes the background color.
#' @param textColor Changes the text color.
#' @param childClassName Changes the class name.
#' @param notiflixIconColor Changes the SVG icon color.
#' @param fontAwesomeClassName Changes the FontAwesome icon class name (FontAwesome has to be added to the project separately.)
#' @param fontAwesomeIconColor Changes the FontAwesome icon color.
#' @param backOverlayColor Changes the color of the background overlay.
#' @param width Changes the width of the notifications.
#' @param distance The distance between positioned notifications and the body element.
#' @param opacity Changes the opacity. (Between 0 and 1)
#' @param borderRadius Changes the radius of the notifications corners.
#' @param rtl Specifies the text direction to "right-to-left".
#' @param messageMaxLength The maximum length of the notifications message text.
#' @param backOverlay Adds a background overlay to the notifications.
#' @param plainText Strips all HTML tags.
#' @param showOnlyTheLastOne Auto-removes all the notifications except for the last one.
#' @param clickToClose Removes the notification when it has been clicked without waiting for the delay.
#' @param pauseOnHover Auto-remove functionality will be paused for each notification element when the pointer(mouse) enters on it.
#' @param ID Changes the ID (attribute) of the notifications.
#' @param className Changes the class name (attribute) of the notifications.
#' @param zindex Changes the z-index of the notifications.
#' @param fontFamily Changes the font-family of the notifications message text.
#' @param fontSize Changes the font-size of the notifications message text.
#' @param cssAnimation Enables/disables CSS animations to show/hide the notifications.
#' @param cssAnimationDuration Changes the CSS animations duration as milliseconds.
#' @param cssAnimationStyle 6 types of styles can be used: fade zoom from-right from-top from-bottom from-left
#' @param closeButton Adds a close button/icon to the notifications. (Notifications with a close button won't disappear until they were clicked.)
#' @param useIcon Allows using built-in SVG or external FontAwesome icons in the notifications. (By default, built-in SVG icons have been defined.)
#' @param useFontAwesome Ignores built-in SVG icons and allows to use of external FontAwesome icons.
#' @param fontAwesomeIconStyle 2 types of styles can be used: basic shadow
#' @param fontAwesomeIconSize Changes the font-size of the FontAwesome icons
#' @param ... Other potential arguments.
#'
#' @return A config `list` that can be used in [notify()] and other `notify_*` functions.
#' @export
#'
#' @example examples/config_notify.R
config_notify <- function(background = NULL,
textColor = NULL,
childClassName = NULL,
notiflixIconColor = NULL,
fontAwesomeClassName = NULL,
fontAwesomeIconColor = NULL,
backOverlayColor = NULL,
width = NULL,
distance = NULL,
opacity = NULL,
borderRadius = NULL,
rtl = NULL,
messageMaxLength = NULL,
backOverlay = NULL,
plainText = NULL,
showOnlyTheLastOne = NULL,
clickToClose = NULL,
pauseOnHover = NULL,
ID = NULL,
className = NULL,
zindex = NULL,
fontFamily = NULL,
fontSize = NULL,
cssAnimation = NULL,
cssAnimationDuration = NULL,
cssAnimationStyle = NULL,
closeButton = NULL,
useIcon = NULL,
useFontAwesome = NULL,
fontAwesomeIconStyle = NULL,
fontAwesomeIconSize = NULL,
...) {
config <- c(as.list(environment()), list(...))
config$success <- config$failure <- dropNulls(config[1:7])
config$info <- config$warning <- dropNulls(config[1:7])
config[1:6] <- NULL
config <- dropNulls(config)
class(config) <- c(class(config), "config_notify")
return(config)
}


# library(rvest)
# docs <- html_table(read_html("https://notiflix.github.io/documentation"))
#
# docs[[1]]
# cat(paste(docs[[2]]$Option, collapse = " = NULL,\n"))
#
# cat(
# paste("#' @param", docs[[1]]$Option, docs[[1]]$Description, "\n")
# )
24 changes: 24 additions & 0 deletions examples/config_notify.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library(shiny)
library(shinybusy)

ui <- fluidPage(
tags$h2("config for notify examples"),
actionButton("success", "Success")
)

server <- function(input, output, session) {

observeEvent(input$success, {
notify_success(
"Well done!",
config_notify(
background = "#0431B4",
notiflixIconColor = "#FFF"
)
)
})

}

if (interactive())
shinyApp(ui, server)
140 changes: 140 additions & 0 deletions man/config_notify.Rd

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

11 changes: 5 additions & 6 deletions man/notify.Rd

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

0 comments on commit 8309152

Please sign in to comment.