getTypographyClass()function

getTypographyClass({ tint, weight, font, case: caseValue, size, ...props }: TypographyVariants): string | undefined
ParamType
propsTypographyVariants
Typographic variant props — font-family, weight, case, size, tint, alignment, and wrap, applied via getTypographyClass() required
    .sizeSizeVariant
Font size of the element.
    .tintTintVariant
Set CSS text color: to one of the shades of the current tint ladder.
    .fontFontVariant
Font family of the element.
    .caseCaseVariant
Text case of the element.
    .weightWeightVariant
Font weight of the element.
    .leftboolean
Align text to the start of the line (LTR: left).
    .centerboolean
Centre text horizontally.
    .rightboolean
Align text to the end of the line (LTR: right).
    .wrapboolean
Enable wrapping.
    .nowrapboolean
Disable wrapping.
Return
string | undefined
The combined typography class string, or undefined when no variants apply.

Get the typography class for a component from its typographic variant props.

Maps the size, weight, font, case, tint, alignment, and wrap variant props to their CSS classes.

The typography variant props set an element's text styling from a single helper — <Heading font="title" size="large">, <Paragraph weight="strong" center>, <Small case="upper">. They're overrides for one-off changes; for an app-wide change, retune the variables below in a theme file.

getTypographyClass({ size, weight, font, case, tint, left, center, right, wrap, nowrap }) maps each prop to a class (e.g. size="large"size-large, font="title"font-title, weight="strong"weight-strong, case="upper"case-upper), and combines them with text alignment, tint colour, and wrapping. It supersedes the former getFontClass(), getSizeClass(), and getWeightClass() helpers, which were merged into this module.

The semantic faces, weights, sizes, and cases are aliases of the base values, so a theme usually only needs to move the small set of base variables.

Theme variables

The following :root variables are defined by this module and can be overridden in a theme file to adjust default styling across the whole app.

Faces

VariableDefaultNotes
--font-sanssystem-uiDefault UI face.
--font-monospaceui-monospace, "SF Mono", "Consolas", "Menlo", monospaceCode face.
--font-serif"Palatino", "Garamond", serifSerif face.
--font-titlevar(--font-sans)Headings and titles.
--font-bodyvar(--font-sans)Body baseline.
--font-labelvar(--font-sans)Labels.
--font-codevar(--font-monospace)Code and preformatted text.

Weights

VariableDefaultUsed for
--weight-normal400Body text.
--weight-strong700Bold / emphasis.
--weight-titlevar(--weight-strong)Headings and titles.
--weight-bodyvar(--weight-normal)Body baseline.
--weight-labelvar(--weight-strong)Labels (<Label>, table/definition headers).
--weight-code500Monospace / code.

Sizes

VariableDefaultNotes
--size-scale1.25Ratio between steps.
--size-normal1remBase size — the root of the modular scale.
--size-xxsmall--size-xxxlargecalc(var(--size-normal) * pow(var(--size-scale), n))Each step is the base scaled by a power of the ratio.
--size-iconvar(--size-large)Icon box size.
--size-labelvar(--size-small)Label text size.
--size-smaller0.875emRelative (em) shrink — e.g. inline <Small>.
--size-larger1.5emRelative grow.
--size-xlarger2.5emRelative grow.
--size-xxlarger5emRelative grow.

Line height

VariableDefaultUsed for
--leadingclamp(1.05em, calc(1em + 0.5rem), 1.5em)Default line height; paired with every font-size variant and the body baseline.
--leading-normal1.5Plain unitless line height for dense blocks.

Case

VariableDefaultUsed for
--case-titlenonetext-transform for titles and headings.
--case-bodynonetext-transform for body text and the body baseline.
--case-labeluppercasetext-transform for labels and tags.
--case-codenonetext-transform for code and preformatted text.

Examples

getTypographyClass({ font: "title", size: "large", center: true })