UNPKG

braid-design-system

Version:
47 lines (46 loc) 1.18 kB
import { jsx } from "react/jsx-runtime"; import assert from "assert"; import { useContext, useMemo } from "react"; import { textStyles } from "../../css/typography.mjs"; import { Typography } from "../private/Typography/Typography.mjs"; import { useDefaultTextProps } from "../private/defaultTextProps.mjs"; import { TextContext } from "./TextContext.mjs"; const Text = ({ size: sizeProp, tone: toneProp, weight: weightProp, maxLines: maxLinesProp, baseline = true, ...typographyProps }) => { assert( !useContext(TextContext), "Text components should not be nested within each other" ); const { size, weight, tone, maxLines } = useDefaultTextProps({ size: sizeProp, weight: weightProp, tone: toneProp, maxLines: maxLinesProp }); const textStylingProps = useMemo( () => ({ tone, size, weight, baseline }), [tone, size, weight, baseline] ); return /* @__PURE__ */ jsx(TextContext.Provider, { value: textStylingProps, children: /* @__PURE__ */ jsx( Typography, { maxLines, ...typographyProps, className: textStyles(textStylingProps) } ) }); }; export { Text };