🔍 An RStudio addin slash regex utility belt
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

108 lines
3.1KB

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