Debian Codegraph @

inst/examples-shiny/build-a-box/R/code_modal.R

raw
1 code_modal <- function(code) {
2 if (rlang::is_call(code)) {
3 code <- rlang::expr_text(code)
4 }
5
6 if (requireNamespace("styler", quietly = TRUE)) {
7 code <- styler::style_text(code)
8 }
9
10 code <- paste(code, collapse = "\n")
11
12 showModal(
13 modalDialog(
14 HTML(
15 sprintf(
16 '<pre><code id="value-box-code">%s</code></pre>',
17 code
18 )
19 ),
20 p(
21 id = "copy-clipboard-not-supported",
22 class = "text-muted d-none",
23 HTML(
24 "Press <kbd>Ctrl</kbd>/<kbd>Cmd</kbd> + <kbd>C</kbd> to copy the value box example code."
25 )
26 ),
27 tags$button(
28 id = "copy-code-to-clipboard",
29 class = "btn btn-outline-primary",
30 onclick = "copyValueBoxCode()",
31 "Copy to clipboard"
32 ),
33 singleton(tags$script(src = "code-modal.js")),
34 footer = modalButton("Done"),
35 easyClose = TRUE
36 )
37 )
38 }