/
argonProgress.R
53 lines (47 loc) · 1.43 KB
/
argonProgress.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#' Create a progress bar
#'
#' Build an argon progress bar
#'
#' @param value Progress value between 0 and 100.
#' @param text Label text.
#' @param status Progress status color. See \url{https://demos.creative-tim.com/argon-design-system/docs/foundation/colors.html}.
#'
#' @examples
#' if (interactive()) {
#' library(argonR)
#' argonProgress(value = 10, status = "danger", text = "Custom Text")
#' }
#'
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
argonProgress <- function(value, text = NULL, status = "primary") {
stopifnot(value <= 100)
progressWrapper <- htmltools::tags$div(class = "progress-wrapper")
progressTag <- htmltools::tags$div(class = "progress-info")
progressLabel <- if (!is.null(text)) {
htmltools::tags$div(
class = "progress-label",
htmltools::tags$span(text)
)
}
progressPercent <- htmltools::tags$div(class = "progress-percentage", htmltools::span(paste0(value, "%")))
progressBar <- htmltools::tags$div(
class = "progress",
htmltools::tags$div(
class = paste0("progress-bar bg-", status),
role = "progressbar",
`aria-valuenow` = value,
`aria-valuemin` = "0",
`aria-valuemax` = "100",
style= paste0("width: ", value, "%;")
)
)
progressTag <- htmltools::tagAppendChildren(
progressTag,
progressLabel,
progressPercent
)
htmltools::tagAppendChildren(progressWrapper, progressTag, progressBar)
}