Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useScaledTextRole.ts

23 lines837 Bytes

1import { useMemo } from "react";
2​
3import { resolveScaledTextRole } from "../../../lib/appearancePreferences";
4import { MOBILE_TYPOGRAPHY } from "../../../lib/typography";
5import { useAppearancePreferences } from "./AppearancePreferencesProvider";
6​
7export interface ScaledTextRole {
8 readonly fontSize: number;
9 readonly lineHeight: number;
11​
12/**
13 * Mirrors the values injected into Uniwind for style-prop consumers that
14 * cannot use a `text-*` class. This deliberately does not subscribe to CSS
15 * variables, so palette-only setTheme calls remain native-only.
16 */
17export function useScaledTextRole(role: keyof typeof MOBILE_TYPOGRAPHY): ScaledTextRole {
18 const { appearance } = useAppearancePreferences();
19 return useMemo(
20 () => resolveScaledTextRole(role, appearance.baseFontSize),
21 [appearance.baseFontSize, role],
22 );