DynamicColor
A color that adjusts itself based on UI state, represented by DynamicScheme.
This color automatically adjusts to accommodate a desired contrast level, or other adjustments such as differing in light mode versus dark mode, or what the theme is, or what the color that produced the theme is, etc.
Colors without backgrounds do not change tone when contrast changes. Colors with backgrounds become closer to their background as contrast lowers, and further when contrast increases.
Prefer the static constructors. They provide a much more simple interface, such as requiring just a hexcode, or just a hexcode and a background.
Ultimately, each component necessary for calculating a color, adjusting it for a desired contrast level, and ensuring it has a certain lightness/tone difference from another color, is provided by a function that takes a DynamicScheme and returns a value. This ensures ultimate flexibility, any desired behavior of a color for any design system, but it usually unnecessary. See the default constructor for more information.
Parameters
The name of the dynamic color.
Function that provides a TonalPalette given DynamicScheme. A TonalPalette is defined by a hue and chroma, so this replaces the need to specify hue/chroma. By providing a tonal palette, when contrast adjustments are made, intended chroma can be preserved.
Function that provides a tone, given a DynamicScheme.
Whether this dynamic color is a background, with some other color as the foreground.
The background of the dynamic color (as a function of a DynamicScheme
), if it exists.
A second background of the dynamic color (as a function of a DynamicScheme
), if it exists.
A ContrastCurve
object specifying how its contrast against its background should behave in various contrast levels options.
A ToneDeltaPair
object specifying a tone delta constraint between two colors. One of them must be the color being constructed.
A function returning the opacity of a color, as a number between 0 and 1.
Constructors
Strongly prefer using one of the convenience constructors. This class is arguably too flexible to ensure it can support any scenario. Functional arguments allow overriding without risks that come with subclasses.