Skip to content

Commit

Permalink
Add TypographyPreset type
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmockett committed Mar 27, 2024
1 parent d4e7754 commit 751bc9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions libs/@guardian/source-foundations/src/typography/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,12 @@ export type Fs = <
unit: ScaleUnit;
},
) => TypographyStyles;

export type TypographyPreset = `
font-family: ${string};
font-size: ${number}rem;
line-height: ${number};
font-weight: ${number};
font-style: ${'normal' | 'italic'};
--source-text-decoration-thickness: ${number}px;
`;
7 changes: 4 additions & 3 deletions libs/@guardian/source-foundations/src/utils/typography.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { TypographyPreset } from '../typography/types';

/*
* Convert font size in typography preset from default rem value to pixels
* Convert `font-size` value in typography preset from rem to px
*/

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

const matches = preset.match(REGEX_FONT_SIZE);
Expand Down

0 comments on commit 751bc9b

Please sign in to comment.