File tree Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { z } from 'zod';
33const length = z
44 . string ( )
55 . regex (
6- / ^ ( [ + - ] ? \d + ) ( % | p x ) ? $ / ,
6+ / ^ ( [ + - ] ? \d + (?: \. \d + ) ? ) ( % | p x ) ? $ / ,
77 "Not a valid length value. Must be of format '10px' or '10%'." ,
88 ) ;
99
Original file line number Diff line number Diff line change @@ -39,14 +39,15 @@ impl FromStr for LengthValue {
3939 type Err = anyhow:: Error ;
4040
4141 /// Parses a string containing a number followed by a unit (`px`, `%`).
42- /// Allows for negative numbers.
42+ /// Allows for negative and fractional numbers.
4343 ///
4444 /// Example:
4545 /// ```
4646 /// LengthValue::from_str("100px") // { amount: 100.0, unit: LengthUnit::Pixel }
47+ /// LengthValue::from_str("50.5%") // { amount: 50.5, unit: LengthUnit::Percentage }
4748 /// ```
4849 fn from_str ( unparsed : & str ) -> anyhow:: Result < Self > {
49- let units_regex = Regex :: new ( r"([+-]?\d+)(%|px)?" ) ?;
50+ let units_regex = Regex :: new ( r"([+-]?\d+(?:\.\d+)? )(%|px)?" ) ?;
5051
5152 let err_msg = format ! (
5253 "Not a valid length value '{}'. Must be of format '10px' or '10%'." ,
You can’t perform that action at this time.
0 commit comments