Skip to contents

[Experimental] Bundles what makes a tip look the way it does: a preset (a named look), a theme (colours, corner and font), a class on the tip box, and how it enters and how big it is. Give the result as style = to tip_on() for one tag, or to use_hovercraft() for the whole page. A part left out is left alone: it is inherited from the page, or from the page's own bslib variables.

Usage

tip_style(
  preset = NULL,
  ...,
  theme = NULL,
  class = NULL,
  motion = NULL,
  gap = NULL,
  max_width = NULL,
  pin_width = NULL
)

Arguments

preset

A preset name from tip_presets(), "none" to clear an inherited preset, or NULL (the default) to inherit. A string with : or ; is not a preset: style is not CSS.

...

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

theme

A tip_theme(), a bslib::bs_theme(), a named list of roles (list(bg = "#1b3a6b")), a named list of CSS variables, or NULL (the default).

class

Class names for the tip box, "" to clear an inherited class, or NULL (the default) to inherit. See the section on the class.

motion

How a tip enters: "fade", "slide" or "none", or NULL (the default) to inherit. A page that sets no motion has none. See the section on size and motion.

gap

The space between the tag and the tip, in pixels: a whole number from 0 to 24, or NULL (the default) to inherit.

max_width

The widest a hint grows, in pixels: a whole number from 160 to 640, or NULL (the default) to inherit. It is also kept inside the window.

pin_width

The widest a pinned tip grows, in pixels: a whole number from 240 to 720, or NULL (the default) to inherit.

Value

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

Details

A value set nearer the tip wins: a tag's style beats the page's. A theme is merged role by role, so a tag that sets only bg keeps the page's text. A preset is replaced as a whole by the nearer one, and "none" clears an inherited preset. A theme beats a preset set at the same place or further out, role by role, so tip_style("sober", theme = ...) is sober with those roles changed; a preset set nearer the tip than a theme beats that theme.

The class

class puts class names on the tip box, so your own CSS can restyle it. Give class names as a vector (c("wide", "audit-tip")) or as text with spaces ("wide audit-tip"), "" to clear a class the page or a parent set, or NULL to inherit. A name has letters, digits, - and _ and does not start with a digit, and must not start with hc-tip, which the tip's own classes use; R stops on a bad name, where the browser would only drop it with a line in its console. The nearest class wins as a whole and the classes are not added together: a tag's class = "wide" replaces a page's class = "brand".

Size and motion

motion is how a tip enters: "fade", "slide" (it moves four pixels from its side while it fades) or "none". gap is the space between the tag and the tip, max_width the widest a hint grows, and pin_width the widest a pinned tip grows, all in pixels and all whole numbers. R checks them against the ranges in the tip engine's page contract, so a value outside one stops with an error that names it. A tip is also kept inside the window.

They are written the way a theme is, on the page or on one tag, and a value set nearer the tip wins, one value at a time: a tag that sets only gap keeps the page's motion. They apply with a preset or without one. A reader's reduced-motion setting always wins over "fade" and "slide"; the tip engine does this, and nothing here switches it off.

There is no delay argument: the tip engine reads the delay before a hint shows only from the file of a preset.

Themes on one tag

A theme given to a tag sets the roles bg, text, border, code_bg, radius, shadow and font. CSS variables given as a list of names that start with -- reach the tip only from the page, not from a tag, because a tip is drawn away from its tag.

Examples

tip_style("sober")
#> tip_style("sober")
tip_style("sober", theme = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff")))
#> tip_style("sober", theme = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff")))
tip_style(class = "wide")
#> tip_style(class = "wide")
tip_style(class = "") # clears a class set above
#> tip_style(class = "")
tip_style("sober", motion = "slide", max_width = 280)
#> tip_style("sober", motion = "slide", max_width = 280)
use_hovercraft(style = tip_style(motion = "fade", gap = 10))
#> [[1]]
#> List of 10
#>  $ name      : chr "hovercraft"
#>  $ version   : chr "0.60.0"
#>  $ src       :List of 1
#>   ..$ file: chr "engine/www"
#>  $ meta      : NULL
#>  $ script    : chr "tip.js"
#>  $ stylesheet: chr "tip.css"
#>  $ head      : NULL
#>  $ attachment: NULL
#>  $ package   : chr "hovercraft"
#>  $ all_files : logi TRUE
#>  - attr(*, "class")= chr "html_dependency"
#> 
#> [[2]]
#> List of 10
#>  $ name      : chr "hovercraft-style"
#>  $ version   : chr "0.0.90"
#>  $ src       :List of 1
#>   ..$ file: chr "runtime"
#>  $ meta      :List of 1
#>   ..$ hovercraft-ops: chr "W3sib3AiOiJjc3MiLCJpZCI6IjczZjg3YWY4MGQzZjIwM2YiLCJ0ZXh0IjoiYm9keSB7XG4g\nIC0taG92ZXJjcmFmdC10aXAtbW90aW9uOiBmY"| __truncated__
#>  $ script    : NULL
#>  $ stylesheet: NULL
#>  $ head      : NULL
#>  $ attachment: NULL
#>  $ package   : chr "hovercraft"
#>  $ all_files : logi FALSE
#>  - attr(*, "class")= chr "html_dependency"
#> 
#> [[3]]
#> List of 10
#>  $ name      : chr "hovercraft-runtime"
#>  $ version   : chr "0.0.90"
#>  $ src       :List of 1
#>   ..$ file: chr "runtime"
#>  $ meta      :List of 1
#>   ..$ hovercraft-config: chr "eyJhdHRyaWJ1dGVzIjp7ImlkIjoiZGF0YS1ob3ZlcmNyYWZ0LXRpcC1pZCIsInBpbnMiOiJk\nYXRhLWhvdmVyY3JhZnQtdGlwLXBpbnMiLCJwa"| __truncated__
#>  $ script    : chr [1:2] "shiny.js" "runtime.js"
#>  $ stylesheet: chr [1:2] "shiny.css" "status.css"
#>  $ head      : NULL
#>  $ attachment: NULL
#>  $ package   : chr "hovercraft"
#>  $ all_files : logi FALSE
#>  - attr(*, "class")= chr "html_dependency"
#> 
tip_on(
  htmltools::tags$button("Run"),
  "Runs the **check**",
  style = tip_style("dense", class = "audit-tip")
)
#> <button data-hovercraft-tip="Runs the **check**" data-hovercraft-tip-preset="dense" data-hovercraft-tip-class="audit-tip">Run</button>