@codegouvfr/react-dsfr
Version:
French State Design System React integration library
20 lines (13 loc) • 481 B
text/typescript
import { assert } from "tsafe/assert";
import { isBrowser } from "./isBrowser";
export function getBaseFontSizePx(): number {
if (!isBrowser) {
return 16;
}
const htmlElement = document.querySelector("html");
assert(htmlElement !== null);
const computedStyle = window.getComputedStyle(htmlElement);
const fontSize = computedStyle.getPropertyValue("font-size");
const fontSizeInPixels = parseFloat(fontSize);
return fontSizeInPixels;
}