| brand_color_pluck | R Documentation |
Safely extracts a color value from a brand object based on the provided
key. This function handles color references and resolves them, including
references to palette colors and other theme colors. It detects and prevents
cyclic references.
brand_color_pluck(brand, key)
brand |
A brand object created by |
key |
A character string representing the color key to extract. |
The function checks for the color key in both the main color theme and the color palette. It can resolve references between colors (e.g., if "primary" references "palette.blue"). If a cyclic reference is detected (e.g., A references B which references A), the function will throw an error.
The resolved color value (typically a hex color code) if the key exists, otherwise returns the key itself.
Other brand.yml helpers:
brand_has(),
brand_pluck(),
with_brand_yml_path()
brand <- as_brand_yml(list(
color = list(
primary = "blue",
secondary = "info",
info = "light-blue",
palette = list(
blue = "#004488",
light_blue = "#c3ddff"
)
)
))
# Extract the primary color
brand_color_pluck(brand, "primary") # "#004488"
# Extract a color that references another color
brand_color_pluck(brand, "info") # "#c3ddff"
# Extract a color that references another color
# which in turn references the palette
brand_color_pluck(brand, "secondary") # "#c3ddff"
# Extract a color that isn't defined
brand_color_pluck(brand, "green") # "green"
# Use brand_pluck() if you need direct (resolved) values
brand_pluck(brand, "color", "primary") # "#004488"
brand_pluck(brand, "color", "info") # "#c3ddff"
brand_pluck(brand, "color", "green") # NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.