* The style functions are now more permissive about color names in the `color` argument. Color names should be valid CSS classes that can also be used as CSS variable names, but the `style_` function only stops with an error if the color name contains spaces. (@jdlom #69)tags/v0.4.1
| @@ -121,8 +121,13 @@ prepare_colors <- function(colors = NULL) { | |||
| call. = FALSE) | |||
| } | |||
| if (any(grepl("[^[:alpha:]_-]", names(colors)))) { | |||
| stop("Color names in `colors` must be valid CSS classes", call. = FALSE) | |||
| maybe_bad_css <- unique(grep("^[_-]|[ .>~*:|+}/]", names(colors), value = TRUE)) | |||
| if (length(maybe_bad_css) > 0) { | |||
| warning( | |||
| "Color names in `colors` should be valid CSS classes: ", | |||
| paste0("'", maybe_bad_css, "'", collapse = ", "), | |||
| call. = FALSE | |||
| ) | |||
| } | |||
| whisker::iteratelist(colors, "color_name") | |||
| @@ -13,9 +13,23 @@ describe("prepare_colors()", { | |||
| it("requires valid CSS names", { | |||
| expect_error(prepare_colors(c("light blue" = "#88f"))) | |||
| expect_error(prepare_colors(c("light/blue" = "#88f"))) | |||
| expect_warning(prepare_colors(c("light/blue" = "#88f")), "light/blue") | |||
| expect_warning(prepare_colors(c("-lightblue" = "#88f")), "-lightblue") | |||
| expect_warning(prepare_colors(c("_lightblue" = "#88f")), "_lightblue") | |||
| colors <- c("light_blue" = "#88f", "light-blue" = "#88f") | |||
| expect_silent( | |||
| expect_equal( | |||
| prepare_colors(colors), | |||
| list( | |||
| list(color_name = "light_blue", value = "#88f"), | |||
| list(color_name = "light-blue", value = "#88f") | |||
| ) | |||
| ) | |||
| ) | |||
| }) | |||
| it("returns list with color_name and value for each color", { | |||
| colors <- c('test' = "#4ed4ed") | |||
| prepared <- prepare_colors(colors) | |||