Skip to content

Commit af8532a

Browse files
committed
refactor: don't use as_css_unit() just work with strings
1 parent 16db15d commit af8532a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

shiny/ui/_theme_brand.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from .._versions import bootstrap as v_bootstrap
1313
from ._theme import Theme
14-
from .css import CssUnit, as_css_unit
1514

1615
YamlScalarType = Union[str, int, bool, float, None]
1716

@@ -383,7 +382,7 @@ def _prepare_typography_vars(brand: Brand) -> dict[str, str]:
383382
for prop_key, prop_value in prop.items():
384383
if prop_key in typography_map[field]:
385384
if field == "base" and prop_key == "size":
386-
prop_value = str(maybe_convert_font_size_to_rem(prop_value))
385+
prop_value = maybe_convert_font_size_to_rem(prop_value)
387386

388387
typo_sass_vars = typography_map[field][prop_key]
389388
for typo_sass_var in typo_sass_vars:
@@ -563,7 +562,7 @@ def _html_dependencies(self) -> list[HTMLDependency]:
563562
return [fonts_dep, *theme_deps]
564563

565564

566-
def maybe_convert_font_size_to_rem(x: str) -> CssUnit:
565+
def maybe_convert_font_size_to_rem(x: str) -> str:
567566
"""
568567
Convert a font size to rem
569568
@@ -579,15 +578,14 @@ def maybe_convert_font_size_to_rem(x: str) -> CssUnit:
579578
7. `42.3mm` is `1rem`.
580579
"""
581580
x_og = f"{x}"
582-
x = as_css_unit(x)
583581

584582
value, unit = split_css_value_and_unit(x)
585583

586584
if unit == "rem":
587585
return x
588586

589587
if unit == "em":
590-
return as_css_unit(f"{value}rem")
588+
return f"{value}rem"
591589

592590
scale = {
593591
"%": 100,
@@ -599,7 +597,7 @@ def maybe_convert_font_size_to_rem(x: str) -> CssUnit:
599597
}
600598

601599
if unit in scale:
602-
return as_css_unit(f"{float(value) / scale[unit]}rem")
600+
return f"{float(value) / scale[unit]}rem"
603601

604602
raise ValueError(
605603
f"Shiny does not support brand.yml font sizes in {unit} units ({x_og!r})"

0 commit comments

Comments
 (0)