🔍 An RStudio addin slash regex utility belt
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

83 lines
3.4KB

  1. # ---- Modified Shiny Inputs ----
  2. # The shiny package as a whole is distributed under GPL-3
  3. # (GNU GENERAL PUBLIC LICENSE version 3).
  4. # See https://github.com/rstudio/shiny/blob/master/LICENSE
  5. #' Modified Text Area Input
  6. #'
  7. #' Standard [shiny::textAreaInput()] with additional `is_code` parameter, added
  8. #' code font style for the input text and with `autocomplete`, `autocorrect`,
  9. #' `autocapitalize` and `spellcheck` set to `off` or `false`.
  10. #'
  11. #' @inheritParams shiny::textAreaInput
  12. #' @param is_code Should the text input be considered verbatim code input?
  13. textAreaInputAlt <- function(inputId, label, value = "", width = NULL, height = NULL,
  14. cols = NULL, rows = NULL, placeholder = NULL, resize = NULL,
  15. is_code = TRUE) {
  16. `%AND%` <- getFromNamespace("%AND%", "shiny")
  17. value <- shiny::restoreInput(id = inputId, default = value)
  18. if (!is.null(resize)) {
  19. resize <- match.arg(resize, c("both", "none", "vertical", "horizontal"))
  20. }
  21. style <- paste(
  22. if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  23. if (!is.null(height)) paste0("height: ", shiny::validateCssUnit(height), ";"),
  24. if (!is.null(resize)) paste0("resize: ", resize, ";"),
  25. if (is_code) 'font-family: "Monaco", "Inconsolata", monospace;'
  26. )
  27. parent_style <- paste(
  28. if (!is.null(width) && grepl("%", width)) paste0("width: ", width, ";"),
  29. if (!is.null(height) && grepl("%", height)) paste0("height: ", height, ";")
  30. )
  31. # Workaround for tag attribute=character(0) bug:
  32. # https://github.com/rstudio/htmltools/issues/65
  33. if (length(style) == 0) style <- NULL
  34. shiny::div(class = "form-group shiny-input-container",
  35. label %AND% shiny::tags$label(label, `for` = inputId),
  36. style = if (!parent_style %in% c(" ", "", " ")) parent_style,
  37. shiny::tags$textarea(
  38. id = inputId,
  39. class = "form-control",
  40. placeholder = placeholder,
  41. style = style,
  42. rows = rows,
  43. cols = cols,
  44. autocomplete = "off",
  45. autocorrect = "off",
  46. autocapitalize = "off",
  47. spellcheck = "false",
  48. value
  49. )
  50. )
  51. }
  52. #' Modified Text Input
  53. #'
  54. #' Standard [shiny::textInput()] with additional `width` parameter, added code
  55. #' font style for the input text and with `autocomplete`, `autocorrect`,
  56. #' `autocapitalize` and `spellcheck` set to `off` or `false`.
  57. #'
  58. #' @inheritParams shiny::textInput
  59. #' @param width Width of `shiny-input-container` div.
  60. textInputCode <- function(inputId, label, value = "", width = NULL,
  61. placeholder = NULL) {
  62. `%AND%` <- getFromNamespace("%AND%", "shiny")
  63. value <- shiny::restoreInput(id = inputId, default = value)
  64. shiny::div(class = "form-group shiny-input-container",
  65. style = if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  66. label %AND% shiny::tags$label(label, `for` = inputId),
  67. shiny::tags$input(id = inputId, type="text", class="form-control", value=value,
  68. style = 'font-family: "Monaco", "Inconsolata", monospace;',
  69. autocomplete = "off", autocorrect = "off",
  70. autocapitalize = "off", spellcheck = "false",
  71. placeholder = placeholder)
  72. )
  73. }