Skip to contents

[Experimental] Sets how the tips look: the fill, words, border and code background, the corner, the shadow and the typeface, for light and for dark. A role left out keeps what the page gives: the tip reads Bootstrap's variables where the page has them (bslib), so a page that already has a bslib::bs_theme() needs no theme, and its tips follow light and dark on their own. Use a theme when the tips must look different from the page, or when the page has no bslib. Give the result to use_hovercraft() once, in the page's UI, or to tip_on() for one tag, as style =.

Usage

tip_theme(..., light = NULL, dark = NULL, mode = "auto")

Arguments

...

Must be empty. It makes a misspelt argument an error.

light, dark

Named lists of roles, or NULL. Roles: bg, text, border, code_bg, radius, shadow, font. radius is a number of pixels or a length such as "0.5rem"; shadow is CSS box-shadow text or "none"; font is CSS font-family text. Values may only hold letters, digits, spaces and , . ' " ( ) # % _ + * -.

mode

"auto" (the default) follows the page: the data-bs-theme attribute that input_dark_mode() in bslib sets on the page, and with none, the visitor's own setting. "light" and "dark" use that mode whatever the page says. A tip is drawn at the page level, so a data-bs-theme on a smaller part of the page does not reach it.

Value

A hovercraft_theme object, to give as style = to use_hovercraft() or tip_on(), or to tip_style(). Its fields are internal; pass the object on.

Details

The roles are bg (the tip's fill), text (its words), border (its border, seen in forced-colours mode and in a tip that stays open), code_bg (behind code), radius (the corner), shadow and font. Colours may be names, hex, grDevices::rgb() output, "rgba(0, 0, 0, 0.8)" text or three numbers from 0 to 255. A value that is a CSS variable, "--team-blue" or "var(--team-blue)", is read by the browser where the page defines it; R cannot check it. A theme can also be a bslib::bs_theme() or a plain list, see tip_style().

A role set in light and not in dark is used in dark mode too, so a brand colour set once holds in both modes.

The tip has a small arrow pointing at its tag. It takes the colour of the tip, so it is drawn only when the bg is opaque: with a translucent bg ("rgba(0, 0, 0, 0.8)") the tip has no arrow.

Contrast warnings

The words of a tip must be readable on its fill. For each mode, the text on the bg (and on the code_bg, if you give one) is measured, and a ratio below 4.5:1, the usual level for text, gives a warning of class hovercraft_contrast; the colours are kept. A role you leave out is taken to be what Bootstrap's default theme gives, a shade of the page: Bootstrap's tertiary background with the page's text colour (a #f8f8f8 fill with #1d1f21 words in light mode, #292d34 with #dee2e6 in dark mode). CSS variables cannot be measured and are skipped. A translucent bg is measured over the page's colour (white, or #1d1f21 in dark mode), and a translucent code_bg over the bg. Set options(hovercraft.contrast_warnings = FALSE) to turn the warnings off, or silence only them:

withCallingHandlers(
  tip_theme(light = list(bg = "#ffffff", text = "#dddddd")),
  hovercraft_contrast = function(w) invokeRestart("muffleWarning")
)

Examples

tip_theme()
#> tip_theme()
tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff", radius = 8))
#> tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff", radius = "8px"))
tip_theme(
  light = list(bg = "#1b3a6b", text = "#ffffff"),
  dark = list(bg = "#9ec5fe", text = "#0b1f3a"),
  mode = "auto"
)
#> tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff"), dark = list(bg = "#9ec5fe", text = "#0b1f3a"))
tip_theme(light = list(bg = "--brand-blue", font = "Georgia, serif"))
#> tip_theme(light = list(bg = "var(--brand-blue)", font = "Georgia, serif"))