|
@@ -1,4 +1,5 @@
|
|
"""The colors used in Reflex are a wrapper around https://www.radix-ui.com/colors."""
|
|
"""The colors used in Reflex are a wrapper around https://www.radix-ui.com/colors."""
|
|
|
|
+
|
|
from dataclasses import dataclass
|
|
from dataclasses import dataclass
|
|
from typing import Literal
|
|
from typing import Literal
|
|
|
|
|
|
@@ -40,6 +41,20 @@ ColorType = Literal[
|
|
ShadeType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
|
ShadeType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
|
|
|
|
|
|
|
|
|
|
|
+def format_color(color: ColorType, shade: ShadeType, alpha: bool) -> str:
|
|
|
|
+ """Format a color as a CSS color string.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ color: The color to use.
|
|
|
|
+ shade: The shade of the color to use.
|
|
|
|
+ alpha: Whether to use the alpha variant of the color.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ The formatted color.
|
|
|
|
+ """
|
|
|
|
+ return f"var(--{color}-{'a' if alpha else ''}{shade})"
|
|
|
|
+
|
|
|
|
+
|
|
@dataclass
|
|
@dataclass
|
|
class Color:
|
|
class Color:
|
|
"""A color in the Reflex color palette."""
|
|
"""A color in the Reflex color palette."""
|
|
@@ -52,3 +67,14 @@ class Color:
|
|
|
|
|
|
# Whether to use the alpha variant of the color
|
|
# Whether to use the alpha variant of the color
|
|
alpha: bool = False
|
|
alpha: bool = False
|
|
|
|
+
|
|
|
|
+ def __format__(self, format_spec: str) -> str:
|
|
|
|
+ """Format the color as a CSS color string.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ format_spec: The format specifier to use.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ The formatted color.
|
|
|
|
+ """
|
|
|
|
+ return format_color(self.color, self.shade, self.alpha)
|