Import a theme from a shadcn / tweakcn registry export
Source:R/theme.R
shad_theme_from_registry.RdExperimental.
Convert a shadcn registry item or tweakcn theme export (its cssVars blocks)
into a shad_theme(), mapping upstream variable names to shadshiny tokens via
the bundled theme map. Unmapped variables are skipped with a single warning.
See also
Other shadshiny theming:
shad_chart_colors(),
shad_current_theme(),
shad_theme(),
shad_theme_echarts4r(),
shad_theme_ggplot2(),
shad_theme_plotly(),
shad_theme_scope(),
shad_tokens()
Examples
# A registry export as JSON text; a file path or URL works too.
registry <- '{"cssVars": {
"light": {"--primary": "oklch(0.6 0.2 250)", "--radius": "0.5rem"},
"dark": {"--primary": "oklch(0.7 0.2 250)"}
}}'
shad_theme_from_registry(registry)
#> $tokens
#> $tokens$primary
#> [1] "oklch(0.6 0.2 250)"
#>
#> $tokens$radius
#> [1] "0.5rem"
#>
#>
#> $dark
#> $tokens
#> $tokens$primary
#> [1] "oklch(0.7 0.2 250)"
#>
#>
#> $dark
#> NULL
#>
#> attr(,"class")
#> [1] "shad_theme"
#>
#> attr(,"class")
#> [1] "shad_theme"