Spaces:
Runtime error
Runtime error
Refactoring the metric views
Browse files- app.py +4 -8
- fragments.py +4 -2
app.py
CHANGED
@@ -25,10 +25,6 @@ def parse_hex(rgb_hex_str: str) -> tuple[float, float, float]:
|
|
25 |
raise ValueError("Invalid hex color")
|
26 |
return tuple(int(rgb_hex_str[i:i+2], 16) / 255 for i in (1, 3, 5))
|
27 |
|
28 |
-
# primary_color_rgb = parse_hex(primary_color)
|
29 |
-
# text_color_rgb = parse_hex(text_color)
|
30 |
-
# background_color_rgb = parse_hex(background_color)
|
31 |
-
# secondary_background_color_rgb = parse_hex(secondary_background_color)
|
32 |
|
33 |
st.header("WCAG contrast ratio")
|
34 |
|
@@ -47,17 +43,17 @@ col1, col2, col3 = st.columns(3)
|
|
47 |
with col1:
|
48 |
synced_color_picker("Primary color", value=primary_color, key="primaryColor")
|
49 |
with col2:
|
50 |
-
fragments.contrast_summary(primary_color, background_color)
|
51 |
with col3:
|
52 |
-
fragments.contrast_summary(primary_color, secondary_background_color)
|
53 |
|
54 |
col1, col2, col3 = st.columns(3)
|
55 |
with col1:
|
56 |
synced_color_picker("Text color", value=text_color, key="textColor")
|
57 |
with col2:
|
58 |
-
fragments.contrast_summary(text_color, background_color)
|
59 |
with col3:
|
60 |
-
fragments.contrast_summary(text_color, secondary_background_color)
|
61 |
|
62 |
|
63 |
st.header("Config")
|
|
|
25 |
raise ValueError("Invalid hex color")
|
26 |
return tuple(int(rgb_hex_str[i:i+2], 16) / 255 for i in (1, 3, 5))
|
27 |
|
|
|
|
|
|
|
|
|
28 |
|
29 |
st.header("WCAG contrast ratio")
|
30 |
|
|
|
43 |
with col1:
|
44 |
synced_color_picker("Primary color", value=primary_color, key="primaryColor")
|
45 |
with col2:
|
46 |
+
fragments.contrast_summary("Primary/Background", primary_color, background_color)
|
47 |
with col3:
|
48 |
+
fragments.contrast_summary("Primary/Secondary background", primary_color, secondary_background_color)
|
49 |
|
50 |
col1, col2, col3 = st.columns(3)
|
51 |
with col1:
|
52 |
synced_color_picker("Text color", value=text_color, key="textColor")
|
53 |
with col2:
|
54 |
+
fragments.contrast_summary("Text/Background", text_color, background_color)
|
55 |
with col3:
|
56 |
+
fragments.contrast_summary("Text/Secondary background", text_color, secondary_background_color)
|
57 |
|
58 |
|
59 |
st.header("Config")
|
fragments.py
CHANGED
@@ -4,14 +4,16 @@ import wcag_contrast_ratio as contrast
|
|
4 |
import util
|
5 |
|
6 |
|
7 |
-
def contrast_summary(foreground_rgb_hex: str, background_rgb_hex: str) -> None:
|
8 |
rgb_foreground = util.parse_hex(foreground_rgb_hex)
|
9 |
rgb_background = util.parse_hex(background_rgb_hex)
|
10 |
contrast_ratio = contrast.rgb(rgb_foreground, rgb_background)
|
11 |
contrast_ratio_str = f"{contrast_ratio:.2f}"
|
12 |
-
|
|
|
13 |
|
14 |
st.markdown(f'<p style="color: {foreground_rgb_hex}; background-color: {background_rgb_hex}; padding: 12px">Lorem ipsum</p>', unsafe_allow_html=True)
|
15 |
|
|
|
16 |
def sample_components(key: str):
|
17 |
st.slider("Slider", min_value=0, max_value=100, key=f"{key}:slider")
|
|
|
4 |
import util
|
5 |
|
6 |
|
7 |
+
def contrast_summary(label: str, foreground_rgb_hex: str, background_rgb_hex: str) -> None:
|
8 |
rgb_foreground = util.parse_hex(foreground_rgb_hex)
|
9 |
rgb_background = util.parse_hex(background_rgb_hex)
|
10 |
contrast_ratio = contrast.rgb(rgb_foreground, rgb_background)
|
11 |
contrast_ratio_str = f"{contrast_ratio:.2f}"
|
12 |
+
|
13 |
+
st.metric(label, value=f"{contrast_ratio_str} : 1", label_visibility="collapsed")
|
14 |
|
15 |
st.markdown(f'<p style="color: {foreground_rgb_hex}; background-color: {background_rgb_hex}; padding: 12px">Lorem ipsum</p>', unsafe_allow_html=True)
|
16 |
|
17 |
+
|
18 |
def sample_components(key: str):
|
19 |
st.slider("Slider", min_value=0, max_value=100, key=f"{key}:slider")
|