MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / serializeColorForPicker

Function serializeColorForPicker

client/src/modules/colorPicker.js:52–69  ·  view source on GitHub ↗
(color, format = "smart", fallback = "#000000")

Source from the content-addressed store, hash-verified

50}
51
52export function serializeColorForPicker(color, format = "smart", fallback = "#000000") {
53 const { red, green, blue, alpha } = getRgbColorChannels(color, fallback);
54
55 if (format === "rgba") {
56 return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
57 }
58
59 const hex = [red, green, blue]
60 .map((channel) => channel.toString(16).padStart(2, "0"))
61 .join("")
62 .toUpperCase();
63
64 if (format === "smart" && alpha < 1) {
65 return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
66 }
67
68 return `#${hex}`;
69}

Callers 2

ColorPickerControlFunction · 0.90
handleChangeFunction · 0.90

Calls 1

getRgbColorChannelsFunction · 0.85

Tested by

no test coverage detected