🔍 An RStudio addin slash regex utility belt
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

111 lines
3.3KB

  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. #' @family modified shiny inputs
  14. textAreaInputAlt <- function(
  15. inputId,
  16. label,
  17. value = "",
  18. width = NULL,
  19. height = NULL,
  20. cols = NULL,
  21. rows = NULL,
  22. placeholder = NULL,
  23. resize = NULL,
  24. is_code = TRUE
  25. ) {
  26. `%AND%` <- getFromNamespace("%AND%", "shiny")
  27. value <- shiny::restoreInput(id = inputId, default = value)
  28. if (!is.null(resize)) {
  29. resize <- match.arg(resize, c("both", "none", "vertical", "horizontal"))
  30. }
  31. style <- paste(
  32. if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  33. if (!is.null(height)) paste0("height: ", shiny::validateCssUnit(height), ";"),
  34. if (!is.null(resize)) paste0("resize: ", resize, ";"),
  35. if (is_code) 'font-family: "Monaco", "Inconsolata", monospace;'
  36. )
  37. parent_style <- paste(
  38. if (!is.null(width) && grepl("%", width)) paste0("width: ", width, ";"),
  39. if (!is.null(height) && grepl("%", height)) paste0("height: ", height, ";")
  40. )
  41. # Workaround for tag attribute=character(0) bug:
  42. # https://github.com/rstudio/htmltools/issues/65
  43. if (length(style) == 0) style <- NULL
  44. shiny::div(
  45. class = "form-group shiny-input-container",
  46. label %AND% shiny::tags$label(label, `for` = inputId),
  47. style = if (!parent_style %in% c(" ", "", " ")) parent_style,
  48. shiny::tags$textarea(
  49. id = inputId,
  50. class = "form-control",
  51. placeholder = placeholder,
  52. style = style,
  53. rows = rows,
  54. cols = cols,
  55. autocomplete = "off",
  56. autocorrect = "off",
  57. autocapitalize = "off",
  58. spellcheck = "false",
  59. value
  60. )
  61. )
  62. }
  63. #' Modified Text Input
  64. #'
  65. #' Standard [shiny::textInput()] with additional `width` parameter, added code
  66. #' font style for the input text and with `autocomplete`, `autocorrect`,
  67. #' `autocapitalize` and `spellcheck` set to `off` or `false`.
  68. #'
  69. #' @inheritParams shiny::textInput
  70. #' @param width Width of `shiny-input-container` div.
  71. #' @param ... Extra elements to be included in the `input-group` div.
  72. #' @family modified shiny inputs
  73. textInputCode <- function(
  74. inputId,
  75. label,
  76. value = "",
  77. width = NULL,
  78. placeholder = NULL,
  79. ...
  80. ) {
  81. `%AND%` <- getFromNamespace("%AND%", "shiny")
  82. value <- shiny::restoreInput(id = inputId, default = value)
  83. shiny::div(
  84. class = "input-group shiny-input-container",
  85. style = if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  86. label %AND% shiny::tags$label(label, `for` = inputId),
  87. shiny::tags$input(
  88. id = inputId,
  89. type = "text",
  90. class = "form-control",
  91. value = value,
  92. style = 'font-family: "Monaco", "Inconsolata", monospace;',
  93. autocomplete = "off",
  94. autocorrect = "off",
  95. autocapitalize = "off",
  96. spellcheck = "false",
  97. placeholder = placeholder
  98. ),
  99. ...
  100. )
  101. }