Basecoat assets

Description

The Basecoat stylesheet and scripts as an htmltools::htmlDependency(), placed in the page <head>. Served from the files bundled with this package by default, or from jsDelivr.

Usage

bc_deps(
  style = NULL,
  js = FALSE,
  theme = NULL,
  source = c("local", "cdn"),
  viewport = TRUE,
  version = bc_version
)

Arguments

Argument Description
style String or NULL. A style pack, one of vega, nova, maia, lyra, mira, luma, sera, rhea, or "base" for tokens and structure with no visual style at all.
js Bool or character vector. FALSE by default; components attach their own scripts. TRUE for all of them, or name the ones to load.
theme String or NULL. Path to a CSS file of your own, loaded after the style pack so its tokens win. See bc_theme().
source String. "local" to serve the bundled files, "cdn" to serve Basecoat's own from jsDelivr, which lays out several components wrong, or a URL prefix such as "/basecoat/" that the bundled directory is served from.
viewport Bool. Add the mobile viewport meta tag to the page head.
version String. The basecoat-css release to serve. Only 1.0.2 is bundled, so any other release needs source = "cdn".

Value

An htmltools::htmlDependency(), or a list of two when theme is given.

Details

Call once per page. Components attach their own scripts, so js is only needed for hand-written markup.

Load any other Tailwind build before this one, never after.

Serving the files yourself

Serve system.file("basecoat", package = "basecoat") under a path, then name that path as source.

plumber2::api_statics(api, at = "/basecoat/", path = system.file("basecoat", package = "basecoat"))
htmltools::renderDependencies(list(bc_deps(source = "/basecoat/")), "href")

Examples

bc_deps()

bc_deps(style = "maia", js = c("select", "toast"))

bc_deps(source = "cdn")

bc_deps(style = "lyra", source = "/basecoat/")

css <- tempfile(fileext = ".css")
writeLines(":root { --primary: oklch(0.54 0.16 320); }", css)

htmltools::attachDependencies(bc_button("Save"), bc_deps(theme = css))