R/tooltip.R

Defines functions tooltip_extra

Documented in tooltip_extra

#' Tool-tip for table headers
#'
#' @param content The content to be displayed in the tool-tip
#' @param theme The theme of the tool-tip, either "light", "light-border", "material" or
#'   "translucent"
#'
#' @examples
#' reactable::colDef(header = tooltip_extra("This is my tool-tip", theme = "material"))
#'
#' @return Custom JS tool-tip renderer for reactable
#'
#' @export
tooltip_extra <- function(content, theme = "light") {
  reactable::JS(
    htmltools::doRenderTags(
      htmltools::htmlTemplate(
        text_ = "function(columnInfo) {
                 return React.createElement(TooltipExtras,
                 {column: columnInfo.name, tooltip: '{{content}}',
                 theme: '{{theme}}'})
        }",
        content = content,
        theme = theme
      )
    )
  )
}

Try the reactable.extras package in your browser

Any scripts or data that you put into this service are public.

reactable.extras documentation built on Oct. 30, 2024, 9:14 a.m.