import {type TextStyle} from 'react-native' import {isWeb} from '../platform' import * as tokens from '../tokens' /** * Util to calculate lineHeight from a text size atom and a leading atom (which * are unitless). On native, this will evaluate to a rounded pixel value. On * web, it will be a unitless string. * * Example: * `leading({ * fontSize: 15, * lineHeight: 1.2 * })` // => { lineHeight: 17 } */ export function leading(textStyle: TextStyle): Pick { const lineHeight = textStyle?.lineHeight || tokens.lineHeight.snug if (isWeb) { return { lineHeight: String(lineHeight) as unknown as TextStyle['lineHeight'], } } else { const size = textStyle?.fontSize || tokens.fontSize.sm return { lineHeight: Math.round(size * lineHeight), } } }