Set a custom named color #332
-
Hi all, Working on this PR and was wondering how (or if) I can extend the base In our code, certain shades have developer-friendly (but not CSS-defined) names, e.g., def get_css_color(name: str) -> Optional[str]:
"""
Tries to look up a hex code value from a named css color, otherwise will
return None if not a valid color.
"""
name = name.lower()
if name in pl_colors:
return pl_colors[name]
if Color.match(name) is None:
warnings.warn(f"{name} is not a valid color name; defaulting to no color")
return None
return Color(name).to_string(hex=True) Any insight is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I imagine you are working within sRGB, so I'd create a custom sRGB color space class. Probably good to use the CSS variant so you can fall back to all the CSS serialization. Check out this working example here. Just press edit to see/copy all the code. You can omit the |
Beta Was this translation helpful? Give feedback.
I imagine you are working within sRGB, so I'd create a custom sRGB color space class. Probably good to use the CSS variant so you can fall back to all the CSS serialization.
Check out this working example here. Just press edit to see/copy all the code.
You can omit the
to_string
serialization override if you have no need to serialize to those custom names.