Skip to content

Commit bb4ac8a

Browse files
authored
fix: color conversion (#1501)
1 parent 06f219c commit bb4ac8a

File tree

3 files changed

+69
-22
lines changed

3 files changed

+69
-22
lines changed

docs/configuration/settings.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,30 @@ UNFOLD = {
6767
"BORDER_RADIUS": "6px",
6868
"COLORS": {
6969
"base": {
70-
"50": "249, 250, 251",
71-
"100": "243, 244, 246",
72-
"200": "229, 231, 235",
73-
"300": "209, 213, 219",
74-
"400": "156, 163, 175",
75-
"500": "107, 114, 128",
76-
"600": "75, 85, 99",
77-
"700": "55, 65, 81",
78-
"800": "31, 41, 55",
79-
"900": "17, 24, 39",
80-
"950": "3, 7, 18",
70+
"50": "oklch(98.5% .002 247.839)",
71+
"100": "oklch(96.7% .003 264.542)",
72+
"200": "oklch(92.8% .006 264.531)",
73+
"300": "oklch(87.2% .01 258.338)",
74+
"400": "oklch(70.7% .022 261.325)",
75+
"500": "oklch(55.1% .027 264.364)",
76+
"600": "oklch(44.6% .03 256.802)",
77+
"700": "oklch(37.3% .034 259.733)",
78+
"800": "oklch(27.8% .033 256.848)",
79+
"900": "oklch(21% .034 264.665)",
80+
"950": "oklch(13% .028 261.692)",
8181
},
8282
"primary": {
83-
"50": "250, 245, 255",
84-
"100": "243, 232, 255",
85-
"200": "233, 213, 255",
86-
"300": "216, 180, 254",
87-
"400": "192, 132, 252",
88-
"500": "168, 85, 247",
89-
"600": "147, 51, 234",
90-
"700": "126, 34, 206",
91-
"800": "107, 33, 168",
92-
"900": "88, 28, 135",
93-
"950": "59, 7, 100",
83+
"50": "oklch(97.7% .014 308.299)",
84+
"100": "oklch(94.6% .033 307.174)",
85+
"200": "oklch(90.2% .063 306.703)",
86+
"300": "oklch(82.7% .119 306.383)",
87+
"400": "oklch(71.4% .203 305.504)",
88+
"500": "oklch(62.7% .265 303.9)",
89+
"600": "oklch(55.8% .288 302.321)",
90+
"700": "oklch(49.6% .265 301.924)",
91+
"800": "oklch(43.8% .218 303.724)",
92+
"900": "oklch(38.1% .176 304.987)",
93+
"950": "oklch(29.1% .149 302.717)",
9494
},
9595
"font": {
9696
"subtle-light": "var(--color-base-500)", # text-base-500

src/unfold/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,9 @@ def convert_color(value: str) -> str:
202202
return value
203203
elif isinstance(value, str) and all(part.isdigit() for part in value.split()):
204204
return f"rgb({', '.join(value.split(' '))})"
205+
elif isinstance(value, str) and all(
206+
part.strip().isdigit() for part in value.split(",")
207+
):
208+
return f"rgb({', '.join(part.strip() for part in value.split(','))})"
205209

206210
return value

tests/test_colors.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,49 @@ def test_colors_rgb():
9393
assert context["colors"]["primary"][950] == "rgb(8, 47, 73)"
9494

9595

96+
@override_settings(
97+
UNFOLD={
98+
**CONFIG_DEFAULTS,
99+
**{
100+
"COLORS": {
101+
"primary": {
102+
50: "240, 249, 255",
103+
100: "224, 242, 254",
104+
200: "186, 230, 253",
105+
300: "125, 211, 252",
106+
400: "56, 189, 248",
107+
500: "14, 165, 233",
108+
600: "2, 132, 199",
109+
700: "3, 105, 161",
110+
800: "7, 89, 133",
111+
900: "12, 74, 110",
112+
950: "8, 47, 73",
113+
}
114+
},
115+
},
116+
}
117+
)
118+
def test_colors_rgb_with_commas():
119+
admin_site = UnfoldAdminSite()
120+
request = RequestFactory().get("/rand")
121+
request.user = AnonymousUser()
122+
context = admin_site.each_context(request)
123+
assert "colors" in context
124+
assert "primary" in context["colors"]
125+
126+
assert context["colors"]["primary"][50] == "rgb(240, 249, 255)"
127+
assert context["colors"]["primary"][100] == "rgb(224, 242, 254)"
128+
assert context["colors"]["primary"][200] == "rgb(186, 230, 253)"
129+
assert context["colors"]["primary"][300] == "rgb(125, 211, 252)"
130+
assert context["colors"]["primary"][400] == "rgb(56, 189, 248)"
131+
assert context["colors"]["primary"][500] == "rgb(14, 165, 233)"
132+
assert context["colors"]["primary"][600] == "rgb(2, 132, 199)"
133+
assert context["colors"]["primary"][700] == "rgb(3, 105, 161)"
134+
assert context["colors"]["primary"][800] == "rgb(7, 89, 133)"
135+
assert context["colors"]["primary"][900] == "rgb(12, 74, 110)"
136+
assert context["colors"]["primary"][950] == "rgb(8, 47, 73)"
137+
138+
96139
@override_settings(
97140
UNFOLD={
98141
**CONFIG_DEFAULTS,

0 commit comments

Comments
 (0)