serializeColor
serializeColor(
props):string
Defined in: packages/core/src/fields/color/convert.ts:290
Serialises a colour into one of the supported CSS notations.
Alpha is emitted only when the colour is not fully opaque, so an opaque
colour produces #e8622a rather than #e8622aff and rgb(...) rather than
rgba(..., 1).
Parameters
Section titled “Parameters”Input props.
The colour to write.
format
Section titled “format”"hex" | "rgb" | "hsl" | "oklch"
The notation to write it in.
Returns
Section titled “Returns”string
A CSS colour string in format.
Throws
Section titled “Throws”An Error if an unrecognised format is given. Reaching this is a
compile error: the default arm binds the exhausted union to never.
Example
Section titled “Example”const ember = { r: 232, g: 98, b: 42, a: 1 };serializeColor({ color: ember, format: "hex" }) // "#e8622a"serializeColor({ color: ember, format: "oklch" }) // "oklch(65.7% 0.1793 40.9)"