posit-dev / py-faicons

An interface to Font Awesome for use in PyShiny
MIT License
5 stars 1 forks source link

Allow percentage `%` unit for length + width (`_parse_lenth_units()`) #7

Open chendaniely opened 11 months ago

chendaniely commented 11 months ago

Description

when i try to pass in "100%" as a width string into favicons.icon_svg() I get a

raise ValueError(
ValueError: Values provided to `height` and `width` must have a numerical value followed by a CSS length unit.

What I Did

showcase=faicons.icon_svg('piggy-bank', width="100%")

Tracing through where the error is coming from: https://github.com/posit-dev/py-faicons/blob/main/faicons/_core.py#L185

It seems that % is allowed as a _css_lenth_unit but the regex check is only looking for [a-z]+ after all the numbers, and is missing the ability to take in a % symbol

I think the fix could/should be changing the regex pattern to: "^^[0-9]*\\.?[0-9]+[a-z%]+$"