Given a base color and a background, generate a pair of colors (light and dark) with sufficient perceptual contrast using WCAG or APCA methods.

adjust_contrast_pair(
  color,
  contrast = 4.5,
  method = "auto",
  background = "#FFFFFF",
  quiet = FALSE
)

Arguments

color

A base color in hexadecimal format (e.g., "#6699CC").

contrast

Minimum desired contrast ratio (default is 4.5).

method

Contrast method: "WCAG", "APCA", or "auto" to try both.

background

Background color (default: "#FFFFFF").

quiet

Logical. If TRUE, suppresses warnings.

Value

A list with elements light, dark, contrast, and method.

Examples

adjust_contrast_pair("#777777", contrast = 4.5, method = "auto", background = "#000000")
#> $light
#> [1] "#F1F1F1"
#> 
#> $dark
#> [1] "#303030"
#> 
#> $contrast
#> [1] 18.59245
#> 
#> $method
#> [1] "WCAG"
#> 

adjust_contrast_pair("#66CCFF", contrast = 4.5, method = "APCA", background = "#FAFAFA")
#> $light
#> [1] "#ADA025"
#> 
#> $dark
#> [1] NA
#> 
#> $contrast
#> [1] 48.95491
#> 
#> $method
#> [1] "APCA"
#>