Skip to content

Commit

Permalink
Add comment to conversion function
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmockett committed Mar 25, 2024
1 parent af8d66c commit 90b8beb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libs/@guardian/source-foundations/src/utils/typography.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const REGEX_FONT_SIZE = /font-size:\s(\d+\.\d+)rem/;
/*
* Convert font size in typography preset from default rem value to pixels
*/

export const presetToPx = (preset: string) => {
const REGEX_FONT_SIZE = /font-size:\s(\d+\.\d+)rem/;

const matches = preset.match(REGEX_FONT_SIZE);
if (matches?.[1]) {
const pxVal = parseFloat(matches[1]) * 16;
return preset.replace(REGEX_FONT_SIZE, `font-size: ${pxVal}px`);
}

return preset;
};

0 comments on commit 90b8beb

Please sign in to comment.