/
highlight.R
117 lines (103 loc) · 3.72 KB
/
highlight.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#' Highlight & Initialise
#'
#' Initialise and highlight an element.
#'
#' @param el Id of element to be highlighted.
#' @param title Title on the popover.
#' @param description Body of the popover.
#' @param position Where to position the popover.
#' See positions section.
#' @param class className to wrap this specific step
#' popover in addition to the general className in Driver
#' options.
#' @param show_btns Whether to show control buttons.
#' @param close_btn_text Text on the close button.
#' @param next_btn_text Next button text.
#' @param prev_btn_text Previous button text.
#' @param animate Whether to animate or not.
#' @param opacity Background opacity (0 means only popovers
#' and without overlay).
#' @param padding Distance of element from around the edges.
#' @param allow_close Whether the click on overlay should close
#' or not.
#' @param overlay_click_next Whether the click on overlay should
#' move next.
#' @param done_btn_text Text on the final button.
#' @param close_btn_text Text on the close button for this step.
#' @param stage_background Background color for the staged behind
#' highlighted element.
#' @param next_btn_text Next button text for this step.
#' @param prev_btn_text Previous button text for this step.
#' @param show_btns Do not show control buttons in footer.
#' @param keyboard_control Allow controlling through keyboard (escape
#' to close, arrow keys to move).
#' @param session A valid Shiny session if \code{NULL}
#' the function attempts to get the session with
#' \link[shiny]{getDefaultReactiveDomain}.
#'
#' @section Position:
#' * left
#' * right
#' * left-center
#' * left-bottom
#' * top
#' * top-center
#' * top-right
#' * right
#' * right-center
#' * right-bottom
#' * bottom
#' * bottom-center
#' * mid-center
#'
#' @name highlight
#' @export
highlight <- function(el, title = NULL, description = NULL, position = NULL,
class = NULL, show_btns = NULL, close_btn_text = NULL,
next_btn_text = NULL, prev_btn_text = NULL, session = NULL) {
if(is.null(session))
session <- shiny::getDefaultReactiveDomain()
assertthat::assert_that(!missing(el))
el <- paste0("#", el)
popover <- list()
if(!is.null(class)) popover$className <- class
if(!is.null(title)) popover$title <- title
if(!is.null(description)) popover$description <- description
if(!is.null(position)) popover$position <- position
if(!is.null(show_btns)) popover$showButtons <- show_btns
if(!is.null(close_btn_text)) popover$closeBtnText <- close_btn_text
if(!is.null(next_btn_text)) popover$nextBtnText <- next_btn_text
if(!is.null(prev_btn_text)) popover$prevBtnText <- prev_btn_text
step = list(element = el)
if(length(popover))
step$popover <- popover
session$sendCustomMessage("cicerone-highlight-man", step)
invisible()
}
#' @rdname highlight
#' @export
initialise <- function(animate = TRUE, opacity = .75, padding = 10,
allow_close = TRUE, overlay_click_next = FALSE, done_btn_text = "Done",
close_btn_text = "Close", stage_background = "#ffffff", next_btn_text = "Next",
prev_btn_text = "Previous", show_btns = TRUE, keyboard_control = TRUE, session = NULL) {
if(is.null(session))
session <- shiny::getDefaultReactiveDomain()
globals <- list(
animate = animate,
opacity = opacity,
padding = padding,
allowClose = allow_close,
overlayClickNext = overlay_click_next,
doneBtnText = done_btn_text,
closeBtnText = close_btn_text,
stageBackground = stage_background,
nextBtnText = next_btn_text,
prevBtnText = prev_btn_text,
showButtons = show_btns,
keyboardControl = keyboard_control
)
if(is.null(session))
session <- shiny::getDefaultReactiveDomain()
session$sendCustomMessage("cicerone-init", list(globals = globals))
invisible()
}